更新模板语法

master
yutent 2024-02-05 18:42:54 +08:00
parent 59608c7409
commit dc87a4b287
3 changed files with 31 additions and 25 deletions

View File

@ -43,30 +43,33 @@ export const FONT_TMPL = `
<?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 font-carrier
</metadata>
<metadata>Created by @bytedo/font-generator</metadata>
<defs>
<font id="<%= font.id %>" horiz-adv-x="<%= font.horizAdvX %>" vert-adv-y="<%= font.horizAdvX %>" >
<font-face
<% for(var v in fontface){ %>
<% print(v + '="' + fontface[v] + '"') %>
<%} %>
/>
<missing-glyph />
<font id="${font.id}" horiz-adv-x="${font.horizAdvX}" vert-adv-y="${
font.horizAdvX
}" >
<font-face ${Object.keys(fontface)
.map(k => `${k}="${fontface[k]}"`)
.join(' ')} />
<missing-glyph />
<% if(!hasX){ %>
<glyph glyph-name="x" unicode="&#x78;" horiz-adv-x="100"
d="M20 20 L50 20 L50 -20 Z" />
<% } %>
<% for(var i in glyphs){
var glyph = glyphs[i].options;
%>
<glyph glyph-name="<%= glyph['glyphName'] %>" unicode="<%= glyph['unicode']%>" d="<%= glyph['d']%>" <% if (glyph['horizAdvX']) print('horiz-adv-x="'+ glyph['horizAdvX']+'"') %> <% if (glyph['vertAdvY']) print('vert-adv-y="'+ glyph['vertAdvY']+'"') %> />
<% } %>
${
hasX
? ''
: '<glyph glyph-name="x" unicode="&#x78;" horiz-adv-x="100" d="M20 20 L50 20 L50 -20 Z" />'
}
${glyphs
.map(
glyph =>
`<glyph glyph-name="${glyph.glyphName}" unicode="${
glyph.unicode
}" d="${glyph.d}" ${
glyph.horizAdvX ? `horiz-adv-x="${glyph.horizAdvX}"` : ''
} ${glyph.vertAdvY ? `vert-adv-y="${glyph.vertAdvY}"` : ''} />`
)
.join('\n')}
</font>
</defs>
</svg>
@ -75,7 +78,11 @@ export const FONT_TMPL = `
export const SVG_TMPL = `
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" <% if(!options['skipViewport']){ %> x="0" y="0" width="<%= options['width'] %>" height="<%= options['height'] %>" <% } %> viewBox="0 0 <%= glyph['horizAdvX'] %> <%= glyph['vertAdvY'] %>">
<path d="<%= glyph['d'] %>"/>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ${
options.skipViewport
? ''
: `x="0" y="0" width="${options.width}" height="${options.height}"`
} viewBox="0 0 ${glyph.horizAdvX} ${glyph.vertAdvY}">
<path d="${glyph.d}"/>
</svg>
`

View File

@ -91,7 +91,6 @@ export function load(str) {
fontElem = doc.getElementsByTagName('font')[0]
if (!fontElem) {
console.log(doc)
throw new Error(
"Can't find <font> tag. Make sure you SVG file is font, not image."
)

View File

@ -11,4 +11,4 @@ let svg = fs.cat('test/game.svg').toString()
let ttf = svg2ttf(svg)
console.log(ttf)
// console.log(ttf)