From e62af8986381d22aeea52c48276611777632da6c Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Fri, 7 Oct 2022 13:59:02 +0200 Subject: position composite rewrite --- .../gui/composites/PositioningComposite.java | 20 +- .../pdfover/gui/composites/SignaturePanel.java | 384 ++++++++------------- 2 files changed, 164 insertions(+), 240 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java index 1953a035..9f90cbbc 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java @@ -235,12 +235,12 @@ public class PositioningComposite extends StateComposite { case KeyEvent.VK_UP: case KeyEvent.VK_KP_UP: - sigYOffset -= Constants.SIGNATURE_KEYBOARD_POSITIONING_OFFSET; + sigYOffset += Constants.SIGNATURE_KEYBOARD_POSITIONING_OFFSET; break; case KeyEvent.VK_DOWN: case KeyEvent.VK_KP_DOWN: - sigYOffset += Constants.SIGNATURE_KEYBOARD_POSITIONING_OFFSET; + sigYOffset -= Constants.SIGNATURE_KEYBOARD_POSITIONING_OFFSET; break; } @@ -335,11 +335,11 @@ public class PositioningComposite extends StateComposite { * @param sigXOffset * signature placeholder horizontal position offset * @param sigYOffset - * signature placeholder vertical position offset + * signature placeholder vertical position offset (negative is down) */ public void translateSignaturePosition(final int sigXOffset, final int sigYOffset) { EventQueue.invokeLater(() -> { - this.viewer.translateSignaturePosition(sigXOffset, sigYOffset); + this.viewer.translateSignaturePagePosition(sigXOffset, sigYOffset); }); } @@ -350,12 +350,14 @@ public class PositioningComposite extends StateComposite { * the signature position */ void setFinalPosition() { - if (this.currentPage == 0) + if (this.currentPage == 0) { this.position = new SignaturePosition(); - else + } else { this.position = new SignaturePosition( - this.viewer.getSignaturePositionX(), - this.viewer.getSignaturePositionY(), this.currentPage); + this.viewer.getSigPageX(), + this.viewer.getSigPageY(), + this.currentPage); + } PositioningComposite.this.state.updateStateMachine(); } @@ -369,7 +371,7 @@ public class PositioningComposite extends StateComposite { * @param page * the page the signature is on */ - public void setPosition(float x, float y, int page) { + public void setPosition(double x, double y, int page) { showPage(page); if (this.viewer != null) this.viewer.setSignaturePosition(x, y); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java index bad000ea..72811050 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java @@ -24,8 +24,6 @@ import java.awt.Graphics; import java.awt.Image; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.geom.AffineTransform; -import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; @@ -57,52 +55,85 @@ public class SignaturePanel extends JPanel { /** The PDF file being displayed */ private PDDocument pdf = null; private PDFRenderer renderer = null; + /** The image of the rendered PDF page being displayed */ Image currentImage = null; - /** The current PDFPage that was rendered into currentImage */ - private PDPage currentPage = null; - /** The current transform from screen to page space */ - AffineTransform currentTransform = null; + + /** The current scale for rendering pdf to image */ + private float pageToImageScale; + /** The current scale for rendering image to screen */ + private double imageToScreenScale; + /* scaling */ + private enum U { + /* (0,0) is bottom-left of page */ + PAGE_ABS, + /* (0,0) is top-left of page */ + PAGE_REL, + /* pixels, (0,0) is top-left of image */ + IMAGE, + /* pixels, (0,0) is top-left of image */ + SCREEN_REL, + /* pixels, (0,0) is top-left of canvas */ + SCREEN_ABS }; + private enum Dim { X, Y }; + private double scale(double v, U from, U to, Dim d) + { + if (from == to) return v; + + if (from == U.PAGE_ABS) { + return scale((d == Dim.X) ? v : (this.pageHeight - v), U.PAGE_REL, to, d); + } else if (from == U.PAGE_REL) { + if (to == U.PAGE_ABS) + return ((d == Dim.X) ? v : (this.pageHeight - v)); + else + return scale(v * this.pageToImageScale, U.IMAGE, to, d); + } else if (from == U.IMAGE) { + if ((to == U.PAGE_ABS) || (to == U.PAGE_REL)) + return scale(v / this.pageToImageScale, U.PAGE_REL, to, d); + else + return scale(v * this.imageToScreenScale, U.SCREEN_REL, to, d); + } else if (from == U.SCREEN_REL) { + if (to == U.SCREEN_ABS) + return (v + ((d == Dim.X) ? this.offX : this.offY)); + else + return scale(v / this.imageToScreenScale, U.IMAGE, to, d); + } else if (from == U.SCREEN_ABS) { + return scale(v - ((d == Dim.X) ? this.offX : this.offY), U.SCREEN_REL, to, d); + } else throw new RuntimeException("unreachable"); + } + + private float pageWidth = 0; + private float pageHeight = 0; /** The horizontal offset of the image from the left edge of the panel */ - int offX = 0; + private int offX = 0; /** The vertical offset of the image from the top of the panel */ - int offY = 0; - /** The position of the signature, in page space */ - Point2D sigPagePos = null; - /** The position of the signature, in screen space */ - Point2D sigScreenPos = null; + private int offY = 0; + /** The position of the top-left corner of the signature, in absolute page space */ + private Point2D sigPagePos = null; + public double getSigPageX() { return this.sigPagePos.getX(); } + public double getSigPageY() { return this.sigPagePos.getY(); } /** The signature placeholder image */ private Image sigPlaceholder = null; - /** Current scaled signature placeholder image */ - BufferedImage sigPlaceholderScaled = null; /** Width of the signature placeholder in page space */ private int sigPageWidth = 0; /** Height of the signature placeholder in page space */ private int sigPageHeight = 0; - /** Width of the signature placeholder in screen space */ - int sigScreenWidth = 0; - /** Height of the signature placeholder in screen space */ - int sigScreenHeight = 0; - /** Previous Width of the signature placeholder in screen space */ - int prevSigScreenWidth = 0; - /** Previous Height of the signature placeholder in screen space */ - int prevSigScreenHeight = 0; /** Color of the signature placeholder border */ private Color sigPlaceholderBorderColor = Color.BLUE; /** Current page */ - int currentPageNo = 0; + private int currentPageNo = 0; /** Number of pages in the document */ - int numPages = 0; + private int numPages = 0; /** Cursor types */ - static enum Cursors {DEFAULT, HAND, MOVE}; + private static enum Cursors {DEFAULT, HAND, MOVE}; /** Default arrow cursor */ - final Cursor defaultCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); + private final Cursor defaultCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); /** Hand cursor */ - final Cursor handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); + private final Cursor handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); /** Move cursor */ - final Cursor moveCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); + private final Cursor moveCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); /** Current cursor */ - Cursors currentCursor = Cursors.DEFAULT; + private Cursors currentCursor = Cursors.DEFAULT; /** * Create a new PagePanel. @@ -126,6 +157,7 @@ public class SignaturePanel extends JPanel { { this.renderer = new PDFRenderer(pdf); this.numPages = pdf.getNumberOfPages(); + this.currentPageNo = -1; showPage(this.numPages); } else @@ -166,6 +198,7 @@ public class SignaturePanel extends JPanel { * @param page the number of the page to display */ public void showPage(int page) { + if (this.currentPageNo == page) return; this.currentPageNo = page; renderPageToImage(); repaint(); @@ -180,44 +213,22 @@ public class SignaturePanel extends JPanel { showPage(this.numPages + 1); } - /** - * Translate the signature placeholder position - * @param sigXOffset signature placeholder horizontal position offset - * @param sigYOffset signature placeholder vertical position offset - */ - public void translateSignaturePosition(int sigXOffset, int sigYOffset) { - updateSigPos((int) this.sigScreenPos.getX() + sigXOffset, (int) this.sigScreenPos.getY() + sigYOffset); - } - /** * Set the signature placeholder position - * Call showPage afterwards to update actual position * @param x the horizontal signature position * @param y the vertical signature position */ - public void setSignaturePosition(float x, float y) + public void setSignaturePosition(double x, double y) { - this.sigPagePos = new Point2D.Double(x, y); - } - - /** - * Get the current horizontal position of the signature - * @return signature x coordinate - */ - public float getSignaturePositionX() { - if (this.sigPagePos == null) - return 0; - return Math.max((float) this.sigPagePos.getX(), 0); + this.sigPagePos = new Point2D.Double( + clamp(x, 0, this.pageWidth - this.sigPageWidth), + clamp(y, this.sigPageHeight, this.pageHeight) + ); + repaint(); } - /** - * Get the current vertical position of the signature - * @return signature y coordinate - */ - public float getSignaturePositionY() { - if (this.sigPagePos == null) - return 0; - return Math.max((float) this.sigPagePos.getY(), 0); + public void translateSignaturePagePosition(float dX, float dY) { + setSignaturePosition(this.sigPagePos.getX() + dX, this.sigPagePos.getY() + dY); } /** @@ -229,95 +240,61 @@ public class SignaturePanel extends JPanel { if (this.pdf == null) { this.currentImage = null; - this.currentTransform = null; return; } boolean newPage = false; + PDPage currentPage; // set up the new page if (this.currentPageNo > this.numPages) { // New last page - use old last page as template - this.currentPage = this.pdf.getPage(this.numPages-1); + currentPage = this.pdf.getPage(this.numPages-1); newPage = true; } else - this.currentPage = this.pdf.getPage(this.currentPageNo-1); + currentPage = this.pdf.getPage(this.currentPageNo-1); - if (this.currentPage == null) { + if (currentPage == null) { // no page this.currentImage = null; - this.currentTransform = null; - } else { - // start drawing - Dimension renderPanelSize = getSize(); - if (renderPanelSize.width + renderPanelSize.height == 0) { - // no image to draw. - return; - } - - PDRectangle actualPageSize = this.currentPage.getBBox(); - double desiredAspectRatio = actualPageSize.getHeight() / actualPageSize.getWidth(); - double renderRatioAvailable = (double)renderPanelSize.height / (double)renderPanelSize.width; - Dimension actualRenderSize = (Dimension)renderPanelSize.clone(); - if (renderRatioAvailable > desiredAspectRatio) - actualRenderSize.height = (int)(actualRenderSize.width * desiredAspectRatio + 0.5); - else - actualRenderSize.width = (int)(actualRenderSize.height / desiredAspectRatio + 0.5); - - // get the new image - if (newPage) - { - this.currentImage = new BufferedImage(actualRenderSize.width, actualRenderSize.height, BufferedImage.TYPE_INT_RGB); - Graphics g = this.currentImage.getGraphics(); - g.setColor(Color.WHITE); - g.fillRect(0, 0, actualRenderSize.width, actualRenderSize.height); - } - else - { - int whichPage = Math.min(this.currentPageNo, this.numPages); - float scale = 1; - if (actualRenderSize.width == renderPanelSize.width) - scale = ((float) renderPanelSize.width) / actualPageSize.getWidth(); - else if (actualRenderSize.height == renderPanelSize.height) - scale = ((float) renderPanelSize.height) / actualPageSize.getHeight(); - - try { - this.currentImage = renderer.renderImage(whichPage-1, scale); - } catch (IOException e) { - log.error(String.format("Failed to render image for page %d of %d", whichPage, this.numPages), e); - } - } - - // calculate the transform from page to screen space - this.currentTransform = new AffineTransform(1, 0, 0, -1, 0, actualRenderSize.height); - double scaleX = ((double)actualRenderSize.width) / actualPageSize.getWidth(); - double scaleY = ((double)actualRenderSize.height) / actualPageSize.getHeight(); - this.currentTransform.scale(scaleX, scaleY); - this.currentTransform.translate(-actualPageSize.getLowerLeftX(), -actualPageSize.getLowerLeftY()); - - if (this.sigPagePos != null) - this.sigScreenPos = this.currentTransform.transform(this.sigPagePos, this.sigScreenPos); - this.sigScreenWidth = (int) Math.round(this.sigPageWidth * this.currentTransform.getScaleX()); - this.sigScreenHeight = (int) Math.round(this.sigPageHeight * this.currentTransform.getScaleX()); + return; + } + + PDRectangle actualPageSize = currentPage.getBBox(); + this.pageWidth = actualPageSize.getWidth(); + this.pageHeight = actualPageSize.getHeight(); + this.pageToImageScale = getToolkit().getScreenSize().height / this.pageHeight; + + // get the new image + if (newPage) + { + int renderHeight = (int)(0.5 + this.scale(actualPageSize.getHeight(), U.PAGE_REL, U.IMAGE, Dim.X)); + int renderWidth = (int)(0.5 + this.scale(actualPageSize.getWidth(), U.PAGE_REL, U.IMAGE, Dim.Y)); + this.currentImage = new BufferedImage(renderWidth, renderHeight, BufferedImage.TYPE_INT_RGB); + Graphics g = this.currentImage.getGraphics(); + g.setColor(Color.WHITE); + g.fillRect(0, 0, renderWidth, renderHeight); + } + else + { + int whichPage = Math.min(this.currentPageNo, this.numPages); - // invert the transform (screen to page space) try { - this.currentTransform = this.currentTransform.createInverse(); - } catch (NoninvertibleTransformException nte) { - log.error("Error inverting page transform!", nte); + this.currentImage = renderer.renderImage(whichPage-1, this.pageToImageScale); + } catch (IOException e) { + log.error(String.format("Failed to render image for page %d of %d", whichPage, this.numPages), e); + this.currentImage = null; } + } - if (this.sigPagePos == null) - { - this.sigScreenPos = new Point2D.Double( - clamp((int) (actualRenderSize.getWidth() / 2), 0, this.currentImage.getWidth(null) - this.sigScreenWidth), - clamp((int) ((actualRenderSize.getHeight() / 4) * 3), 0, this.currentImage.getHeight(null) - this.sigScreenHeight)); - this.sigPagePos = this.currentTransform.transform(this.sigScreenPos, this.sigPagePos); - } - else - updateSigPos((int) this.sigScreenPos.getX(), (int) this.sigScreenPos.getY()); + if (this.sigPagePos == null) + { + setSignaturePosition( + actualPageSize.getWidth() * .5, + actualPageSize.getHeight() * .75 + ); } } @@ -331,73 +308,36 @@ public class SignaturePanel extends JPanel { g.fillRect(0, 0, getWidth(), getHeight()); if (this.currentImage == null) { g.setColor(Color.black); - g.drawString(Messages.getString("error.SignaturePanel.NoPage"), getWidth() / 2 - 30, getHeight() / 2); - if (this.currentPage != null) { - renderPageToImage(); - repaint(); - } + g.drawString(Messages.getString("common.working"), getWidth() / 2 - 30, getHeight() / 2); } else { + this.imageToScreenScale = Math.min( + renderPanelSize.getWidth() / this.currentImage.getWidth(null), + renderPanelSize.getHeight() / this.currentImage.getHeight(null)); // draw the image - int actualRenderWidth = this.currentImage.getWidth(null); - int actualRenderHeight = this.currentImage.getHeight(null); + int actualRenderWidth = (int)(this.currentImage.getWidth(null) * this.imageToScreenScale); + int actualRenderHeight = (int)(this.currentImage.getHeight(null) * this.imageToScreenScale); // draw it centered within the panel this.offX = (renderPanelSize.width - actualRenderWidth) / 2; this.offY = (renderPanelSize.height - actualRenderHeight) / 2; - if ((actualRenderWidth == renderPanelSize.width && actualRenderHeight <= renderPanelSize.height) - || (actualRenderHeight == renderPanelSize.height && actualRenderWidth <= renderPanelSize.width)) { - - // draw document - g.drawImage(this.currentImage, this.offX, this.offY, this); - - // draw signature - int sigX = (int) (this.offX + this.sigScreenPos.getX()); - int sigY = (int) (this.offY + this.sigScreenPos.getY()); - if (this.sigPlaceholder == null) { - g.setColor(Color.red); - g.drawRect(sigX, sigY, 100, 40); - } - else { - if ( - ((this.sigScreenWidth != this.prevSigScreenWidth) || - (this.sigScreenHeight != this.prevSigScreenHeight)) && - ((this.sigScreenWidth != 0) && (this.sigScreenHeight != 0))) - { - // redraw scaled transparent placeholder - this.prevSigScreenWidth = this.sigScreenWidth; - this.prevSigScreenHeight = this.sigScreenHeight; - Image placeholder = this.sigPlaceholder.getScaledInstance( - this.sigScreenWidth, this.sigScreenHeight, Image.SCALE_SMOOTH); - - //Make placeholder transparent - this.sigPlaceholderScaled = new BufferedImage(this.sigScreenWidth, this.sigScreenHeight, BufferedImage.TYPE_INT_ARGB); - Graphics g_phs = this.sigPlaceholderScaled.getGraphics(); - g_phs.drawImage(placeholder, 0, 0, null); - g_phs.dispose(); - - int[] phpixels = new int[this.sigScreenWidth * this.sigScreenHeight]; - phpixels = this.sigPlaceholderScaled.getRGB(0, 0, this.sigScreenWidth, this.sigScreenHeight, phpixels, 0, this.sigScreenWidth); - for (int i = 0; i < phpixels.length; ++i) { - Color c = new Color(phpixels[i]); - c = new Color(c.getRed(), c.getGreen(), c.getBlue(), 170); - phpixels[i] = c.getRGB(); - } - this.sigPlaceholderScaled.setRGB(0, 0, this.sigScreenWidth, this.sigScreenHeight, phpixels, 0, this.sigScreenWidth); - } - g.drawImage(this.sigPlaceholderScaled, sigX, sigY, null); - g.setColor(this.sigPlaceholderBorderColor); - g.drawRect(sigX, sigY, this.sigScreenWidth-1, this.sigScreenHeight-1); - } - - } else { - // the image is bogus. try again, or give up. - if (this.currentPage != null) - renderPageToImage(); + // draw document + g.drawImage(this.currentImage, this.offX, this.offY, actualRenderWidth, actualRenderHeight, null); + - g.setColor(Color.black); - g.drawString(Messages.getString("error.SignaturePanel.NoRender"), getWidth() / 2 - 30, - getHeight() / 2); + // draw signature + int sigX = (int) this.scale(this.sigPagePos.getX(), U.PAGE_ABS, U.SCREEN_ABS, Dim.X); + int sigY = (int) this.scale(this.sigPagePos.getY(), U.PAGE_ABS, U.SCREEN_ABS, Dim.Y); + if (this.sigPlaceholder == null) { + g.setColor(Color.red); + g.drawRect(sigX, sigY, 100, 40); + } + else { + int sigScreenWidth = (int)this.scale(this.sigPageWidth, U.PAGE_REL, U.SCREEN_REL, Dim.X); + int sigScreenHeight = (int)this.scale(this.sigPageHeight, U.PAGE_REL, U.SCREEN_REL, Dim.Y); + g.drawImage(this.sigPlaceholder, sigX, sigY, sigScreenWidth, sigScreenHeight, null); + g.setColor(this.sigPlaceholderBorderColor); + g.drawRect(sigX, sigY, sigScreenWidth-1, sigScreenHeight-1); } } } @@ -423,17 +363,18 @@ public class SignaturePanel extends JPanel { private int dragXOffset = 0; private int dragYOffset = 0; - private void updateSigPos(int sigx, int sigy) { - SignaturePanel.this.updateSigPos( - sigx - SignaturePanel.this.offX, - sigy - SignaturePanel.this.offY); + private void updateSigPosDrag(MouseEvent evt) { + SignaturePanel.this.setSignaturePosition( + SignaturePanel.this.scale(evt.getX() - this.dragXOffset, U.SCREEN_ABS, U.PAGE_ABS, Dim.X), + SignaturePanel.this.scale(evt.getY() - this.dragYOffset, U.SCREEN_ABS, U.PAGE_ABS, Dim.Y) + ); } /** Handles a mouseMoved event */ @Override public void mouseMoved(MouseEvent evt) { try { - boolean onSig = isOnSignature(evt.getX(), evt.getY()); + boolean onSig = isOnSignature(evt); setCursor(onSig ? Cursors.HAND : Cursors.DEFAULT); } catch (NullPointerException e) { // do nothing @@ -446,19 +387,15 @@ public class SignaturePanel extends JPanel { if (evt.getButton() == MouseEvent.BUTTON1) { this.doDrag = true; - if (isOnSignature(evt.getX(), evt.getY())) { - this.dragXOffset = (int) - (SignaturePanel.this.sigScreenPos.getX() - - (evt.getX() - SignaturePanel.this.offX)); - this.dragYOffset = (int) - (SignaturePanel.this.sigScreenPos.getY() - - (evt.getY() - SignaturePanel.this.offY)); - } - else { + if (isOnSignature(evt)) { + /* offsets (in screen units) from top-left corner of signature to cursor on drag start */ + this.dragXOffset = (int)(evt.getX() - SignaturePanel.this.scale(SignaturePanel.this.sigPagePos.getX(), U.PAGE_ABS, U.SCREEN_ABS, Dim.X)); + this.dragYOffset = (int)(evt.getY() - SignaturePanel.this.scale(SignaturePanel.this.sigPagePos.getY(), U.PAGE_ABS, U.SCREEN_ABS, Dim.Y)); + } else { this.dragXOffset = 0; this.dragYOffset = 0; } - updateSigPos(evt.getX() + this.dragXOffset, evt.getY() + this.dragYOffset); + updateSigPosDrag(evt); setCursor(Cursors.MOVE); } } @@ -467,7 +404,7 @@ public class SignaturePanel extends JPanel { @Override public void mouseReleased(MouseEvent evt) { this.doDrag = false; - boolean onSig = isOnSignature(evt.getX(), evt.getY()); + boolean onSig = isOnSignature(evt); setCursor(onSig ? Cursors.HAND : Cursors.DEFAULT); } @@ -477,7 +414,7 @@ public class SignaturePanel extends JPanel { @Override public void mouseDragged(MouseEvent evt) { if (this.doDrag) - updateSigPos(evt.getX() + this.dragXOffset, evt.getY() + this.dragYOffset); + updateSigPosDrag(evt); } }; @@ -507,37 +444,22 @@ public class SignaturePanel extends JPanel { /** * Check whether given point is on signature placeholder - * @param x x coordinate - * @param y y coordinate + * @param x x coordinate (screen) + * @param y y coordinate (screen) * @return true if given point is on signature placeholder */ - boolean isOnSignature(int x, int y) + private boolean isOnSignature(MouseEvent evt) { - if (this.sigScreenPos == null) + if (this.sigPagePos == null) return false; Rectangle2D sig = new Rectangle2D.Double( - this.sigScreenPos.getX() + this.offX, - this.sigScreenPos.getY() + this.offY, - this.sigScreenWidth, - this.sigScreenHeight); - Point2D pos = new Point2D.Double(x, y); - return (sig.contains(pos)); - } - - /** - * Update the signature placeholder position - * @param sigx X position on the document (screen coordinates) - * @param sigy Y position on the document (screen coordinates) - */ - void updateSigPos(int sigx, int sigy) { - if (this.currentImage == null) - return; - sigx = clamp(sigx, 0, this.currentImage.getWidth(null) - this.sigScreenWidth); - sigy = clamp(sigy, 0, this.currentImage.getHeight(null) - this.sigScreenHeight); - this.sigScreenPos = new Point2D.Double(sigx, sigy); - this.sigPagePos = this.currentTransform.transform(this.sigScreenPos, this.sigPagePos); - repaint(); + this.scale(this.sigPagePos.getX(), U.PAGE_ABS, U.SCREEN_ABS, Dim.X), + this.scale(this.sigPagePos.getY(), U.PAGE_ABS, U.SCREEN_ABS, Dim.Y), + this.scale(this.sigPageWidth, U.PAGE_REL, U.SCREEN_REL, Dim.X), + this.scale(this.sigPageHeight, U.PAGE_REL, U.SCREEN_REL, Dim.Y) + ); + return sig.contains(evt.getX(), evt.getY()); } /** @@ -547,7 +469,7 @@ public class SignaturePanel extends JPanel { * @param max maximum value * @return clamped x */ - static int clamp(int x, int min, int max) + private static double clamp(double x, double min, double max) { if (x < min) x = min; -- cgit v1.2.3