mirror of
https://github.com/weiweihuanghuang/Work-Sans.git
synced 2024-11-25 09:24:09 +03:00
Added xsl for parsing TTXs to replace brace glyphs from Glyphs App generated GX fonts
This commit is contained in:
parent
bed547722b
commit
0819698489
@ -1,9 +1,12 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
### WIP macOS build script for Work Sans Upright and Italic VF, based on a build script by Mike LaGuttuta
|
||||
# To add brace trick glyphs, define them in $BraceGlyphs variable, and save the source VF in the same folder as the script
|
||||
|
||||
# Setting the Source and VF name, determine if it's for Italic or Upright source from the argument passed to this script
|
||||
|
||||
glyphsSource="WorkSans-build.glyphs"
|
||||
glyphsSource="WorkSans.glyphs"
|
||||
VFname="WorkSans-VF"
|
||||
GXname="WorkSansGX"
|
||||
|
||||
@ -13,18 +16,21 @@ if [ "$1" == "Upright" ]; then
|
||||
elif [ "$1" == "Italic" ]; then
|
||||
BraceGlyphs="ae,e,s"
|
||||
# Italic
|
||||
glyphsSource=${glyphsSource/"-build.glyphs"/"-Italic-build.glyphs"}
|
||||
glyphsSource=${glyphsSource/".glyphs"/"-Italic.glyphs"}
|
||||
VFname=${VFname/"-VF"/"-Italic-VF"}
|
||||
GXname=${GXname/"GX"/"ItalicGX"}
|
||||
fi
|
||||
|
||||
python tools/makeGlyphsFileWithExportingBracketGlyphs.py "${glyphsSource}" "$1"
|
||||
glyphsBuildSource=${glyphsSource/".glyphs"/"-build.glyphs"}
|
||||
|
||||
# Call fontmake to generate variable font
|
||||
fontmake -o variable -g $glyphsSource
|
||||
fontmake -o variable -g $glyphsBuildSource
|
||||
echo "${VFname}.ttf generated"
|
||||
|
||||
# Clean up files
|
||||
mv variable_ttf/${VFname}.ttf ${VFname}.ttf
|
||||
|
||||
rm $glyphsBuildSource
|
||||
rm -rf master_ufo
|
||||
rm -rf instance_ufo
|
||||
rm -rf variable_ttf
|
||||
|
@ -7,5 +7,4 @@ for i in *.glyphs; do
|
||||
style="Upright"
|
||||
fi
|
||||
python tools/makeGlyphsFileWithOnlyBraceGlyphs.py "$i" "$style"
|
||||
python tools/makeGlyphsFileWithExportingBracketGlyphs.py "$i" "$style"
|
||||
done
|
81
sources/tools/replaceBraceGlyphs.xsl
Executable file
81
sources/tools/replaceBraceGlyphs.xsl
Executable file
@ -0,0 +1,81 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Transform a ttFont file Target.ttx by replacing some glyphs
|
||||
with copies from Source.ttx. If replacenames is not empty,
|
||||
then replace only glyphs whose name is in replacenames
|
||||
(and is in both Target.ttx and Source.ttx).
|
||||
Replacing a glyph replaces the whole TTGlyph element
|
||||
and/or the whole glyphVariations element.
|
||||
|
||||
author: grammal at freelancer.com
|
||||
-->
|
||||
<xsl:transform version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<!-- File to transform is a ttFont ttx xml document -->
|
||||
|
||||
<!-- replacements: source of replacement glyphs (filepath to ttx xml) -->
|
||||
<xsl:param name="replacements"/>
|
||||
|
||||
<!-- replacenames: glyphs to replace (comma separated string without space)-->
|
||||
<xsl:param name="replacenames"/>
|
||||
|
||||
<xsl:variable name="replacementsDoc" select="document($replacements)"/>
|
||||
<xsl:variable name="replacementsGlyf" select="$replacementsDoc/ttFont/glyf"/>
|
||||
<xsl:variable name="replacementsGvar" select="$replacementsDoc/ttFont/gvar"/>
|
||||
<xsl:variable name="replacenamesBookended" select="concat(',',$replacenames,',')"/>
|
||||
|
||||
<!--
|
||||
Replace TTGlpyph with a copy from replacements,
|
||||
if replacenames is empty or TTYGlyph name is in replacenames.
|
||||
Otherwise copy the existing TTGlyph from the target file.
|
||||
(Log if replaced, or if name matches but not found in replacements.)
|
||||
-->
|
||||
<xsl:template match="TTGlyph">
|
||||
<xsl:variable name="name" select="@name"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="(not($replacenames) or string-length($replacenames)=0 or
|
||||
contains($replacenamesBookended, concat(',',$name,',')))
|
||||
and $replacementsGlyf/TTGlyph[@name=$name]">
|
||||
<xsl:copy-of select="$replacementsGlyf/TTGlyph[@name=$name]"/>
|
||||
<xsl:message><TTYGlyph name="<xsl:value-of select="$name"/>"> replaced</xsl:message>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:copy-of select="."/>
|
||||
<xsl:if test="contains($replacenamesBookended, concat(',',$name,','))">
|
||||
<xsl:message><TTYGlyph name="<xsl:value-of select="$name"/>"> not in <xsl:value-of select="$replacements"/></xsl:message>
|
||||
</xsl:if>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<!--
|
||||
Replace glyphVariations with a copy from replacements,
|
||||
if replacenames is empty or glyphVariations glyph is in replacenames.
|
||||
Otherwise copy the existing glyphVariations from the target file.
|
||||
(Log if replaced, or if name matches but not found in replacements.)
|
||||
-->
|
||||
<xsl:template match="glyphVariations">
|
||||
<xsl:variable name="glyph" select="@glyph"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="(not($replacenames) or string-length($replacenames)=0 or
|
||||
contains($replacenamesBookended, concat(',',$glyph,',')))
|
||||
and $replacementsGvar/glyphVariations[@glyph=$glyph]">
|
||||
<xsl:copy-of select="$replacementsGvar/glyphVariations[@glyph=$glyph]"/>
|
||||
<xsl:message><glyphVariations name="<xsl:value-of select="$glyph"/>"> replaced</xsl:message>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:copy-of select="."/>
|
||||
<xsl:if test="contains($replacenamesBookended, concat(',',$glyph,','))">
|
||||
<xsl:message><glyphVariations name="<xsl:value-of select="$glyph"/>"> not in <xsl:value-of select="$replacements"/></xsl:message>
|
||||
</xsl:if>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="@*|node()|comment()">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="@*|node()"/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:transform>
|
@ -25,11 +25,11 @@ if style == "Upright":
|
||||
"peseta": "peseta.169_230",
|
||||
"uni20A9": "uni20A9.169_230"}),
|
||||
([{"wght": (0.564, 1)}], {"uni20B1": "uni20B1.136_230",
|
||||
"Adieresis.tf": "Adieresis.tf.136_230",
|
||||
"Udieresis.tf": "Udieresis.tf.136_230"}),
|
||||
"Adieresis.titl": "Adieresis.titl.136_230",
|
||||
"Udieresis.titl": "Udieresis.titl.136_230"}),
|
||||
([{"wght": (0.424, 1)}], {"uni2761": "uni2761.79_230",
|
||||
"paragraph": "paragraph.79_230",
|
||||
"Odieresis.tf": "Odieresis.tf.106_230"}),
|
||||
"Odieresis.titl": "Odieresis.titl.106_230"}),
|
||||
]
|
||||
elif style == "Italic":
|
||||
condSubst = [
|
||||
|
Loading…
Reference in New Issue
Block a user