You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2021/05/18 17:17:24 UTC

svn commit: r1890009 - /pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java

Author: tilman
Date: Tue May 18 17:17:23 2021
New Revision: 1890009

URL: http://svn.apache.org/viewvc?rev=1890009&view=rev
Log:
PDFBOX-5194: use AFM only

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java?rev=1890009&r1=1890008&r2=1890009&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java Tue May 18 17:17:23 2021
@@ -159,28 +159,24 @@ public class CreateCheckBox
             }
             else
             {
-                // The caption is not unicode, but the Zapf Dingbats code in the PDF
-                // Thus convert it back to unicode
-                // Assume that only the first character is used.
-                String name = PDType1Font.ZAPF_DINGBATS.codeToName(normalCaption.codePointAt(0));
-                String unicode = PDType1Font.ZAPF_DINGBATS.getGlyphList().toUnicode(name);
-                Rectangle2D bounds = PDType1Font.ZAPF_DINGBATS.getPath(name).getBounds2D();
-                if (bounds.isEmpty())
+                Rectangle2D bounds = new Rectangle2D.Float();
+                String unicode = null;
+
+                // ZapfDingbats font may be missing or substituted, let's use AFM resources instead.
+                AFMParser parser = new AFMParser(PDType1Font.class.getResourceAsStream(
+                        "/org/apache/pdfbox/resources/afm/ZapfDingbats.afm"));
+                FontMetrics metric = parser.parse();
+                for (CharMetric cm : metric.getCharMetrics())
                 {
-                    // ZapfDingbats font missing, let's use AFM resources instead.
-                    // You can remove this code block if you know that you have the font.
-                    AFMParser parser = new AFMParser(PDType1Font.class.getResourceAsStream(
-                            "/org/apache/pdfbox/resources/afm/ZapfDingbats.afm"));
-                    FontMetrics metric = parser.parse();
-                    for (CharMetric cm : metric.getCharMetrics())
+                    // The caption is not unicode, but the Zapf Dingbats code in the PDF.
+                    // Assume that only the first character is used.
+                    if (normalCaption.codePointAt(0) == cm.getCharacterCode())
                     {
-                        if (normalCaption.codePointAt(0) == cm.getCharacterCode())
-                        {
-                            BoundingBox bb = cm.getBoundingBox();
-                            bounds = new Rectangle2D.Float(bb.getLowerLeftX(), bb.getLowerLeftY(), 
-                                                           bb.getWidth(), bb.getHeight());
-                            unicode = PDType1Font.ZAPF_DINGBATS.getGlyphList().toUnicode(cm.getName());
-                        }
+                        BoundingBox bb = cm.getBoundingBox();
+                        bounds = new Rectangle2D.Float(bb.getLowerLeftX(), bb.getLowerLeftY(), 
+                                                       bb.getWidth(), bb.getHeight());
+                        unicode = PDType1Font.ZAPF_DINGBATS.getGlyphList().toUnicode(cm.getName());
+                        break;
                     }
                 }
                 if (bounds.isEmpty())