|
158 | 158 | 'com.google.fonts/check/epar', |
159 | 159 | 'com.google.fonts/check/font_copyright', |
160 | 160 | 'com.google.fonts/check/italic_angle', |
| 161 | + 'com.google.fonts/check/slant_direction', |
161 | 162 | 'com.google.fonts/check/has_ttfautohint_params', |
162 | 163 | 'com.google.fonts/check/name/version_format', |
163 | 164 | 'com.google.fonts/check/name/familyname_first_char', |
@@ -3164,6 +3165,65 @@ def com_google_fonts_check_italic_angle(ttFont, style): |
3164 | 3165 | f' with style="{style}".') |
3165 | 3166 |
|
3166 | 3167 |
|
| 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 | + |
3167 | 3227 | @check( |
3168 | 3228 | id = 'com.google.fonts/check/mac_style', |
3169 | 3229 | conditions = ['style'], |
|
0 commit comments