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:20 UTC

svn commit: r1890008 - /pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java

Author: tilman
Date: Tue May 18 17:17:19 2021
New Revision: 1890008

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

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

Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java?rev=1890008&r1=1890007&r2=1890008&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java (original)
+++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java Tue May 18 17:17:19 2021
@@ -155,28 +155,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())