Skip to content

Commit

Permalink
PDFBOX-5924: apply font scaling when using Zapf Dingbats font; replac…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
THausherr committed Dec 18, 2024
1 parent 3338d0d commit af63a31
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import java.awt.geom.PathIterator;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.PDAppearanceContentStream;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.Standard14Fonts;
import org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName;
import org.apache.pdfbox.pdmodel.graphics.blend.BlendMode;
Expand Down Expand Up @@ -429,7 +431,10 @@ private void drawStar(PDAnnotationText annotation, final PDAppearanceContentStre
contentStream.setLineCapStyle(0);
contentStream.setLineWidth(0.59f); // value from Adobe

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

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

contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
List<Number> fontMatrix = new PDType1Font(FontName.ZAPF_DINGBATS).getFontBoxFont().getFontMatrix();
float xScale = (float) fontMatrix.get(0);
float yScale = (float) fontMatrix.get(3);
contentStream.transform(Matrix.getScaleInstance(xScale * min / 0.8f, yScale * min / 0.8f));
contentStream.transform(Matrix.getTranslateInstance(0, 50));

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

contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
List<Number> fontMatrix = new PDType1Font(FontName.ZAPF_DINGBATS).getFontBoxFont().getFontMatrix();
float xScale = (float) fontMatrix.get(0);
float yScale = (float) fontMatrix.get(3);
contentStream.transform(Matrix.getScaleInstance(xScale * min / 0.8f, yScale * min / 0.8f));
contentStream.transform(Matrix.getTranslateInstance(0, 50));

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

contentStream.saveGraphicsState();
// rescale so that the glyph fits into circle and move it to circle center
// values gathered by trial and error
contentStream.transform(Matrix.getScaleInstance(0.001f * min / 1.3f, 0.001f * min / 1.3f));
contentStream.transform(Matrix.getTranslateInstance(200, 300));

// we get the shape of a Zapf Dingbats right arrow (0x2794) and use that one.
// Adobe uses a different font (which one?), or created the shape from scratch.
GeneralPath path = Standard14Fonts.getGlyphPath(FontName.ZAPF_DINGBATS, "a160");
addPath(contentStream, path);
contentStream.moveTo(8, 17.5f);
contentStream.lineTo(8, 13.5f);
contentStream.lineTo(3, 13.5f);
contentStream.lineTo(3, 6.5f);
contentStream.lineTo(8, 6.5f);
contentStream.lineTo(8, 2.5f);
contentStream.lineTo(18, 10);
contentStream.closePath();
contentStream.restoreGraphicsState();
// surprisingly, this one not counterclockwise.
drawCircle(contentStream, min / 2, min / 2, min / 2 - 1);
Expand Down

0 comments on commit af63a31

Please sign in to comment.