You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2018/11/17 13:29:00 UTC
[jira] [Comment Edited] (PDFBOX-4379) hasGlyph returns false when a
two character glyph does exist
[ https://issues.apache.org/jira/browse/PDFBOX-4379?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16690541#comment-16690541 ]
Tilman Hausherr edited comment on PDFBOX-4379 at 11/17/18 1:28 PM:
-------------------------------------------------------------------
I had a look in the source code… hasGlyph is used to find out whether the character code found in a PDF (this is NOT a Unicode! In font subsets, an a can be 1, and c can be 2, and a z can be code 3!) is supported by the font. If not, a log message is produced.
What you want to do is to find out whether a glyph is in a font. At this time, the only solution is to call showText and see if an IllegalArgumentException occurs.
was (Author: tilman):
I had a look in the source code… hasGlyph is used to find out whether the character code found in a PDF (this is NOT a Unicode! In font subsets, an a can be 1, and c can be 2, and a z can be code 3!) is supported by the font. If not, a log message is produced.
What you want to do is to find out whether a glyph is in a font. At this time, the only solution is to call showText and see if an Exception occurs (IllegalParameterException I think).
> hasGlyph returns false when a two character glyph does exist
> ------------------------------------------------------------
>
> Key: PDFBOX-4379
> URL: https://issues.apache.org/jira/browse/PDFBOX-4379
> Project: PDFBox
> Issue Type: Bug
> Components: FontBox
> Affects Versions: 2.0.12
> Reporter: Darren Croft
> Priority: Major
> Attachments: Symbola_hint.ttf
>
>
> The following codes runs without exception and adds the glyph to the page, but it prints "no glyph" to standard output. It should print "has glyph" on standard output.
> {code:java}
> public class FontTest {
> public static void main(String[] args) throws IOException {
> try {
> PDDocument doc = new PDDocument();
> PDPage page = new PDPage(PDRectangle.LETTER);
> doc.addPage(page);
> InputStream in = FontTest.class.getResourceAsStream("/Symbola_hint.ttf");
> PDType0Font emojiFont = PDType0Font.load(doc, in);
> PDPageContentStream stream = new PDPageContentStream(doc, page);
> stream.beginText();
> stream.setFont(emojiFont, 12);
> stream.setLeading(12 * 1.2f);
> int codepoint=0x1F609;
> if(emojiFont.hasGlyph(codepoint)) {
> System.out.println("has Glyph");
> } else {
> System.out.println("no Glyph");
> }
> String s=new String(Character.toChars(codepoint));
> stream.showText(s);
> stream.close();
> doc.save("emojiTest.pdf");
> } catch (Exception exception) {
> System.out.println(exception.getMessage());
> exception.printStackTrace();
> }
> }
> }
> {code}
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org