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

TrueTypeParser : Error on CMapEntry with the subtype0 ?

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • 1.0.0, 1.1.0
    • None
    • FontBox
    • None

    Description

      Hi,

      I'm encountering a problem using the TrueType Font parser.
      I think the glyphIToCharacterCode isn't correctly initialized with a TrueType character mapping table Format 0.

      According to the TrueType specification, the glyphMapping array should be "An array that maps character codes to glyph index values".
      However, the current implementation sees the glyphMapping as an array that maps glyph index values to character codes.

      Here is the current implementation :

      public void initSubtable( TrueTypeFont ttf, TTFDataStream data ) throws IOException
      {
      data.seek( ttf.getCMAP().getOffset() + subTableOffset );
      int subtableFormat = data.readUnsignedShort();
      int length = data.readUnsignedShort();
      int version = data.readUnsignedShort();
      int numGlyphs = ttf.getMaximumProfile().getNumGlyphs();
      if( subtableFormat == 0 )
      {
      byte[] glyphMapping = data.read( 256 );
      glyphIdToCharacterCode = new int[256];
      for( int i=0;i < glyphMapping.length; i++ )

      { glyphIdToCharacterCode[i]=(glyphMapping[i]+256)%256; }

      }
      ...

      I think it should be :

      public void initSubtable( TrueTypeFont ttf, TTFDataStream data ) throws IOException
      {
      data.seek( ttf.getCMAP().getOffset() + subTableOffset );
      int subtableFormat = data.readUnsignedShort();
      int length = data.readUnsignedShort();
      int version = data.readUnsignedShort();
      int numGlyphs = ttf.getMaximumProfile().getNumGlyphs();
      if( subtableFormat == 0 )
      {
      byte[] glyphMapping = data.read( 256 );
      glyphIdToCharacterCode = new int[256];
      for( int i=0;i < glyphMapping.length; i++ )

      { int glyphIndex = (glyphMapping[i]+256)%256; glyphIdToCharacterCode[glyphIndex]=i; }

      }

      In attachment, you can find a PDF which uses a TrueType font with a character mapping table Format 0 and the Font Program. (it is a subset)

      Regards,
      Eric

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              leleueri Eric Leleu
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: