Skip to content
Merged
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
5 changes: 5 additions & 0 deletions MODIFICATIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Modifications

## [2.0.4-mod.2025.5]

- Add `.js` extensions to all relative imports in sources so generated `*.d.ts` are resolvable in native ESM environments


## [2.0.4-mod.2025.4]

- Fix type declaration: Fix return type of `Subset#encode` to be `Uint8Array`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@denkiyagi/fontkit",
"version": "2.0.4-mod.2025.4",
"version": "2.0.4-mod.2025.5",
"description": "A modified version of fontkit. An advanced font engine for Node and the browser",
"keywords": [
"opentype",
Expand Down Expand Up @@ -73,7 +73,8 @@
"files": [
"src",
"dist",
"types"
"types",
"MODIFICATIONS.md"
],
"author": "DenkiYagi Inc. (modified version author), Devon Govett <devongovett@gmail.com> (orignal version author)",
"license": "MIT",
Expand Down
8 changes: 4 additions & 4 deletions src/CmapProcessor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { binarySearch, range } from './utils/arrays';
import { encodingExists, getEncoding, getEncodingMapping } from './encodings';
import { cache } from './decorators';
import { AssertionError, InvalidFontDataError, UnsupportedFontDataError } from './errors';
import { binarySearch, range } from './utils/arrays.js';
import { encodingExists, getEncoding, getEncodingMapping } from './encodings.js';
import { cache } from './decorators.js';
import { AssertionError, InvalidFontDataError, UnsupportedFontDataError } from './errors.js';

export default class CmapProcessor {
constructor(cmapTable) {
Expand Down
42 changes: 21 additions & 21 deletions src/TTFFont.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as r from 'restructure';
import { cache } from './decorators';
import { isLoggingWarnings, getDefaultLanguage as getGlobalDefaultLanguage } from './base';
import Directory from './tables/directory';
import tables from './tables/index';
import CmapProcessor from './CmapProcessor';
import LayoutEngine from './layout/LayoutEngine';
import TTFGlyph from './glyph/TTFGlyph';
import CFFGlyph from './glyph/CFFGlyph';
import SBIXGlyph from './glyph/SBIXGlyph';
import COLRGlyph from './glyph/COLRGlyph';
import GlyphVariationProcessor from './glyph/GlyphVariationProcessor';
import TTFSubset from './subset/TTFSubset';
import CFFSubset from './subset/CFFSubset';
import BBox from './glyph/BBox';
import { asciiDecoder } from './utils/decode';
import { InvalidCallerInputError } from './errors';
import { cache } from './decorators.js';
import { isLoggingWarnings, getDefaultLanguage as getGlobalDefaultLanguage } from './base.js';
import Directory from './tables/directory.js';
import tables from './tables/index.js';
import CmapProcessor from './CmapProcessor.js';
import LayoutEngine from './layout/LayoutEngine.js';
import TTFGlyph from './glyph/TTFGlyph.js';
import CFFGlyph from './glyph/CFFGlyph.js';
import SBIXGlyph from './glyph/SBIXGlyph.js';
import COLRGlyph from './glyph/COLRGlyph.js';
import GlyphVariationProcessor from './glyph/GlyphVariationProcessor.js';
import TTFSubset from './subset/TTFSubset.js';
import CFFSubset from './subset/CFFSubset.js';
import BBox from './glyph/BBox.js';
import { asciiDecoder } from './utils/decode.js';
import { InvalidCallerInputError } from './errors.js';

/**
* This is the base class for all SFNT-based font formats in fontkit.
Expand Down Expand Up @@ -346,7 +346,7 @@ export default class TTFFont {
* Does not perform any advanced substitutions (there is no context to do so).
*
* @param {number} codePoint
* @return {import('./glyph/Glyph').default}
* @return {import('./glyph/Glyph.js').default}
*/
glyphForCodePoint(codePoint) {
return this.getGlyph(this._cmapProcessor.lookup(codePoint), [codePoint]);
Expand All @@ -359,7 +359,7 @@ export default class TTFFont {
* provides a much more advanced mapping supporting AAT and OpenType shaping.
*
* @param {string} string
* @return {import('./glyph/Glyph').default[]}
* @return {import('./glyph/Glyph.js').default[]}
*/
glyphsForString(string) {
let glyphs = [];
Expand Down Expand Up @@ -414,8 +414,8 @@ export default class TTFFont {
*
* @param {string} string
* @param {string[] | Record<string, boolean>} [userFeatures]
* @param {import('./types').LayoutAdvancedParams} [advancedParams]
* @return {import('./layout/GlyphRun').default}
* @param {import('./types.js').LayoutAdvancedParams} [advancedParams]
* @return {import('./layout/GlyphRun.js').default}
*/
layout(string, userFeatures, advancedParams) {
return this._layoutEngine.layout(string, userFeatures, advancedParams);
Expand Down Expand Up @@ -469,7 +469,7 @@ export default class TTFFont {
*
* @param {number} glyph
* @param {number[]} characters
* @return {import('./glyph/Glyph').default}
* @return {import('./glyph/Glyph.js').default}
*/
getGlyph(glyph, characters = []) {
if (!this._glyphs[glyph]) {
Expand Down
6 changes: 3 additions & 3 deletions src/TrueTypeCollection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as r from 'restructure';
import TTFFont from './TTFFont';
import { asciiDecoder } from './utils/decode';
import { AssertionError } from './errors';
import TTFFont from './TTFFont.js';
import { asciiDecoder } from './utils/decode.js';
import { AssertionError } from './errors.js';

let TTCHeader = new r.VersionedStruct(r.uint32, {
0x00010000: {
Expand Down
6 changes: 3 additions & 3 deletions src/aat/AATLayoutEngine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as AATFeatureMap from './AATFeatureMap';
import * as Script from '../layout/Script';
import AATMorxProcessor from './AATMorxProcessor';
import * as AATFeatureMap from './AATFeatureMap.js';
import * as Script from '../layout/Script.js';
import AATMorxProcessor from './AATMorxProcessor.js';

export default class AATLayoutEngine {
constructor(font) {
Expand Down
6 changes: 3 additions & 3 deletions src/aat/AATLookupTable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {cache} from '../decorators';
import {range} from '../utils/arrays';
import { InvalidFontDataError } from '../errors';
import {cache} from '../decorators.js';
import {range} from '../utils/arrays.js';
import { InvalidFontDataError } from '../errors.js';

export default class AATLookupTable {
constructor(table) {
Expand Down
8 changes: 4 additions & 4 deletions src/aat/AATMorxProcessor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AATStateMachine from './AATStateMachine';
import AATLookupTable from './AATLookupTable';
import {cache} from '../decorators';
import { InvalidFontDataError, UnsupportedFontDataError } from '../errors';
import AATStateMachine from './AATStateMachine.js';
import AATLookupTable from './AATLookupTable.js';
import {cache} from '../decorators.js';
import { InvalidFontDataError, UnsupportedFontDataError } from '../errors.js';

// indic replacement flags
const MARK_FIRST = 0x8000;
Expand Down
2 changes: 1 addition & 1 deletion src/aat/AATStateMachine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AATLookupTable from './AATLookupTable';
import AATLookupTable from './AATLookupTable.js';

const START_OF_TEXT_STATE = 0;
const START_OF_LINE_STATE = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// @ts-ignore
import { DecodeStream } from 'restructure';
import { UnsupportedFontFileFormatError } from './errors';
import { UnsupportedFontFileFormatError } from './errors.js';

// -----------------------------------------------------------------------------

Expand Down Expand Up @@ -63,4 +63,4 @@ export function setDefaultLanguage(lang = 'en') {

// -----------------------------------------------------------------------------

export { default as DefaultShaper } from './opentype/shapers/DefaultShaper';
export { default as DefaultShaper } from './opentype/shapers/DefaultShaper.js';
6 changes: 3 additions & 3 deletions src/cff/CFFDict.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CFFOperand from './CFFOperand';
import CFFOperand from './CFFOperand.js';
import { PropertyDescriptor } from 'restructure';
import { equalArray } from '../utils/deep-equal';
import { InvalidFontDataError } from '../errors';
import { equalArray } from '../utils/deep-equal.js';
import { InvalidFontDataError } from '../errors.js';

export default class CFFDict {
constructor(ops = []) {
Expand Down
10 changes: 5 additions & 5 deletions src/cff/CFFFont.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as r from 'restructure';
import CFFIndex from './CFFIndex';
import CFFTop from './CFFTop';
import CFFPrivateDict from './CFFPrivateDict';
import standardStrings from './CFFStandardStrings';
import { InvalidFontDataError } from '../errors';
import CFFIndex from './CFFIndex.js';
import CFFTop from './CFFTop.js';
import CFFPrivateDict from './CFFPrivateDict.js';
import standardStrings from './CFFStandardStrings.js';
import { InvalidFontDataError } from '../errors.js';

class CFFFont {
constructor(stream) {
Expand Down
2 changes: 1 addition & 1 deletion src/cff/CFFIndex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as r from 'restructure';
import { AssertionError, InvalidFontDataError } from '../errors';
import { AssertionError, InvalidFontDataError } from '../errors.js';

export default class CFFIndex {
constructor(type) {
Expand Down
6 changes: 3 additions & 3 deletions src/cff/CFFPrivateDict.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CFFDict from './CFFDict';
import CFFIndex from './CFFIndex';
import CFFPointer from './CFFPointer';
import CFFDict from './CFFDict.js';
import CFFIndex from './CFFIndex.js';
import CFFPointer from './CFFPointer.js';

class CFFBlendOp {
static decode(stream, parent, operands) {
Expand Down
16 changes: 8 additions & 8 deletions src/cff/CFFTop.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as r from 'restructure';
import { resolveLength } from 'restructure';
import CFFDict from './CFFDict';
import CFFIndex from './CFFIndex';
import CFFPointer from './CFFPointer';
import CFFPrivateDict from './CFFPrivateDict';
import StandardStrings from './CFFStandardStrings';
import { StandardEncoding, ExpertEncoding } from './CFFEncodings';
import { ISOAdobeCharset, ExpertCharset, ExpertSubsetCharset } from './CFFCharsets';
import { ItemVariationStore } from '../tables/variations';
import CFFDict from './CFFDict.js';
import CFFIndex from './CFFIndex.js';
import CFFPointer from './CFFPointer.js';
import CFFPrivateDict from './CFFPrivateDict.js';
import StandardStrings from './CFFStandardStrings.js';
import { StandardEncoding, ExpertEncoding } from './CFFEncodings.js';
import { ISOAdobeCharset, ExpertCharset, ExpertSubsetCharset } from './CFFCharsets.js';
import { ItemVariationStore } from '../tables/variations.js';

// Checks if an operand is an index of a predefined value,
// otherwise delegates to the provided type.
Expand Down
3 changes: 3 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Workaround for Parcel module resolution issue: JS files cannot resolve TS files with `*.js` extension.

export * from './errors.ts';
2 changes: 1 addition & 1 deletion src/fs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { create } from './base';
import { create } from './base.js';
import fs from 'fs';

export function openSync(filename, postscriptName) {
Expand Down
6 changes: 3 additions & 3 deletions src/glyph/CFFGlyph.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Glyph from './Glyph';
import Path from './Path';
import { InvalidFontDataError } from '../errors';
import Glyph from './Glyph.js';
import Path from './Path.js';
import { InvalidFontDataError } from '../errors.js';

/**
* Represents an OpenType PostScript glyph, in the Compact Font Format.
Expand Down
4 changes: 2 additions & 2 deletions src/glyph/COLRGlyph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Glyph from './Glyph';
import BBox from './BBox';
import Glyph from './Glyph.js';
import BBox from './BBox.js';

class COLRLayer {
constructor(glyph, color) {
Expand Down
10 changes: 5 additions & 5 deletions src/glyph/Glyph.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cache } from '../decorators';
import Path from './Path';
import { cache } from '../decorators.js';
import Path from './Path.js';
import { isMark } from 'unicode-properties';
import StandardNames from './StandardNames';
import StandardNames from './StandardNames.js';

/**
* Glyph objects represent a glyph in the font. They have various properties for accessing metrics and
Expand Down Expand Up @@ -99,7 +99,7 @@ export default class Glyph {
* See [here](http://www.freetype.org/freetype2/docs/glyphs/glyphs-6.html#section-2)
* for a more detailed description.
*
* @type {import('./BBox').default}
* @type {import('./BBox.js').default}
*/
@cache
get cbox() {
Expand All @@ -109,7 +109,7 @@ export default class Glyph {
/**
* The glyph’s bounding box, i.e. the rectangle that encloses the
* glyph outline as tightly as possible.
* @type {import('./BBox').default}
* @type {import('./BBox.js').default}
*/
@cache
get bbox() {
Expand Down
2 changes: 1 addition & 1 deletion src/glyph/GlyphVariationProcessor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InvalidFontDataError } from '../errors';
import { InvalidFontDataError } from '../errors.js';

const TUPLES_SHARE_POINT_NUMBERS = 0x8000;
const TUPLE_COUNT_MASK = 0x0fff;
Expand Down
2 changes: 1 addition & 1 deletion src/glyph/Path.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BBox from './BBox';
import BBox from './BBox.js';

const SVG_COMMANDS = {
moveTo: 'M',
Expand Down
2 changes: 1 addition & 1 deletion src/glyph/SBIXGlyph.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import TTFGlyph from './TTFGlyph';
import TTFGlyph from './TTFGlyph.js';
import * as r from 'restructure';

let SBIXImage = new r.Struct({
Expand Down
8 changes: 4 additions & 4 deletions src/glyph/TTFGlyph.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Glyph from './Glyph';
import Path from './Path';
import BBox from './BBox';
import Glyph from './Glyph.js';
import Path from './Path.js';
import BBox from './BBox.js';
import * as r from 'restructure';
import { InvalidFontDataError } from '../errors';
import { InvalidFontDataError } from '../errors.js';

// The header for both simple and composite glyphs
let GlyfHeader = new r.Struct({
Expand Down
30 changes: 15 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { registerFormat } from './base';
import TTFFont from './TTFFont';
import TrueTypeCollection from './TrueTypeCollection';
import { registerFormat } from './base.js';
import TTFFont from './TTFFont.js';
import TrueTypeCollection from './TrueTypeCollection.js';

// Register font formats
registerFormat(TTFFont);
registerFormat(TrueTypeCollection);

export * from './base';
export { DefaultShaper } from './base'; // Explicit export for preventing tree-shaking
export * from './base.js';
export { DefaultShaper } from './base.js'; // Explicit export for preventing tree-shaking

export * from './errors';
export * from './errors.js';

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';
export type { default as GlyphPosition } from './layout/GlyphPosition';
export type { default as GlyphRun } from './layout/GlyphRun';
export type { default as Subset } from './subset/Subset';
export type { default as TTFFont } from './TTFFont.js';
export type { default as TrueTypeCollection } from './TrueTypeCollection.js';
export type { default as Glyph } from './glyph/Glyph.js';
export type { default as BBox } from './glyph/BBox.js';
export type { default as Path } from './glyph/Path.js';
export type { default as GlyphPosition } from './layout/GlyphPosition.js';
export type { default as GlyphRun } from './layout/GlyphRun.js';
export type { default as Subset } from './subset/Subset.js';

export type {
GlyphInfo,
ShapingPlan,
LayoutAdvancedParams,
Shaper,
} from './types';
} from './types.js';
Loading