1
2
3
4
5
6
7
8
9
10
11
12
13
14\startluacode
15
16local concat = table.concat
17local formatters = string.formatters
18local validstring = string.valid
19
20local f_setbounds = formatters["setbounds currentpicture to (%s) enlarged %.4G;"]
21local f_index = formatters['draw anchored.bot(textext("\\tttf\\setstrut\\strut index %i") ysized 10bp ,.5[llcorner currentpicture,lrcorner currentpicture] shifted (0,%.4G));']
22local f_unicode = formatters['draw anchored.bot(textext("\\tttf\\setstrut\\strut unicode %05X") ysized 10bp ,.5[llcorner currentpicture,lrcorner currentpicture] shifted (0,%.4G));']
23
24local f_in_red = formatters["draw %s withpen pencircle scaled .15 withcolor .5red;"]
25local f_in_green = formatters["draw %s withpen pencircle scaled .15 withcolor .5green;"]
26local f_in_blue = formatters["draw %s withpen pencircle scaled .15 withcolor .5blue;"]
27local f_in_gray = formatters["draw image(%s) withcolor .75yellow;"]
28
29local f_glyph = formatters [ [[
30pickup pencircle scaled .15;
31pointlabelfont := "Mono sa .125";
32pointlabelscale := 1bp ;
33drawoptionsfactor := .2bp ;
34originlength := 2bp ;
35%s;
36]] ]
37
38local metapost = fonts.metapost
39
40local variables = interfaces.variables
41
42local v_all = variables.all
43local v_page = variables.page
44local v_text = variables.text
45local v_command = variables.command
46local v_box = variables.box
47local v_width = variables.width
48local v_min = variables.min
49local v_max = variables.max
50local v_comment = variables.comment
51local v_simple = variables.simple
52
53function metapost.showglyph(specification)
54 local fontid = font.current()
55 local shapedata = fonts.hashes.shapes[fontid]
56 local chardata = fonts.hashes.characters[fontid]
57 local shapeglyphs = shapedata.glyphs or { }
58 local character = validstring(specification.character)
59 local index = validstring(specification.index)
60 local alternative = validstring(specification.alternative)
61 local command = validstring(specification.command)
62 local options = utilities.parsers.settings_to_set(specification.option)
63 local all = not next(options) and not options[v_simple] or options[v_all]
64 local function shape(index,what,f_comment)
65 if not index then
66 return
67 end
68 local glyph = shapeglyphs[index]
69 if glyph and (glyph.segments or glyph.sequence) then
70 local units = shapedata.units or 1000
71 local factor = 100/units
72 local paths = metapost.paths(glyph,factor)
73 if #paths > 0 and glyph.boundingbox and glyph.width then
74 local graphic = f_glyph(concat{
75 f_in_gray (metapost.fill(paths)),
76 metapost.draw(paths,true),
77 (all or options[v_box]) and f_in_red (metapost.boundingbox(glyph,factor)) or "",
78 (all or options[v_width]) and f_in_green (metapost.widthline(glyph,factor)) or "",
79 (all or options[v_min]) and f_in_blue (metapost.zeroline(glyph,factor)) or "",
80 (all or options[v_max]) and f_setbounds(metapost.maxbounds(data,index,factor),offset or 1) or "",
81 (all or options[v_comment]) and f_comment (what,1) or "",
82 })
83 if alternative == v_page then
84 context.startMPpage()
85 context(graphic)
86 context.stopMPpage()
87 elseif alternative == v_command then
88 context[command](graphic)
89 else
90 context.startMPcode()
91 context(graphic)
92 context.stopMPcode()
93 end
94 end
95 end
96 end
97
98 if character == v_all then
99 for u, c in table.sortedhash(chardata) do
100 shape(c.index,u,f_unicode)
101 end
102 return
103 end
104 if type(character) == "string" then
105 character = utf.byte(character)
106 end
107 if type(character) == "number" then
108 local c = chardata[character]
109 if c then
110 shape(c.index,c.index,f_index)
111 end
112 return
113 end
114 if type(index) == "number" then
115 shape(index,index,f_index)
116 return
117 end
118 local first, last
119 if type(index) == "string" then
120 first, last = string.split(index,":")
121 if first and last then
122 first = tonumber(first)
123 last = tonumber(last)
124 else
125 first = tonumber(index)
126 last = first
127 end
128 if not first then
129 first = 1
130 last = #shapeglyphs
131 elseif not last then
132 last = first
133 end
134 else
135 first = 1
136 last = #shapeglyphs
137 end
138 for index=first,last do
139 shape(index,index,f_index)
140 end
141end
142
143\stopluacode
144
145\unprotect
146
147
148
149\unexpanded\def\showshape
150 {\dosingleargument\meta_shapes_show}
151
152\def\meta_shapes_show[#1]
153 {\begingroup
154 \letdummyparameter\c!index\empty
155 \letdummyparameter\c!character\empty
156 \letdummyparameter\c!alternative\v!text
157 \letdummyparameter\c!command\empty
158 \letdummyparameter\c!option\v!all
159 \getdummyparameters[#1]
160 \ctxlua{fonts.metapost.showglyph{
161 character = "\dummyparameter\c!character",
162 index = "\dummyparameter\c!index",
163 alternative = "\dummyparameter\c!alternative",
164 command = "\dummyparameter\c!command",
165 option = "\dummyparameter\c!option",
166 }}
167 \endgroup}
168
169\protect
170
171\continueifinputfile{metaimpoutlines.mkiv}
172
173\starttext
174
175
176
177
178
179
180
181
182\usemodule[art01]
183
184
185
186\startcombination[3*1]
187 {\ruledhbox{\startMPcode draw textext("\showshape[character=a]") ; \stopMPcode}} {}
188 {\ruledhbox{\startMPcode draw textext("\showshape[character=x]") ; \stopMPcode}} {}
189 {\ruledhbox{\showshape[character=P,alternative=text]}} {}
190\stopcombination
191
192\startcombination[3*1]
193 {\ruledhbox{\startMPcode draw textext("\showshape[character=a,option={simple}]") ; \stopMPcode}} {}
194 {\ruledhbox{\startMPcode draw textext("\showshape[character=x,option={simple}]") ; \stopMPcode}} {}
195 {\ruledhbox{\showshape[character=P,alternative=text,option=simple]}} {}
196\stopcombination
197
198
199
200
201
202
203
204\stoptext
205 |