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