opentypejs / opentype.js

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

Differences between graphemes in case of diatrics #355

Open Mickael-van-der-Beek opened 6 years ago

Mickael-van-der-Beek commented 6 years ago

I am not a font specialist but my understanding of glyphs in OpenType is that they can be defined either as a standalone character or as a combinations of other glyphs (the components array attribute of the glyph).

Now in this case, I would expect for both to have the same path and bounding box.

My example uses Node.js 9.x, opentype.js 0.10.x on OSX and the font is "Menlo Regular" that can be found here: https://github.com/hbin/top-programming-fonts/blob/master/Menlo-Regular.ttf

e.g:

> const opentype = require('opentype.js');

> const font = opentype.loadSync('/Some/Path/Downloads/Menlo-Regular.ttf')

> font.charToGlyph('ў')
Glyph {
  index: 916,
  name: 'uni045E',
  unicode: 1118,
  unicodes: [ 1118 ],
  advanceWidth: 1233,
  components: 
   [ { glyphIndex: 651,
       xScale: 1,
       scale01: 0,
       scale10: 0,
       yScale: 1,
       dx: 0,
       dy: 0 },
     { glyphIndex: 92,
       xScale: 1,
       scale01: 0,
       scale10: 0,
       yScale: 1,
       dx: 0,
       dy: 0 } ] ... }

> font.stringToGlyphs('y\u0306')
[ Glyph {
    index: 92,
    name: 'y',
    unicode: 121,
    unicodes: [ 121 ],
    advanceWidth: 1233 ... },
  Glyph {
    index: 651,
    name: 'uni0306',
    unicode: 774,
    unicodes: [ 774 ],
    advanceWidth: 1233 ... } ]

Since the glyph at index 916 is defined as the sum of the glyphs at index 92 and 651, I would expect for both bounding boxes to be identical but that doesn't seem to be the case.

e.g:

> font.getPath('y\u0306', 0, 0, 12).getBoundingBox()
BoundingBox { x1: 0.609375, y1: -9.421875, x2: 12.673828125, y2: 2.49609375 }

> font.getPath('ў', 0, 0, 12).getBoundingBox()
BoundingBox { x1: 0.609375, y1: -9.421875, x2: 6.755859375, y2: 2.49609375 }

If we look at the path, they look to be identical besides the fact that the order of the diatric (\u0306) compared to the letter (y) is inverted. The user input string has the diatric after the letter but the "components" of the glyph has it before the letter.

e.g: https://www.diffchecker.com/gCdoMNrU

Is this a misconception by me or this considered to be a bug? Visually they seem identical so it seems weird for the paths Thanks in advance!

Jolg42 commented 6 years ago

Hi!

It looks like a bug but I won't be able to investigate more unfortunately.

Note: You can check the glyphs visually with the Glyph Inspector

Mickael-van-der-Beek commented 6 years ago

@Jolg42 Thanks for the quick reply. I'll try to find a different way then, thanks.