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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
--
--
-- Experimental svg back end
--
--
--print ("mflua_svg_backend")
local MFbuiltin = mflua.MFbuiltin
local MF = mflua.MF
print_scaled = mflua.MF.print_scaled
local svg = svg or {}
svg = {
['enabled']=true,
['enabled_raw']=false,
['output_dir']='svg',
['svg_preamble'] = [=[<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="15cm" height="15cm" viewBox="%s %s %s %s"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<title>cubic Bézier commands in path data</title>
<desc>B char</desc>
<style type="text/css"><![CDATA[
.Border { fill:none; stroke:blue; stroke-width:1 }
.Connect { fill:none; stroke:#888888; stroke-width:2 }
.SamplePath { fill:none; stroke:black; stroke-width:1 }
.EndPoint { fill:none; stroke:#888888; stroke-width:2 }
.CtlPoint { fill:#888888; stroke:none }
.AutoCtlPoint { fill:none; stroke:blue; stroke-width:4 }
.Label { font-size:22; font-family:Verdana }
]]></style>
<g transform="matrix(1 0 0 -1 0 0)">
<g transform="translate(0 %s)">
%s
</g>
</g>
</svg>]=],
['emsize']= 1000,
['filename']= 'SourceCode',
['font'] = [=[
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg>
<metadata>
Created by FontForge 20110222 at Sun Sep 18 10:37:34 2011
By root
Copyleft 2002, 2003, 2005 Free Software Foundation.
</metadata>
<defs>
<font id="SourceCode" >
<font-face
font-size='%s'
units-per-em="%s"
ascent='800' descent='200'
x-height='%s'
font-family="SourceCode"
font-weight="400"
font-stretch="normal"
panose-1="2 2 6 3 5 4 5 2 3 4"
alphabetic='0'
/>
<missing-glyph horiz-adv-x="280" />
%s
</font>
</defs></svg>
]=],
['glyph'] =
[==[<glyph glyph-name="%s" unicode="%s" orientation="h"
horiz-adv-x="%s" vert-adv-y="%s"
d="%s" >%s
</glyph>
]==],
['hkern'] = [==[<hkern g1="%s" u1="%s" g2="%s" u2="%s" k="%s" />]==],
['vkern'] = [==[<vkern g1="%s" u1="%s" g2="%s" u2="%s" k="%s" />]==],
['hkerns']='',
['vkerns']='',
['char']={
['0']={glyph_name='uni0393',unicode='Γ'}, -- U+0393 GREEK CAPITAL LETTER GAMMA
['1']={glyph_name='uni0394',unicode='Δ'}, --U+0394 GREEK CAPITAL LETTER DELTA
['2']={glyph_name='uni0398',unicode='Θ'}, -- U+0398 GREEK CAPITAL LETTER THETA
['3']={glyph_name='uni039b',unicode='Λ'}, -- U+039B GREEK CAPITAL LETTER LAMBDA
['4']={glyph_name='uni039e',unicode='Ξ'}, --U+039E GREEK CAPITAL LETTER XI
['5']={glyph_name='uni03a0',unicode='Π'}, --U+03A0 GREEK CAPITAL LETTER PI
['6']={glyph_name='uni03a3',unicode='Σ'}, -- U+03A3 GREEK CAPITAL LETTER SIGMA
['7']={glyph_name='uni03a5',unicode='Υ'}, --U+03A5 GREEK CAPITAL LETTER UPSILON
['8']={glyph_name='uni03a6',unicode='Φ'}, -- U+03A6 GREEK CAPITAL LETTER PHI
['9']={glyph_name='uni03a8',unicode='Ψ'}, -- U+03A8 GREEK CAPITAL LETTER PSI
['10']={glyph_name='uni03a9',unicode='Ω'}, -- U+03A9 GREEK CAPITAL LETTER OMEGA
['11']={glyph_name='unifb00',unicode='ff'}, -- U+FB00 LATIN SMALL LIGATURE FF
['12']={glyph_name='unifb01',unicode='fi'}, --U+FB01 LATIN SMALL LIGATURE FI
['13']={glyph_name='unifb02',unicode='fl'}, -- U+FB02 LATIN SMALL LIGATURE FL
['14']={glyph_name='unifb03',unicode='ffi'}, --U+FB03 LATIN SMALL LIGATURE FFI
['15']={glyph_name='unifb04',unicode='ffl'}, -- U+FB04 LATIN SMALL LIGATURE FFL
['16']={glyph_name='uni0131',unicode='ı'}, -- U+0131 LATIN SMALL LETTER DOTLESS I
['17']={glyph_name='uni0237',unicode='ȷ'}, -- U+0237 LATIN SMALL LETTER DOTLESS J
['18']={glyph_name='uni0060',unicode='`'}, -- U+0060 GRAVE ACCENT
['19']={glyph_name='uni00b4',unicode='´'}, -- U+00B4 ACUTE ACCENT
['20']={glyph_name='uni02c7',unicode='ˇ'}, -- U+02C7 CARON
['21']={glyph_name='uni02d8',unicode='˘'}, -- U+02D8 BREVE
['22']={glyph_name='uni00af',unicode='¯'}, -- U+00AF MACRON
['23']={glyph_name='uni02da',unicode='˚'}, -- U+02DA RING ABOVE
['24']={glyph_name='uni00b8',unicode='¸'}, -- U+00B8 CEDILLA
['25']={glyph_name='uni00df',unicode='ß'}, -- U+00DF LATIN SMALL LETTER SHARP S
['26']={glyph_name='uni00e6',unicode='æ'}, -- U+00E6 LATIN SMALL LETTER AE
['27']={glyph_name='uni0153',unicode='œ'}, -- U+0153 LATIN SMALL LIGATURE OE
['28']={glyph_name='uni00f8',unicode='ø'}, -- U+00F8 LATIN SMALL LETTER O WITH STROKE
['29']={glyph_name='uni00c6',unicode='Æ'}, --U+00C6 LATIN CAPITAL LETTER AE
['30']={glyph_name='uni0152',unicode='Œ'}, --U+0152 LATIN CAPITAL LIGATURE OE
['31']={glyph_name='uni00D8',unicode='Ø'}, --U+00D8 LATIN CAPITAL LETTER O WITH STROKE
['32']={glyph_name='uni0337',unicode='̷'}, --U+0337 COMBINING SHORT SOLIDUS OVERLAY
['33']={glyph_name='uni0021',unicode='!'},
['34']={glyph_name='uni201d',unicode='”'}, -- U+201D RIGHT DOUBLE QUOTATION MARK
['35']={glyph_name='uni0023',unicode='#'},
['36']={glyph_name='uni0024',unicode='$'},
['37']={glyph_name='uni0025',unicode='%'},
['38']={glyph_name='uni0026',unicode='&'},
['39']={glyph_name='uni0027',unicode='''},
['40']={glyph_name='uni0028',unicode='('},
['41']={glyph_name='uni0029',unicode=')'},
['42']={glyph_name='uni002a',unicode='*'},
['43']={glyph_name='uni002b',unicode='+'},
['44']={glyph_name='uni002c',unicode=','},
['45']={glyph_name='uni002d',unicode='-'}, -- U+002D HYPHEN-MINUS
['46']={glyph_name='uni002e',unicode='.'},
['47']={glyph_name='uni002f',unicode='/'},
['48']={glyph_name='uni0030',unicode='0'},
['49']={glyph_name='uni0031',unicode='1'},
['50']={glyph_name='uni0032',unicode='2'},
['51']={glyph_name='uni0033',unicode='3'},
['52']={glyph_name='uni0034',unicode='4'},
['53']={glyph_name='uni0035',unicode='5'},
['54']={glyph_name='uni0036',unicode='6'},
['55']={glyph_name='uni0037',unicode='7'},
['56']={glyph_name='uni0038',unicode='8'},
['57']={glyph_name='uni0039',unicode='9'},
['58']={glyph_name='uni003a',unicode=':'},
['59']={glyph_name='uni003b',unicode=';'},
['60']={glyph_name='uni00a1',unicode='¡'}, -- U+00A1 INVERTED EXCLAMATION MARK, but only if ligs>1
['61']={glyph_name='uni003d',unicode='='},
['62']={glyph_name='uni00bf',unicode='¿'}, --U+00BF INVERTED QUESTION MARK
['63']={glyph_name='uni003f',unicode='?'},
['64']={glyph_name='uni0040',unicode='@'},
['65']={glyph_name='uni0041',unicode='A'},
['66']={glyph_name='uni0042',unicode='B'},
['67']={glyph_name='uni0043',unicode='C'},
['68']={glyph_name='uni0044',unicode='D'},
['69']={glyph_name='uni0045',unicode='E'},
['70']={glyph_name='uni0046',unicode='F'},
['71']={glyph_name='uni0047',unicode='G'},
['72']={glyph_name='uni0048',unicode='H'},
['73']={glyph_name='uni0049',unicode='I'},
['74']={glyph_name='uni004a',unicode='J'},
['75']={glyph_name='uni004b',unicode='K'},
['76']={glyph_name='uni004c',unicode='L'},
['77']={glyph_name='uni004d',unicode='M'},
['78']={glyph_name='uni004e',unicode='N'},
['79']={glyph_name='uni004f',unicode='O'},
['80']={glyph_name='uni0050',unicode='P'},
['81']={glyph_name='uni0051',unicode='Q'},
['82']={glyph_name='uni0052',unicode='R'},
['83']={glyph_name='uni0053',unicode='S'},
['84']={glyph_name='uni0054',unicode='T'},
['85']={glyph_name='uni0055',unicode='U'},
['86']={glyph_name='uni0056',unicode='V'},
['87']={glyph_name='uni0057',unicode='W'},
['88']={glyph_name='uni0058',unicode='X'},
['89']={glyph_name='uni0059',unicode='Y'},
['90']={glyph_name='uni005a',unicode='Z'},
['91']={glyph_name='uni005b',unicode='['},
['92']={glyph_name='uni201c',unicode='“'}, -- U+201C LEFT DOUBLE QUOTATION MARK
['93']={glyph_name='uni005d',unicode=']'},
['94']={glyph_name='uni0302',unicode='̂'}, --U+0302 COMBINING CIRCUMFLEX ACCENT
['95']={glyph_name='uni0307',unicode='̇'}, --U+0307 COMBINING DOT ABOVE
['96']={glyph_name='uni2018',unicode='‘'}, --U+2018 LEFT SINGLE QUOTATION MARK
['97']={glyph_name='uni0061',unicode='a'},
['98']={glyph_name='uni0062',unicode='b'},
['99']={glyph_name='uni0063',unicode='c'},
['100']={glyph_name='uni0064',unicode='d'},
['101']={glyph_name='uni0065',unicode='e'},
['102']={glyph_name='uni0066',unicode='f'},
['103']={glyph_name='uni0067',unicode='g'},
['104']={glyph_name='uni0068',unicode='h'},
['105']={glyph_name='uni0069',unicode='i'},
['106']={glyph_name='uni006a',unicode='j'},
['107']={glyph_name='uni006b',unicode='k'},
['108']={glyph_name='uni006c',unicode='l'},
['109']={glyph_name='uni006d',unicode='m'},
['110']={glyph_name='uni006e',unicode='n'},
['111']={glyph_name='uni006f',unicode='o'},
['112']={glyph_name='uni0070',unicode='p'},
['113']={glyph_name='uni0071',unicode='q'},
['114']={glyph_name='uni0072',unicode='r'},
['115']={glyph_name='uni0073',unicode='s'},
['116']={glyph_name='uni0074',unicode='t'},
['117']={glyph_name='uni0075',unicode='u'},
['118']={glyph_name='uni0076',unicode='v'},
['119']={glyph_name='uni0077',unicode='w'},
['120']={glyph_name='uni0078',unicode='x'},
['121']={glyph_name='uni0079',unicode='y'},
['122']={glyph_name='uni007a',unicode='z'},
['123']={glyph_name='uni2013',unicode='–'}, -- U+2013 EN DASH
['124']={glyph_name='uni2014',unicode='—'}, -- U+2014 EM DASH
['125']={glyph_name='uni030b',unicode='̋'}, --U+030B COMBINING DOUBLE ACUTE ACCENT
['126']={glyph_name='uni0303',unicode='̃'}, --U+0303 COMBINING TILDE
['127']={glyph_name='uni0308',unicode='̈'}, --U+0308 COMBINING DIAERESIS
['128']={glyph_name='uni0080',unicode='€'},
['129']={glyph_name='uni0081',unicode=''},
['130']={glyph_name='uni0082',unicode='‚'},
['131']={glyph_name='uni0083',unicode='ƒ'},
['132']={glyph_name='uni0084',unicode='„'},
['133']={glyph_name='uni0085',unicode='…'},
['134']={glyph_name='uni0086',unicode='†'},
['135']={glyph_name='uni0087',unicode='‡'},
['136']={glyph_name='uni0088',unicode='ˆ'},
['137']={glyph_name='uni0089',unicode='‰'},
['138']={glyph_name='uni008a',unicode='Š'},
['139']={glyph_name='uni008b',unicode='‹'},
['140']={glyph_name='uni008c',unicode='Œ'},
['141']={glyph_name='uni008d',unicode=''},
['142']={glyph_name='uni008e',unicode='Ž'},
['143']={glyph_name='uni008f',unicode=''},
['144']={glyph_name='uni0090',unicode=''},
['145']={glyph_name='uni0091',unicode='‘'},
['146']={glyph_name='uni0092',unicode='’'},
['147']={glyph_name='uni0093',unicode='“'},
['148']={glyph_name='uni0094',unicode='”'},
['149']={glyph_name='uni0095',unicode='•'},
['150']={glyph_name='uni0096',unicode='–'},
['151']={glyph_name='uni0097',unicode='—'},
['152']={glyph_name='uni0098',unicode='˜'},
['153']={glyph_name='uni0099',unicode='™'},
['154']={glyph_name='uni009a',unicode='š'},
['155']={glyph_name='uni009b',unicode='›'},
['156']={glyph_name='uni009c',unicode='œ'},
['157']={glyph_name='uni009d',unicode=''},
['158']={glyph_name='uni009e',unicode='ž'},
['159']={glyph_name='uni009f',unicode='Ÿ'},
['160']={glyph_name='uni00a0',unicode=' '},
['161']={glyph_name='uni00a1',unicode='¡'},
['162']={glyph_name='uni00a2',unicode='¢'},
['163']={glyph_name='uni00a3',unicode='£'},
['164']={glyph_name='uni00a4',unicode='¤'},
['165']={glyph_name='uni00a5',unicode='¥'},
['166']={glyph_name='uni00a6',unicode='¦'},
['167']={glyph_name='uni00a7',unicode='§'},
['168']={glyph_name='uni00a8',unicode='¨'},
['169']={glyph_name='uni00a9',unicode='©'},
['170']={glyph_name='uni00aa',unicode='ª'},
['171']={glyph_name='uni00ab',unicode='«'},
['172']={glyph_name='uni00ac',unicode='¬'},
['173']={glyph_name='uni00ad',unicode='­'},
['174']={glyph_name='uni00ae',unicode='®'},
['175']={glyph_name='uni00af',unicode='¯'},
['176']={glyph_name='uni00b0',unicode='°'},
['177']={glyph_name='uni00b1',unicode='±'},
['178']={glyph_name='uni00b2',unicode='²'},
['179']={glyph_name='uni00b3',unicode='³'},
['180']={glyph_name='uni00b4',unicode='´'},
['181']={glyph_name='uni00b5',unicode='µ'},
['182']={glyph_name='uni00b6',unicode='¶'},
['183']={glyph_name='uni00b7',unicode='·'},
['184']={glyph_name='uni00b8',unicode='¸'},
['185']={glyph_name='uni00b9',unicode='¹'},
['186']={glyph_name='uni00ba',unicode='º'},
['187']={glyph_name='uni00bb',unicode='»'},
['188']={glyph_name='uni00bc',unicode='¼'},
['189']={glyph_name='uni00bd',unicode='½'},
['190']={glyph_name='uni00be',unicode='¾'},
['191']={glyph_name='uni00bf',unicode='¿'},
['192']={glyph_name='uni00c0',unicode='À'},
-- ['193']={glyph_name='uni00c1',unicode='Á'},
['193']={glyph_name='uni0060',unicode='`'},
-- ['194']={glyph_name='uni00c2',unicode='Â'},
['194']={glyph_name='uni00b4',unicode='´'},
-- ['195']={glyph_name='uni00c3',unicode='Ã'},
['195']={glyph_name='uni005e',unicode='^'},
['196']={glyph_name='uni00c4',unicode='Ä'},
['197']={glyph_name='uni00c5',unicode='Å'},
['198']={glyph_name='uni00c6',unicode='Æ'},
['199']={glyph_name='uni00c7',unicode='Ç'},
['200']={glyph_name='uni00c8',unicode='È'},
['201']={glyph_name='uni00c9',unicode='É'},
['202']={glyph_name='uni00ca',unicode='Ê'},
['203']={glyph_name='uni00cb',unicode='Ë'},
['204']={glyph_name='uni00cc',unicode='Ì'},
['205']={glyph_name='uni00cd',unicode='Í'},
['206']={glyph_name='uni00ce',unicode='Î'},
['207']={glyph_name='uni00cf',unicode='Ï'},
['208']={glyph_name='uni00d0',unicode='Ð'},
['209']={glyph_name='uni00d1',unicode='Ñ'},
['210']={glyph_name='uni00d2',unicode='Ò'},
['211']={glyph_name='uni00d3',unicode='Ó'},
['212']={glyph_name='uni00d4',unicode='Ô'},
['213']={glyph_name='uni00d5',unicode='Õ'},
['214']={glyph_name='uni00d6',unicode='Ö'},
['215']={glyph_name='uni00d7',unicode='×'},
['216']={glyph_name='uni00d8',unicode='Ø'},
['217']={glyph_name='uni00d9',unicode='Ù'},
['218']={glyph_name='uni00da',unicode='Ú'},
['219']={glyph_name='uni00db',unicode='Û'},
['220']={glyph_name='uni00dc',unicode='Ü'},
['221']={glyph_name='uni00dd',unicode='Ý'},
['222']={glyph_name='uni00de',unicode='Þ'},
['223']={glyph_name='uni00df',unicode='ß'},
['224']={glyph_name='uni00e0',unicode='à'},
['225']={glyph_name='uni00e1',unicode='á'},
['226']={glyph_name='uni00e2',unicode='â'},
['227']={glyph_name='uni00e3',unicode='ã'},
['228']={glyph_name='uni00e4',unicode='ä'},
['229']={glyph_name='uni00e5',unicode='å'},
['230']={glyph_name='uni00e6',unicode='æ'},
['231']={glyph_name='uni00e7',unicode='ç'},
['232']={glyph_name='uni00e8',unicode='è'},
['233']={glyph_name='uni00e9',unicode='é'},
['234']={glyph_name='uni00ea',unicode='ê'},
['235']={glyph_name='uni00eb',unicode='ë'},
['236']={glyph_name='uni00ec',unicode='ì'},
['237']={glyph_name='uni00ed',unicode='í'},
['238']={glyph_name='uni00ee',unicode='î'},
['239']={glyph_name='uni00ef',unicode='ï'},
['240']={glyph_name='uni00f0',unicode='ð'},
['241']={glyph_name='uni00f1',unicode='ñ'},
['242']={glyph_name='uni00f2',unicode='ò'},
['243']={glyph_name='uni00f3',unicode='ó'},
['244']={glyph_name='uni00f4',unicode='ô'},
['245']={glyph_name='uni00f5',unicode='õ'},
['246']={glyph_name='uni00f6',unicode='ö'},
['247']={glyph_name='uni00f7',unicode='÷'},
['248']={glyph_name='uni00f8',unicode='ø'},
['249']={glyph_name='uni00f9',unicode='ù'},
['250']={glyph_name='uni00fa',unicode='ú'},
['251']={glyph_name='uni00fb',unicode='û'},
['252']={glyph_name='uni00fc',unicode='ü'},
['253']={glyph_name='uni00fd',unicode='ý'},
['254']={glyph_name='uni00fe',unicode='þ'},
['255']={glyph_name='uni00ff',unicode='ÿ'},
['256']={glyph_name='uni0100',unicode='Ā'},
},
}
local function _eval_tonumber(q,offset)
local qx,qy,xo,yo
local w
local _offset = offset
if _offset == nil then _offset = '(0,0)' end
w=string.gmatch(q,"[-0-9.]+"); qx,qy=w(),w()
w=string.gmatch(_offset,"[-0-9.]+"); xo,yo=w(),w()
return {tonumber(qx+xo),tonumber(qy+yo)}
end
local function get_svg_glyph(valid_curves,char,cycles,tfm)
-- Write the svg
--
-- print('BEZ MFbuiltin.hppp='..print_scaled(MFbuiltin.hppp()))
-- print('BEZ MFbuiltin.vppp='..print_scaled(MFbuiltin.vppp()))
-- print('BEZ MFbuiltin.designsize='..print_scaled(MFbuiltin.designsize()))
local tfm = tfm
local index = tostring( char['index'] ) -- better a string or a number
local design_size=tonumber ( print_scaled(MFbuiltin.designsize()) ) --pt
local char_wd=tonumber( char['char_wd'] ) -- pt
local char_ht=tonumber( char['char_ht'] ) -- pt
local char_dp=tonumber( char['char_dp'] ) -- pt
--local xheight = 0.458333 * design_size -- must be read from tfm !!
local x_resolution = math.floor(0.5+tonumber( print_scaled(MFbuiltin.hppp()) )* 72.27)
local y_resolution = math.floor(0.5+tonumber( print_scaled(MFbuiltin.vppp()) )* 72.27)
assert(x_resolution==y_resolution, string.format('Error on _get_svg_glyph x_res=%d and y_res=%d differ',x_resolution,y_resolution))
local resolution = x_resolution
local emsize = mflua.svg.emsize -- 1000, type 1, also known as em_unit: 1000 emsize = 1em
local em_unit = emsize
local em_unit_for_pixel = (72.27/design_size) * (emsize / resolution)
local bp_for_pt = 72/72.27
local char_wd_emunit = (char_wd/design_size) *em_unit
local char_ht_emunit = (char_ht/design_size) *em_unit
local char_dp_emunit = (char_dp/design_size) *em_unit
local outdir = mflua.svg.output_dir or '.'
local fname = tostring(char['charname'])
if fname and fname ~= '' then
mflua.svg.char[index] ={glyph_name='', unicode = ''};
mflua.svg.char[index].glyph_name = fname
local w = string.gmatch(fname,'uni(.+)')
local unicode_hex = w()
mflua.svg.char[index].unicode = [[&#x]] .. unicode_hex ..';'
end
fname = mflua.svg.char[index].glyph_name
assert(fname~=nil, string.format("Error on svg file name for char index %s: it's nil",index))
--local f = io.open(outdir..'/'.. fname..'.svg','w')
local w = string.gmatch(fname,'uni(.+)')
local unicode_hex = w()
local unicode = mflua.svg.char[index].unicode
local unicode_range = 'U+'..unicode_hex
local glyph_name = fname
local bezier = ''
local maxx,maxy=-1e9,-1e9
local minx,miny=1e9,1e9
for i,cycle in pairs(cycles) do
local path=''
local _i=1
for _,j in ipairs(cycle) do
--local curve = valid_curves[j]
local curve = j
local p,c1,c2,q,offset=curve[1],curve[2],curve[3],curve[4],curve[5]
p=_eval_tonumber(p,offset)
c1=_eval_tonumber(c1,offset)
c2=_eval_tonumber(c2,offset)
q=_eval_tonumber(q,offset)
-- em_unit_for_pixel
p[1],p[2] = p[1]*em_unit_for_pixel,p[2]*em_unit_for_pixel
q[1],q[2] = q[1]*em_unit_for_pixel,q[2]*em_unit_for_pixel
c1[1],c1[2] = c1[1]*em_unit_for_pixel,c1[2]*em_unit_for_pixel
c2[1],c2[2] = c2[1]*em_unit_for_pixel,c2[2]*em_unit_for_pixel
if _i==1 then bezier = bezier..string.format("M%s %s ",p[1],p[2]) end
_i=_i+1
bezier = bezier .. string.format("C%s %s %s %s %s %s\n",c1[1],c1[2],c2[1],c2[2],q[1],q[2])
--print("BEZ bez="..bezier)
if p[1]>maxx then maxx=p[1] end
if c1[1]>maxx then maxx=c1[1] end
if c2[1]>maxx then maxx=c2[1] end
if q[1]>maxx then maxx=q[1] end
if p[2]>maxy then maxy=p[2] end
if c1[2]>maxy then maxy=c1[2] end
if c2[2]>maxy then maxy=c2[2] end
if q[2]>maxy then maxy=q[2] end
--
if p[1]<minx then minx=p[1] end
if c1[1]<minx then minx=c1[1] end
if c2[1]<minx then minx=c2[1] end
if q[1]<minx then minx=q[1] end
if p[2]<miny then miny=p[2] end
if c1[2]<miny then miny=c1[2] end
if c2[2]<miny then miny=c2[2] end
if q[2]<miny then miny=q[2] end
end
bezier = bezier .. 'Z\n'
end
--print('BEZ (x,y) (X,Y)=',minx,miny,maxx,maxy)
--print('BEZ', svg_glyph,glyph_name,unicode,char_wd_emunit,char_ht_emunit,bezier)
local trunk = ''
local svg_glyph = mflua.svg.glyph
local svg_font = mflua.svg.font
trunk = string.format(svg_glyph,
glyph_name,unicode,
char_wd_emunit,
char_ht_emunit,
bezier,'')
local svg_preamble = mflua.svg.svg_preamble
local paths = string.format('<path style="fill:#000000;stroke=none;fill-rule:nonzero" d="%s" />', bezier)
local raw=string.format(svg_preamble,minx,miny,maxx,maxy,-maxy,paths)
return trunk,raw
end -- _get_svg_glyph
local function svg_kern_and_lig(chartable,t,tfm)
--
-- Store kerns and ligs
--
local current_chars={}
local index
local kern, next_char,additional_space
local bp_for_pt = 72/72.27
local x_resolution = math.floor(0.5+tonumber( print_scaled(MFbuiltin.hppp()) )* bp_for_pt)
local y_resolution = math.floor(0.5+tonumber( print_scaled(MFbuiltin.vppp()) )* bp_for_pt)
local design_size=tfm.font.designsize -- pt
assert(x_resolution==y_resolution, string.format('Error on _get_svg_glyph x_res=%d and y_res=%d differ',x_resolution,y_resolution))
local resolution = x_resolution
local emsize = mflua.svg.emsize -- 1000, type 1, also known as em_unit: 1000 emsize = 1em
local em_unit = emsize
local em_unit_for_pixel = (bp_for_pt/design_size) * (emsize / resolution)
local hkern,vkern = '' ,''
for i,_ in ipairs(t) do
index = t[i]
current_chars[index]=true
end
for i,_ in ipairs(t) do
index = t[i]
if tfm.chars[index] and tfm.chars[index].kern then
kerntable = tfm.chars[index].kern
for _,k in ipairs(kerntable) do
next_char,additional_space = tostring(k.next_char),tonumber(k.additional_space)
--
if additional_space~=0 then
local a_name,a_unicode = mflua.svg.char[tostring(index)].glyph_name,mflua.svg.char[tostring(index)].unicode
local b_name,b_unicode = mflua.svg.char[next_char].glyph_name,mflua.svg.char[next_char].unicode
hkern = hkern .. "\n".. string.format(mflua.svg.hkern,
a_name,a_unicode,
b_name,b_unicode,
additional_space*design_size*em_unit_for_pixel)
end
end
end
end
return hkern,vkern
end
local function store_svg_font(tfm)
-- local outdir = mflua.svg.output_dir or '.'
-- local fname = mflua.svg.filename
-- assert(fname~=nil, string.format("Error on svg file name for %s: it's nil",fname))
-- local f = io.open(outdir..'/'.. fname..'.svg','w')
local svg_font = mflua.svg.font
local design_size=tonumber ( print_scaled(MFbuiltin.designsize()) ) --pt
local emsize = mflua.svg.emsize -- 1000, type 1, also known as em_unit: 1000 emsize = 1em
local bp_for_pt = 72/72.27
local xheight = tfm.font.x_height * design_size --0.458333 * design_size -- must be read from tfm !!
local trunk =''
local char = mflua.svg.char
for index=0,2^16-1 do
if not(char[tostring(index)]==nil) then
--print("BEZ char[tostring(index)].data=",index,char[tostring(index)].data)
trunk= trunk.. (char[tostring(index)].data or '')
end
end
trunk = trunk.."\n"..mflua.svg.hkerns.."\n"..mflua.svg.vkerns
trunk = string.format(svg_font,
string.format("%2.2f",design_size*bp_for_pt),
emsize,
string.format("%2.2f",xheight*bp_for_pt),
trunk)
return trunk
end
svg.get_svg_glyph = get_svg_glyph
svg.svg_kern_and_lig = svg_kern_and_lig
svg.store_svg_font = store_svg_font
return svg
|