File: build_font

package info (click to toggle)
fonts-junicode 2.211%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 104,448 kB
  • sloc: python: 304; sh: 236; xml: 18; makefile: 16
file content (230 lines) | stat: -rwxr-xr-x 5,073 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash

# This script is for building the Junicode font, version 2. It will not work
# for Junicode 1 or other fonts.

# For this script to work properly for all flavors of the font, these
# tools are needed:
#
# glyphspkg (Python -- install with pip)
# xsltproc (probably already installed on Mac or Linux)
# fontmake (and dependencies -- Python -- install with pip)
# ttfautohint (for static truetype)
# psautohint (for static otf -- Python -- install with pip)
# xgridfit (for variable and static truetype -- Python -- install with pip)

delete_tmp () {
  if [ ! -z "$tmp_d" ]
  then
    echo "Deleting temporary file ${tmp_d}."
    rm -fr $tmp_d
  fi
}

HOMEDIR=`pwd`

SOURCEDIR=$HOMEDIR/

DESTDIR=$HOMEDIR/dist/

BUILDDIR=$HOMEDIR/build/

outputtype="ttf"

instanceparam="-i"

gvarparam=""

hinting=true

generateufo=true

# cffoptions="--no-subroutinize"
cffoptions=""

xslfile="fix_wdth_axis.xsl"

fontstyle="roman"

fontbasename="Junicode"

while getopts "nusird:o:b:" options; do
  case "${options}" in
    n)
      hinting=false
      ;;
    u)
      generateufo=false
      ;;
    s)
      xslfile="fix_wdth_axis-shorter.xsl"
      ;;
    r)
      fontstyle="roman"
      ;;
    i)
      fontstyle="italic"
      ;;
    d)
      SOURCEDIR=${OPTARG}
      ;;
    o)
      DESTDIR=${OPTARG}
      ;;
    b)
      BUILDDIR=${OPTARG}
      ;;
    esac
  done

if [ $(( $# - $OPTIND )) -eq 0 ]
then
  outputtype=${@:$OPTIND:1}
fi

if [ $outputtype == "variable" ]
then
  fontbasename=${fontbasename}VF
  # gvarparam="--no-optimize-gvar"
fi

if [[ $outputtype == "otf" && $hinting == false ]]
then
    cffoptions=""
fi

if [ $fontstyle == "italic" ]
then
  glyphsfilename="Junicode-Italic"
  fontbasename=${fontbasename}-Italic
else
  glyphsfilename="Junicode-width"
  fontbasename=${fontbasename}-Roman
fi
glyphspackage=${glyphsfilename}.glyphspackage
glyphsfile=${glyphsfilename}.glyphs

if [ $generateufo == true ]
then
  rm -rf $BUILDDIR
  mkdir -p $BUILDDIR
else
  [ ! -d $BUILDDIR ] && mkdir -p $BUILDDIR
fi
[ ! -d $DESTDIR ] && mkdir $DESTDIR
cd $BUILDDIR

glyphspkg -o $BUILDDIR $SOURCEDIR$glyphspackage/

if [ $outputtype == "variable" ]
then
  instanceparam=""
  tmp_d=$(mktemp -d)
  tmp_f=$tmp_d/$glyphsfile
  echo "Saving temporary file ${tmp_f}."
  sed -e 's/familyName *= *Junicode;/familyName = "Junicode VF";/' $glyphsfile > $tmp_f
  glyphsfile=$tmp_f
fi

if [ "$generateufo" = true ]
then
  echo "Generating UFOs and designspace file from Glyphs source."
  glyphs2ufo --propagate-anchors --no-preserve-glyphsapp-metadata --generate-GDEF \
    --output-dir $BUILDDIR --designspace-path ${BUILDDIR}/${glyphsfilename}.designspace \
    --write-public-skip-export-glyphs $glyphsfile
  if [ $? -ne 0 ]
  then
    echo "glyphs2ufo failed"
    delete_tmp
    exit 1
  fi
  echo "Cleaning up designspace file"
  xsltproc -o ${glyphsfilename}-fixed.designspace $SOURCEDIR$xslfile ${glyphsfilename}.designspace
  if [ $? -ne 0 ]
  then
   echo "xsltproc failed"
   delete_tmp
   exit 1
  fi
fi

echo "building font(s)"
#fontmake -o $outputtype $instanceparam $gvarparam -m ${glyphsfilename}-fixed.designspace
fontmake -m ${glyphsfilename}-fixed.designspace -o $outputtype $instanceparam $gvarparam $cffoptions
if [ $? -ne 0 ]
then
 echo "fontmake failed"
 delete_tmp
 exit 1
fi

if [ $outputtype == "ttf" ]
then
  cd instance_ttf
  for f in Jun*.ttf; do python ${SOURCEDIR}code_pages.py $f; done
  if [ $hinting == true ]
  then
    mkdir hinted
    for f in Jun*.ttf; do echo "Hinting ${f}"; ttfautohint $f hinted/$f; done
    cd hinted
    for f in Jun*.ttf; do python ${SOURCEDIR}rmfleuroninstructions.py $f; done
    mkdir fixed
    for f in Jun*.ttf;
    do
      echo "Adding hints to ${f}."
      ff="$(basename -- $f)"
      fff="${ff%.*}"
      xgridfit -q -m -i $f -o fixed/$f ${SOURCEDIR}xgf/$fff.xgf
    done
    cp fixed/Jun*.ttf $DESTDIR
  else
    cp Jun*.ttf ${DESTDIR}
  fi
  cd $HOMEDIR
fi

if [ $outputtype == "otf" ]
then
  cd instance_otf
  for f in Jun*.otf; do python ${SOURCEDIR}code_pages.py $f; done
  if [ $hinting == true ]
  then
    mkdir hinted
    for f in Jun*.otf; do
      psautohint -x `cat ${SOURCEDIR}no_hint_list` -o hinted/$f $f
      cffsubr -i hinted/$f
    done
    mv hinted/Jun*.otf ${DESTDIR}
  else
    mv Jun*.otf ${DESTDIR}
  fi
  cd $HOMEDIR
fi

if [ $outputtype == "variable" ]
then
  python ${SOURCEDIR}mkstat.py variable_ttf/${glyphsfilename}-fixed-VF.ttf ${fontbasename}.ttf
  # cp variable_ttf/${glyphsfilename}-fixed-VF.ttf ${fontbasename}.ttf
  python ${SOURCEDIR}code_pages.py ${fontbasename}.ttf
  if [ $hinting == true ]
  then
    echo "Compiling hints..."
    y_file=${SOURCEDIR}xgf/${fontbasename}.yaml
    echo $y_file
    xgridfit -q -i ${fontbasename}.ttf -o ${fontbasename}-hinted.ttf ${SOURCEDIR}xgf/${fontbasename}.yaml
    if [ $? -eq 0 ]
    then
      cp ${fontbasename}-hinted.ttf ${DESTDIR}${fontbasename}.ttf
    else
      echo "Hinting failed."
      cp ${fontbasename}.ttf ${DESTDIR}
    fi
  else
    cp ${fontbasename}.ttf ${DESTDIR}
  fi
  cd $HOMEDIR
fi

delete_tmp

exit 0