Skip to content

Instantly share code, notes, and snippets.

@geta6
Last active December 18, 2015 16:39
Show Gist options
  • Save geta6/5813281 to your computer and use it in GitHub Desktop.
Save geta6/5813281 to your computer and use it in GitHub Desktop.
Pragmataをベースに日本語空間にMigu-1Mを合成します
#!/bin/zsh
#########################
# PLUSMATA
#########################
VERSION=0.0.3
FONT_FAMILY=Plusmata
FONT_ASCENT=860
FONT_DESCENT=200
FONT_GENERATOR="Gen-Plus.pe"
ASCII_REGU_WIDTH=0
ASCII_BOLD_WIDTH=30
#########################
# SCRIPTING
#########################
FONTFORGE=fontforge
FONT_DIR="${HOME}/Library/Fonts"
GEN_PRAG="Gen-Prag.pe"
PRAG_REGU="PragmataPro.ttf"
PRAG_BOLD="PragmataPro-B.ttf"
PRAG_ITAL="PragmataPro-I.ttf"
MOD_PRAG_REGU="Mod-${PRAG_REGU}.sfd"
MOD_PRAG_BOLD="Mod-${PRAG_BOLD}.sfd"
MOD_PRAG_ITAL="Mod-${PRAG_ITAL}.sfd"
GEN_MIGU="Gen-Migu.pe"
MIGU_REGU="migu-1m-regular.ttf"
MIGU_BOLD="migu-1m-bold.ttf"
MIGU_ITAL="migu-1m-italic.ttf" # ok to not exists
MOD_MIGU_REGU="Mod-${MIGU_REGU}.sfd"
MOD_MIGU_BOLD="Mod-${MIGU_BOLD}.sfd"
MOD_MIGU_ITAL="Mod-${MIGU_ITAL}.sfd"
a
if ! which $FONTFORGE > /dev/null 2>&1; then
echo "Error: fontforge command not found" >&2
exit 1
else
FONTFORGE=`which $FONTFORGE`
fi
PRAG_REGU=`find $FONT_DIR -follow -name $PRAG_REGU | head -n 1`
[[ -z $PRAG_REGU ]] && echo "Error: Pragmata Regular not found" >&2 && exit 1
PRAG_BOLD=`find $FONT_DIR -follow -name $PRAG_BOLD | head -n 1`
[[ -z $PRAG_BOLD ]] && echo "Error: Pragmata Bold not found" >&2 && exit 1
PRAG_ITAL=`find $FONT_DIR -follow -name $PRAG_ITAL | head -n 1`
[[ -z $PRAG_ITAL ]] && echo "Error: Pragmata Italic not found" >&2 && exit 1
MIGU_REGU=`find $FONT_DIR -follow -name $MIGU_REGU | head -n 1`
[[ -z $MIGU_REGU ]] && echo "Error: Migu 1M Regulat not found" >&2 && exit 1
MIGU_BOLD=`find $FONT_DIR -follow -name $MIGU_BOLD | head -n 1`
[[ -z $MIGU_BOLD ]] && echo "Error: Migu 1M Bold not found" >&2 && exit 1
TMPDIR=`mktemp -d /tmp/plugmata.XXXXXX` || exit 2
trap "[[ -d \"$TMPDIR\" ]] && rm -rf $TMPDIR && echo 'Plusmata Generated!' && exit 3" HUP INT QUIT
trap "[[ -d \"$TMPDIR\" ]] && rm -rf $TMPDIR && echo 'Plusmata Generated!'" EXIT
#########################
# Gen PRAGMATA
#########################
cat > $TMPDIR/$GEN_PRAG << _EOL_
#!$FONTFORGE -script
src = ["$PRAG_REGU", "$PRAG_BOLD", "$PRAG_ITAL"]
dst = ["$MOD_PRAG_REGU", "$MOD_PRAG_BOLD", "$MOD_PRAG_ITAL"]
i = 0; while (i < SizeOf(src))
Print("Open " + src[i])
Open(src[i])
ScaleToEm(860, 140)
SelectWorthOutputting()
ClearInstrs(); UnlinkReference()
Save("$TMPDIR/" + dst[i])
Print("Save " + dst[i])
Close()
i += 1; endloop
Quit()
_EOL_
#########################
# Gen MIGU 1M
#########################
cat > $TMPDIR/$GEN_MIGU << _EOL_
#!$FONTFORGE -script
src = ["$MIGU_REGU", "$MIGU_BOLD"]
dst = ["$MOD_MIGU_REGU", "$MOD_MIGU_BOLD", "$MOD_MIGU_ITAL"]
i = 0; while (i < SizeOf(src))
Print("Open " + src[i])
Open(src[i])
ScaleToEm(860, 140)
SelectWorthOutputting()
ClearInstrs(); UnlinkReference()
SetWidth(-1, 1); Scale(91, 91, 0, 0); SetWidth(110, 2); SetWidth(1, 1)
Move(23, 0); SetWidth(-23, 1)
RoundToInt(); RemoveOverlap(); RoundToInt()
Save("$TMPDIR/" + dst[i])
Print("Save " + dst[i])
Close()
i += 1; endloop
Print("Open " + src[0])
Open(src[0])
ScaleToEm(860, 140)
SelectWorthOutputting()
ClearInstrs(); UnlinkReference()
Skew(12); SetWidth(-1, 1); Scale(91, 91, 0, 0); SetWidth(110, 2); SetWidth(1, 1)
Move(23, 0); SetWidth(-23, 1)
RoundToInt(); RemoveOverlap(); RoundToInt()
Save("$TMPDIR/" + dst[2])
Print("Save " + dst[2])
Close()
Quit()
_EOL_
#########################
# Gen PLUSMATA
#########################
cat > $TMPDIR/$FONT_GENERATOR << _EOL_
#!$FONTFORGE -script
src_p = ["$TMPDIR/$MOD_PRAG_REGU", "$TMPDIR/$MOD_PRAG_BOLD", "$TMPDIR/$MOD_PRAG_ITAL"]
src_m = ["$TMPDIR/$MOD_MIGU_REGU", "$TMPDIR/$MOD_MIGU_BOLD", "$TMPDIR/$MOD_MIGU_ITAL"]
styles = ["Regular", "Bold", "Italic"]
weight = [400, 700, 400]
panose = [5, 8, 5]
i = 0; while (i < SizeOf(styles))
New()
Reencode("unicode")
SetFontNames( \\
"$FONT_FAMILY-" + styles[i], \\
"$FONT_FAMILY", \\
"$FONT_FAMILY " + styles[i], \\
styles[i], "", "$VERSION" )
ScaleToEm(860, 140)
SetOS2Value("Weight", weight[i])
SetOS2Value("Width", 5)
SetOS2Value("FSType", 0)
SetOS2Value("VendorID", "PfEd")
SetOS2Value("IBMFamily", 2057)
SetOS2Value("WinAscentIsOffset", 0)
SetOS2Value("WinDescentIsOffset", 0)
SetOS2Value("TypoAscentIsOffset", 0)
SetOS2Value("TypoDescentIsOffset", 0)
SetOS2Value("HHeadAscentIsOffset", 0)
SetOS2Value("HHeadDescentIsOffset", 0)
SetOS2Value("WinAscent", $FONT_ASCENT)
SetOS2Value("WinDescent", $FONT_DESCENT)
SetOS2Value("TypoAscent", 860)
SetOS2Value("TypoDescent", -140)
SetOS2Value("TypoLineGap", 0)
SetOS2Value("HHeadAscent", $FONT_ASCENT)
SetOS2Value("HHeadDescent", -$FONT_DESCENT)
SetOS2Value("HHeadLineGap", 0)
SetPanose([2, 11, panose[i], 9, 2, 2, 3, 2, 2, 7])
Print("Merge " + src_p[i]:t + " + " + src_m[i]:t)
MergeFonts(src_p[i])
MergeFonts(src_m[i])
# zenkaku space
Select(0u2610); Copy(); Select(0u3000); Paste()
Select(0u271a); Copy(); Select(0u3000); PasteInto()
OverlapIntersect()
# zenkaku comma / period
Select(0uff0c); Scale(150, 150, 100, 0); SetWidth(1000)
Select(0uff0e); Scale(150, 150, 100, 0); SetWidth(1000)
# zenkaku colon / semicolon
Select(0uff0c); Copy(); Select(0uff1b); Paste()
Select(0uff0e); Copy(); Select(0uff1b); PasteWithOffset(0, 400)
CenterInWidth()
Select(0uff1a); Paste(); PasteWithOffset(0, 400)
CenterInWidth()
# zenkaku brackets
Select(0u0028); Copy(); Select(0uff08); Paste(); Move(250, 0); SetWidth(1000) # (
Select(0u0029); Copy(); Select(0uff09); Paste(); Move(250, 0); SetWidth(1000) # )
Select(0u005b); Copy(); Select(0uff3b); Paste(); Move(250, 0); SetWidth(1000) # [
Select(0u005d); Copy(); Select(0uff3d); Paste(); Move(250, 0); SetWidth(1000) # ]
Select(0u007b); Copy(); Select(0uff5b); Paste(); Move(250, 0); SetWidth(1000) # {
Select(0u007d); Copy(); Select(0uff5d); Paste(); Move(250, 0); SetWidth(1000) # }
Select(0u003c); Copy(); Select(0uff1c); Paste(); Move(250, 0); SetWidth(1000) # <
Select(0u003e); Copy(); Select(0uff1e); Paste(); Move(250, 0); SetWidth(1000) # >
# en dash
Select(0u2013); Copy()
PasteWithOffset(200, 0); PasteWithOffset(-200, 0)
OverlapIntersect()
# edit em dash
Select(0u2014); Copy()
PasteWithOffset(320, 0); PasteWithOffset(-320, 0)
Select(0u007c); Copy(); Select(0u2014); PasteInto()
OverlapIntersect()
# detach and remove .notdef
Select(".notdef")
DetachAndRemoveGlyphs()
SelectWorthOutputting()
RoundToInt(); RemoveOverlap(); RoundToInt()
Generate("$FONT_FAMILY-" + styles[i] + ".ttf", "", 0x84)
Print("Save $FONT_FAMILY-" + styles[i] + ".ttf")
Close()
i += 1; endloop
Quit()
_EOL_
echo '>> Generate Modified Pragmata'
$FONTFORGE -script $TMPDIR/$GEN_PRAG 2> /dev/null || exit 4
echo ''
echo '>> Generate Modified Migu 1M'
$FONTFORGE -script $TMPDIR/$GEN_MIGU 2> /dev/null || exit 4
echo ''
echo '>> Generate Plusmata'
$FONTFORGE -script $TMPDIR/$FONT_GENERATOR 2> /dev/null || exit 4
echo ''
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment