Skip to content

Compound glyphs are not rendered #2749

Closed
@taohkubo

Description

@taohkubo

Symptom

When a font includes a compound font, it's not rendered at all or rendered in a wrong shape. The issue occurs depending on what font is used. In my environment, the issue is observable in Albany font and Arial Unicode MS. In Albany font case, all glyphs belongs to Hangul Syllables Unicode block and 40 glyphs in Latin Extended Additional are not rendered at all or rendered in wrong shape.

Reproduce

Please obtain Albany font or Arial Unicode MS font and make base64 encoded font script file as I cannot attach the font file. The following reproduce step is based on Arial Unicode MS ver 1.01x coming with Office 2016.

  1. Get the attached testcase.zip file and extract it
    testcase.zip
  2. Deploy the font script file of Arial Unicode MS font in the same folder
  3. Open testcase.html extracted from testcase.zip with a browser, result pdf file will be exported. This may take 30 seconds or more depending on the client spec.
  4. Review the exported pdf file and observe the Hangul characters are not rendered.

As the testcase exports all characters between 0xAC00 and 0xd7af code point, it will take relatively long time to export. Please edit the testcase.html file to change the exporting characters as needed.

The attached testcase.zip file also include the sample exported pdf file showing the issue and the expected pdf file for reference.

Findings

It seems the issue occurs because glyph id becomes a negative number in CompoundGlyph function. When reading additional glyphs of the compound glyph, glyph id is read using the following code.
this.glyphIDs.push(data.readShort());

Data.readShort() returns a number as signed integer. But according to the doc below, glyph IDs seems to be unsigned integer numbers.
https://docs.microsoft.com/en-us/typography/opentype/spec/glyf

Glyphs are referenced by identifiers (glyph IDs), which are sequential integers beginning at zero.

Assuming this is applicable in jsPDF logic, the glyph id needs to be handled as unsigned integer. Then the above logic would need to be like below?
this.glyphIDs.push(data.readUInt16());

With this change, the compound glyphs seems to be rendered as expected. Please find the expected result pdf in the attached zip file which is generated with this code change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions