[ https://issues.apache.org/jira/browse/PDFBOX-1296?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13274571#comment-13274571 ]
Tilman Hausherr commented on PDFBOX-1296: ----------------------------------------- After reading the PDF spec, http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf I found that "+" means that it is a subset of a font, see page 258, or 9.6.4. While waiting for a real solution (might be related to issues PDFBOX-490 and PDFBOX-412) here's an updated workaround code, which now also cuts off the "+". /** * Font.canDisplayUpTo() is buggy: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6623219 * http://stackoverflow.com/questions/1754697/displaying-chinese-text-in-an-applet * * @param font * @param s * @return -1 when all is good * * This method returns an offset into the String s which is the first * character this Font cannot display without using the missing glyph code. * If the Font can display all characters, -1 is returned. */ int canDisplayUpTo(Font font, String s) { if (!font.canDisplay(' ') || !font.canDisplay('a') || !font.canDisplay('A')) { return 0; //TH font.canDisplay does not always tell the truth } int len = s.length(); int index = 0; while (index < len) { int codePoint = s.codePointAt(index); if (!font.canDisplay(codePoint)) { return index; } index += Character.charCount(codePoint); } return -1; } /** * {@inheritDoc} */ @Override public void drawString(String string, Graphics g, float fontSize, AffineTransform at, float x, float y) throws IOException { Font _awtFont = getawtFont(); // mdavis - fix fontmanager.so/dll on sun.font.FileFont.getGlyphImage // for font with bad cmaps? // Type1 fonts are not affected as they don't have cmaps // if (!isType1Font() && _awtFont.canDisplayUpTo(string) != -1) if (!isType1Font() && canDisplayUpTo(_awtFont, string) != -1) { Font _awtFontOld = _awtFont; String name = null; String style; if (_awtFont.getName().indexOf('+') > 0) { name = _awtFont.getName().substring(_awtFont.getName().indexOf('+') + 1); } else if (_awtFont.getName().startsWith("DejaVu") || _awtFont.getName().startsWith("Liberation")) { if (_awtFont.getName().startsWith("DejaVu Sans")) { name = "Lucida Sans"; } else if (_awtFont.getName().startsWith("Liberation Serif")) { name = "Times New Roman"; } else if (_awtFont.getName().startsWith("Liberation Sans")) { name = "Arial"; } else if (_awtFont.getName().startsWith("Liberation Mono")) { name = "Courier New"; } else { name = "Lucida Sans"; } } if (name == null) { _awtFont = Font.decode(null); } else { switch (_awtFont.getStyle()) { case Font.BOLD: style = "BOLD"; break; case Font.ITALIC: style = "ITALIC"; break; case Font.PLAIN: style = "PLAIN"; break; default: if (_awtFont.getStyle() == (Font.BOLD | Font.ITALIC)) { style = "BOLDITALIC"; } else { style = "PLAIN"; } } if (_awtFont.getName().endsWith("Bold")) { style = "BOLD"; } else if (_awtFont.getName().endsWith("Bold Italic")) { style = "BOLDITALIC"; } else if (_awtFont.getName().endsWith("Italic")) { style = "ITALIC"; } _awtFont = Font.decode(name + "-" + style + "-" + Integer.toString(_awtFont.getSize())); } log.warn("Changing font on <" + string + "> from <" + _awtFontOld + "> to <" + _awtFont + ">"); } Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); writeFont(g2d, at, _awtFont, x, y, string); } > Warnung: Changing font on < > from <AMAKEA+TimesNewRoman> to the default font > ----------------------------------------------------------------------------- > > Key: PDFBOX-1296 > URL: https://issues.apache.org/jira/browse/PDFBOX-1296 > Project: PDFBox > Issue Type: Bug > Components: PDModel > Affects Versions: 1.6.0 > Environment: XP, JDK 1.7 > Reporter: Tilman Hausherr > Attachments: outside-in-01.png, outside-in.pdf, shortcuts-01.png, > shortcuts.pdf > > > Pdfbox does not produce the correct fonts in the PNG file created with the > following code and I get a lot of warnings: > PDDocument document = null; > try > { > document = PDDocument.load(pdfFile); > List pages = document.getDocumentCatalog().getAllPages(); > int p = 0; > for (Object pobj : pages) > { > PDPage page = (PDPage) pobj; > ++p; > BufferedImage bim = page.convertToImage(); > // Test with output in memory, to see the size > ByteArrayOutputStream memout = new > ByteArrayOutputStream(); > boolean memoutok = ImageIO.write(bim, "png", memout); > if (!memoutok) > System.err.println ("mem write failed for " + p); > memout.reset(); > memout.close(); > // Test with output to png file > String fname = String.format("%s-%02d.png", prefix, p); > boolean foutok = ImageIO.write(bim, "png", new > File(fname)); > if (!foutok) > System.err.println ("file write failed for " + p); > .... > Apr 26, 2012 2:41:11 PM org.apache.pdfbox.util.PDFStreamEngine processOperator > Information: unsupported/disabled operation: i > Apr 26, 2012 2:41:12 PM org.apache.pdfbox.util.PDFStreamEngine processOperator > Information: unsupported/disabled operation: ri > Apr 26, 2012 2:41:12 PM org.apache.pdfbox.pdmodel.font.PDSimpleFont drawString > Warnung: Changing font on < > from <AMAKEA+TimesNewRoman> to the default font > Apr 26, 2012 2:41:13 PM org.apache.pdfbox.pdmodel.font.PDSimpleFont drawString > Warnung: Changing font on < > from <AMAKEA+TimesNewRoman> to the default font > Apr 26, 2012 2:41:13 PM org.apache.pdfbox.pdmodel.font.PDSimpleFont drawString > Warnung: Changing font on <O> from <AMAKME+Arial,Bold> to the default font > Apr 26, 2012 2:41:13 PM org.apache.pdfbox.pdmodel.font.PDSimpleFont drawString -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira