Check-in [9a99a4c5e4]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a basic command line parser based on the Penlight library pl.lapp module, and use it to check arguments, produce a usage message, and implement a proper --verbose option.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:9a99a4c5e4a8e67a525ee2ec7b3e13b6dcb2dc86
User & Date: Ross 2015-12-30 01:19:12
Context
2015-12-31
01:05
Fixed a bug in the calculation of the font bounding box with matching change to the seven segment font definition. This showed in Windows by the font being clipped at the baseline instead of allowing the descenders in the comman and colon to show. check-in: 76c607c341 user: Ross tags: trunk
2015-12-30
01:19
Add a basic command line parser based on the Penlight library pl.lapp module, and use it to check arguments, produce a usage message, and implement a proper --verbose option. check-in: 9a99a4c5e4 user: Ross tags: trunk
00:51
First cut at separating the font description out of the dotfonter tool. Font descriptions are now in .dotfont files, which are syntactically just Lua. The seven segment font is added to the source kit as a sample. check-in: 4dd7982320 user: Ross tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/dotfonter.lua.

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
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--]]












local ttfont = require "ttfont"
local verbose = true


function V(...) if not verbose then return end io.write(...) io.write'\n' end





-- The command line should get more elaborate processing and usage 
local f = arg[1]
V('basename: ', f)

-- open the font description
local ok, dotfont = pcall(dofile, f .. ".dotfont")
if not ok then 
    print(f, ':', dotfont)
    os.exit(1)
end
V('loaded: ', f, '.dotfont')

-- Run through the caracters in the rom and assemble a glyph for each
-- one and map in in the font.
local n = 0
for _,glyph in ipairs(dotfont.Glyphs) do
    ttfont.PlaceGlyph(glyph)
    ttfont.MapGlyph("unicode", glyph.unicode, glyph.name)
    if glyph.mac then
        ttfont.MapGlyph("mac", glyph.mac, glyph.name)
    end
    ttfont.MapGlyph("win", glyph.win, glyph.name)
    n = n + 1
end
V('placed: ', n, ' glyphs')

--[[ Set the strings. 

Note that ffam, fsub, ufid, name, vers, and PSnm are required by Windows.
Of those, fsub defaults to 'Regular' and name gets a sensible defaults based
on ffam and fsub.

--]]
assert(dotfont.Names.ffam)
assert(dotfont.Names.ufid)
ttfont.SetNames(dotfont.Names)









-- get the finished font and write it as TTX
local font = ttfont.GetFont()
--print(font)
font:save(f .. ".ttx")
V('wrote: ', f, '.ttx')








>
>
>
>
>
>
>
>
>
>
>

<

>
|
>
>
>

>

<
|


|

|


|













|










|
>
>
>
>
>
>
>
>




|
|
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
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--]]

local lapp = require 'pl.lapp'
local args = lapp [[
Create a TTF font from a simple description, intended to easily 
handle fonts modeled after dot matrix or segmented displays. The
output is suitable for compiling to a font with TTX.

  -v,--verbose            Chatter about progress
  <basename>   (string)   base name of .dotfont and .ttx file
]]


local ttfont = require "ttfont"


function V(...) 
    if not args.verbose then return end 
    io.write(...) 
    io.write'\n' 
end


-- The command line should get more elaborate processing and usage 

V('basename: ', args.basename)

-- open the font description
local ok, dotfont = pcall(dofile, args.basename .. ".dotfont")
if not ok then 
    print(args.basename, ':', dotfont)
    os.exit(1)
end
V('loaded: ', args.basename, '.dotfont')

-- Run through the caracters in the rom and assemble a glyph for each
-- one and map in in the font.
local n = 0
for _,glyph in ipairs(dotfont.Glyphs) do
    ttfont.PlaceGlyph(glyph)
    ttfont.MapGlyph("unicode", glyph.unicode, glyph.name)
    if glyph.mac then
        ttfont.MapGlyph("mac", glyph.mac, glyph.name)
    end
    ttfont.MapGlyph("win", glyph.win, glyph.name)
    n = n + 1
end
V('placed: 4 system glyphs and ', n, ' defined glyphs, total ', n+4, '.')

--[[ Set the strings. 

Note that ffam, fsub, ufid, name, vers, and PSnm are required by Windows.
Of those, fsub defaults to 'Regular' and name gets a sensible defaults based
on ffam and fsub.

--]]
assert(dotfont.Names.ffam)
assert(dotfont.Names.ufid)
local names = ttfont.SetNames(dotfont.Names)
if args.verbose then
    for i=0, 32767 do 
        if names[i] then
            V(("%0.f: %q"):format(i, names[i]))
        end
    end
end


-- get the finished font and write it as TTX
local font = ttfont.GetFont()
--print(font)
font:save(args.basename .. ".ttx")
V('wrote: ', args.basename, '.ttx')

Changes to src/ttfname.lua.

170
171
172
173
174
175
176

177
178
179
180


181
182
183
184
185
186
187
188
189
190
191
192
        
    platforms = platforms or {
        {plat=1,enc=0,lang="0x0",unicode='True'},
        {plat=3,enc=1,lang="0x409"}
    }
    
    local name = xml.new{[0]="name"}

    for _,p in ipairs(platforms) do
        for nid=0,32767,1 do
            local value = ntab[nid] or ntab[nameEntries[nid]] or defaults[nid]
            if value then


                name:append{
                    [0]='namerecord', 
                    nameID=nid, platformID=p.plat, platEncID=p.enc, langID=p.lang, unicode=p.unicode, 
                    [1]=value,
                }
            end
        end
    end
    return name
end

return M







>




>
>








|



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
        
    platforms = platforms or {
        {plat=1,enc=0,lang="0x0",unicode='True'},
        {plat=3,enc=1,lang="0x409"}
    }
    
    local name = xml.new{[0]="name"}
    local t = {}
    for _,p in ipairs(platforms) do
        for nid=0,32767,1 do
            local value = ntab[nid] or ntab[nameEntries[nid]] or defaults[nid]
            if value then
                if nameEntries[nid] then t[nameEntries[nid]] = value end
                t[nid] = value
                name:append{
                    [0]='namerecord', 
                    nameID=nid, platformID=p.plat, platEncID=p.enc, langID=p.lang, unicode=p.unicode, 
                    [1]=value,
                }
            end
        end
    end
    return name, t
end

return M

Changes to src/ttfont.lua.

258
259
260
261
262
263
264

265

266
267
268
269
270
271
272
occaecat cupidatat non proident, sunt in culpa qui officia 
deserunt mollit anim id est laborum.
]]
--]=]    
}

function M.SetNames(t)

    tables.name = ttfname.BuildNameTable(t)

end

function M.GetFont()
    
    ttfhhea.ascent = M.maxY
    ttfos_2.sTypoAscender = M.maxY
    ttfos_2.usWinAscent = M.maxY







>
|
>







258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
occaecat cupidatat non proident, sunt in culpa qui officia 
deserunt mollit anim id est laborum.
]]
--]=]    
}

function M.SetNames(t)
    local names
    tables.name, names = ttfname.BuildNameTable(t)
    return names
end

function M.GetFont()
    
    ttfhhea.ascent = M.maxY
    ttfos_2.sTypoAscender = M.maxY
    ttfos_2.usWinAscent = M.maxY