Skip to content

Commit

Permalink
Merge pull request #193 from googlefonts/location-base-issue-191
Browse files Browse the repository at this point in the history
Add support for glyph source locationBase field
  • Loading branch information
justvanrossum authored Jul 24, 2024
2 parents d88b8a3 + 3d4050b commit ee023e8
Show file tree
Hide file tree
Showing 14 changed files with 746 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/fontra_rcjk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def buildVariableGlyphFromLayerGlyphs(layerGlyphs, fontAxes) -> VariableGlyph:
sources = [
GlyphSource(
name="<default>",
locationBase=defaultGlyph.lib.get("robocjk.locationBase"),
layerName="foreground",
customData={FONTRA_STATUS_KEY: defaultGlyph.lib.get("robocjk.status", 0)},
)
Expand Down Expand Up @@ -209,13 +210,15 @@ def buildVariableGlyphFromLayerGlyphs(layerGlyphs, fontAxes) -> VariableGlyph:
if components:
layerGlyph.components += components

locationBase = varDict.get("locationBase")
location = varDict["location"]
location = {
k: float(v) if isinstance(v, str) else v for k, v in location.items()
}
sources.append(
GlyphSource(
name=sourceName,
locationBase=locationBase,
location=location,
layerName=fontraLayerNameMapping.get(layerName, layerName),
inactive=inactiveFlag,
Expand Down Expand Up @@ -362,6 +365,10 @@ def buildLayerGlyphsFromVariableGlyph(
devStatus = source.customData.get(FONTRA_STATUS_KEY, 0)
if source.layerName == defaultLayerName:
defaultGlyph.lib["robocjk.status"] = devStatus
if source.locationBase is not None:
defaultGlyph.lib["robocjk.locationBase"] = source.locationBase
else:
defaultGlyph.lib.pop("robocjk.locationBase", None)
# This is the default glyph, we don't treat it like a layer in .rcjk
continue

Expand All @@ -372,9 +379,13 @@ def buildLayerGlyphsFromVariableGlyph(
"location": source.location,
"status": devStatus,
}

if layerGlyph.width != defaultGlyph.width:
varDict["width"] = layerGlyph.width

if source.locationBase is not None:
varDict["locationBase"] = source.locationBase

deepComponents = buildLibComponentsFromVariableComponents(
layerGlyph.variableComponents
)
Expand Down
97 changes: 97 additions & 0 deletions tests/data/MutatorSansLocationBase.rcjk/characterGlyph/A_.glif
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="A" format="2">
<advance width="396"/>
<unicode hex="0041"/>
<unicode hex="0061"/>
<outline>
<contour>
<point x="20" y="0" type="line"/>
<point x="60" y="0" type="line"/>
<point x="200" y="700" type="line"/>
<point x="165" y="700" type="line"/>
</contour>
<contour>
<point x="75" y="164" type="line"/>
<point x="325" y="164" type="line"/>
<point x="325" y="200" type="line"/>
<point x="75" y="200" type="line"/>
</contour>
<contour>
<point x="332" y="0" type="line"/>
<point x="376" y="0" type="line"/>
<point x="231" y="700" type="line"/>
<point x="192" y="700" type="line"/>
</contour>
<contour>
<point x="175" y="661" type="line"/>
<point x="222" y="661" type="line"/>
<point x="222" y="700" type="line"/>
<point x="175" y="700" type="line"/>
</contour>
</outline>
<lib>
<dict>
<key>robocjk.locationBase</key>
<string>5bea6334</string>
<key>robocjk.status</key>
<integer>0</integer>
<key>robocjk.variationGlyphs</key>
<array>
<dict>
<key>fontraLayerName</key>
<string>MutatorSansBoldCondensed/foreground</string>
<key>layerName</key>
<string>MutatorSansBoldCondensed_foreground.db3714ad9ac4</string>
<key>location</key>
<dict/>
<key>locationBase</key>
<string>f22d1bbd</string>
<key>on</key>
<true/>
<key>sourceName</key>
<string>BoldCondensed</string>
<key>status</key>
<integer>0</integer>
<key>width</key>
<integer>740</integer>
</dict>
<dict>
<key>fontraLayerName</key>
<string>MutatorSansLightWide/foreground</string>
<key>layerName</key>
<string>MutatorSansLightWide_foreground.8bb25a79b80b</string>
<key>location</key>
<dict/>
<key>locationBase</key>
<string>d7abd222</string>
<key>on</key>
<true/>
<key>sourceName</key>
<string>LightWide</string>
<key>status</key>
<integer>0</integer>
<key>width</key>
<integer>1190</integer>
</dict>
<dict>
<key>fontraLayerName</key>
<string>MutatorSansBoldWide/foreground</string>
<key>layerName</key>
<string>MutatorSansBoldWide_foreground.53eb9954912f</string>
<key>location</key>
<dict/>
<key>locationBase</key>
<string>5d4e7f1d</string>
<key>on</key>
<true/>
<key>sourceName</key>
<string>BoldWide</string>
<key>status</key>
<integer>0</integer>
<key>width</key>
<integer>1290</integer>
</dict>
</array>
</dict>
</lib>
</glyph>
133 changes: 133 additions & 0 deletions tests/data/MutatorSansLocationBase.rcjk/characterGlyph/B_.glif
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="B" format="2">
<advance width="443"/>
<unicode hex="0042"/>
<unicode hex="0062"/>
<outline>
<contour>
<point x="60" y="0" type="line"/>
<point x="100" y="0" type="line"/>
<point x="100" y="700" type="line"/>
<point x="60" y="700" type="line"/>
</contour>
<contour>
<point x="80" y="333" type="line"/>
<point x="210" y="333" type="line" smooth="yes"/>
<point x="315" y="333"/>
<point x="364" y="269"/>
<point x="364" y="183" type="curve" smooth="yes"/>
<point x="364" y="93"/>
<point x="312" y="36"/>
<point x="200" y="36" type="curve" smooth="yes"/>
<point x="80" y="36" type="line"/>
<point x="80" y="0" type="line"/>
<point x="190" y="0" type="line" smooth="yes"/>
<point x="343" y="0"/>
<point x="403" y="79"/>
<point x="403" y="183" type="curve" smooth="yes"/>
<point x="403" y="273"/>
<point x="353" y="351"/>
<point x="233" y="361" type="curve"/>
<point x="253" y="350" type="line"/>
<point x="342" y="366"/>
<point x="383" y="439"/>
<point x="383" y="517" type="curve" smooth="yes"/>
<point x="383" y="618"/>
<point x="341" y="700"/>
<point x="180" y="700" type="curve" smooth="yes"/>
<point x="80" y="700" type="line"/>
<point x="80" y="664" type="line"/>
<point x="190" y="664" type="line" smooth="yes"/>
<point x="310" y="664"/>
<point x="344" y="603"/>
<point x="344" y="517" type="curve" smooth="yes"/>
<point x="344" y="431"/>
<point x="295" y="368"/>
<point x="190" y="368" type="curve" smooth="yes"/>
<point x="80" y="368" type="line"/>
</contour>
</outline>
<lib>
<dict>
<key>robocjk.locationBase</key>
<string>5bea6334</string>
<key>robocjk.status</key>
<integer>0</integer>
<key>robocjk.variationGlyphs</key>
<array>
<dict>
<key>fontraLayerName</key>
<string>MutatorSansBoldCondensed/foreground</string>
<key>layerName</key>
<string>MutatorSansBoldCondensed_foreground.db3714ad9ac4</string>
<key>location</key>
<dict/>
<key>locationBase</key>
<string>f22d1bbd</string>
<key>on</key>
<true/>
<key>sourceName</key>
<string>BoldCondensed</string>
<key>status</key>
<integer>0</integer>
<key>width</key>
<integer>710</integer>
</dict>
<dict>
<key>fontraLayerName</key>
<string>MutatorSansLightWide/foreground</string>
<key>layerName</key>
<string>MutatorSansLightWide_foreground.8bb25a79b80b</string>
<key>location</key>
<dict/>
<key>locationBase</key>
<string>d7abd222</string>
<key>on</key>
<true/>
<key>sourceName</key>
<string>LightWide</string>
<key>status</key>
<integer>0</integer>
<key>width</key>
<integer>1173</integer>
</dict>
<dict>
<key>fontraLayerName</key>
<string>MutatorSansBoldWide/foreground</string>
<key>layerName</key>
<string>MutatorSansBoldWide_foreground.53eb9954912f</string>
<key>location</key>
<dict/>
<key>locationBase</key>
<string>5d4e7f1d</string>
<key>on</key>
<true/>
<key>sourceName</key>
<string>BoldWide</string>
<key>status</key>
<integer>0</integer>
<key>width</key>
<integer>1270</integer>
</dict>
<dict>
<key>fontraLayerName</key>
<string>MutatorSansLightCondensed/support.crossbar</string>
<key>layerName</key>
<string>MutatorSansLightCondensed_support.cro.1347e01e146b</string>
<key>location</key>
<dict/>
<key>locationBase</key>
<string>3aa9223b</string>
<key>on</key>
<true/>
<key>sourceName</key>
<string>support.crossbar</string>
<key>status</key>
<integer>0</integer>
<key>width</key>
<integer>645</integer>
</dict>
</array>
</dict>
</lib>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="A" format="2">
<advance width="740"/>
<unicode hex="0041"/>
<unicode hex="0061"/>
<outline>
<contour>
<point x="-10" y="0" type="line"/>
<point x="250" y="0" type="line"/>
<point x="334" y="800" type="line"/>
<point x="104" y="800" type="line"/>
</contour>
<contour>
<point x="110" y="120" type="line"/>
<point x="580" y="120" type="line"/>
<point x="580" y="330" type="line"/>
<point x="110" y="330" type="line"/>
</contour>
<contour>
<point x="390" y="0" type="line"/>
<point x="730" y="0" type="line"/>
<point x="614" y="800" type="line"/>
<point x="294" y="800" type="line"/>
</contour>
<contour>
<point x="204" y="540" type="line"/>
<point x="474" y="540" type="line"/>
<point x="474" y="800" type="line"/>
<point x="204" y="800" type="line"/>
</contour>
</outline>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="B" format="2">
<advance width="710"/>
<unicode hex="0042"/>
<unicode hex="0062"/>
<outline>
<contour>
<point x="30" y="0" type="line"/>
<point x="340" y="0" type="line"/>
<point x="340" y="800" type="line"/>
<point x="30" y="800" type="line"/>
</contour>
<contour>
<point x="280" y="347" type="line"/>
<point x="345" y="347" type="line" smooth="yes"/>
<point x="374" y="347"/>
<point x="397" y="340"/>
<point x="397" y="292" type="curve" smooth="yes"/>
<point x="397" y="249"/>
<point x="374" y="238"/>
<point x="345" y="238" type="curve" smooth="yes"/>
<point x="280" y="238" type="line"/>
<point x="280" y="0" type="line"/>
<point x="396" y="0" type="line" smooth="yes"/>
<point x="651" y="0"/>
<point x="700" y="94"/>
<point x="700" y="230" type="curve" smooth="yes"/>
<point x="700" y="356"/>
<point x="645" y="417"/>
<point x="551" y="434" type="curve"/>
<point x="541" y="377" type="line"/>
<point x="618" y="392"/>
<point x="690" y="444"/>
<point x="690" y="563" type="curve" smooth="yes"/>
<point x="690" y="711"/>
<point x="621" y="800"/>
<point x="385" y="800" type="curve" smooth="yes"/>
<point x="280" y="800" type="line"/>
<point x="280" y="574" type="line"/>
<point x="345" y="574" type="line" smooth="yes"/>
<point x="374" y="574"/>
<point x="397" y="564"/>
<point x="397" y="523" type="curve" smooth="yes"/>
<point x="397" y="475"/>
<point x="374" y="470"/>
<point x="345" y="470" type="curve" smooth="yes"/>
<point x="280" y="470" type="line"/>
</contour>
</outline>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="A" format="2">
<advance width="1290"/>
<unicode hex="0041"/>
<unicode hex="0061"/>
<outline>
<contour>
<point x="20" y="0" type="line"/>
<point x="350" y="0" type="line"/>
<point x="640" y="800" type="line"/>
<point x="360" y="800" type="line"/>
</contour>
<contour>
<point x="210" y="120" type="line"/>
<point x="940" y="120" type="line"/>
<point x="940" y="340" type="line"/>
<point x="210" y="340" type="line"/>
</contour>
<contour>
<point x="800" y="0" type="line"/>
<point x="1270" y="0" type="line"/>
<point x="930" y="800" type="line"/>
<point x="480" y="800" type="line"/>
</contour>
<contour>
<point x="410" y="540" type="line"/>
<point x="830" y="540" type="line"/>
<point x="830" y="800" type="line"/>
<point x="410" y="800" type="line"/>
</contour>
</outline>
</glyph>
Loading

0 comments on commit ee023e8

Please sign in to comment.