Skip to content

Commit

Permalink
Merge pull request #20 from pakutoma/#13-add-nerdfont
Browse files Browse the repository at this point in the history
Nerd Fontsを追加
  • Loading branch information
pakutoma authored Aug 6, 2022
2 parents 41c761c + 8846906 commit b7bcde7
Show file tree
Hide file tree
Showing 6 changed files with 1,009 additions and 40 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ Juglans (ユグランス)は、 Inconsolata と源真ゴシックをベー
- 字形の変更をプログラミングに必要な最小限に留めています。
- 標準ウェイト・太字ウェイトがあります。
- EastAsianWidth における W および F のみを全角フォントとしています。
- Windows Terminal および iTerm2 向けに調整済みの Powerline グリフを含む Nerd Fonts を合成しています。

## サンプル
### Notepad++, 12pt, スケーリング150%, 標準・太字ウェイト利用
<img width="700" alt="Notepad++" src="https://user-images.githubusercontent.com/31642509/181803388-a23e142b-cca0-49c9-862b-b11d46dfcbc1.png">

### Windows Terminal, 14pt, スケーリング150%
<img width="700" alt="WindowsTerminal" src="https://user-images.githubusercontent.com/31642509/181803500-942ed719-6538-4b7d-b7ed-541adc38ae24.png">
<img width="700" alt="windowsterminal" src="https://user-images.githubusercontent.com/31642509/183258376-f37e4962-e5b2-49e2-a1dd-95ee7fa29571.png">

## ライセンス
Juglans フォント、生成スクリプト共に SIL OPEN FONT LICENSE Version 1.1 の下で利用できます。
Expand All @@ -23,6 +24,7 @@ Inconsolata (ASCII 文字)
源真ゴシック (全角文字)
Anonymous Pro Minus(ASCII 文字のアスタリスクとチルダ)
DejaVu LGC (Inconsolata に未収録の半角文字)
Nerd Fonts (Pomicon を除く記号文字)

## 利用フォントのライセンス
サードパーティーライセンス.txt を参照してください。
132 changes: 115 additions & 17 deletions Source/juglans_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@


# version
newfont_version = "2.003.20220730"
newfont_version = "2.004.20220807"
newfont_sfntRevision = 0x00010000

# set font name
newfont_name = ("../Work/Juglans-Regular.ttf", "Juglans-Regular", "Juglans", "Juglans Regular")
newfont_name_bold = ("../Work/Juglans-Bold.ttf", "Juglans-Bold", "Juglans", "Juglans Bold")
newfont_name = (f"../Work/Juglans-{sys.argv[2]}-for-{sys.argv[1]}.ttf", "Juglans-Regular", "Juglans", "Juglans Regular")
newfont_name_bold = (f"../Work/Juglans-{sys.argv[2]}-for-{sys.argv[1]}.ttf", "Juglans-Bold", "Juglans", "Juglans Bold")
# source file
srcfont_incosolata = "../SourceTTF/Inconsolata-Regular.ttf"
srcfont_incosolata_bold = "../SourceTTF/Inconsolata-Bold.ttf"
Expand All @@ -24,6 +24,8 @@
srcfont_dejavu_bold = "../SourceTTF/DejaVuLGCSansMono-Bold.ttf"
srcfont_anonpro = "../SourceTTF/AnonymousProMinus.ttf"
srcfont_anonpro_bold = "../SourceTTF/AnonymousProMinusB.ttf"
srcfont_nerdfonts = "../SourceTTF/NerdFonts-without-pomicon-Regular.ttf"
srcfont_powerline = "../SourceTTF/Powerline-Mod.ttf"


# out file
Expand Down Expand Up @@ -80,16 +82,24 @@
print("Juglans generator " + newfont_version)
print("This script is for generating 'Juglans' font")

if len(sys.argv) > 1 and sys.argv[1] == "bold":
print("Generate Juglans-Bold")
if sys.argv[1] == "WindowsTerminal":
powerline_y = -210
powerline_h = 1.09
elif sys.argv[1] == "iTerm2":
powerline_y = -175
powerline_h = 1.065
else:
powerline_y = -200
powerline_y = 1.0

print(f"Generate Juglans {sys.argv[2]} for {sys.argv[1]}")
if sys.argv[2] == "Bold":
newfont_name = newfont_name_bold
newfont_weight = newfont_weight_bold
srcfont_incosolata = srcfont_incosolata_bold
srcfont_GenShin = srcfont_GenShin_bold
srcfont_anonpro = srcfont_anonpro_bold
panose_base = panose_base_bold
else:
print("Generate Juglans-Normal")

if os.path.exists(srcfont_incosolata) == False:
print("Error: " + srcfont_incosolata + " not found")
Expand All @@ -101,6 +111,39 @@
########################################
# define function
########################################


class Matrix:
def __init__(self):
self.ps_mat = None

def move(self, x, y):
mat = psMat.translate(x, y)
self._compose(mat)
return self

def scale(self, x, y=None):
if y is None:
y = x
mat = psMat.scale(x, y)
self._compose(mat)
return self

def to_ff(self):
return self.ps_mat

def _compose(self, mat):
if self.ps_mat is None:
self.ps_mat = mat
return
self.ps_mat = psMat.compose(self.ps_mat, mat)



def composeChain(mat):
return psMat.compose(self, chain)


def matRescale(origin_x, origin_y, scale_x, scale_y):
return psMat.compose(
psMat.translate(-origin_x, -origin_y), psMat.compose(
Expand Down Expand Up @@ -286,7 +329,6 @@ def setFontProp(font, fontInfo):

font.upos = 45


charASCII = rng(0x0021, 0x007E)
charZHKana = list(u"ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをん"),
charZKKana = list(u"ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ"),
Expand All @@ -297,7 +339,6 @@ def setFontProp(font, fontInfo):
# modified Inconsolata
########################################

print()
print("Open " + srcfont_incosolata)
fIn = fontforge.open(srcfont_incosolata)

Expand Down Expand Up @@ -331,7 +372,7 @@ def setFontProp(font, fontInfo):
# modify Anonymous Pro Minus
########################################

print("\nOpen " + srcfont_anonpro)
print("Open " + srcfont_anonpro)
anon_font = fontforge.open(srcfont_anonpro)

# modify
Expand Down Expand Up @@ -361,11 +402,66 @@ def setFontProp(font, fontInfo):
anon_font.generate("../Work/modAnon.ttf", '', generate_flags)
anon_font.close()

########################################
# modify Powerline
########################################

print("Open " + srcfont_powerline)
powerline = fontforge.open(srcfont_powerline)

# modify
print("modify")

# modify em
powerline.em = newfont_em
powerline.ascent = newfont_ascent
powerline.descent = newfont_descent

# move
for glyph in powerline.glyphs():
mat = (Matrix()
.move(0, 200)
.scale(1.0, powerline_h)
.move(0, powerline_y)
.to_ff())
glyph.transform(mat)

powerline.selection.all()
powerline.round()

powerline.generate("../Work/modPower.ttf", '', generate_flags)
powerline.close()

########################################
# modify Nerd Fonts
########################################

print("Open " + srcfont_nerdfonts)
nerd_font = fontforge.open(srcfont_nerdfonts)

# modify
print("modify")

# modify em
nerd_font.em = newfont_em
nerd_font.ascent = newfont_ascent
nerd_font.descent = newfont_descent

# move
for glyph in nerd_font.glyphs():
glyph.transform(psMat.translate(0, 60))

nerd_font.selection.all()
nerd_font.round()

nerd_font.generate("../Work/modNerd.ttf", '', generate_flags)
nerd_font.close()

########################################
# modify DejaVu LGC
########################################

print("\nOpen " + srcfont_dejavu)
print("Open " + srcfont_dejavu)
de_font = fontforge.open(srcfont_dejavu)

# modify
Expand Down Expand Up @@ -399,7 +495,6 @@ def setFontProp(font, fontInfo):
# modified GenShin
########################################

print()
print("Open " + srcfont_GenShin)
fGs = fontforge.open(srcfont_GenShin)

Expand Down Expand Up @@ -442,11 +537,7 @@ def setFontProp(font, fontInfo):
# create Juglans
########################################
ju_font = fontforge.open("../Work/modIncosolata.ttf")
de_font = fontforge.open("../Work/modDejaVu.ttf")
ge_font = fontforge.open("../Work/modGenShin.ttf")
an_font = fontforge.open("../Work/modAnon.ttf")

print()
print("Build " + newfont_name[0])

# pre-process
Expand All @@ -456,9 +547,16 @@ def setFontProp(font, fontInfo):
print("merge Anonymous Pro")
ju_font.mergeFonts("../Work/modAnon.ttf")

# merge Powerline
print("merge Powerline")
ju_font.mergeFonts("../Work/modPower.ttf")

# merge Nerd Fonts
print("merge Nerd Fonts")
ju_font.mergeFonts("../Work/modNerd.ttf")

# merge DejaVu
print("merge DejaVu")
# マージ
ju_font.mergeFonts("../Work/modDejaVu.ttf")

# merge GenShin
Expand Down
57 changes: 35 additions & 22 deletions Source/juglans_generator.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
#!/bin/sh
echo フォント生成
mkdir ../Work
echo Regularフォントの生成
fontforge -lang=py -script juglans_generator.py
echo Boldフォントの生成
fontforge -lang=py -script juglans_generator.py bold

echo xAvgCharWidthの書き換え
# Regular
ttx -f -t 'OS/2' -d ../Work ../Work/Juglans-Regular.ttf
ttx -f -t 'OS/2' -d ../Work ../SourceTTF/Inconsolata-Regular.ttf
xAvgCharWidth=$(grep xAvgCharWidth ../Work/Inconsolata-Regular.ttx | sed -e 's/.*value="\([0-9]*\)".*/\1/')
sed -i -e "s/^\(.*<xAvgCharWidth value=\"\)[0-9]*\(.*\)/\1$xAvgCharWidth\2/" ../Work/Juglans-Regular.ttx
ttx -f -m ../Work/Juglans-Regular.ttf ../Work/Juglans-Regular.ttx
# Bold
ttx -f -t 'OS/2' -d ../Work ../Work/Juglans-Bold.ttf
ttx -f -t 'OS/2' -d ../Work ../SourceTTF/Inconsolata-Bold.ttf
xAvgCharWidth=$(grep xAvgCharWidth ../Work/Inconsolata-Bold.ttx | sed -e 's/.*value="\([0-9]*\)".*/\1/')
sed -i -e "s/^\(.*<xAvgCharWidth value=\"\)[0-9]*\(.*\)/\1$xAvgCharWidth\2/" ../Work/Juglans-Bold.ttx
ttx -f -m ../Work/Juglans-Bold.ttf ../Work/Juglans-Bold.ttx
# productにコピー
cp ../Work/Juglans-Regular.ttf ../product/Juglans-Regular.ttf
cp ../Work/Juglans-Bold.ttf ../product/Juglans-Bold.ttf
terminals=(
"WindowsTerminal"
"iTerm2"
)

weights=(
"Regular"
"Bold"
)

for terminal in "${terminals[@]}" ; do
for weight in "${weights[@]}" ; do
echo "${terminal} ${weight} フォント生成"
fontforge -lang=py -script juglans_generator.py $terminal $weight 2> /dev/null

src_ttf="../SourceTTF/Inconsolata-${weight}.ttf"
work_ttf="../Work/Juglans-${weight}-for-${terminal}.ttf"
src_ttx="../Work/Inconsolata-${weight}.ttx"
work_ttx="../Work/Juglans-${weight}-for-${terminal}.ttx"
dst_ttf="../product/Juglans-${weight}-for-${terminal}.ttf"

echo xAvgCharWidthの書き換え
ttx -f -t 'OS/2' -d ../Work $work_ttf
ttx -f -t 'OS/2' -d ../Work $src_ttf
xAvgCharWidth=$(grep xAvgCharWidth $src_ttx | sed -e 's/.*value="\([0-9]*\)".*/\1/')
sed -i -e "s/^\(.*<xAvgCharWidth value=\"\)[0-9]*\(.*\)/\1$xAvgCharWidth\2/" $work_ttx
ttx -f -m $work_ttf $work_ttx

# productにコピー
cp $work_ttf $dst_ttf
done
done

echo 圧縮ファイルの作成
tar -Jcf ../product/Juglans.tar.xz -C ../product/ Juglans-Regular.ttf Juglans-Bold.ttf -C ../ LICENSE README.md サードパーティーライセンス.txt
zip ../product/Juglans.zip -j ../product/Juglans-Regular.ttf ../product/Juglans-Bold.ttf ../LICENSE ../README.md ../サードパーティーライセンス.txt
find ../product -name '*.ttf' -printf "%f\0" | xargs -0 tar -Jcf ../product/Juglans.tar.xz -C ../ LICENSE README.md サードパーティーライセンス.txt -C product
zip -q ../product/Juglans.zip -j ../product/*.ttf ../LICENSE ../README.md ../サードパーティーライセンス.txt
echo 完了
Binary file added SourceTTF/NerdFonts-without-pomicon-Regular.ttf
Binary file not shown.
Binary file added SourceTTF/Powerline-Mod.ttf
Binary file not shown.
Loading

0 comments on commit b7bcde7

Please sign in to comment.