Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN is given to glyph.advanceWidth in parseCFFCharstring #397

Open
aihornmac opened this issue Jul 23, 2019 · 1 comment
Open

NaN is given to glyph.advanceWidth in parseCFFCharstring #397

aihornmac opened this issue Jul 23, 2019 · 1 comment
Assignees
Labels

Comments

@aihornmac
Copy link

aihornmac commented Jul 23, 2019

this line of code override previous value (say 377 for a specific case) to NaN

Expected Behavior

Skip if it is NaN and give previous value default value

Current Behavior

Write NaN anyway

Possible Solution

Maybe sth like this?

if (!Number.isNaN(width)) {
    glyph.advanceWidth = width
}
if (Number.isNaN(glyph.advanceWidth)) {
    glyph.advanceWidth = fonts.unitsPerEm
}

Steps to Reproduce (for bugs)

  1. Extract SourceHanSansK from SourceHanSans.ttc
  2. Make a subset like
export function makeSubFont(font: opentype.Font, content: string) {
  return new opentype.Font({
    familyName: font.names.fontFamily.en,
    styleName: font.names.fontSubfamily.en,
    unitsPerEm: font.unitsPerEm,
    ascender: font.ascender,
    descender: font.descender,
    glyphs: font.stringToGlyphs(Array.from(new Set(content.split(''))).join('')),
  })
}
  1. save the subset to a local file
  2. parse from local file. If you read advanceWidth from glyph at this stage, it is correct.
  3. getPath and advanceWidth becomes NaN

FYI:
An example of the content used in step 2 is 上与乡互他伊作全公制前包单司客工布带开括旅晓朗机村棒游环球的相着离程管糖网罕联至蕾视足踏迹遍频颗高︐︒﹁﹂

Context

Your Environment

  • Version used: both 0.11.0 and 1.1.0
  • Font used: SourceHanSansK.otf
  • Browser Name and version: node v10.12.0
  • Operating System and version (desktop or mobile): OSX10.14.5 (18F132)
  • Link to your project:

SourceHanSans-Regular.otf.zip

@aihornmac
Copy link
Author

It seems to be lack of 0 glyph. I changed the makeSubFont function to this, and the problem disappears.

export function makeSubFont(font: opentype.Font, content: string) {
  const glyphs = font.stringToGlyphs(Array.from(new Set(content.split(''))).join(''))
  glyphs.unshift(font.glyphs.get(0))
  return new opentype.Font({
    familyName: font.names.fontFamily.en,
    styleName: font.names.fontSubfamily.en,
    unitsPerEm: font.unitsPerEm,
    ascender: font.ascender,
    descender: font.descender,
    glyphs,
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants