Check-in [4dd7982320]
Not logged in

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

Overview
Comment: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.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4dd79823203627c8262939edf8c01253fd6a860c
User & Date: Ross 2015-12-30 00:51:28.988
Context
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
00:12
Clean up fossil extras a bit. check-in: 0a28bda947 user: Ross tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/dotfonter.lua.
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

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"
--[[
require "luaXml"
if not xml then xml = require "luaXml" end
local X = xml.new
--]]
--[[
##Seven segment display contours

These are ready to be added to a glyph if called out in the rom.
The style here is very angular, and does not include any gaps
between segments that would have to appear in practical display
construction.
]]

local segments = {
    a={
        { 10, 896},
        {630, 896},
        {502, 768},
        {138, 768},
    },
    b={
        {640, 886},
        {640, 458},
        {512, 522},
        {512, 758},
    },
    c={
        {640, 438},
        {640,  10},
        {512, 138},
        {512, 374},
    },
    d={
        {630,   0},
        { 10,   0},
        {138, 128},
        {502, 128},
    },
    e={
        {  0,  10},
        {  0, 438},
        {128, 374},
        {128, 138},
    },
    f={
        {  0, 458},
        {  0, 886},
        {128, 758},
        {128, 522},
    },
    g={
        {10,  448},
        {138, 512},
        {502, 512},
        {630, 448},
        {502, 384},
        {138, 384},
    },
    h={
        {704,  10},
        {704, 138},
        {830, 138},
        {830,  10},
    },
    i={
        {704,    0},
        {830,    0},
        {704, -128},
    },
    j={
        {704, 512},
        {704, 638},
        {830, 638},
        {830, 512},
    },
}

--[[ 
##seven segment character generator ROM for HEX digits

The segments are arranged as follows

    +-a-+
    f   b
    +-g-+ j
    e   c
    +-d-+ h
          i
          
and usually coded with a on bit 0 through g on bit 6.

Because Lua likes strings, we use a simpler coding here where each 
character maps to a string contain a list of lit segments. From that
list, characters not in [a-g] will simply be ignored.

--]]
local rom = {
    ['0'] = {'abcdef ', n='zero'}, --0x3f,
    ['1'] = {' bc    ', n='one', lsb=512},--0x06,
    ['2'] = {'ab de g', n='two'},--0x5b,
    ['3'] = {'abcd  g', n='three'},--0x4f,
    ['4'] = {' bc  fg', n='four'},--0x66,
    ['5'] = {'a cd fg', n='five'},--0x6d,
    ['6'] = {'a cdefg', n='six'}, --0x7d,
    ['7'] = {'abc    ', n='seven'}, --0x07,
    ['8'] = {'abcdefg', n='eight'}, --0x7f,
    ['9'] = {'abc  fg', n='nine'}, --0x67,
    ['A'] = 'abc efg', --0x77,
    ['B'] = '  cdefg', --0x7c,
    ['C'] = 'a  def ', --0x39,
    ['D'] = ' bcde g', --0x5e,
    ['E'] = 'a  defg', --0x79,
    ['F'] = 'a   efg', --0x71,
    ['.'] = {'h', n='period', lsb=704}, --0x80,
    [','] = {'hi', n='comma', lsb=704}, --0x180,
    [':'] = {'hj', n='colon', lsb=704}, --0x80,
    [';'] = {'hij', n='semicolon', lsb=704}, --0x180,
    ['#'] = {'abcdefghij', n='numbersign', lsb=0}, --0x3ff,
}

-- Run through the caracters in the rom and assemble a glyph for each
-- one and map in in the font.
for char,pat in pairs(rom) do
    local bars, name, lsb, a, d = pat, char, 0, 896, -128
    if type(pat) == 'table' then
        bars, name, lsb = pat[1], rom[char].n, rom[char].lsb or 0
        a, d = rom[char].a or 896, rom[char].d or 0
    end
    local g = { name=name, lsb=lsb, a=a, d=d }
    for seg in ('abcdefghij'):gmatch'.' do
        if bars:find(seg) then
            g[#g+1] = segments[seg]
        end
    end
    
    ttfont.PlaceGlyph(g, {width=1024, lsb=lsb, a = 896, d=-128})
    ttfont.MapGlyph("unicode", char:byte(), name)
    if char:byte() <= 0x7f then
        ttfont.MapGlyph("mac", char:byte(), name)
    end
    ttfont.MapGlyph("win", char:byte(), name)

end


--[[ 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.

--]]


ttfont.SetNames{
    copy='Copyright Ross Berteig 2015.',
    ffam='Upright Seven Segments',
    PSnm='UprightSevenSegments-Regular',
    ufid='Upright Seven Segments '.. os.date"%Y-%m-%d" ,
    vers='Version 001.042',
    demo='ABCDEF 0123456789',
}

-- get the finished font and write it as TTX
local font = ttfont.GetFont()
--print(font)
font:save("temp.ttx")








<
<
<
|
<
<
<

<
<
<
|
|
>
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
|
<
|
<
<
<
<
<
<
|
<
|
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<



<
<
<
<
<
<
|
<
<
<
<
<
|
|
|
|
|

|
>

>








>
>
|
<
<
<
<
<
<
<




|
>
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
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')
Added src/sevensegment.dotfont.




































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
--[[ 
#Seven segments for dotfonter
--]]

--[[
#License
Copyright (C) 2015 Cheshire Engineering Corp.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
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.
--]]


--[[
##Seven segment display contours

These are ready to be added to a glyph if called out in the rom.
The style here is very angular, and does not include any gaps
between segments that would have to appear in practical display
construction.

These are drawn on a design grid with 1024 units per em. and use 
nothing but on-contour points, and so have nothing but sharp 
corners.

The segments are arranged as follows

    +-a-+
    f   b
    +-g-+ j
    e   c
    +-d-+ h
          i
          
and usually coded with a on bit 0 through g on bit 6. 

Most seven segment components include at least the decimal point dot
aligned with the lower segment. Those intended for use in clocks
include a second dot to make a colon. Because a font isn't constrained
by wiring, I've included a third dot to make the tail of a comma, 
allowing the inclusion of period, comma, colon, and semicolon 
punctuation marks.

]]
local segments = {
    a={
        { 10, 896},
        {630, 896},
        {502, 768},
        {138, 768},
    },
    b={
        {640, 886},
        {640, 458},
        {512, 522},
        {512, 758},
    },
    c={
        {640, 438},
        {640,  10},
        {512, 138},
        {512, 374},
    },
    d={
        {630,   0},
        { 10,   0},
        {138, 128},
        {502, 128},
    },
    e={
        {  0,  10},
        {  0, 438},
        {128, 374},
        {128, 138},
    },
    f={
        {  0, 458},
        {  0, 886},
        {128, 758},
        {128, 522},
    },
    g={
        {10,  448},
        {138, 512},
        {502, 512},
        {630, 448},
        {502, 384},
        {138, 384},
    },
    h={
        {704,  10},
        {704, 138},
        {830, 138},
        {830,  10},
    },
    i={
        {704,    0},
        {830,    0},
        {704, -128},
    },
    j={
        {704, 512},
        {704, 638},
        {830, 638},
        {830, 512},
    },
}

-- Normalize a a glyph in the character ROM. 
-- Create an array of countours from its pat entry and provide defaults 
-- for metrics, name, and character codes.
local function Glyph(t)
    assert(type(t)=='table')
    local pat = assert(t.pat)
    
    -- default metrics
    t.width = t.width or 1024
    t.lsb = t.lsb or 0
    t.a, t.d = t.a or 896, t.d or 0
    
    -- default mapping
    assert(t.name)
    if not t.unicode then t.unicode = t.name:byte() end
    if not t.mac and t.unicode < 127 then t.mac = t.unicode end
    if not t.win then t.win = t.unicode end
    
    -- fill out array of contours
    for seg in ('abcdefghij'):gmatch'.' do
        if pat:find(seg) then
            t[#t+1] = segments[seg]
        end
    end
    return t
end

--[[ 
##seven segment character generator ROM for HEX digits

In a real character ROM, these are coded in a single binary word, 
usually with segment 'a' at bit 0, and 'g' at bit 6.

Because Lua likes strings, we use a simpler coding here where each 
character maps to a string contain a list of lit segments. From that
list, characters not in [a-g] will simply be ignored.

Each entry is keyed by the character, and can be either a string or
table. If it is a string, that string is treated as item [1] in an
otherwise empty table.

The table has the pattern at [1], and optionally includes fields named
n for name, lsb for left side bearing, a for ascent, d for descent, 
width for width, 
--]]
return {
    Glyphs = {
        Glyph{unicode=0x30, pat='abcdef ', name='zero'}, 
        Glyph{unicode=0x31, pat=' bc    ', name='one', lsb=512},
        Glyph{unicode=0x32, pat='ab de g', name='two'},
        Glyph{unicode=0x33, pat='abcd  g', name='three'},
        Glyph{unicode=0x34, pat=' bc  fg', name='four'},
        Glyph{unicode=0x35, pat='a cd fg', name='five'},
        Glyph{unicode=0x36, pat='a cdefg', name='six'}, 
        Glyph{unicode=0x37, pat='abc    ', name='seven'},
        Glyph{unicode=0x38, pat='abcdefg', name='eight'},
        Glyph{unicode=0x39, pat='abc  fg', name='nine'},
        Glyph{unicode=0x41, pat='abc efg', name='A'},
        Glyph{unicode=0x42, pat='  cdefg', name='B'},
        Glyph{unicode=0x43, pat='a  def ', name='C'},
        Glyph{unicode=0x44, pat=' bcde g', name='D'},
        Glyph{unicode=0x45, pat='a  defg', name='E'},
        Glyph{unicode=0x46, pat='a   efg', name='F'},
        Glyph{unicode=0x2E, pat='h', name='period', lsb=704},
        Glyph{unicode=0x2C, pat='hi', name='comma', lsb=704},
        Glyph{unicode=0x3A, pat='hj', name='colon', lsb=704},
        Glyph{unicode=0x3B, pat='hij', name='semicolon', lsb=704},
        Glyph{unicode=0x23, pat='abcdefghij', name='numbersign', lsb=0},
    },

    --[[ 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.

    --]]
    Names = {
        copy='Copyright Ross Berteig 2015.',
        ffam='Upright Seven Segments',
        PSnm='UprightSevenSegments-Regular',
        ufid='Upright Seven Segments '.. os.date"%Y-%m-%d" ,
        vers='Version 001.042',
        demo='ABCDEF 0123456789',
    }
}