This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nicofont.nim
128 lines (115 loc) · 3.25 KB
/
nicofont.nim
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
import os
import parseopt
import parseutils
import strutils
import nico_font_tool
proc echoHelp() =
echo "nicofont {fontFilePath} {outputsDir} {outputsName}\n"
echo "options:"
echo " -fs, --fontSize"
echo " Glyph rasterize size when using OpenType font."
echo " -gox, --glyphOffsetX"
echo " Glyph offset x."
echo " -goy, --glyphOffsetY"
echo " Glyph offset y."
echo " -gaw, --glyphAdjustWidth"
echo " Glyph adjust width."
echo " -gah, --glyphAdjustHeight"
echo " Glyph adjust height."
echo " -m, --mode"
echo " Png sheet color mode, can be 'palette' or 'rgba', default is 'palette'."
let cmdParams = commandLineParams()
if cmdParams.len <= 0:
echoHelp()
quit(0)
var params = initOptParser(cmdParams)
var fontFilePath: string = ""
var outputsDir: string = ""
var outputsName: string = ""
var fontSize: uint = 0
var glyphOffsetX: int = 0
var glyphOffsetY: int = 0
var glyphAdjustWidth: int = 0
var glyphAdjustHeight: int = 0
var mode: string = "palette"
var argumentPosition = 0
for kind, key, val in params.getopt():
case kind:
of cmdArgument:
if argumentPosition == 0:
fontFilePath = key
elif argumentPosition == 1:
outputsDir = key
elif argumentPosition == 2:
outputsName = key
argumentPosition += 1
of cmdLongOption:
case key.toLowerAscii():
of "fontSize".toLowerAscii():
discard parseUInt(val, fontSize)
of "glyphOffsetX".toLowerAscii():
glyphOffsetX = parseInt(val)
of "glyphOffsetY".toLowerAscii():
glyphOffsetY = parseInt(val)
of "glyphAdjustWidth".toLowerAscii():
glyphAdjustWidth = parseInt(val)
of "glyphAdjustHeight".toLowerAscii():
glyphAdjustHeight = parseInt(val)
of "mode":
mode = val.toLowerAscii()
of cmdShortOption:
case key.toLowerAscii():
of "fs":
discard parseUInt(val, fontSize)
of "gox":
glyphOffsetX = parseInt(val)
of "goy":
glyphOffsetY = parseInt(val)
of "gaw":
glyphAdjustWidth = parseInt(val)
of "gah":
glyphAdjustHeight = parseInt(val)
of "m":
mode = val.toLowerAscii()
of cmdEnd:
break
echo "fontFilePath: ", fontFilePath
echo "outputsDir: ", outputsDir
echo "outputsName: ", outputsName
echo "fontSize: ", fontSize
echo "glyphOffsetX: ", glyphOffsetX
echo "glyphOffsetY: ", glyphOffsetY
echo "glyphAdjustWidth: ", glyphAdjustWidth
echo "glyphAdjustHeight: ", glyphAdjustHeight
echo "mode: ", mode
echo ""
if fontFilePath == "":
echo "'fontFilePath' must not be empty\n"
echoHelp()
quit(1)
if outputsDir == "":
echo "'outputsDir' must not be empty\n"
echoHelp()
quit(1)
if outputsName == "":
echo "'outputsName' must not be empty\n"
echoHelp()
quit(1)
if mode != "palette" and mode != "rgba":
echo "Unsupported mode: ", mode, "\n"
echoHelp()
quit(1)
let (sheetData, alphabet) = createSheet(
fontFilePath,
fontSize,
glyphOffsetX,
glyphOffsetY,
glyphAdjustWidth,
glyphAdjustHeight,
)
createDir(outputsDir)
if mode == "palette":
savePalettePng(sheetData, outputsDir, outputsName)
else:
saveRgbaPng(sheetData, outputsDir, outputsName)
saveDatFile(alphabet, outputsDir, outputsName)