svg2ttf-new
Advanced tools
Comparing version 5.3.0-beta.2 to 5.3.0-beta.3
@@ -0,1 +1,7 @@ | ||
5.3.0 / WIP | ||
------------------ | ||
- Generated OS/2 table version is bumped from 1 to 5, #106. | ||
5.2.0 / 2021-04-07 | ||
@@ -2,0 +8,0 @@ ------------------ |
22
index.js
@@ -17,3 +17,3 @@ /* | ||
var VERSION_RE = /^(Version )?\s*(\d+[.]\d+)$/i; | ||
var VERSION_RE = /^(Version )?(\d+[.]\d+)$/i; | ||
@@ -32,6 +32,6 @@ | ||
font.url = options.url || 'http://fontello.com'; | ||
font.sfntNames.push({ id: 2, value: (options.subfamilyname || svgFont.subfamilyName || 'Regular').trim() }); // subfamily name | ||
font.sfntNames.push({ id: 4, value: (options.fullname || svgFont.id).trim() }); // full name | ||
font.sfntNames.push({ id: 2, value: options.subfamilyname || svgFont.subfamilyName || 'Regular' }); // subfamily name | ||
font.sfntNames.push({ id: 4, value: options.fullname || svgFont.id }); // full name | ||
var versionString = (options.version || 'Version 1.0').trim(); | ||
var versionString = options.version || 'Version 1.0'; | ||
@@ -47,3 +47,3 @@ if (typeof versionString !== 'string') { | ||
font.sfntNames.push({ id: 5, value: versionString }); // version ID for TTF name table | ||
font.sfntNames.push({ id: 6, value: (options.fullname || svgFont.id).replace(/[\s\(\)\[\]<>%\/]/g, '').substr(0, 62).trim() }); // Postscript name for the font, required for OSX Font Book | ||
font.sfntNames.push({ id: 6, value: (options.fullname || svgFont.id).replace(/[\s\(\)\[\]<>%\/]/g, '').substr(0, 62) }); // Postscript name for the font, required for OSX Font Book | ||
@@ -61,6 +61,10 @@ if (typeof options.ts !== 'undefined') { | ||
font.vertOriginY = svgFont.vertOriginY || 0; | ||
font.width = svgFont.width || svgFont.unitsPerEm; | ||
font.height = svgFont.height || svgFont.unitsPerEm; | ||
font.descent = !isNaN(svgFont.descent) ? svgFont.descent : -font.vertOriginY; | ||
font.ascent = svgFont.ascent || (font.unitsPerEm - font.vertOriginY); | ||
font.width = svgFont.width || svgFont.unitsPerEm; | ||
font.height = svgFont.height || svgFont.unitsPerEm; | ||
font.descent = !isNaN(svgFont.descent) ? svgFont.descent : -font.vertOriginY; | ||
font.ascent = svgFont.ascent || (font.unitsPerEm - font.vertOriginY); | ||
// Values for font substitution. We're mostly working with icon fonts, so they aren't expected to be substituted. | ||
// https://docs.microsoft.com/en-us/typography/opentype/spec/os2#sxheight | ||
font.capHeight = svgFont.capHeight || 0; // 0 is a valid value if "H" glyph doesn't exist | ||
font.xHeight = svgFont.xHeight || 0; // 0 is a valid value if "x" glyph doesn't exist | ||
@@ -67,0 +71,0 @@ if (typeof svgFont.weightClass !== 'undefined') { |
@@ -52,2 +52,4 @@ 'use strict'; | ||
this.int_descent = -150; | ||
this.xHeight = 0; | ||
this.capHeight = 0; | ||
@@ -194,3 +196,2 @@ //getters and setters | ||
// TODO: Under special circumstances, the yMax returned by cubic2quad is too large. | ||
Object.defineProperty(this, 'yMax', { | ||
@@ -197,0 +198,0 @@ get: function () { |
@@ -131,2 +131,4 @@ 'use strict'; | ||
unitsPerEm: 'units-per-em', | ||
capHeight: 'cap-height', | ||
xHeight: 'x-height', | ||
underlineThickness: 'underline-thickness', | ||
@@ -133,0 +135,0 @@ underlinePosition: 'underline-position' |
@@ -40,6 +40,6 @@ 'use strict'; | ||
if (font.copyright) { | ||
result.push.apply(result, getStrings(font.copyright.trim(), TTF_NAMES.COPYRIGHT)); | ||
result.push.apply(result, getStrings(font.copyright, TTF_NAMES.COPYRIGHT)); | ||
} | ||
if (font.familyName) { | ||
result.push.apply(result, getStrings(font.familyName.trim(), TTF_NAMES.FONT_FAMILY)); | ||
result.push.apply(result, getStrings(font.familyName, TTF_NAMES.FONT_FAMILY)); | ||
} | ||
@@ -49,7 +49,7 @@ if (font.id) { | ||
} | ||
result.push.apply(result, getStrings(font.description.trim(), TTF_NAMES.DESCRIPTION)); | ||
result.push.apply(result, getStrings(font.url.trim(), TTF_NAMES.URL_VENDOR)); | ||
result.push.apply(result, getStrings(font.description, TTF_NAMES.DESCRIPTION)); | ||
result.push.apply(result, getStrings(font.url, TTF_NAMES.URL_VENDOR)); | ||
_.forEach(font.sfntNames, function (sfntName) { | ||
result.push.apply(result, getStrings(sfntName.value.trim(), sfntName.id)); | ||
result.push.apply(result, getStrings(sfntName.value, sfntName.id)); | ||
}); | ||
@@ -56,0 +56,0 @@ |
@@ -25,5 +25,12 @@ 'use strict'; | ||
var buf = new ByteBuffer(86); | ||
// use at least 2 for ligatures and kerning | ||
var maxContext = font.ligatures.map(function (l) { | ||
return l.unicode.length; | ||
}).reduce(function (a, b) { | ||
return Math.max(a, b); | ||
}, 2); | ||
buf.writeUint16(1); //version | ||
var buf = new ByteBuffer(100); | ||
buf.writeUint16(5); //version | ||
buf.writeInt16(font.avgWidth); // xAvgCharWidth | ||
@@ -66,15 +73,18 @@ buf.writeUint16(font.weightClass); // usWeightClass | ||
buf.writeInt16(font.lineGap); // lineGap | ||
// Enlarge win acscent/descent to avoid clipping | ||
// In IE9, 10, 11, if usWinAscent=usWinDescent=0, IE will report an error and refuse to display. | ||
// Spec: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswinascent | ||
// ufo2ft: https://github.com/googlefonts/ufo2ft/blob/a5267d135d5a8dba7e6a5d3ac44139afa6159429/Lib/ufo2ft/fontInfoData.py#L245-L246 | ||
buf.writeInt16(font.ascent + font.lineGap); // usWinAscent(Windows ascender), Fallback to ascender + typoLineGap. | ||
// Spec: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswindescent | ||
// ufo2ft: https://github.com/googlefonts/ufo2ft/blob/a5267d135d5a8dba7e6a5d3ac44139afa6159429/Lib/ufo2ft/fontInfoData.py#L254 | ||
buf.writeInt16(Math.abs(font.descent)); // usWinDescent(Windows descender), Fallback to descender. | ||
// WinAscent - WinDecent should at least be equal to TypoAscender - TypoDescender + TypoLineGap: | ||
// https://www.high-logic.com/font-editor/fontcreator/tutorials/font-metrics-vertical-line-spacing | ||
buf.writeInt16(Math.max(font.yMax, font.ascent + font.lineGap)); // usWinAscent | ||
buf.writeInt16(-Math.min(font.yMin, font.descent)); // usWinDescent | ||
buf.writeInt32(1); // ulCodePageRange1, Latin 1 | ||
buf.writeInt32(0); // ulCodePageRange2 | ||
buf.writeInt16(font.xHeight); // sxHeight | ||
buf.writeInt16(font.capHeight); // sCapHeight | ||
buf.writeUint16(0); // usDefaultChar, pointing to missing glyph (always id=0) | ||
buf.writeUint16(0); // usBreakChar, code=32 isn't guaranteed to be a space in icon fonts | ||
buf.writeUint16(maxContext); // usMaxContext, use at least 2 for ligatures and kerning | ||
// if font isn't designed for multiple optical-sized variants, | ||
// following fields should be 0x0000-0xFFFF | ||
buf.writeUint16(0); // usLowerOpticalPointSize | ||
buf.writeUint16(0xFFFF); // usUpperOpticalPointSize | ||
@@ -81,0 +91,0 @@ return buf; |
{ | ||
"name": "svg2ttf-new", | ||
"version": "5.3.0-beta.2", | ||
"version": "5.3.0-beta.3", | ||
"description": "Converts SVG font to TTF font", | ||
@@ -23,3 +23,3 @@ "keywords": [ | ||
"scripts": { | ||
"lint": "eslint --fix .", | ||
"lint": "eslint .", | ||
"test": "npm run lint && mocha", | ||
@@ -30,3 +30,3 @@ "update_fixture": "./svg2ttf.js --ts 1457357570703 test/fixtures/test.svg test/fixtures/test.ttf" | ||
"argparse": "^2.0.1", | ||
"cubic2quad": "^1.2.0", | ||
"cubic2quad": "^1.2.1", | ||
"lodash": "^4.17.10", | ||
@@ -39,5 +39,5 @@ "microbuffer": "^1.0.0", | ||
"eslint": "^7.0.0", | ||
"mocha": "^7.1.2", | ||
"mocha": "^8.3.2", | ||
"opentype.js": "^1.3.3" | ||
} | ||
} | ||
} |
svg2ttf-new | ||
======= | ||
[![CI](https://github.com/fontello/svg2ttf/actions/workflows/ci.yml/badge.svg)](https://github.com/fontello/svg2ttf/actions/workflows/ci.yml) | ||
[![NPM version](https://img.shields.io/npm/v/svg2ttf.svg?style=flat)](https://www.npmjs.org/package/svg2ttf) | ||
[![CI](https://github.com/yisibl/svg2ttf/actions/workflows/ci.yml/badge.svg)](https://github.com/yisibl/svg2ttf/actions/workflows/ci.yml) | ||
[![NPM version](https://img.shields.io/npm/v/svg2ttf-new.svg?style=flat)](https://www.npmjs.org/package/svg2ttf-new) | ||
@@ -25,3 +25,3 @@ > Converts SVG fonts to TTF format. It was initially written for | ||
``` bash | ||
npm install -g svg2ttf | ||
npm install -g svg2ttf-new | ||
``` | ||
@@ -28,0 +28,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81956
2156
Updatedcubic2quad@^1.2.1