Skip to content

Commit

Permalink
[skrifa] cff: allow empty private dict and fix scaling
Browse files Browse the repository at this point in the history
We were erroneously rejecting a Private DICT with length 0. Also, the value `Fixed::ONE` was used as a sentinel for unscaled drawing but this value can be produced when upem is 512 and requested ppem is 8, resulting in incorrect scaling. Replaced the scale factor with an option to correct this.
  • Loading branch information
dfrg committed Oct 10, 2024
1 parent 1dbd698 commit 195e552
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 18 deletions.
3 changes: 3 additions & 0 deletions font-test-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub static AHEM: &[u8] = include_bytes!("../test_data/ttf/ahem.ttf");

pub static AVAR2_CHECKER: &[u8] = include_bytes!("../test_data/ttf/avar2checker.ttf");

pub static MATERIAL_ICONS_SUBSET: &[u8] =
include_bytes!("../test_data/ttf/material_icons_subset.ttf");

pub mod varc {
pub static CJK_6868: &[u8] = include_bytes!("../test_data/ttf/varc-6868.ttf");
pub static CONDITIONALS: &[u8] = include_bytes!("../test_data/ttf/varc-ac01-conditional.ttf");
Expand Down
10 changes: 10 additions & 0 deletions font-test-data/test_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ Describes the provenance, usage and generation procedures for font data used for
pyftsubset notoserif-regular.ttf --layout-features+=c2sc --no-hinting --text=Hfix
```

* _material_icons_subset_
* font: Google Material Icons Regular
* source: https://fonts.googleapis.com/icon?family=Material+Icons
* license: [Apache 2][Apache2]
* usage: testing empty Private DICT and scaling with upem=512, ppem=8
* subset: just a single glyph to check scaling
```shell
pyftsubset material_icons.otf --gids=2
```

* _avar2checker_
* font: avar2 checker
* source: https://github.com/Lorp/fencer/tree/main/src/fonts
Expand Down
Binary file not shown.
256 changes: 256 additions & 0 deletions font-test-data/test_data/ttx/material_icons_subset.ttx
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="OTTO" ttLibVersion="4.41">

<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="_10k"/>
</GlyphOrder>

<head>
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="1.0"/>
<fontRevision value="1.0"/>
<checkSumAdjustment value="0xb5599c1c"/>
<magicNumber value="0x5f0f3cf5"/>
<flags value="00001000 00000011"/>
<unitsPerEm value="512"/>
<created value="Mon Jun 24 14:21:21 2024"/>
<modified value="Thu Oct 10 13:07:35 2024"/>
<xMin value="-1"/>
<yMin value="0"/>
<xMax value="513"/>
<yMax value="512"/>
<macStyle value="00000000 00000000"/>
<lowestRecPPEM value="3"/>
<fontDirectionHint value="2"/>
<indexToLocFormat value="0"/>
<glyphDataFormat value="0"/>
</head>

<hhea>
<tableVersion value="0x00010000"/>
<ascent value="512"/>
<descent value="0"/>
<lineGap value="0"/>
<advanceWidthMax value="512"/>
<minLeftSideBearing value="0"/>
<minRightSideBearing value="-1"/>
<xMaxExtent value="513"/>
<caretSlopeRise value="1"/>
<caretSlopeRun value="0"/>
<caretOffset value="0"/>
<reserved0 value="0"/>
<reserved1 value="0"/>
<reserved2 value="0"/>
<reserved3 value="0"/>
<metricDataFormat value="0"/>
<numberOfHMetrics value="1"/>
</hhea>

<maxp>
<tableVersion value="0x5000"/>
<numGlyphs value="2"/>
</maxp>

<OS_2>
<!-- The fields 'usFirstCharIndex' and 'usLastCharIndex'
will be recalculated by the compiler -->
<version value="4"/>
<xAvgCharWidth value="512"/>
<usWeightClass value="400"/>
<usWidthClass value="5"/>
<fsType value="00000000 00000000"/>
<ySubscriptXSize value="0"/>
<ySubscriptYSize value="0"/>
<ySubscriptXOffset value="0"/>
<ySubscriptYOffset value="0"/>
<ySuperscriptXSize value="0"/>
<ySuperscriptYSize value="0"/>
<ySuperscriptXOffset value="0"/>
<ySuperscriptYOffset value="0"/>
<yStrikeoutSize value="0"/>
<yStrikeoutPosition value="0"/>
<sFamilyClass value="0"/>
<panose>
<bFamilyType value="0"/>
<bSerifStyle value="0"/>
<bWeight value="0"/>
<bProportion value="0"/>
<bContrast value="0"/>
<bStrokeVariation value="0"/>
<bArmStyle value="0"/>
<bLetterForm value="0"/>
<bMidline value="0"/>
<bXHeight value="0"/>
</panose>
<ulUnicodeRange1 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange2 value="00010000 00000000 00000000 00000000"/>
<ulUnicodeRange3 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange4 value="00000000 00000000 00000000 00000000"/>
<achVendID value="????"/>
<fsSelection value="00000000 10000000"/>
<usFirstCharIndex value="59729"/>
<usLastCharIndex value="59729"/>
<sTypoAscender value="512"/>
<sTypoDescender value="0"/>
<sTypoLineGap value="0"/>
<usWinAscent value="512"/>
<usWinDescent value="0"/>
<ulCodePageRange1 value="00000000 00000000 00000000 00000000"/>
<ulCodePageRange2 value="00000000 00000000 00000000 00000000"/>
<sxHeight value="0"/>
<sCapHeight value="0"/>
<usDefaultChar value="0"/>
<usBreakChar value="32"/>
<usMaxContext value="0"/>
</OS_2>

<name>
<namerecord nameID="0" platformID="3" platEncID="1" langID="0x409">
Copyright 2019-2023 Google LLC. All Rights Reserved.
</namerecord>
<namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
Google Material Icons
</namerecord>
<namerecord nameID="2" platformID="3" platEncID="1" langID="0x409">
Regular
</namerecord>
<namerecord nameID="3" platformID="3" platEncID="1" langID="0x409">
Google Material Icons 2024-06-24T07:13:04.639094
</namerecord>
<namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
Google Material Icons Regular
</namerecord>
<namerecord nameID="5" platformID="3" platEncID="1" langID="0x409">
2024-06-24T07:13:04.639094
</namerecord>
<namerecord nameID="6" platformID="3" platEncID="1" langID="0x409">
GoogleMaterialIcons-Regular
</namerecord>
</name>

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
<map code="0xe951" name="_10k"/><!-- ???? -->
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0xe951" name="_10k"/><!-- ???? -->
</cmap_format_4>
</cmap>

<post>
<formatType value="3.0"/>
<italicAngle value="0.0"/>
<underlinePosition value="0"/>
<underlineThickness value="0"/>
<isFixedPitch value="0"/>
<minMemType42 value="0"/>
<maxMemType42 value="0"/>
<minMemType1 value="0"/>
<maxMemType1 value="0"/>
</post>

<CFF>
<major value="1"/>
<minor value="0"/>
<CFFFont name="GoogleMaterialIcons-Regular">
<FullName value="GoogleMaterialIcons-Regular"/>
<isFixedPitch value="0"/>
<ItalicAngle value="0"/>
<UnderlinePosition value="-100"/>
<UnderlineThickness value="50"/>
<PaintType value="0"/>
<CharstringType value="2"/>
<FontMatrix value="0.001953125 0 0 0.001953125 0 0"/>
<FontBBox value="-1 0 513 512"/>
<StrokeWidth value="0"/>
<!-- charset is dumped separately as the 'GlyphOrder' element -->
<Encoding name="StandardEncoding"/>
<Private>
<BlueScale value="0.039625"/>
<BlueShift value="7"/>
<BlueFuzz value="1"/>
<ForceBold value="0"/>
<LanguageGroup value="0"/>
<ExpansionFactor value="0.06"/>
<initialRandomSeed value="0"/>
<defaultWidthX value="0"/>
<nominalWidthX value="0"/>
</Private>
<CharStrings>
<CharString name=".notdef">
512 endchar
</CharString>
<CharString name="_10k">
512 405 448 rmoveto
-298 hlineto
-24 -19 -19 -24 hvcurveto
-298 vlineto
-24 19 -19 24 vhcurveto
298 hlineto
24 19 19 24 hvcurveto
298 vlineto
24 -19 19 -24 vhcurveto
-128 vmoveto
-213 -298 181 21 -96 32 128 -53 85 298 -85 vlineto
-74 -48 rmoveto
48 -32 -128 32 48 vlineto
37 -48 37 0 -48 64 48 64 -37 0 -37 -48 rlineto
-128 -80 rmoveto
53 hlineto
12 9 10 11 hvcurveto
86 vlineto
11 -9 10 -12 vhcurveto
-53 hlineto
-12 -10 -10 -11 hvcurveto
-86 vlineto
-11 10 -10 12 vhcurveto
10 96 rmoveto
32 -64 -32 64 hlineto
endchar
</CharString>
</CharStrings>
</CFFFont>

<GlobalSubrs>
<!-- The 'index' attribute is only for humans; it is ignored when parsed. -->
</GlobalSubrs>
</CFF>

<GSUB>
<Version value="0x00010000"/>
<ScriptList>
<!-- ScriptCount=2 -->
<ScriptRecord index="0">
<ScriptTag value="DFLT"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=0 -->
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
<ScriptRecord index="1">
<ScriptTag value="latn"/>
<Script>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
</ScriptList>
<FeatureList>
<!-- FeatureCount=0 -->
</FeatureList>
<LookupList>
<!-- LookupCount=0 -->
</LookupList>
</GSUB>

<hmtx>
<mtx name=".notdef" width="512" lsb="0"/>
<mtx name="_10k" width="512" lsb="0"/>
</hmtx>

</ttFont>
Loading

0 comments on commit 195e552

Please sign in to comment.