Check-in [b0577ee769]
Not logged in

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

Overview
Comment:Move TTX details of TrueType contours into ttfont where it belongs, leaving a very simple array of arrays for the glyph outline exposed to scripting.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b0577ee7690ac8216fddb751f3fbff916871ee54
User & Date: Ross 2015-12-24 01:11:51
Context
2015-12-30
00:12
Clean up fossil extras a bit. check-in: 0a28bda947 user: Ross tags: trunk
2015-12-24
01:11
Move TTX details of TrueType contours into ttfont where it belongs, leaving a very simple array of arrays for the glyph outline exposed to scripting. check-in: b0577ee769 user: Ross tags: trunk
2015-12-23
21:15
Clarify the comments about the name strings. check-in: ef0d83aeec user: Ross tags: trunk
Changes
Hide Diffs Unified Diffs 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
...
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
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=X{[0]='contour',
        {[0]='pt', x=10,  y=896, on=1},
        {[0]='pt', x=630, y=896, on=1},
        {[0]='pt', x=502, y=768, on=1},
        {[0]='pt', x=138, y=768, on=1},
    },
    b=X{[0]='contour',
        {[0]='pt', x=640, y=886, on=1},
        {[0]='pt', x=640, y=458, on=1},
        {[0]='pt', x=512, y=522, on=1},
        {[0]='pt', x=512, y=758, on=1},
    },
    c=X{[0]='contour',
        {[0]='pt', x=640, y=438, on=1},
        {[0]='pt', x=640, y=10,  on=1},
        {[0]='pt', x=512, y=138, on=1},
        {[0]='pt', x=512, y=374, on=1},
    },
    d=X{[0]='contour',
        {[0]='pt', x=630, y=0, on=1},
        {[0]='pt', x=10,  y=0, on=1},
        {[0]='pt', x=138, y=128, on=1},
        {[0]='pt', x=502, y=128, on=1},
    },
    e=X{[0]='contour',
        {[0]='pt', x=0,   y=10,  on=1},
        {[0]='pt', x=0,   y=438, on=1},
        {[0]='pt', x=128, y=374, on=1},
        {[0]='pt', x=128, y=138, on=1},
    },
    f=X{[0]='contour',
        {[0]='pt', x=0,   y=458, on=1},
        {[0]='pt', x=0,   y=886, on=1},
        {[0]='pt', x=128, y=758, on=1},
        {[0]='pt', x=128, y=522, on=1},
    },
    g=X{[0]='contour',
        {[0]='pt', x=10,  y=448, on=1},
        {[0]='pt', x=138, y=512, on=1},
        {[0]='pt', x=502, y=512, on=1},
        {[0]='pt', x=630, y=448, on=1},
        {[0]='pt', x=502, y=384, on=1},
        {[0]='pt', x=138, y=384, on=1},
    },
    h=X{[0]='contour',
        {[0]='pt', x=704, y=10, on=1},
        {[0]='pt', x=704, y=138, on=1},
        {[0]='pt', x=830, y=138, on=1},
        {[0]='pt', x=830, y=10, on=1},
    },
    i=X{[0]='contour',
        {[0]='pt', x=704, y=0, on=1},
        {[0]='pt', x=830, y=0, on=1},
        {[0]='pt', x=704, y=-128, on=1},
    },
    j=X{[0]='contour',
        {[0]='pt', x=704, y=512, on=1},
        {[0]='pt', x=704, y=638, on=1},
        {[0]='pt', x=830, y=638, on=1},
        {[0]='pt', x=830, y=512, on=1},
    },
}

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

The segments are arranged as follows
................................................................................
    [';'] = {'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 = pat, char, 0
    if type(pat) == 'table' then
        bars, name, lsb = pat[1], rom[char].n, rom[char].lsb or 0

    end
    local g = X{[0]="TTGlyph", name=name,}

    for seg in ('abcdefghij'):gmatch'.' do
        if bars:find(seg) then
            g[#g+1] = segments[seg]
        end
    end
    g[#g+1] = X{[0]='instructions',X{[0]='assembly'}}
    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







|



|









|
|
|
|
|

|
|
|
|
|

|
|
|
|
|

|
|
|
|
|

|
|
|
|
|

|
|
|
|
|

|
|
|
|
|
|
|

|
|
|
|
|

|
|
|
|

|
|
|
|
|







 







|


>

<
>





|







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
...
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
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
................................................................................
    [';'] = {'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

Changes to src/ttfont.lua.

83
84
85
86
87
88
89
90








91
92
93














94
95
96
97
98
99
100
...
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
tables.hmtx = X"hmtx"

-- Glyph outlines for each glyph, along with an empty 
-- index table that will be entirely filled by the
-- TTX to TTF compiler
tables.loca = X"loca"
tables.glyf = X"glyf"
    








    
    
function M.PlaceGlyph(glyph, t)














    tables.GlyphOrder:append{[0]="GlyphID", id=tables.nextid, name=glyph.name}
    tables.nextid = tables.nextid + 1
    tables.glyf:append(glyph)
    
    M.minX = M.minX < (t.lsb or 0) and M.minX or t.lsb
    M.maxX = M.maxX > (t.width or 0) and M.maxX or t.width
    M.minY = M.minY < (t.d or 0) and M.minY or t.d
................................................................................

-- standards recommmend that .notdef look like an empty box, a box 
-- with an X in it, or a box with a '?' in it. Because the diagonal 
-- lines will stand out from the dots making up all other glyphs more
-- than a plain box would, I've made it be a boxed X. A '?' would be
-- more distinct, but I'd have to plot it and the X is much simpler.
local notdefglyph = xml.new{[0]="TTGlyph", name=".notdef",
    {[0]='contour',
        {[0]='pt', x=128, y=  0, on=1},
        {[0]='pt', x=128, y=768, on=1},
        {[0]='pt', x=896, y=768, on=1},
        {[0]='pt', x=896, y=  0, on=1},
    },
    {[0]='contour',
        {[0]='pt', x=192, y= 64, on=1},
        {[0]='pt', x=832, y= 64, on=1},
        {[0]='pt', x=832, y=704, on=1},
        {[0]='pt', x=192, y=704, on=1},
    },
    {[0]='contour',
        {[0]='pt', x=128, y= 45, on=1},
        {[0]='pt', x=851, y=768, on=1},
        {[0]='pt', x=896, y=723, on=1},
        {[0]='pt', x=183, y=  0, on=1},
    },
    {[0]='contour',
        {[0]='pt', x=128, y=723, on=1},
        {[0]='pt', x=183, y=768, on=1},
        {[0]='pt', x=896, y= 45, on=1},
        {[0]='pt', x=851, y=  0, on=1},
    }, 
    {[0]='instructions',{[0]='assembly'}},
}
-- an empty glyph.
local nullglyph = xml.new{[0]="TTGlyph", name=".null" }
local crglyph = xml.new{[0]="TTGlyph", name="nonmarkingreturn" }
local spaceglyph = xml.new{[0]="TTGlyph", name="space" }

-- first four glyphs are recommended to be .notdef, .null, CR, and space








>
>
>
>
>
>
>
>


|
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|
|
|

|
|
|
|
|

|
|
|
|
|

|
|
|
|
|

|







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
...
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
tables.hmtx = X"hmtx"

-- Glyph outlines for each glyph, along with an empty 
-- index table that will be entirely filled by the
-- TTX to TTF compiler
tables.loca = X"loca"
tables.glyf = X"glyf"
    
function contour(t)
    local c = xml.new"contour"
    for i=1,#t do
        local pt=t[i]
        c:append(X{[0]='pt', x=pt[1], y=pt[2], on=pt[3] or 1})
    end
    return c
end
    
    
function M.PlaceGlyph(g, t)
    t = t or g
    local glyph
    
    if g[0] then
        glyph = g
    else
        glyph = xml.new'TTGlyph'
        glyph.name = g.name
        for i=1,#g do
            glyph:append(contour(g[i]))
        end
        glyph:append(xml.new{[0]='instructions',X{[0]='assembly'}})
    end
    
    tables.GlyphOrder:append{[0]="GlyphID", id=tables.nextid, name=glyph.name}
    tables.nextid = tables.nextid + 1
    tables.glyf:append(glyph)
    
    M.minX = M.minX < (t.lsb or 0) and M.minX or t.lsb
    M.maxX = M.maxX > (t.width or 0) and M.maxX or t.width
    M.minY = M.minY < (t.d or 0) and M.minY or t.d
................................................................................

-- standards recommmend that .notdef look like an empty box, a box 
-- with an X in it, or a box with a '?' in it. Because the diagonal 
-- lines will stand out from the dots making up all other glyphs more
-- than a plain box would, I've made it be a boxed X. A '?' would be
-- more distinct, but I'd have to plot it and the X is much simpler.
local notdefglyph = xml.new{[0]="TTGlyph", name=".notdef",
    contour{
        {128,   0},
        {128, 768},
        {896, 768},
        {896,   0},
    },
    contour{
        {192,  64},
        {832,  64},
        {832, 704},
        {192, 704},
    },
    contour{
        {128,  45},
        {851, 768},
        {896, 723},
        {183,   0},
    },
    contour{
        {128, 723},
        {183, 768},
        {896,  45},
        {851,   0},
    }, 
    xml.new{[0]='instructions',xml.new'assembly'},
}
-- an empty glyph.
local nullglyph = xml.new{[0]="TTGlyph", name=".null" }
local crglyph = xml.new{[0]="TTGlyph", name="nonmarkingreturn" }
local spaceglyph = xml.new{[0]="TTGlyph", name="space" }

-- first four glyphs are recommended to be .notdef, .null, CR, and space