[cantarell-fonts] Instantiator: properly(?) generate OS/2 width class
- From: Nikolaus Waxweiler <nwaxweiler src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cantarell-fonts] Instantiator: properly(?) generate OS/2 width class
- Date: Fri, 17 May 2019 23:24:32 +0000 (UTC)
commit 8c7e6e218826c3addedb98035be046ceb7d99d43
Author: Nikolaus Waxweiler <madigens gmail com>
Date: Sat May 18 00:23:53 2019 +0100
Instantiator: properly(?) generate OS/2 width class
scripts/instantiator.py | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/scripts/instantiator.py b/scripts/instantiator.py
index f5e9f485..73732273 100644
--- a/scripts/instantiator.py
+++ b/scripts/instantiator.py
@@ -34,6 +34,19 @@ Location = Mapping[str, float]
# to reduce differences between the variable and static instances.
fontMath.mathFunctions.setRoundIntegerFunction(fontTools.misc.fixedTools.otRound)
+# For mapping `wdth` axis user values to the OS2 table's width class field.
+WDTH_VALUE_TO_OS2_WIDTH_CLASS = {
+ 50: 1,
+ 62.5: 2,
+ 75: 3,
+ 87.5: 4,
+ 100: 5,
+ 112.5: 6,
+ 125: 7,
+ 150: 8,
+ 200: 9,
+}
+
@attr.s(auto_attribs=True, frozen=True, slots=True)
class Instantiator:
@@ -193,9 +206,13 @@ class Instantiator:
if "wdth" in self.weight_width_axes:
width_axis = self.weight_width_axes["wdth"]
width_axis_instance_location = instance.location[width_axis.name]
- font.info.openTypeOS2WidthClass = fontTools.misc.fixedTools.otRound(
- width_axis.map_backward(width_axis_instance_location)
+ width_value = width_axis.map_backward(width_axis_instance_location)
+ width_class = int(
+ varLib.models.piecewiseLinearMap(
+ width_value, WDTH_VALUE_TO_OS2_WIDTH_CLASS
+ )
)
+ font.info.openTypeOS2WidthClass = width_class
# Glyphs
for glyph_name, glyph_mutator in self.glyph_mutators.items():
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]