Skip to content

Commit 0915ae7

Browse files
Merge branch 'main' into new-check-CPAL-brightness
2 parents c431b19 + 34b929a commit 0915ae7

6 files changed

Lines changed: 133 additions & 4 deletions

File tree

ā€ŽCHANGELOG.mdā€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ Below are the most important changes from each release.
22
A more detailed list of changes is available in the corresponding milestones for each release in the Github issue tracker (https://github.com/googlefonts/fontbakery/milestones?state=closed).
33

44

5-
## Upcoming release: 0.8.11 (2022-Sep-??)
5+
## Upcoming release: 0.8.11 (2022-Oct-??)
66
### New Checks
77
#### Added to the Google Fonts Profile
88
- **[com.google.fonts/check/colorfont_tables]:** Fonts must have neither or both the tables `COLR` and `SVG`. (issue #3886)
99
- **[com.google.fonts/check/description/noto_has_article]:** Noto fonts must have an ARTICLE.en_us.html file. (issue #3841)
10-
- **[com.google.fonts/check/color_cpal_brightness]:** Warn if COLRv0 layers are colored too dark or too bright instead of foreground color
10+
- **[com.google.fonts/check/color_cpal_brightness]:** Warn if COLRv0 layers are colored too dark or too bright instead of foreground color (PR #3908)
11+
- **[com.google.fonts/check/slant_direction]:** Check slant direction of outline to match values of slnt axis extrema. (PR #3910)
1112

1213
### BugFixes
1314
- **[com.adobe.fonts/check/varfont/valid_default_instance_nameids]:** The check did not account for nameID 17. (issue #3895)
14-
- **[com.google.fonts/check/colorfont_tables]:** Check for four-digit 'SVG ' table instead of 'SVG'
15+
- **[com.google.fonts/check/colorfont_tables]:** Check for four-digit 'SVG ' table instead of 'SVG' (PR #3903)
1516
- Added a `--timeout` parameter and set timeouts on all network requests. (PR #3892)
1617

1718
### Changes to existing checks

ā€ŽLib/fontbakery/profiles/googlefonts.pyā€Ž

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
'com.google.fonts/check/epar',
159159
'com.google.fonts/check/font_copyright',
160160
'com.google.fonts/check/italic_angle',
161+
'com.google.fonts/check/slant_direction',
161162
'com.google.fonts/check/has_ttfautohint_params',
162163
'com.google.fonts/check/name/version_format',
163164
'com.google.fonts/check/name/familyname_first_char',
@@ -3164,6 +3165,65 @@ def com_google_fonts_check_italic_angle(ttFont, style):
31643165
f' with style="{style}".')
31653166

31663167

3168+
@condition
3169+
def uharfbuzz_blob(font):
3170+
import uharfbuzz as hb
3171+
return hb.Blob.from_file_path(font)
3172+
3173+
3174+
@check(
3175+
id = 'com.google.fonts/check/slant_direction',
3176+
conditions = ['is_variable_font'],
3177+
rationale = """
3178+
The 'slnt' axis values are defined as negative values for a clockwise (right)
3179+
lean, and positive values for counter-clockwise lean. This is counter-intuitive
3180+
for many designers who are used to think of a positive slant as a lean to
3181+
the right.
3182+
3183+
This check ensures that the slant axis direction is consistent with the specs.
3184+
3185+
https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxistag_slnt
3186+
""",
3187+
proposal = 'https://github.com/googlefonts/fontbakery/pull/3910'
3188+
)
3189+
def com_google_fonts_check_slant_direction(ttFont, uharfbuzz_blob):
3190+
"""Checking direction of slnt axis angles"""
3191+
from fontbakery.utils import (axis,
3192+
PointsPen)
3193+
import uharfbuzz as hb
3194+
3195+
if not axis(ttFont, 'slnt'):
3196+
return PASS, "Font has no slnt axis"
3197+
3198+
hb_face = hb.Face(uharfbuzz_blob)
3199+
hb_font = hb.Font(hb_face)
3200+
buf = hb.Buffer()
3201+
buf.add_str("H")
3202+
features = {"kern": True,
3203+
"liga": True}
3204+
hb.shape(hb_font, buf, features)
3205+
3206+
def x_delta(slant):
3207+
"""
3208+
Return the x delta (difference of x position between highest and lowest point)
3209+
for the given slant value.
3210+
"""
3211+
hb_font.set_variations({"slnt": slant})
3212+
pen = PointsPen()
3213+
hb_font.draw_glyph_with_pen(buf.glyph_infos[0].codepoint, pen)
3214+
x_delta = pen.highestPoint()[0] - pen.lowestPoint()[0]
3215+
return x_delta
3216+
3217+
if x_delta(axis(ttFont, 'slnt').minValue) < x_delta(axis(ttFont, 'slnt').maxValue):
3218+
yield FAIL,\
3219+
Message("positive-value-for-clockwise-lean",
3220+
"The right-leaning glyphs have a positive 'slnt' axis value,"
3221+
" which is likely a mistake. It needs to be negative"
3222+
" to lean rightwards.")
3223+
else:
3224+
yield PASS, "Angle of 'slnt' axis looks good."
3225+
3226+
31673227
@check(
31683228
id = 'com.google.fonts/check/mac_style',
31693229
conditions = ['style'],

ā€ŽLib/fontbakery/utils.pyā€Ž

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,4 +653,59 @@ def iterate_lookup_list_with_extensions(ttFont, table, callback, *args):
653653
callback(lookup, *args)
654654

655655

656-
656+
def axis(ttFont, tag):
657+
"""Return the axis with the given tag."""
658+
for axis in ttFont["fvar"].axes:
659+
if axis.axisTag == tag:
660+
return axis
661+
662+
663+
from fontTools.pens.basePen import BasePen
664+
class PointsPen(BasePen):
665+
def __init__(self):
666+
super().__init__()
667+
self.points = []
668+
669+
def _moveTo(self, pt):
670+
self.points.append(pt)
671+
672+
def _lineTo(self, pt):
673+
self.points.append(pt)
674+
675+
def _curveToOne(self, pt1, pt2, pt3):
676+
self.points.append(pt1)
677+
self.points.append(pt2)
678+
self.points.append(pt3)
679+
680+
def _qCurveToOne(self, pt1, pt2):
681+
self.points.append(pt1)
682+
self.points.append(pt2)
683+
684+
def _closePath(self):
685+
pass
686+
687+
def _endPath(self):
688+
self.points = []
689+
self.beginPath()
690+
691+
def getPoints(self):
692+
return self.points
693+
694+
def highestPoint(self):
695+
highest = None
696+
for p in self.points:
697+
if (highest is None
698+
or p[1] > highest[1]): # pylint: disable=unsubscriptable-object
699+
highest = p
700+
return highest
701+
702+
def lowestPoint(self):
703+
lowest = None
704+
for p in self.points:
705+
if (lowest is None
706+
or p[1] < lowest[1]): # pylint: disable=unsubscriptable-object
707+
lowest = p
708+
return lowest
709+
710+
def _addComponent(self, glyphName, transformation):
711+
self.glyphSet[glyphName].draw(self)
680 KB
Binary file not shown.
688 KB
Binary file not shown.

ā€Žtests/profiles/googlefonts_test.pyā€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,6 +2298,19 @@ def test_check_italic_angle():
22982298
f'with italic-angle:{value} style:{style}...')
22992299

23002300

2301+
def test_check_slant_direction():
2302+
"""Checking direction of slnt axis angles"""
2303+
check = CheckTester(googlefonts_profile,
2304+
"com.google.fonts/check/slant_direction")
2305+
2306+
font = TEST_FILE("slant_direction/Cairo_correct_slnt_axis.ttf")
2307+
assert_PASS(check(font))
2308+
2309+
font = TEST_FILE("slant_direction/Cairo_wrong_slnt_axis.ttf")
2310+
assert_results_contain(check(font),
2311+
FAIL, 'positive-value-for-clockwise-lean')
2312+
2313+
23012314
def test_check_mac_style():
23022315
""" Checking head.macStyle value. """
23032316
check = CheckTester(googlefonts_profile,

0 commit comments

Comments
Ā (0)
⚔