opentypejs / opentype.js

Read and write OpenType fonts using JavaScript.
https://opentype.js.org/
MIT License
4.46k stars 476 forks source link

Write OS/2 Table with sxHeight & sCapHeight #409

Closed signalwerk closed 4 years ago

signalwerk commented 4 years ago

When I do the following:

var test = new Font({
  familyName: "TestFont",
  styleName: "Bold",
  unitsPerEm: 2048,
  ascender: 1500,
  descender: -500,
  glyphs: [
    new Glyph({
      name: ".notdef",
      advanceWidth: 650,
      path: new Path()
    })
  ]
});

test.tables.os2 = {
  ...test.tables.os2,
  sxHeight: 1100,
  sCapHeight: 1400
};
test.download();

and convert then the font with Fonttools TTX I see the following (wrong) values:

<sxHeight value="750"/>
<sCapHeight value="0"/>

Is there a logic to it? Or what do I do wrong?

fizfaz commented 4 years ago

If I understand it correctly: the values for sxHeight and sCapHeight are calculated here: https://github.com/opentypejs/opentype.js/blob/342fac9e81a34ef08b69c5f08a0ec71727e0b832/src/tables/sfnt.js#L248-L249

and not settable. Does this help?

signalwerk commented 4 years ago

@fizfaz thanks a lot for pointing to the specific code! I Made a PR here: https://github.com/opentypejs/opentype.js/pull/410

Jolg42 commented 4 years ago

Thank you for opening the issue, I'm now closing it as the other PR was merged and published see https://github.com/opentypejs/opentype.js/pull/422

signalwerk commented 4 years ago

perfect! thank you!