CreateCheckBox.java (pdfbox-2.0.23-src) | : | CreateCheckBox.java (pdfbox-2.0.24-src) | ||
---|---|---|---|---|
skipping to change at line 158 | skipping to change at line 158 | |||
// Adobe paints a cross instead of using the Zapf Dingbats cross sym bol | // Adobe paints a cross instead of using the Zapf Dingbats cross sym bol | |||
yesAPCS.setStrokingColor(0f); | yesAPCS.setStrokingColor(0f); | |||
yesAPCS.moveTo(lineWidth * 2, rect.getHeight() - lineWidth * 2); | yesAPCS.moveTo(lineWidth * 2, rect.getHeight() - lineWidth * 2); | |||
yesAPCS.lineTo(rect.getWidth() - lineWidth * 2, lineWidth * 2); | yesAPCS.lineTo(rect.getWidth() - lineWidth * 2, lineWidth * 2); | |||
yesAPCS.moveTo(rect.getWidth() - lineWidth * 2, rect.getHeight() - l ineWidth * 2); | yesAPCS.moveTo(rect.getWidth() - lineWidth * 2, rect.getHeight() - l ineWidth * 2); | |||
yesAPCS.lineTo(lineWidth * 2, lineWidth * 2); | yesAPCS.lineTo(lineWidth * 2, lineWidth * 2); | |||
yesAPCS.stroke(); | yesAPCS.stroke(); | |||
} | } | |||
else | else | |||
{ | { | |||
// The caption is not unicode, but the Zapf Dingbats code in the PDF | Rectangle2D bounds = new Rectangle2D.Float(); | |||
// Thus convert it back to unicode | String unicode = null; | |||
// Assume that only the first character is used. | ||||
String name = PDType1Font.ZAPF_DINGBATS.codeToName(normalCaption.cod | // ZapfDingbats font may be missing or substituted, let's use AFM re | |||
ePointAt(0)); | sources instead. | |||
String unicode = PDType1Font.ZAPF_DINGBATS.getGlyphList().toUnicode( | AFMParser parser = new AFMParser(PDType1Font.class.getResourceAsStre | |||
name); | am( | |||
Rectangle2D bounds = PDType1Font.ZAPF_DINGBATS.getPath(name).getBoun | "/org/apache/pdfbox/resources/afm/ZapfDingbats.afm")); | |||
ds2D(); | FontMetrics metric = parser.parse(); | |||
if (bounds.isEmpty()) | for (CharMetric cm : metric.getCharMetrics()) | |||
{ | { | |||
// ZapfDingbats font missing, let's use AFM resources instead. | // The caption is not unicode, but the Zapf Dingbats code in the | |||
// You can remove this code block if you know that you have the | PDF. | |||
font. | // Assume that only the first character is used. | |||
AFMParser parser = new AFMParser(PDType1Font.class.getResourceAs | if (normalCaption.codePointAt(0) == cm.getCharacterCode()) | |||
Stream( | ||||
"/org/apache/pdfbox/resources/afm/ZapfDingbats.afm")); | ||||
FontMetrics metric = parser.parse(); | ||||
for (CharMetric cm : metric.getCharMetrics()) | ||||
{ | { | |||
if (normalCaption.codePointAt(0) == cm.getCharacterCode()) | BoundingBox bb = cm.getBoundingBox(); | |||
{ | bounds = new Rectangle2D.Float(bb.getLowerLeftX(), bb.getLow | |||
BoundingBox bb = cm.getBoundingBox(); | erLeftY(), | |||
bounds = new Rectangle2D.Float(bb.getLowerLeftX(), bb.ge | bb.getWidth(), bb.getHeight() | |||
tLowerLeftY(), | ); | |||
bb.getWidth(), bb.getHeig | unicode = PDType1Font.ZAPF_DINGBATS.getGlyphList().toUnicode | |||
ht()); | (cm.getName()); | |||
unicode = PDType1Font.ZAPF_DINGBATS.getGlyphList().toUni | break; | |||
code(cm.getName()); | ||||
} | ||||
} | } | |||
} | } | |||
if (bounds.isEmpty()) | if (bounds.isEmpty()) | |||
{ | { | |||
throw new IOException("Bounds rectangle for chosen glyph is empt y"); | throw new IOException("Bounds rectangle for chosen glyph is empt y"); | |||
} | } | |||
float size = (float) Math.min(bounds.getWidth(), bounds.getHeight()) / 1000; | float size = (float) Math.min(bounds.getWidth(), bounds.getHeight()) / 1000; | |||
// assume that checkmark has square size | // assume that checkmark has square size | |||
// the calculations approximate what Adobe is doing, i.e. put the gl yph in the middle | // the calculations approximate what Adobe is doing, i.e. put the gl yph in the middle | |||
float fontSize = (rect.getWidth() - lineWidth * 2) / size * 0.6666f; | float fontSize = (rect.getWidth() - lineWidth * 2) / size * 0.6666f; | |||
End of changes. 3 change blocks. | ||||
28 lines changed or deleted | 22 lines changed or added |