Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3708

hasGlyph() contradicts encode()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.4, 3.0.0 PDFBox
    • 2.0.5, 3.0.0 PDFBox
    • None
    • None

    Description

              PDDocument doc = new PDDocument();
              PDType0Font font = PDType0Font.load(doc, new FileInputStream("c:/windows/fonts/arial.ttf"));
              System.out.println(font.hasGlyph('\n'));
              PDPage page = new PDPage();
              doc.addPage(page);
              PDPageContentStream cs = new PDPageContentStream(doc, page);
              cs.beginText();
              cs.setFont(font, 100);
              cs.showText("\n");
      

      The output:

      true
      Exception in thread "main" java.lang.IllegalArgumentException: No glyph for U+000A in font ArialMT
      	at org.apache.pdfbox.pdmodel.font.PDCIDFontType2.encode(PDCIDFontType2.java:402)
      	at org.apache.pdfbox.pdmodel.font.PDType0Font.encode(PDType0Font.java:351)
      	at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:316)
      	at org.apache.pdfbox.pdmodel.PDPageContentStream.showText(PDPageContentStream.java:362)
      

      Either this is a bug in hasGlyph(), or it is a documentation (javadoc) problem, e.g. because the parameter to hasGlyph isn't a character code but something else, then this should be clarified.

      Attachments

        Activity

          People

            Unassigned Unassigned
            tilman Tilman Hausherr
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: