text-shaper 0.1.15 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/dist/font/font.d.ts +34 -1
- package/dist/font/ttc.d.ts +10 -0
- package/dist/hinting/instructions/delta.d.ts +1 -1
- package/dist/hinting/programs.d.ts +2 -0
- package/dist/hinting/types.d.ts +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -10
- package/dist/raster/types.d.ts +11 -0
- package/dist/shaper/complex/arabic.d.ts +4 -0
- package/package.json +1 -1
- package/dist/index.js.map +0 -137
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://github.com/wiedymi)
|
|
4
4
|
[](https://x.com/wiedymi)
|
|
5
5
|
[](mailto:contact@wiedymi.com)
|
|
6
|
-
[](https://discord.gg/
|
|
6
|
+
[](https://discord.gg/zemMZtrkSb)
|
|
7
7
|
[](https://github.com/sponsors/vivy-company)
|
|
8
8
|
|
|
9
9
|
Pure TypeScript text shaping engine with OpenType layout, TrueType hinting, and FreeType-style rasterization. Works in browsers and Bun/Node.js with zero dependencies.
|
|
@@ -92,6 +92,21 @@ for (const text of texts) {
|
|
|
92
92
|
}
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
### TTC Collections
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { Font } from "text-shaper";
|
|
99
|
+
|
|
100
|
+
const buffer = await fetch("fonts.ttc").then(r => r.arrayBuffer());
|
|
101
|
+
const collection = Font.collection(buffer);
|
|
102
|
+
|
|
103
|
+
if (collection) {
|
|
104
|
+
console.log(collection.count);
|
|
105
|
+
const names = collection.names();
|
|
106
|
+
const font = collection.get(0);
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
95
110
|
### With Features
|
|
96
111
|
|
|
97
112
|
```typescript
|
package/dist/font/font.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GlyphId, TableRecord, Tag } from "../types.ts";
|
|
2
2
|
import { Reader } from "./binary/reader.ts";
|
|
3
|
+
import { type TtcHeader } from "./ttc.ts";
|
|
3
4
|
import { type AvarTable } from "./tables/avar.ts";
|
|
4
5
|
import { type BaseTable } from "./tables/base.ts";
|
|
5
6
|
import { type CbdtTable, type CblcTable } from "./tables/cbdt.ts";
|
|
@@ -44,6 +45,25 @@ import { type VvarTable } from "./tables/vvar.ts";
|
|
|
44
45
|
export interface FontLoadOptions {
|
|
45
46
|
/** Tables to parse eagerly (default: lazy) */
|
|
46
47
|
eagerTables?: Tag[];
|
|
48
|
+
/** TTC collection index (default: 0 when loading a TTC) */
|
|
49
|
+
collectionIndex?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface CollectionFaceName {
|
|
52
|
+
index: number;
|
|
53
|
+
fullName?: string;
|
|
54
|
+
family?: string;
|
|
55
|
+
subfamily?: string;
|
|
56
|
+
postScriptName?: string;
|
|
57
|
+
}
|
|
58
|
+
export declare class FontCollection {
|
|
59
|
+
private readonly buffer;
|
|
60
|
+
private readonly header;
|
|
61
|
+
private readonly loadFace;
|
|
62
|
+
private namesCache;
|
|
63
|
+
constructor(buffer: ArrayBuffer, header: TtcHeader, loadFace: (index: number, options?: FontLoadOptions) => Font);
|
|
64
|
+
get count(): number;
|
|
65
|
+
get(index: number, options?: FontLoadOptions): Font;
|
|
66
|
+
names(): CollectionFaceName[];
|
|
47
67
|
}
|
|
48
68
|
/**
|
|
49
69
|
* Represents a loaded font file.
|
|
@@ -96,7 +116,7 @@ export declare class Font {
|
|
|
96
116
|
private _cvt;
|
|
97
117
|
private _gasp;
|
|
98
118
|
private constructor();
|
|
99
|
-
/** Load font from ArrayBuffer (sync -
|
|
119
|
+
/** Load font from ArrayBuffer (sync - WOFF2 requires async loading) */
|
|
100
120
|
static load(buffer: ArrayBuffer, options?: FontLoadOptions): Font;
|
|
101
121
|
/** Load font from ArrayBuffer with WOFF2 support (async) */
|
|
102
122
|
static loadAsync(buffer: ArrayBuffer, options?: FontLoadOptions): Promise<Font>;
|
|
@@ -104,6 +124,10 @@ export declare class Font {
|
|
|
104
124
|
static fromURL(url: string, options?: FontLoadOptions): Promise<Font>;
|
|
105
125
|
/** Load font from file path (Bun only, supports WOFF2) */
|
|
106
126
|
static fromFile(path: string, options?: FontLoadOptions): Promise<Font>;
|
|
127
|
+
/** Create a TTC collection helper if buffer is a TrueType Collection */
|
|
128
|
+
static collection(buffer: ArrayBuffer): FontCollection | null;
|
|
129
|
+
private static loadFromBuffer;
|
|
130
|
+
private static loadFromTtc;
|
|
107
131
|
/** Check if font has a specific table */
|
|
108
132
|
hasTable(tag: Tag): boolean;
|
|
109
133
|
/** Get table record */
|
|
@@ -163,6 +187,15 @@ export declare class Font {
|
|
|
163
187
|
get descender(): number;
|
|
164
188
|
/** Line gap (from hhea) */
|
|
165
189
|
get lineGap(): number;
|
|
190
|
+
/** Line height (ascender - descender + lineGap for TrueType, ascender - descender for CFF) */
|
|
191
|
+
get height(): number;
|
|
192
|
+
/**
|
|
193
|
+
* Get scale factor for converting font units to pixels
|
|
194
|
+
* @param sizePx Target size in pixels
|
|
195
|
+
* @param mode Sizing mode: "em" (default) or "height"
|
|
196
|
+
* @returns Scale factor to multiply font units by
|
|
197
|
+
*/
|
|
198
|
+
scaleForSize(sizePx: number, mode?: "em" | "height"): number;
|
|
166
199
|
/** Is this a TrueType font (vs CFF)? */
|
|
167
200
|
get isTrueType(): boolean;
|
|
168
201
|
/** Is this a CFF font? */
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface TtcHeader {
|
|
2
|
+
version: number;
|
|
3
|
+
numFonts: number;
|
|
4
|
+
offsets: number[];
|
|
5
|
+
dsigTag?: number;
|
|
6
|
+
dsigOffset?: number;
|
|
7
|
+
dsigLength?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function isTtc(buffer: ArrayBuffer): boolean;
|
|
10
|
+
export declare function parseTtcHeader(buffer: ArrayBuffer): TtcHeader;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* at specific pixel-per-em (ppem) sizes. This is useful for fixing
|
|
6
6
|
* rendering issues that only appear at certain sizes.
|
|
7
7
|
*/
|
|
8
|
-
import type
|
|
8
|
+
import { type ExecContext } from "../types.ts";
|
|
9
9
|
/**
|
|
10
10
|
* DELTAP1 - Delta exception point (ppem 0-15 + deltaBase)
|
|
11
11
|
*/
|
package/dist/hinting/types.d.ts
CHANGED
|
@@ -46,6 +46,10 @@ export declare enum TouchFlag {
|
|
|
46
46
|
Y = 32,
|
|
47
47
|
Both = 48
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Render mode used for GETINFO responses.
|
|
51
|
+
*/
|
|
52
|
+
export type HintRenderMode = "mono" | "gray" | "lcd" | "lcd_v";
|
|
49
53
|
/**
|
|
50
54
|
* Glyph zone - holds glyph points
|
|
51
55
|
*/
|
|
@@ -191,6 +195,10 @@ export interface ExecContext {
|
|
|
191
195
|
scale: number;
|
|
192
196
|
scaleFix: number;
|
|
193
197
|
lightMode: boolean;
|
|
198
|
+
grayscale: boolean;
|
|
199
|
+
renderMode: HintRenderMode;
|
|
200
|
+
backwardCompatibility: number;
|
|
201
|
+
isComposite: boolean;
|
|
194
202
|
error: string | null;
|
|
195
203
|
instructionCount: number;
|
|
196
204
|
maxInstructions: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { adaptiveBlur as $adaptiveBlur, BitmapBuilder, bitmap, blur as $blur, bo
|
|
|
6
6
|
export type { AutoRasterOptions, CanvasOptions, RasterOptions, SVGElementOptions, SVGOptions, TransformState, } from "./fluent/types.ts";
|
|
7
7
|
export { Reader } from "./font/binary/reader.ts";
|
|
8
8
|
export { createFace, Face } from "./font/face.ts";
|
|
9
|
-
export { Font, type FontLoadOptions } from "./font/font.ts";
|
|
9
|
+
export { Font, FontCollection, type CollectionFaceName, type FontLoadOptions, } from "./font/font.ts";
|
|
10
10
|
export type { AvarTable, AxisSegmentMap } from "./font/tables/avar.ts";
|
|
11
11
|
export { applyAvar, applyAvarMapping } from "./font/tables/avar.ts";
|
|
12
12
|
export type { AxisTable as BaseAxisTable, BaselineValue, BaseScriptRecord, BaseTable, BaseValues, FeatMinMaxRecord, MinMax, MinMaxRecord, } from "./font/tables/base.ts";
|