Skip to content

Commit af63a31

Browse files
committed
PDFBOX-5924: apply font scaling when using Zapf Dingbats font; replace RightArrow with own arrow path because of problems with DejaVu Sans
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922583 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3338d0d commit af63a31

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
import java.awt.geom.PathIterator;
2121
import java.io.IOException;
2222
import java.util.HashSet;
23+
import java.util.List;
2324
import java.util.Set;
2425
import org.apache.logging.log4j.Logger;
2526
import org.apache.logging.log4j.LogManager;
2627
import org.apache.pdfbox.cos.COSName;
2728
import org.apache.pdfbox.pdmodel.PDAppearanceContentStream;
2829
import org.apache.pdfbox.pdmodel.PDDocument;
2930
import org.apache.pdfbox.pdmodel.common.PDRectangle;
31+
import org.apache.pdfbox.pdmodel.font.PDType1Font;
3032
import org.apache.pdfbox.pdmodel.font.Standard14Fonts;
3133
import org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName;
3234
import org.apache.pdfbox.pdmodel.graphics.blend.BlendMode;
@@ -429,7 +431,10 @@ private void drawStar(PDAnnotationText annotation, final PDAppearanceContentStre
429431
contentStream.setLineCapStyle(0);
430432
contentStream.setLineWidth(0.59f); // value from Adobe
431433

432-
contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
434+
List<Number> fontMatrix = new PDType1Font(FontName.ZAPF_DINGBATS).getFontBoxFont().getFontMatrix();
435+
float xScale = (float) fontMatrix.get(0);
436+
float yScale = (float) fontMatrix.get(3);
437+
contentStream.transform(Matrix.getScaleInstance(xScale * min / 0.8f, yScale * min / 0.8f));
433438

434439
// we get the shape of a Zapf Dingbats star (0x2605) and use that one.
435440
// Adobe uses a different font (which one?), or created the shape from scratch.
@@ -453,7 +458,10 @@ private void drawCheck(PDAnnotationText annotation, final PDAppearanceContentStr
453458
contentStream.setLineCapStyle(0);
454459
contentStream.setLineWidth(0.59f); // value from Adobe
455460

456-
contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
461+
List<Number> fontMatrix = new PDType1Font(FontName.ZAPF_DINGBATS).getFontBoxFont().getFontMatrix();
462+
float xScale = (float) fontMatrix.get(0);
463+
float yScale = (float) fontMatrix.get(3);
464+
contentStream.transform(Matrix.getScaleInstance(xScale * min / 0.8f, yScale * min / 0.8f));
457465
contentStream.transform(Matrix.getTranslateInstance(0, 50));
458466

459467
// we get the shape of a Zapf Dingbats check (0x2714) and use that one.
@@ -476,7 +484,10 @@ private void drawRightPointer(PDAnnotationText annotation, final PDAppearanceCon
476484
contentStream.setLineCapStyle(0);
477485
contentStream.setLineWidth(0.59f); // value from Adobe
478486

479-
contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
487+
List<Number> fontMatrix = new PDType1Font(FontName.ZAPF_DINGBATS).getFontBoxFont().getFontMatrix();
488+
float xScale = (float) fontMatrix.get(0);
489+
float yScale = (float) fontMatrix.get(3);
490+
contentStream.transform(Matrix.getScaleInstance(xScale * min / 0.8f, yScale * min / 0.8f));
480491
contentStream.transform(Matrix.getTranslateInstance(0, 50));
481492

482493
// we get the shape of a Zapf Dingbats right pointer (0x27A4) and use that one.
@@ -577,15 +588,14 @@ private void drawRightArrow(PDAnnotationText annotation, final PDAppearanceConte
577588
contentStream.restoreGraphicsState();
578589

579590
contentStream.saveGraphicsState();
580-
// rescale so that the glyph fits into circle and move it to circle center
581-
// values gathered by trial and error
582-
contentStream.transform(Matrix.getScaleInstance(0.001f * min / 1.3f, 0.001f * min / 1.3f));
583-
contentStream.transform(Matrix.getTranslateInstance(200, 300));
584-
585-
// we get the shape of a Zapf Dingbats right arrow (0x2794) and use that one.
586-
// Adobe uses a different font (which one?), or created the shape from scratch.
587-
GeneralPath path = Standard14Fonts.getGlyphPath(FontName.ZAPF_DINGBATS, "a160");
588-
addPath(contentStream, path);
591+
contentStream.moveTo(8, 17.5f);
592+
contentStream.lineTo(8, 13.5f);
593+
contentStream.lineTo(3, 13.5f);
594+
contentStream.lineTo(3, 6.5f);
595+
contentStream.lineTo(8, 6.5f);
596+
contentStream.lineTo(8, 2.5f);
597+
contentStream.lineTo(18, 10);
598+
contentStream.closePath();
589599
contentStream.restoreGraphicsState();
590600
// surprisingly, this one not counterclockwise.
591601
drawCircle(contentStream, min / 2, min / 2, min / 2 - 1);

0 commit comments

Comments
 (0)