Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use svg2ttf-new #54

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 20 additions & 42 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var multiline = require('multiline')

//导出svg的配置
exports.DEFAULT_EXPORT_OPTIONS = {
width: '100px',
Expand All @@ -11,7 +9,6 @@ exports.PATH_DECIMAL = 4

exports.FONT_FAMILY = 'iconfont'


//默认的配置参数
exports.DEFAULT_OPTIONS = {
font: {
Expand Down Expand Up @@ -40,48 +37,29 @@ exports.DEFAULT_OPTIONS = {
}
}



exports.FONT_TMPL = multiline(function() {/*!
<?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>
exports.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 xmlns="http://www.w3.org/2000/svg">
<metadata>Created by font-carrier</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] + '"') %>
<%} %>
/>
<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 />

<% 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']+'"') %> />

<% } %>

</font>
<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']+'"') %> />
<% }
%></font>
</defs>
</svg>
*/
})

</svg>`

exports.SVG_TMPL = multiline(function() {/*!
<?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'] %>">
exports.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>
*/
})
</svg>`
2 changes: 1 addition & 1 deletion lib/helper/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var opentype = require('opentype.js')
var DOMParser = require('xmldom').DOMParser


var svg2ttf = require('svg2ttf')
var svg2ttf = require('svg2ttf-new')
var ttf2svg = require('ttf2svg')
var ttf2eot = require('ttf2eot')
var ttf2woff = require('ttf2woff')
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "font-carrier",
"version": "0.3.1",
"version": "0.4.0-beta.8",
"description": "字体搬运工,中文字体解决方案,iconfont",
"main": "./lib/index.js",
"scripts": {
Expand All @@ -13,9 +13,8 @@
],
"dependencies": {
"lodash": "^4.17.21",
"multiline": "^2.0.0",
"opentype.js": "^1.1.0",
"svg2ttf": "^5.2.0",
"svg2ttf-new": "^6.1.0-beta.3",
"svg_pathify": "^0.0.8",
"svgpath": "^2.3.1",
"ttf2eot": "^2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions test/export.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions test/export2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/font-out/arrow-up.ttf
Binary file not shown.
24 changes: 15 additions & 9 deletions test/font-out/arrow-up.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="1.0"/>
<fontRevision value="1.0"/>
<checkSumAdjustment value="0x91d8b7bf"/>
<checkSumAdjustment value="0x1d208df5"/>
<magicNumber value="0x5f0f3cf5"/>
<flags value="00000000 00001011"/>
<unitsPerEm value="1024"/>
<created value="Tue May 11 07:40:41 2021"/>
<modified value="Tue May 11 07:40:41 2021"/>
<created value="Wed May 26 09:43:49 2021"/>
<modified value="Wed May 26 09:43:49 2021"/>
<xMin value="0"/>
<yMin value="-130"/>
<xMax value="1024"/>
<yMax value="32148"/>
<yMax value="896"/>
<macStyle value="00000000 00000000"/>
<lowestRecPPEM value="8"/>
<fontDirectionHint value="2"/>
Expand Down Expand Up @@ -52,7 +52,7 @@
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="0x10000"/>
<numGlyphs value="2"/>
<maxPoints value="29"/>
<maxPoints value="28"/>
<maxContours value="1"/>
<maxCompositePoints value="0"/>
<maxCompositeContours value="0"/>
Expand All @@ -70,7 +70,7 @@
<OS_2>
<!-- The fields 'usFirstCharIndex' and 'usLastCharIndex'
will be recalculated by the compiler -->
<version value="1"/>
<version value="5"/>
<xAvgCharWidth value="1024"/>
<usWeightClass value="500"/>
<usWidthClass value="5"/>
Expand Down Expand Up @@ -109,10 +109,17 @@
<sTypoAscender value="896"/>
<sTypoDescender value="-128"/>
<sTypoLineGap value="92"/>
<usWinAscent value="32148"/>
<usWinAscent value="988"/>
<usWinDescent value="130"/>
<ulCodePageRange1 value="00000000 00000000 00000000 00000001"/>
<ulCodePageRange2 value="00000000 00000000 00000000 00000000"/>
<sxHeight value="0"/>
<sCapHeight value="0"/>
<usDefaultChar value="0"/>
<usBreakChar value="0"/>
<usMaxContext value="2"/>
<usLowerOpticalPointSize value="0.0"/>
<usUpperOpticalPointSize value="3276.75"/>
</OS_2>

<hmtx>
Expand Down Expand Up @@ -149,11 +156,10 @@

<TTGlyph name="glyph00000"/><!-- contains no outline data -->

<TTGlyph name="up" xMin="0" yMin="-130" xMax="924" yMax="32148">
<TTGlyph name="up" xMin="0" yMin="-130" xMax="924" yMax="896">
<contour>
<pt x="567" y="-68" on="1"/>
<pt x="567" y="693" on="1"/>
<pt x="567" y="32147" on="0"/>
<pt x="567" y="694" on="1"/>
<pt x="827" y="406" on="1"/>
<pt x="837" y="395" on="0"/>
Expand Down
Binary file modified test/font-out/font1.ttf
Binary file not shown.
38 changes: 19 additions & 19 deletions test/font-out/font1.ttx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.20">
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.26">

<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
Expand All @@ -15,12 +15,12 @@
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="1.0"/>
<fontRevision value="1.0"/>
<checkSumAdjustment value="0x7c06b8e3"/>
<checkSumAdjustment value="0x140694f9"/>
<magicNumber value="0x5f0f3cf5"/>
<flags value="00000000 00001011"/>
<unitsPerEm value="1024"/>
<created value="Tue May 11 07:40:41 2021"/>
<modified value="Tue May 11 07:40:41 2021"/>
<created value="Fri Aug 20 12:38:00 2021"/>
<modified value="Fri Aug 20 12:38:00 2021"/>
<xMin value="-1"/>
<yMin value="-212"/>
<xMax value="1350"/>
Expand All @@ -36,7 +36,7 @@
<tableVersion value="0x00010000"/>
<ascent value="812"/>
<descent value="-212"/>
<lineGap value="0"/>
<lineGap value="92"/>
<advanceWidthMax value="1350"/>
<minLeftSideBearing value="-1"/>
<minRightSideBearing value="0"/>
Expand Down Expand Up @@ -74,7 +74,7 @@
<OS_2>
<!-- The fields 'usFirstCharIndex' and 'usLastCharIndex'
will be recalculated by the compiler -->
<version value="1"/>
<version value="4"/>
<xAvgCharWidth value="924"/>
<usWeightClass value="400"/>
<usWidthClass value="5"/>
Expand Down Expand Up @@ -112,11 +112,16 @@
<usLastCharIndex value="58881"/>
<sTypoAscender value="812"/>
<sTypoDescender value="-212"/>
<sTypoLineGap value="92"/>
<usWinAscent value="813"/>
<sTypoLineGap value="0"/>
<usWinAscent value="904"/>
<usWinDescent value="212"/>
<ulCodePageRange1 value="00000000 00000000 00000000 00000001"/>
<ulCodePageRange2 value="00000000 00000000 00000000 00000000"/>
<sxHeight value="0"/>
<sCapHeight value="0"/>
<usDefaultChar value="0"/>
<usBreakChar value="0"/>
<usMaxContext value="2"/>
</OS_2>

<hmtx>
Expand Down Expand Up @@ -387,8 +392,9 @@
<pt x="0" y="763" on="0"/>
<pt x="0" y="728" on="1"/>
<pt x="0" y="-128" on="1"/>
<pt x="0" y="-161" on="0"/>
<pt x="53" y="-211" on="0"/>
<pt x="0" y="-150" on="0"/>
<pt x="25" y="-188" on="0"/>
<pt x="65" y="-211" on="0"/>
<pt x="87" y="-211" on="1"/>
<pt x="1274" y="-211" on="1"/>
<pt x="1307" y="-211" on="0"/>
Expand Down Expand Up @@ -444,9 +450,7 @@

<name>
<namerecord nameID="0" platformID="1" platEncID="0" langID="0x0" unicode="True">

Created by font-carrier

Created by font-carrier
</namerecord>
<namerecord nameID="1" platformID="1" platEncID="0" langID="0x0" unicode="True">
iconfont
Expand All @@ -473,9 +477,7 @@
http://fontello.com
</namerecord>
<namerecord nameID="0" platformID="3" platEncID="1" langID="0x409">

Created by font-carrier

Created by font-carrier
</namerecord>
<namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
iconfont
Expand Down Expand Up @@ -532,8 +534,6 @@
<psName name="_"/>
<psName name="uniE600"/>
<psName name="uniE601"/>
<psName name=""/>
<psName name=""/>
</extraNames>
</post>

Expand Down Expand Up @@ -580,7 +580,7 @@
<LookupType value="4"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1">
<LigatureSubst index="0">
</LigatureSubst>
</Lookup>
</LookupList>
Expand Down
Binary file modified test/font-out/font2.eot
Binary file not shown.
Loading