googlefonts / how-to-hint-variable-fonts

A how-to guide to TrueType hinting variable fonts, with VTT
https://googlefonts.github.io/how-to-hint-variable-fonts
Apache License 2.0
38 stars 4 forks source link

How to write Custom Code #26

Open davelab6 opened 2 years ago

davelab6 commented 2 years ago

If the measured outline distance between the base glyph and the accent is the same across the variation space, this code can be used. If the accent distance measurement varies, custom code is needed.

I propose a few concrete examples of such code could be added, plus explanatory text giving ideas about how to think about writing code original custom code

mikedug commented 2 years ago

thanks Dave. I do go into more detail on this later in the document, explaining the new accent positioning code. The sample font also has this code in a selection of documented accents. I do not write a lot of custom code, I am not a programmer. This code was checked with GregH, and the discussion on it, is stored on the repository here

https://github.com/googlefonts/how-to-hint-variable-fonts/tree/main/ReferenceDocuments

Details on custom code for accents later in the document in the Positioning accents section Solution After the second OFFSET command, type the following code to ensure the following.

Position the accent correctly for both higher and lower resolutions Maintain white space between the base glyph and the accent, keeping the glyph open and readable at all sizes and for all of the variations in the font. SVTCA[Y]

CALL[], 0, 7, 114

MDRP[m>RWh], 38

IUP[Y]

IUP[X]

Compile the glyph program and save.

Y-Positioning code details

Note: Comments before each line describes the code.

Sets Vector to coordinate axis Y

SVTCA[ Y ]

This code emulates a ResYAnchor and a minimum distance.

0, is a point at the lowercase round overshoot height on the base composite glyph. Point 0, at the top round of the lowercase ‘e’.

7 is a reference to cvt 7, the lowercase round overshoot height cvt.

114 is the Function that is generated by the Res command to ensure the correct rounding is applied for different rendering environments

CALL[], 0, 7, 114

38 is the on-curve point on the bottom of the dot accent. This code moves the accent to be at least one pixel from the base glyph for all sizes, variations, and rendering environments, while also maintaining the correct outline distance for all variations.

MDRP[ m>RWh ], 38

Smooths out the rest of the outline points.

IUP[ Y ]

IUP[ X ]

Use this code technique for all other composite glyphs, changing the point and cvt references.

Note: All composites where the measured high resolution outline distance, in the y-direction, between the base glyph and the accent glyph, changes across the variation design space, should use this code technique to position accent correctly.

davelab6 commented 2 years ago

Great!

Also in chat you pointed out https://typedrawers.com/discussion/4270/vtt-zone-shift is related to this.

Seems this area of the docs could benefit from more detail, via a collaboration with you and Greg or someone like him :)