[ https://issues.apache.org/jira/browse/PDFBOX-3353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16144666#comment-16144666 ]
chitgoks edited comment on PDFBOX-3353 at 8/29/17 2:35 AM: ----------------------------------------------------------- The arrows that you created lacks a sharper tip to make it look like the line dimension arrow point in Acrobat. for line arrows, here is my code in case you are interested (same as acrobat). {code:java} double arrowMeasureAngle = Math.atan2(ym2 - ym1, xm2 - xm1); int arrowMeasureLength = 10; int distanceMeasure = 1; // Draw start arrow head. float[] lineMeasureProp = lengthenEndLine(xm2, ym2, xm1, ym1, -distanceMeasure); cs.moveTo(lineMeasureProp[2], lineMeasureProp[3]); cs.lineTo((float) (xm1 + arrowMeasureLength * Math.cos(arrowMeasureAngle - Math.PI / 6)), (float) (ym1 + arrowMeasureLength * Math.sin(arrowMeasureAngle - Math.PI / 6))); cs.moveTo(lineMeasureProp[2], lineMeasureProp[3]); cs.lineTo((float) (xm1 + arrowMeasureLength * Math.cos(arrowMeasureAngle + Math.PI / 6)), (float) (ym1 + arrowMeasureLength * Math.sin(arrowMeasureAngle + Math.PI / 6))); // Draw end arrow head. lineMeasureProp =lengthenEndLine(xm1, ym1, xm2, ym2, -distanceMeasure); cs.moveTo(lineMeasureProp[2], lineMeasureProp[3]); cs.lineTo((float) (xm2 - arrowMeasureLength * Math.cos(arrowMeasureAngle - Math.PI / 6)), (float) (ym2 - arrowMeasureLength * Math.sin(arrowMeasureAngle - Math.PI / 6))); cs.moveTo(lineMeasureProp[2], lineMeasureProp[3]); cs.lineTo((float) (xm2 - arrowMeasureLength * Math.cos(arrowMeasureAngle + Math.PI / 6)), (float) (ym2 - arrowMeasureLength * Math.sin(arrowMeasureAngle + Math.PI / 6))); cs.stroke(); {code} This is before you rotate the matrix. It uses this custom code to shorten or lengthen the line segment {code:java} public static float[] lengthenEndLine(float startX, float startY, float endX, float endY, int distance) { float dx = endX - startX; float dy = endY - startY; // Vertical line if (dx == 0) { if (endY < startY) endY -= distance; else endY += distance; } // Horizontal line else if (dy == 0) { if (endX < startX) endX -= distance; else endX += distance; } // Diagonal else { float length = (float) Math.sqrt(dx * dx + dy * dy); float scale = (length + distance) / length; dx *= scale; dy *= scale; endX = startX + dx; endY = startY + dy; } return new float[] { startX, startY, endX, endY }; } {code} im not good at math or geometry so the code looks like a hack. arrow length 10 is same as in Acrobat. the angle is a little bit fat although not noticeable. was (Author: chitgoks): The arrows that you created lacks a sharper tip to make it look like the line dimension arrow point in Acrobat. for line arrows, here is my code in case you are interested (same as acrobat). {code:java} double arrowMeasureAngle = Math.atan2(ym2 - ym1, xm2 - xm1); int arrowMeasureLength = 10; int distanceMeasure = 1; // Draw start arrow head. float[] lineMeasureProp = lengthenEndLine(xm2, ym2, xm1, ym1, -distanceMeasure); cs.moveTo(lineMeasureProp[2], lineMeasureProp[3]); cs.lineTo((float) (xm1 + arrowMeasureLength * Math.cos(arrowMeasureAngle - Math.PI / 6)), (float) (ym1 + arrowMeasureLength * Math.sin(arrowMeasureAngle - Math.PI / 6))); cs.moveTo(lineMeasureProp[2], lineMeasureProp[3]); cs.lineTo((float) (xm1 + arrowMeasureLength * Math.cos(arrowMeasureAngle + Math.PI / 6)), (float) (ym1 + arrowMeasureLength * Math.sin(arrowMeasureAngle + Math.PI / 6))); // Draw end arrow head. lineMeasureProp =lengthenEndLine(xm1, ym1, xm2, ym2, -distanceMeasure); cs.moveTo(lineMeasureProp[2], lineMeasureProp[3]); cs.lineTo((float) (xm2 - arrowMeasureLength * Math.cos(arrowMeasureAngle - Math.PI / 6)), (float) (ym2 - arrowMeasureLength * Math.sin(arrowMeasureAngle - Math.PI / 6))); cs.moveTo(lineMeasureProp[2], lineMeasureProp[3]); cs.lineTo((float) (xm2 - arrowMeasureLength * Math.cos(arrowMeasureAngle + Math.PI / 6)), (float) (ym2 - arrowMeasureLength * Math.sin(arrowMeasureAngle + Math.PI / 6))); cs.stroke(); {code} This is before you rotate the matrix. It uses this custom code to shorten the line segment {code:java} public static float[] lengthenEndLine(float startX, float startY, float endX, float endY, int distance) { float dx = endX - startX; float dy = endY - startY; // Vertical line if (dx == 0) { if (endY < startY) endY -= distance; else endY += distance; } // Horizontal line else if (dy == 0) { if (endX < startX) endX -= distance; else endX += distance; } // Diagonal else { float length = (float) Math.sqrt(dx * dx + dy * dy); float scale = (length + distance) / length; dx *= scale; dy *= scale; endX = startX + dx; endY = startY + dy; } return new float[] { startX, startY, endX, endY }; } {code} im not good at math or geometry so the code looks like a hack. arrow length 10 is same as in Acrobat. the angle is a little bit fat although not noticeable. > Create appearance streams for annotations > ----------------------------------------- > > Key: PDFBOX-3353 > URL: https://issues.apache.org/jira/browse/PDFBOX-3353 > Project: PDFBox > Issue Type: Task > Components: PDModel, Rendering > Affects Versions: 1.8.12, 2.0.0, 2.0.1, 2.0.2, 3.0.0 > Reporter: Tilman Hausherr > Labels: Annotations > Attachments: line_dimension_appearance_stream-noAP.pdf, > line_dimension_appearance_stream.pdf, > PDFBOX-3353-highlight-noAP-001796-p1.pdf, PDFBOX-3353-highlight-noAP.pdf, > ShowAnnotation-4.java, showAnnotation.java, SquareAnnotations.pdf, > text_markup_ap_test.pdf > > > Create appearance streams for annotations when missing. > I'll start by replacing current code for Ink and Link annotations. > Good example PDFs: > http://www.pdfill.com/example/pdf_commenting_new.pdf > https://github.com/mozilla/pdf.js/issues/6810 -- This message was sent by Atlassian JIRA (v6.4.14#64029) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org