A glyph is described by a path. A path is described by a collection of Bezier curves. A Bezier curve is described by a collection of control points. These control points are conceptually the same as vector offsets from a glyph origin. Note that this local coordinate system is not affected by any shaping that a complex text system performs.

Similarly, glyphs also have a nominal advance associated with them, which is also unaffected by shaping. This advance is a vector relative to the same glyph origin point.

Enter shaping. Shaping is a process where a complex text system can insert glyphs, delete glyphs, replace glyphs, replace sequences of glyphs with other sequences, and, importantly, move glyphs around. In particular, there are two flavors of “moving glyphs around:”

- Modifying the advance of a glyph, which changes placement of all subsequent glyphs in the line
- Modifying the origin of a glyph, which change the placement of a single glyph but not any subsequent glyphs.

- The glyph’s “base advance” (Note that this is different from the nominal advance described earlier, in that shaping has modified the nominal one to create this one)
- The glyph’s “origin” which is simply a delta from the original pen location which describes where this glyph should be drawn.

Note that when laying out glyphs this way, the glyphs are laid out such that their base advances are laid tail-to-head. These base advances then get you an original pen location for that glyph, and all subsequent vectors are relative to that original pen location.

We can then use this information to describe how to answer questions regarding the text.

If we want to know where to draw each glyph, then that is the green dots.

If we want to know where to place the caret between two glyphs, that is the average of

- The tip of the left glyph’s blue arrow (Note that this seems to be in the middle of the above “G” but that is just because the diagram is not to scale)
- The right glyph’s red dot

If we want to know the width of a particular string of text, that is just the tip of the rightmost glyph’s red arrow.

That’s pretty good, but there is one caveat. Most text systems only give you:

- The locations of the green dots (Usually in the form of either the positions of them, or delta vectors from one to the next), and
- The nominal glyph advances (blue arrows)

## No comments:

## Post a Comment