diff --git a/MODIFICATIONS.md b/MODIFICATIONS.md index f80caf69..4e92f0a8 100644 --- a/MODIFICATIONS.md +++ b/MODIFICATIONS.md @@ -1,5 +1,14 @@ # Modifications +## [Unreleased] + +- Remove WOFF format support + - Also removing the `tiny-inflate` dependency (the indirect dependency may remain) +- Remove WOFF2 format support + - Also removing the `brotli` dependency +- Remove DFont format support +- Simplify the published TypeScript types by inlining the concrete format exports (`TTFFont`/`TrueTypeCollection`) in place of the old aliases (`Font`/`FontCollection`). + ## [2.0.4-mod.2025.2] - Improve performance of `CmapProcessor#lookupNonDefaultUVS` by caching variation selector records from `cmap` format 14 subtable diff --git a/README.md b/README.md index c4dc9122..64d61c15 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Fontkit is an advanced font engine for Node and the browser, used by [PDFKit](ht ## Features -* Supports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collection (.ttc), and Datafork TrueType (.dfont) font files +* Supports TrueType (.ttf), OpenType (.otf), and TrueType Collection (.ttc) font files (WOFF/WOFF2/DFont inputs have been removed) * Supports mapping characters to glyphs, including support for ligatures and other advanced substitutions (see below) * Supports reading glyph metrics and laying out glyphs, including support for kerning and other advanced layout features (see below) * Advanced OpenType features including glyph substitution (GSUB) and positioning (GPOS) diff --git a/package-lock.json b/package-lock.json index a43b2b44..e06faf9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,21 +1,19 @@ { "name": "@denkiyagi/fontkit", - "version": "2.0.4-mod.2025.1", + "version": "2.0.4-mod.2025.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@denkiyagi/fontkit", - "version": "2.0.4-mod.2025.1", + "version": "2.0.4-mod.2025.2", "license": "MIT", "dependencies": { "@swc/helpers": "^0.5.12", - "brotli": "^1.3.2", "clone": "^2.1.2", "dfa": "^1.2.0", "fast-deep-equal": "^3.1.3", "restructure": "^3.0.0", - "tiny-inflate": "^1.0.3", "unicode-properties": "^1.4.0", "unicode-trie": "^2.0.0" }, @@ -2316,14 +2314,6 @@ "node": ">=8" } }, - "node_modules/brotli": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/brotli/-/brotli-1.3.3.tgz", - "integrity": "sha512-oTKjJdShmDuGW94SyyaoQvAjf30dZaHnjJ8uAF+u2/vGJkJbJPJAT1gDiOJP5v1Zb6f9KEyW/1HpuaWIXtGHPg==", - "dependencies": { - "base64-js": "^1.1.2" - } - }, "node_modules/browser-stdout": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", diff --git a/package.json b/package.json index f733a36b..624ba6ae 100644 --- a/package.json +++ b/package.json @@ -83,12 +83,10 @@ }, "dependencies": { "@swc/helpers": "^0.5.12", - "brotli": "^1.3.2", "clone": "^2.1.2", "dfa": "^1.2.0", "fast-deep-equal": "^3.1.3", "restructure": "^3.0.0", - "tiny-inflate": "^1.0.3", "unicode-properties": "^1.4.0", "unicode-trie": "^2.0.0" }, diff --git a/src/DFont.js b/src/DFont.js deleted file mode 100644 index 168a563c..00000000 --- a/src/DFont.js +++ /dev/null @@ -1,120 +0,0 @@ -import * as r from 'restructure'; -import TTFFont from './TTFFont'; - -let DFontName = new r.String(r.uint8); -let DFontData = new r.Struct({ - len: r.uint32, - buf: new r.Buffer('len') -}); - -let Ref = new r.Struct({ - id: r.uint16, - nameOffset: r.int16, - attr: r.uint8, - dataOffset: r.uint24, - handle: r.uint32 -}); - -let Type = new r.Struct({ - name: new r.String(4), - maxTypeIndex: r.uint16, - refList: new r.Pointer(r.uint16, new r.Array(Ref, t => t.maxTypeIndex + 1), { type: 'parent' }) -}); - -let TypeList = new r.Struct({ - length: r.uint16, - types: new r.Array(Type, t => t.length + 1) -}); - -let DFontMap = new r.Struct({ - reserved: new r.Reserved(r.uint8, 24), - typeList: new r.Pointer(r.uint16, TypeList), - nameListOffset: new r.Pointer(r.uint16, 'void') -}); - -let DFontHeader = new r.Struct({ - dataOffset: r.uint32, - map: new r.Pointer(r.uint32, DFontMap), - dataLength: r.uint32, - mapLength: r.uint32 -}); - -export default class DFont { - /** - * @type {'DFont'} - */ - type = 'DFont'; - - static probe(buffer) { - let stream = new r.DecodeStream(buffer); - - try { - var header = DFontHeader.decode(stream); - } catch (e) { - return false; - } - - for (let type of header.map.typeList.types) { - if (type.name === 'sfnt') { - return true; - } - } - - return false; - } - - constructor(stream) { - this.stream = stream; - this.header = DFontHeader.decode(this.stream); - - for (let type of this.header.map.typeList.types) { - for (let ref of type.refList) { - if (ref.nameOffset >= 0) { - this.stream.pos = ref.nameOffset + this.header.map.nameListOffset; - ref.name = DFontName.decode(this.stream); - } else { - ref.name = null; - } - } - - if (type.name === 'sfnt') { - this.sfnt = type; - } - } - } - - getFont(name) { - if (!this.sfnt) { - return null; - } - - for (let ref of this.sfnt.refList) { - let pos = this.header.dataOffset + ref.dataOffset + 4; - let stream = new r.DecodeStream(this.stream.buffer.slice(pos)); - let font = new TTFFont(stream); - if ( - font.postscriptName === name || - ( - font.postscriptName instanceof Uint8Array && - name instanceof Uint8Array && - font.postscriptName.every((v, i) => name[i] === v) - ) - ) { - return font; - } - } - - return null; - } - - get fonts() { - let fonts = []; - for (let ref of this.sfnt.refList) { - let pos = this.header.dataOffset + ref.dataOffset + 4; - let stream = new r.DecodeStream(this.stream.buffer.slice(pos)); - fonts.push(new TTFFont(stream)); - } - - return fonts; - } -} diff --git a/src/TTFFont.js b/src/TTFFont.js index 544475b1..77f8a533 100644 --- a/src/TTFFont.js +++ b/src/TTFFont.js @@ -21,7 +21,7 @@ import { asciiDecoder } from './utils'; */ export default class TTFFont { /** - * @type {'TTF' | 'WOFF' | 'WOFF2'} + * @type {'TTF'} */ type = 'TTF'; diff --git a/src/WOFF2Font.js b/src/WOFF2Font.js deleted file mode 100644 index 61ba12c1..00000000 --- a/src/WOFF2Font.js +++ /dev/null @@ -1,217 +0,0 @@ -import * as r from 'restructure'; -import brotli from 'brotli/decompress.js'; -import TTFFont from './TTFFont'; -import TTFGlyph, { Point } from './glyph/TTFGlyph'; -import WOFF2Glyph from './glyph/WOFF2Glyph'; -import WOFF2Directory from './tables/WOFF2Directory'; -import { asciiDecoder } from './utils'; - -/** - * Subclass of TTFFont that represents a TTF/OTF font compressed by WOFF2 - * See spec here: http://www.w3.org/TR/WOFF2/ - */ -export default class WOFF2Font extends TTFFont { - /** @type {'WOFF2'} */ - type = 'WOFF2'; - - static probe(buffer) { - return asciiDecoder.decode(buffer.slice(0, 4)) === 'wOF2'; - } - - _decodeDirectory() { - this.directory = WOFF2Directory.decode(this.stream); - this._dataPos = this.stream.pos; - } - - _decompress() { - // decompress data and setup table offsets if we haven't already - if (!this._decompressed) { - this.stream.pos = this._dataPos; - let buffer = this.stream.readBuffer(this.directory.totalCompressedSize); - - let decompressedSize = 0; - for (let tag in this.directory.tables) { - let entry = this.directory.tables[tag]; - entry.offset = decompressedSize; - decompressedSize += (entry.transformLength != null) ? entry.transformLength : entry.length; - } - - let decompressed = brotli(buffer, decompressedSize); - if (!decompressed) { - throw new Error('Error decoding compressed data in WOFF2'); - } - - this.stream = new r.DecodeStream(decompressed); - this._decompressed = true; - } - } - - _decodeTable(table) { - this._decompress(); - return super._decodeTable(table); - } - - // Override this method to get a glyph and return our - // custom subclass if there is a glyf table. - _getBaseGlyph(glyph, characters = []) { - if (!this._glyphs[glyph]) { - if (this.directory.tables.glyf && this.directory.tables.glyf.transformed) { - if (!this._transformedGlyphs) { this._transformGlyfTable(); } - return this._glyphs[glyph] = new WOFF2Glyph(glyph, characters, this); - - } else { - return super._getBaseGlyph(glyph, characters); - } - } - } - - _transformGlyfTable() { - this._decompress(); - this.stream.pos = this.directory.tables.glyf.offset; - let table = GlyfTable.decode(this.stream); - let glyphs = []; - - for (let index = 0; index < table.numGlyphs; index++) { - let glyph = {}; - let nContours = table.nContours.readInt16BE(); - glyph.numberOfContours = nContours; - - if (nContours > 0) { // simple glyph - let nPoints = []; - let totalPoints = 0; - - for (let i = 0; i < nContours; i++) { - let r = read255UInt16(table.nPoints); - totalPoints += r; - nPoints.push(totalPoints); - } - - glyph.points = decodeTriplet(table.flags, table.glyphs, totalPoints); - for (let i = 0; i < nContours; i++) { - glyph.points[nPoints[i] - 1].endContour = true; - } - - var instructionSize = read255UInt16(table.glyphs); - - } else if (nContours < 0) { // composite glyph - let haveInstructions = TTFGlyph.prototype._decodeComposite.call({ _font: this }, glyph, table.composites); - if (haveInstructions) { - var instructionSize = read255UInt16(table.glyphs); - } - } - - glyphs.push(glyph); - } - - this._transformedGlyphs = glyphs; - } -} - -// Special class that accepts a length and returns a sub-stream for that data -class Substream { - constructor(length) { - this.length = length; - this._buf = new r.Buffer(length); - } - - decode(stream, parent) { - return new r.DecodeStream(this._buf.decode(stream, parent)); - } -} - -// This struct represents the entire glyf table -let GlyfTable = new r.Struct({ - version: r.uint32, - numGlyphs: r.uint16, - indexFormat: r.uint16, - nContourStreamSize: r.uint32, - nPointsStreamSize: r.uint32, - flagStreamSize: r.uint32, - glyphStreamSize: r.uint32, - compositeStreamSize: r.uint32, - bboxStreamSize: r.uint32, - instructionStreamSize: r.uint32, - nContours: new Substream('nContourStreamSize'), - nPoints: new Substream('nPointsStreamSize'), - flags: new Substream('flagStreamSize'), - glyphs: new Substream('glyphStreamSize'), - composites: new Substream('compositeStreamSize'), - bboxes: new Substream('bboxStreamSize'), - instructions: new Substream('instructionStreamSize') -}); - -const WORD_CODE = 253; -const ONE_MORE_BYTE_CODE2 = 254; -const ONE_MORE_BYTE_CODE1 = 255; -const LOWEST_U_CODE = 253; - -function read255UInt16(stream) { - let code = stream.readUInt8(); - - if (code === WORD_CODE) { - return stream.readUInt16BE(); - } - - if (code === ONE_MORE_BYTE_CODE1) { - return stream.readUInt8() + LOWEST_U_CODE; - } - - if (code === ONE_MORE_BYTE_CODE2) { - return stream.readUInt8() + LOWEST_U_CODE * 2; - } - - return code; -} - -function withSign(flag, baseval) { - return flag & 1 ? baseval : -baseval; -} - -function decodeTriplet(flags, glyphs, nPoints) { - let y; - let x = y = 0; - let res = []; - - for (let i = 0; i < nPoints; i++) { - let dx = 0, dy = 0; - let flag = flags.readUInt8(); - let onCurve = !(flag >> 7); - flag &= 0x7f; - - if (flag < 10) { - dx = 0; - dy = withSign(flag, ((flag & 14) << 7) + glyphs.readUInt8()); - - } else if (flag < 20) { - dx = withSign(flag, (((flag - 10) & 14) << 7) + glyphs.readUInt8()); - dy = 0; - - } else if (flag < 84) { - var b0 = flag - 20; - var b1 = glyphs.readUInt8(); - dx = withSign(flag, 1 + (b0 & 0x30) + (b1 >> 4)); - dy = withSign(flag >> 1, 1 + ((b0 & 0x0c) << 2) + (b1 & 0x0f)); - - } else if (flag < 120) { - var b0 = flag - 84; - dx = withSign(flag, 1 + ((b0 / 12) << 8) + glyphs.readUInt8()); - dy = withSign(flag >> 1, 1 + (((b0 % 12) >> 2) << 8) + glyphs.readUInt8()); - - } else if (flag < 124) { - var b1 = glyphs.readUInt8(); - let b2 = glyphs.readUInt8(); - dx = withSign(flag, (b1 << 4) + (b2 >> 4)); - dy = withSign(flag >> 1, ((b2 & 0x0f) << 8) + glyphs.readUInt8()); - - } else { - dx = withSign(flag, glyphs.readUInt16BE()); - dy = withSign(flag >> 1, glyphs.readUInt16BE()); - } - - x += dx; - y += dy; - res.push(new Point(onCurve, false, x, y)); - } - - return res; -} diff --git a/src/WOFFFont.js b/src/WOFFFont.js deleted file mode 100644 index e98d3715..00000000 --- a/src/WOFFFont.js +++ /dev/null @@ -1,37 +0,0 @@ -import TTFFont from './TTFFont'; -import WOFFDirectory from './tables/WOFFDirectory'; -import tables from './tables'; -import inflate from 'tiny-inflate'; -import * as r from 'restructure'; -import { asciiDecoder } from './utils'; - -export default class WOFFFont extends TTFFont { - /** @type {'WOFF'} */ - type = 'WOFF'; - - static probe(buffer) { - return asciiDecoder.decode(buffer.slice(0, 4)) === 'wOFF'; - } - - _decodeDirectory() { - this.directory = WOFFDirectory.decode(this.stream, { _startOffset: 0 }); - } - - _getTableStream(tag) { - let table = this.directory.tables[tag]; - if (table) { - this.stream.pos = table.offset; - - if (table.compLength < table.length) { - this.stream.pos += 2; // skip deflate header - let outBuffer = new Uint8Array(table.length); - let buf = inflate(this.stream.readBuffer(table.compLength - 2), outBuffer); - return new r.DecodeStream(buf); - } else { - return this.stream; - } - } - - return null; - } -} diff --git a/src/base.js b/src/base.js index 7eaf6ebf..b2a7a70d 100644 --- a/src/base.js +++ b/src/base.js @@ -30,7 +30,7 @@ export function registerFormat(format) { /** * @param {ArrayBufferView} buffer * @param {string} [postscriptName] - * @return {(import('./types').Font | import('./types').FontCollection)} + * @return {(import('./TTFFont.js').default | import('./TrueTypeCollection.js').default)} */ export function create(buffer, postscriptName) { for (let i = 0; i < formats.length; i++) { diff --git a/src/glyph/WOFF2Glyph.js b/src/glyph/WOFF2Glyph.js deleted file mode 100644 index 9b451c1b..00000000 --- a/src/glyph/WOFF2Glyph.js +++ /dev/null @@ -1,17 +0,0 @@ -import TTFGlyph from './TTFGlyph'; - -/** - * Represents a TrueType glyph in the WOFF2 format, which compresses glyphs differently. - */ -export default class WOFF2Glyph extends TTFGlyph { - type = 'WOFF2'; - - _decode() { - // We have to decode in advance (in WOFF2Font), so just return the pre-decoded data. - return this._font._transformedGlyphs[this.id]; - } - - _getCBox() { - return this.path.bbox; - } -} diff --git a/src/index.ts b/src/index.ts index 9ce42739..04c29161 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,21 +1,16 @@ import { registerFormat } from './base'; import TTFFont from './TTFFont'; -import WOFFFont from './WOFFFont'; -import WOFF2Font from './WOFF2Font'; import TrueTypeCollection from './TrueTypeCollection'; -import DFont from './DFont'; // Register font formats registerFormat(TTFFont); -registerFormat(WOFFFont); -registerFormat(WOFF2Font); registerFormat(TrueTypeCollection); -registerFormat(DFont); export * from './base'; export { DefaultShaper } from './base'; // Explicit export for preventing tree-shaking export type { default as TTFFont } from './TTFFont'; +export type { default as TrueTypeCollection } from './TrueTypeCollection'; export type { default as Glyph } from './glyph/Glyph'; export type { default as BBox } from './glyph/BBox'; export type { default as Path } from './glyph/Path'; @@ -24,8 +19,6 @@ export type { default as GlyphRun } from './layout/GlyphRun'; export type { default as Subset } from './subset/Subset'; export type { - Font, - FontCollection, GlyphInfo, ShapingPlan, LayoutAdvancedParams, diff --git a/src/node.ts b/src/node.ts index 3f54d0fb..d34de7e9 100644 --- a/src/node.ts +++ b/src/node.ts @@ -1,21 +1,16 @@ import { registerFormat } from './base'; import TTFFont from './TTFFont'; -import WOFFFont from './WOFFFont'; -import WOFF2Font from './WOFF2Font'; import TrueTypeCollection from './TrueTypeCollection'; -import DFont from './DFont'; // Register font formats registerFormat(TTFFont); -registerFormat(WOFFFont); -registerFormat(WOFF2Font); registerFormat(TrueTypeCollection); -registerFormat(DFont); export * from './base'; export { DefaultShaper } from './base'; // Explicit export for preventing tree-shaking export type { default as TTFFont } from './TTFFont'; +export type { default as TrueTypeCollection } from './TrueTypeCollection'; export type { default as Glyph } from './glyph/Glyph'; export type { default as BBox } from './glyph/BBox'; export type { default as Path } from './glyph/Path'; @@ -24,8 +19,6 @@ export type { default as GlyphRun } from './layout/GlyphRun'; export type { default as Subset } from './subset/Subset'; export type { - Font, - FontCollection, GlyphInfo, ShapingPlan, LayoutAdvancedParams, diff --git a/src/tables/WOFF2Directory.js b/src/tables/WOFF2Directory.js deleted file mode 100644 index 91b10531..00000000 --- a/src/tables/WOFF2Directory.js +++ /dev/null @@ -1,74 +0,0 @@ -import * as r from 'restructure'; - -const Base128 = { - decode(stream) { - let result = 0; - let iterable = [0, 1, 2, 3, 4]; - for (let j = 0; j < iterable.length; j++) { - let i = iterable[j]; - let code = stream.readUInt8(); - - // If any of the top seven bits are set then we're about to overflow. - if (result & 0xe0000000) { - throw new Error('Overflow'); - } - - result = (result << 7) | (code & 0x7f); - if ((code & 0x80) === 0) { - return result; - } - } - - throw new Error('Bad base 128 number'); - } -}; - -let knownTags = [ - 'cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'OS/2', 'post', 'cvt ', - 'fpgm', 'glyf', 'loca', 'prep', 'CFF ', 'VORG', 'EBDT', 'EBLC', 'gasp', - 'hdmx', 'kern', 'LTSH', 'PCLT', 'VDMX', 'vhea', 'vmtx', 'BASE', 'GDEF', - 'GPOS', 'GSUB', 'EBSC', 'JSTF', 'MATH', 'CBDT', 'CBLC', 'COLR', 'CPAL', - 'SVG ', 'sbix', 'acnt', 'avar', 'bdat', 'bloc', 'bsln', 'cvar', 'fdsc', - 'feat', 'fmtx', 'fvar', 'gvar', 'hsty', 'just', 'lcar', 'mort', 'morx', - 'opbd', 'prop', 'trak', 'Zapf', 'Silf', 'Glat', 'Gloc', 'Feat', 'Sill' -]; - -let WOFF2DirectoryEntry = new r.Struct({ - flags: r.uint8, - customTag: new r.Optional(new r.String(4), t => (t.flags & 0x3f) === 0x3f), - tag: t => t.customTag || knownTags[t.flags & 0x3f],// || (() => { throw new Error(`Bad tag: ${flags & 0x3f}`); })(); }, - length: Base128, - transformVersion: t => (t.flags >>> 6) & 0x03, - transformed: t => (t.tag === 'glyf' || t.tag === 'loca') ? t.transformVersion === 0 : t.transformVersion !== 0, - transformLength: new r.Optional(Base128, t => t.transformed) -}); - -let WOFF2Directory = new r.Struct({ - tag: new r.String(4), // should be 'wOF2' - flavor: r.uint32, - length: r.uint32, - numTables: r.uint16, - reserved: new r.Reserved(r.uint16), - totalSfntSize: r.uint32, - totalCompressedSize: r.uint32, - majorVersion: r.uint16, - minorVersion: r.uint16, - metaOffset: r.uint32, - metaLength: r.uint32, - metaOrigLength: r.uint32, - privOffset: r.uint32, - privLength: r.uint32, - tables: new r.Array(WOFF2DirectoryEntry, 'numTables') -}); - -WOFF2Directory.process = function() { - let tables = {}; - for (let i = 0; i < this.tables.length; i++) { - let table = this.tables[i]; - tables[table.tag] = table; - } - - return this.tables = tables; -}; - -export default WOFF2Directory; diff --git a/src/tables/WOFFDirectory.js b/src/tables/WOFFDirectory.js deleted file mode 100644 index dfd5d55d..00000000 --- a/src/tables/WOFFDirectory.js +++ /dev/null @@ -1,38 +0,0 @@ -import * as r from 'restructure'; -import tables from './'; - -let WOFFDirectoryEntry = new r.Struct({ - tag: new r.String(4), - offset: new r.Pointer(r.uint32, 'void', {type: 'global'}), - compLength: r.uint32, - length: r.uint32, - origChecksum: r.uint32 -}); - -let WOFFDirectory = new r.Struct({ - tag: new r.String(4), // should be 'wOFF' - flavor: r.uint32, - length: r.uint32, - numTables: r.uint16, - reserved: new r.Reserved(r.uint16), - totalSfntSize: r.uint32, - majorVersion: r.uint16, - minorVersion: r.uint16, - metaOffset: r.uint32, - metaLength: r.uint32, - metaOrigLength: r.uint32, - privOffset: r.uint32, - privLength: r.uint32, - tables: new r.Array(WOFFDirectoryEntry, 'numTables') -}); - -WOFFDirectory.process = function() { - let tables = {}; - for (let table of this.tables) { - tables[table.tag] = table; - } - - this.tables = tables; -}; - -export default WOFFDirectory; diff --git a/src/types.ts b/src/types.ts index a851b9a9..16d05f69 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,13 +1,6 @@ import type TTFFont from './TTFFont.js'; -import type WOFFFont from './WOFFFont.js'; -import type WOFF2Font from './WOFF2Font.js'; -import type TrueTypeCollection from './TrueTypeCollection.js'; -import type DFont from './DFont.js'; -import type GlyphInfo from './opentype/GlyphInfo.js'; -import type ShapingPlan from './opentype/ShapingPlan.js'; - -export type Font = TTFFont | WOFFFont | WOFF2Font; -export type FontCollection = TrueTypeCollection | DFont; +import type GlyphInfo from './opentype/GlyphInfo.js'; +import type ShapingPlan from './opentype/ShapingPlan.js'; export type { GlyphInfo, ShapingPlan }; diff --git a/test/data/NotoSans/NotoSans.dfont b/test/data/NotoSans/NotoSans.dfont deleted file mode 100644 index 2ecbfd23..00000000 Binary files a/test/data/NotoSans/NotoSans.dfont and /dev/null differ diff --git a/test/data/SourceSansPro/SourceSansPro-Regular.otf.woff b/test/data/SourceSansPro/SourceSansPro-Regular.otf.woff deleted file mode 100644 index 94659aeb..00000000 Binary files a/test/data/SourceSansPro/SourceSansPro-Regular.otf.woff and /dev/null differ diff --git a/test/data/SourceSansPro/SourceSansPro-Regular.otf.woff2 b/test/data/SourceSansPro/SourceSansPro-Regular.otf.woff2 deleted file mode 100644 index e002972a..00000000 Binary files a/test/data/SourceSansPro/SourceSansPro-Regular.otf.woff2 and /dev/null differ diff --git a/test/data/SourceSansPro/SourceSansPro-Regular.ttf.woff b/test/data/SourceSansPro/SourceSansPro-Regular.ttf.woff deleted file mode 100644 index 5945501e..00000000 Binary files a/test/data/SourceSansPro/SourceSansPro-Regular.ttf.woff and /dev/null differ diff --git a/test/data/SourceSansPro/SourceSansPro-Regular.ttf.woff2 b/test/data/SourceSansPro/SourceSansPro-Regular.ttf.woff2 deleted file mode 100644 index df1d2115..00000000 Binary files a/test/data/SourceSansPro/SourceSansPro-Regular.ttf.woff2 and /dev/null differ diff --git a/test/data/SourceSansPro/SourceSansPro-Regular.woff b/test/data/SourceSansPro/SourceSansPro-Regular.woff deleted file mode 100755 index 3e03cc0f..00000000 Binary files a/test/data/SourceSansPro/SourceSansPro-Regular.woff and /dev/null differ diff --git a/test/data/SourceSansPro/SourceSansPro-Regular.woff2 b/test/data/SourceSansPro/SourceSansPro-Regular.woff2 deleted file mode 100755 index a6be1c24..00000000 Binary files a/test/data/SourceSansPro/SourceSansPro-Regular.woff2 and /dev/null differ diff --git a/test/glyphs.js b/test/glyphs.js index aac1aa5a..3e5658f9 100644 --- a/test/glyphs.js +++ b/test/glyphs.js @@ -261,112 +261,4 @@ describe('glyphs', function () { return assert.equal(glyph.name, 'stuckouttonguewinkingeye'); }); }); - - describe('WOFF ttf glyphs', function () { - let font = fontkit.openSync(new URL('data/SourceSansPro/SourceSansPro-Regular.ttf.woff', import.meta.url)); - let glyph = font.glyphsForString('D')[0]; - - it('should get the glyph name', function () { - return assert.equal(glyph.name, 'D'); - }); - - it('should get a TTFGlyph', function () { - return assert.equal(glyph.type, 'TTF'); - }); - - it('should get a quadratic path for the glyph', function () { - return assert.equal(glyph.path.toSVG(), 'M90 0L90 656L254 656Q406 656 485 571.5Q564 487 564 331Q564 174 485.5 87Q407 0 258 0ZM173 68L248 68Q363 68 420.5 137.5Q478 207 478 331Q478 455 420.5 521.5Q363 588 248 588L173 588Z'); - }); - }); - - describe('WOFF otf glyphs', function () { - let font = fontkit.openSync(new URL('data/SourceSansPro/SourceSansPro-Regular.otf.woff', import.meta.url)); - let glyph = font.glyphsForString('D')[0]; - - it('should get the glyph name', function () { - return assert.equal(glyph.name, 'D'); - }); - - it('should get a CFFGlyph', function () { - return assert.equal(glyph.type, 'CFF'); - }); - - it('should get a cubic path for the glyph', function () { - return assert.equal(glyph.path.toSVG(), 'M90 0L258 0C456 0 564 122 564 331C564 539 456 656 254 656L90 656ZM173 68L173 588L248 588C401 588 478 496 478 331C478 165 401 68 248 68Z'); - }); - }); - - describe('WOFF2 ttf glyph', function () { - let font = fontkit.openSync(new URL('data/SourceSansPro/SourceSansPro-Regular.ttf.woff2', import.meta.url)); - - let glyph = font.glyphsForString('D')[0]; - - it('should get the glyph name', function () { - return assert.equal(glyph.name, 'D'); - }); - - it('should get a WOFF2Glyph', function () { - return assert.equal(glyph.type, 'WOFF2'); - }); - - it('should get a path for the glyph', function () { - let tglyph = font.glyphsForString('T')[0]; - return assert.equal(tglyph.path.toSVG(), 'M226 0L226 586L28 586L28 656L508 656L508 586L310 586L310 0Z'); - }); - - it('should get a correct quadratic path for all contours', function () { - return assert.equal(glyph.path.toSVG(), 'M90 0L90 656L254 656Q406 656 485 571.5Q564 487 564 331Q564 174 485.5 87Q407 0 258 0ZM173 68L248 68Q363 68 420.5 137.5Q478 207 478 331Q478 455 420.5 521.5Q363 588 248 588L173 588Z'); - }); - - it('should get the ttf glyph cbox', function () { - assert.equal(glyph.cbox.minX, 90); - assert.equal(glyph.cbox.minY, 0); - assert.equal(glyph.cbox.maxX, 564); - assert.equal(glyph.cbox.maxY, 656); - }); - - it('should get the ttf glyph bbox', function () { - assert.equal(glyph.bbox.minX, 90); - assert.equal(glyph.bbox.minY, 0); - assert.equal(glyph.bbox.maxX, 564); - assert.equal(glyph.bbox.maxY, 656); - }); - }); - - describe('WOFF2 otf glyph', function () { - let font = fontkit.openSync(new URL('data/SourceSansPro/SourceSansPro-Regular.otf.woff2', import.meta.url)); - - let glyph = font.glyphsForString('D')[0]; - - it('should get the glyph name', function () { - return assert.equal(glyph.name, 'D'); - }); - - it('should get a CFFGlyph', function () { - return assert.equal(glyph.type, 'CFF'); - }); - - it('should get a path for the glyph', function () { - let tglyph = font.glyphsForString('T')[0]; - return assert.equal(tglyph.path.toSVG(), 'M226 0L310 0L310 586L508 586L508 656L28 656L28 586L226 586Z'); - }); - - it('should get a correct cubic path for all contours', function () { - return assert.equal(glyph.path.toSVG(), 'M90 0L258 0C456 0 564 122 564 331C564 539 456 656 254 656L90 656ZM173 68L173 588L248 588C401 588 478 496 478 331C478 165 401 68 248 68Z'); - }); - - it('should get the otf glyph cbox', function () { - assert.equal(glyph.cbox.minX, 90); - assert.equal(glyph.cbox.minY, 0); - assert.equal(glyph.cbox.maxX, 564); - assert.equal(glyph.cbox.maxY, 656); - }); - - it('should get the otf glyph bbox', function () { - assert.equal(glyph.bbox.minX, 90); - assert.equal(glyph.bbox.minY, 0); - assert.equal(glyph.bbox.maxX, 564); - assert.equal(glyph.bbox.maxY, 656); - }); - }); }); diff --git a/test/index.js b/test/index.js index 06ef4e9b..73e29390 100644 --- a/test/index.js +++ b/test/index.js @@ -24,18 +24,6 @@ describe('fontkit', function () { font = fontkit.openSync(new URL('data/NotoSans/NotoSans.ttc', import.meta.url), 'NotoSans'); assert.equal(font.type, 'TTF'); - - font = fontkit.openSync(new URL('data/NotoSans/NotoSans.dfont', import.meta.url)); - assert.equal(font.type, 'DFont'); - - font = fontkit.openSync(new URL('data/NotoSans/NotoSans.dfont', import.meta.url), 'NotoSans'); - assert.equal(font.type, 'TTF'); - - font = fontkit.openSync(new URL('data/SourceSansPro/SourceSansPro-Regular.woff', import.meta.url)); - assert.equal(font.type, 'WOFF'); - - font = fontkit.openSync(new URL('data/SourceSansPro/SourceSansPro-Regular.woff2', import.meta.url)); - assert.equal(font.type, 'WOFF2'); }); it('should open fonts lacking PostScript name', function () { @@ -65,14 +53,4 @@ describe('fontkit', function () { return assert.equal(font.postscriptName, 'NotoSans-Italic'); }); - it('should get collection objects for dfonts', function () { - let collection = fontkit.openSync(new URL('data/NotoSans/NotoSans.dfont', import.meta.url)); - assert.equal(collection.type, 'DFont'); - - let names = collection.fonts.map(f => f.postscriptName); - assert.deepEqual(names, ['NotoSans', 'NotoSans-Bold', 'NotoSans-Italic', 'NotoSans-BoldItalic']); - - let font = collection.getFont('NotoSans-Italic'); - return assert.equal(font.postscriptName, 'NotoSans-Italic'); - }); });