Check-in [e68ddc1529]
Not logged in

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

Overview
Comment:Add support for additional raw XML tables provided by a dotfont file. This is experimental and will change. It is demonstrated in sevensegmentextended.dotfont as a way to provide teh kerning table.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e68ddc15297a1e3d58a0e9a2328a92b0db7f7eee
User & Date: Ross 2016-03-19 02:35:16
Context
2016-03-19
02:36
Snapshot updates to the other example fonts, mostly with the font license, demo string, and documentation updated. check-in: 79f4ed1094 user: Ross tags: trunk
02:35
Add support for additional raw XML tables provided by a dotfont file. This is experimental and will change. It is demonstrated in sevensegmentextended.dotfont as a way to provide teh kerning table. check-in: e68ddc1529 user: Ross tags: trunk
2016-03-15
00:02
Add table overrides, add ASCII aliases, fix typos, fix character orientation to match paper tape specification, and add tape edge lines. check-in: f19c56a4b9 user: Ross tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/dotfonter.lua.

32
33
34
35
36
37
38




39
40
41
42
43
44
45
..
96
97
98
99
100
101
102






103
104
105
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
................................................................................
        end
    end
end


-- get the finished font and write it as TTX
local font = ttfont.GetFont(dotfont.Overrides)






--print(font)
font:save(args.basename .. ".ttx")
V('wrote: ', args.basename, '.ttx')







>
>
>
>







 







>
>
>
>
>
>



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
output is suitable for compiling to a font with TTX.

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


require "luaXml"
if not xml then xml = require "luaXml" end
X = xml.new
local X = X
local ttfont = require "ttfont"

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


-- get the finished font and write it as TTX
local font = ttfont.GetFont(dotfont.Overrides)
if dotfont.AddTables then
    for _,t in ipairs(dotfont.AddTables) do
        font:append(t)
    end
end

--print(font)
font:save(args.basename .. ".ttx")
V('wrote: ', args.basename, '.ttx')

Added src/sevensegmentextended.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
--[[ 
#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, 
--]]
local 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=0x61, pat='abc efg', name='a'},
    Glyph{unicode=0x62, pat='  cdefg', name='b'},
    Glyph{unicode=0x63, pat='a  def ', name='c'},
    Glyph{unicode=0x64, pat=' bcde g', name='d'},
    Glyph{unicode=0x65, pat='a  defg', name='e'},
    Glyph{unicode=0x66, pat='a   efg', name='f'},
    Glyph{unicode=0x2E, pat='h', name='period', lsb=704},
    Glyph{unicode=0x2C, pat='hi', name='comma', lsb=704, d=-128},
    Glyph{unicode=0x3A, pat='hj', name='colon', lsb=704},
    Glyph{unicode=0x3B, pat='hij', name='semicolon', lsb=704, d=-128},
    Glyph{unicode=0x23, pat='abcdefghij', name='numbersign', lsb=0, d=-128},
    
    Glyph{unicode=0x53, pat='a cd fg', name='S'},
    Glyph{unicode=0x73, pat='a cd fg', name='s'},
    Glyph{unicode=0x76, pat='  cde  ', name='v'},
    Glyph{unicode=0x6e, pat='  c e g', name='n'},
    Glyph{unicode=0x6d, pat='ab   f ', name='m'},
    Glyph{unicode=0x67, pat='abcd fg', name='g'},
    Glyph{unicode=0x74, pat='   defg', name='t'},

}
local char,floor = string.char, math.floor
for i=0,0x3ff do
    local pat,n = '',i
    for b=0,9 do
        if n % 2 == 1 then pat = pat..char(97+b) end
        n = floor(n / 2)
    end
    Glyphs[#Glyphs+1] = Glyph{
        unicode = 0xE800+i, 
        pat=pat, 
        name=("uni%04X"):format(0xE800+i),
        lsb = 0,
        d = -128,
    }
end

--[[
Add kerning information to tuck punctuation segments against a previous hex digit. 
Ignore kerning for array of all 10-bit segment pattern characters. We assume that 
if you are using those, you will choose a different character to light up the 
decimal point a after a digit as you would in an embedded system directly driving
a block of seven segment display devices.

The kerning data here is fairly raw. A future revision to dotfonter should have some
support for advanced TTF features like kerning built in more nicely than directly 
rendering the TTF kerning table as we do here.
--]]
Kern = X"kern"
Kern:append(X{[0]='version', value="0"})
Kern:append(X{[0]='kernsubtable', coverage="1", format="0"})
local left={'zero','one','two','three','four','five','six','seven','eight','nine',
    'A','B','C','D','E','F','a','b','c','d','e','f'}
local right={'period','comma','colon','semicolon'}
for _,l in ipairs(left) do
    for _,r in ipairs(right) do
        Kern[2][#Kern[2]+1] = {[0]='pair', l=l, r=r, v=-1024}
    end
end


return {
    --[[ Set the character glyphs ]]
    Glyphs = Glyphs,
    
    AddTables={ X(Kern) },
    
    Overrides = {
        OS_2 = {
            xAvgCharWidth = "1024",
            ulUnicodeRange1 = "00000000 00000000 00000000 00000011",
            ulUnicodeRange2 = "00010000 00000000 00000000 00000000", -- Private use area
            ulCodePageRange1 = "00000000 00000000 00000000 00000001",
        },
    },
    
    
    --[[ 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='Seven Segments',
        PSnm='SevenSegments-Regular',
        ufid='Seven Segments '.. os.date"%Y-%m-%d" ,
        vers='Version 001.044',
        demo='ABCDEF 0123456789',
        desc='This font provides coverage for all of the characters that can'
        ..' be displayed on a seven segment display, including three additional'
        ..' dots for forming a decimal point, colon, and comma. The characters'
        ..' provided are the hex digits: 0123456789ABCDEF and puncutation marks'
        ..' period, comma, colon, and semicolon.\n'
        ..'For testing, the number sign displays as all segments lit.\n'
        ..'In addition, the private use area starting at U+E800 thru U+EDFF is'
        ..' filled with every possible combination of the 10 segments. The bars'
        ..' are assigned to bits clockwise from the top: bit 0 is the top bar,'
        ..' bit 1 is the upper right bar, and so on with bit 6 being the center'
        ..' bar. After than, bit 7 is the decimal point, bit 8 the comma extension,'
        ..' and bit 9 the upper dot of the colon.'
        ..'We supply a kerning pair table which, if kerning is enabled in your'
        ..' application, will kern the four punctuation marks against an adjacent'
        ..' hex digit. The only kerning pairs are hex digit and punctuation, the'
        ..' private use characters are completely ignored by kerning.\n',
        lice=[[
This font is licensed under the Creative Commons 
Attribution 4.0 International License. (CC-BY) 
]],
        URLl='https://creativecommons.org/licenses/by/4.0/',
        URLv='http://curioser.cheshireeng.com/',
        URLd='http://curioser.cheshireeng.com/category/projects/dotfonter/',
        desi='Ross Berteig',
    }
}