textmode.js 0.1.8-beta.2 → 0.1.8
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/dist/textmode.esm.js +1144 -953
- package/dist/textmode.esm.min.js +1108 -917
- package/dist/textmode.umd.js +19 -19
- package/dist/textmode.umd.min.js +17 -17
- package/dist/types/Textmode.d.ts +21 -31
- package/dist/types/export/image/types.d.ts +1 -1
- package/dist/types/export/svg/SVGPathGenerator.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/textmode/Canvas.d.ts +3 -3
- package/dist/types/textmode/ConversionPipeline.d.ts +7 -2
- package/dist/types/textmode/Textmodifier.d.ts +29 -20
- package/dist/types/textmode/converters/Converter.d.ts +4 -4
- package/dist/types/textmode/converters/FeatureConverter.d.ts +3 -3
- package/dist/types/textmode/font/CharacterColorMapper.d.ts +4 -9
- package/dist/types/textmode/font/CharacterExtractor.d.ts +15 -25
- package/dist/types/textmode/font/MetricsCalculator.d.ts +34 -9
- package/dist/types/textmode/font/TextmodeFont.d.ts +3 -2
- package/dist/types/textmode/font/TextureAtlas.d.ts +29 -13
- package/dist/types/textmode/font/index.d.ts +3 -1
- package/dist/types/textmode/font/types.d.ts +2 -136
- package/dist/types/textmode/font/typr/Typr.d.ts +18 -0
- package/dist/types/textmode/font/typr/types.d.ts +254 -0
- package/dist/types/textmode/font/utils/CmapParser.d.ts +47 -0
- package/dist/types/textmode/font/utils/FontConstants.d.ts +60 -0
- package/dist/types/textmode/font/utils/FontTableReader.d.ts +56 -0
- package/dist/types/textmode/font/utils/index.d.ts +9 -0
- package/dist/types/textmode/mixins/ConversionMixin.d.ts +3 -4
- package/dist/types/textmode/mixins/ExportMixin.d.ts +2 -14
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +1 -0
- package/package.json +1 -1
|
@@ -9,9 +9,10 @@ import type { ExportCapabilities } from './mixins/ExportMixin';
|
|
|
9
9
|
import type { FontCapabilities } from './mixins/FontMixin';
|
|
10
10
|
import type { ConversionCapabilities } from './mixins/ConversionMixin';
|
|
11
11
|
/**
|
|
12
|
-
* Supported capture sources for textmode rendering
|
|
12
|
+
* Supported capture sources for textmode rendering.
|
|
13
|
+
* @ignore
|
|
13
14
|
*/
|
|
14
|
-
export type
|
|
15
|
+
export type TextmodeCaptureSource = HTMLCanvasElement | HTMLVideoElement;
|
|
15
16
|
/**
|
|
16
17
|
* Options for creating a {@link Textmodifier} instance.
|
|
17
18
|
*/
|
|
@@ -21,7 +22,7 @@ export type TextmodeOptions = {
|
|
|
21
22
|
/**
|
|
22
23
|
* Automatic rendering mode. Defaults to 'auto'.
|
|
23
24
|
* - 'manual': Requires manual `render()` calls
|
|
24
|
-
* - 'auto': Automatically renders using requestAnimationFrame
|
|
25
|
+
* - 'auto': Automatically renders using [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame)
|
|
25
26
|
*/
|
|
26
27
|
renderMode?: 'manual' | 'auto';
|
|
27
28
|
/** Maximum frames per second for auto rendering. Defaults to 60. */
|
|
@@ -31,9 +32,9 @@ export type TextmodeOptions = {
|
|
|
31
32
|
/** The height of the canvas in standalone mode. Defaults to 600. */
|
|
32
33
|
height?: number;
|
|
33
34
|
/**
|
|
34
|
-
* URL or path to a custom font file (.otf/.ttf)
|
|
35
|
-
* Required when using minified builds that don't include
|
|
36
|
-
* Optional for full builds (will override embedded font if provided)
|
|
35
|
+
* URL or path to a custom font file *(.otf/.ttf)*.
|
|
36
|
+
* Required when using minified builds that don't include a default font.
|
|
37
|
+
* Optional for full builds *(will override embedded font if provided)*.
|
|
37
38
|
*/
|
|
38
39
|
fontSource?: string;
|
|
39
40
|
};
|
|
@@ -51,8 +52,10 @@ declare const Textmodifier_base: typeof TextmodifierCore;
|
|
|
51
52
|
/**
|
|
52
53
|
* Manages textmode rendering on a canvas or video element.
|
|
53
54
|
*
|
|
54
|
-
* Each `Textmodifier` instance
|
|
55
|
-
*
|
|
55
|
+
* Each `Textmodifier` instance applies a `HTMLCanvasElement` with custom WebGL rendering on top of the original content.
|
|
56
|
+
*
|
|
57
|
+
* If the `Textmodifier` instance is created in `standalone` mode without a capture source,
|
|
58
|
+
* it simply creates a new `HTMLCanvasElement` to draw on using the `textmode.js` drawing API.
|
|
56
59
|
*/
|
|
57
60
|
export declare class Textmodifier extends Textmodifier_base {
|
|
58
61
|
/** The element to capture content from (optional for standalone mode) */
|
|
@@ -76,14 +79,24 @@ export declare class Textmodifier extends Textmodifier_base {
|
|
|
76
79
|
private _drawCallback;
|
|
77
80
|
private _resizedCallback;
|
|
78
81
|
private _windowResizeListener;
|
|
79
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Creates an instance of Textmodifier.
|
|
84
|
+
* @param source The HTML canvas or video element to capture content from. Pass `null` for standalone mode.
|
|
85
|
+
* @param opts Optional configuration options for the Textmodifier instance.
|
|
86
|
+
* @ignore
|
|
87
|
+
*/
|
|
88
|
+
constructor(source?: TextmodeCaptureSource | null, opts?: TextmodeOptions);
|
|
80
89
|
/**
|
|
81
90
|
* Static factory method for creating and initializing a Textmodifier instance.
|
|
82
91
|
* @param source The HTML canvas or video element to capture content from. Pass `null` for standalone mode.
|
|
83
92
|
* @param opts Optional configuration options for the `Textmodifier` instance.
|
|
84
93
|
* @ignore
|
|
85
94
|
*/
|
|
86
|
-
static create
|
|
95
|
+
static create(source?: TextmodeCaptureSource | null, opts?: TextmodeOptions): Promise<Textmodifier>;
|
|
96
|
+
/**
|
|
97
|
+
* Setup event listeners for resize handling.
|
|
98
|
+
* @ignore
|
|
99
|
+
*/
|
|
87
100
|
$setupEventListeners(): void;
|
|
88
101
|
/**
|
|
89
102
|
* Apply textmode rendering to the canvas.
|
|
@@ -141,8 +154,6 @@ export declare class Textmodifier extends Textmodifier_base {
|
|
|
141
154
|
/**
|
|
142
155
|
* Update the rendering mode.
|
|
143
156
|
*
|
|
144
|
-
* If called without arguments, returns the current mode.
|
|
145
|
-
*
|
|
146
157
|
* - `'manual'`: Requires manual [render](#render) calls
|
|
147
158
|
* - `'auto'`: Automatically renders using [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame)
|
|
148
159
|
*
|
|
@@ -299,7 +310,8 @@ export declare class Textmodifier extends Textmodifier_base {
|
|
|
299
310
|
isLooping(): boolean;
|
|
300
311
|
/**
|
|
301
312
|
* Set a draw callback function that will be executed before each render.
|
|
302
|
-
* This method is primarily useful for standalone textmodifier instances
|
|
313
|
+
* This method is primarily useful for standalone textmodifier instances,
|
|
314
|
+
* but can also be used to draw on top of the captured video or canvas.
|
|
303
315
|
* @param callback The function to call before each render
|
|
304
316
|
*
|
|
305
317
|
* @example
|
|
@@ -354,6 +366,8 @@ export declare class Textmodifier extends Textmodifier_base {
|
|
|
354
366
|
windowResized(callback: () => void): void;
|
|
355
367
|
/**
|
|
356
368
|
* Resize the `textmode.js` canvas.
|
|
369
|
+
*
|
|
370
|
+
* Can only be used in `standalone` mode since the textmode canvas otherwise automatically adjusts to the video/canvas size.
|
|
357
371
|
* @param width The new width of the canvas.
|
|
358
372
|
* @param height The new height of the canvas.
|
|
359
373
|
*/
|
|
@@ -361,14 +375,8 @@ export declare class Textmodifier extends Textmodifier_base {
|
|
|
361
375
|
/**
|
|
362
376
|
* Completely destroy this Textmodifier instance and free all associated resources.
|
|
363
377
|
*
|
|
364
|
-
* This method performs comprehensive cleanup of:
|
|
365
|
-
* - WebGL resources (framebuffers, textures, shaders)
|
|
366
|
-
* - Animation frames and timers
|
|
367
|
-
* - Event listeners
|
|
368
|
-
* - DOM elements
|
|
369
|
-
* - Font resources
|
|
370
|
-
*
|
|
371
378
|
* After calling this method, the instance should not be used and will be eligible for garbage collection.
|
|
379
|
+
*
|
|
372
380
|
* This method is idempotent and safe to call multiple times.
|
|
373
381
|
*
|
|
374
382
|
* @example
|
|
@@ -402,6 +410,7 @@ export declare class Textmodifier extends Textmodifier_base {
|
|
|
402
410
|
get width(): number;
|
|
403
411
|
/** Get the height of the canvas. */
|
|
404
412
|
get height(): number;
|
|
413
|
+
/** Get the textmodifier canvas containing the rendered output. */
|
|
405
414
|
get canvas(): TextmodeCanvas;
|
|
406
415
|
/** Check if the instance has been disposed/destroyed. */
|
|
407
416
|
get isDisposed(): boolean;
|
|
@@ -31,9 +31,9 @@ export declare class TextmodeConverter {
|
|
|
31
31
|
$resize(): void;
|
|
32
32
|
/**
|
|
33
33
|
* Enables or disables the converter.
|
|
34
|
-
* @param enabled Whether to enable or disable the converter
|
|
34
|
+
* @param enabled Whether to enable or disable the converter.<br/>Accepts boolean or number *(0 = false, any other number = true)*.
|
|
35
35
|
*/
|
|
36
|
-
enabled(enabled: boolean): void;
|
|
36
|
+
enabled(enabled: boolean | number): void;
|
|
37
37
|
/**
|
|
38
38
|
* Enables the converter.
|
|
39
39
|
*/
|
|
@@ -44,7 +44,7 @@ export declare class TextmodeConverter {
|
|
|
44
44
|
disable(): void;
|
|
45
45
|
/**
|
|
46
46
|
* Dispose of all framebuffers used by this converter.
|
|
47
|
-
*
|
|
47
|
+
* @ignore
|
|
48
48
|
*/
|
|
49
49
|
$dispose(): void;
|
|
50
50
|
/** Returns the framebuffer containing character data. */
|
|
@@ -57,6 +57,6 @@ export declare class TextmodeConverter {
|
|
|
57
57
|
get rotationFramebuffer(): Framebuffer;
|
|
58
58
|
/** Returns the framebuffer containing transformation data. */
|
|
59
59
|
get transformFramebuffer(): Framebuffer;
|
|
60
|
-
/** Returns the
|
|
60
|
+
/** Returns the defined options for this converter. */
|
|
61
61
|
get options(): any;
|
|
62
62
|
}
|
|
@@ -18,13 +18,13 @@ export declare abstract class TextmodeFeatureConverter extends TextmodeConverter
|
|
|
18
18
|
abstract $convert(sourceFramebuffer: Framebuffer): void;
|
|
19
19
|
/**
|
|
20
20
|
* Sets the characters used for mapping.
|
|
21
|
-
* @param characters The characters to use for mapping, usually ordered from
|
|
21
|
+
* @param characters The characters to use for mapping, usually ordered from least dense to most dense.
|
|
22
22
|
*/
|
|
23
23
|
characters(characters: string): void;
|
|
24
24
|
/**
|
|
25
25
|
* Sets the color of the characters affected by the converter.
|
|
26
26
|
* This is only used when `characterColorMode` is set to `'fixed'`.
|
|
27
|
-
* @param r Red component (0-255) or hex string (e.g., '#FF0000', '#F00', 'FF0000', 'F00')
|
|
27
|
+
* @param r Red component (0-255) or hex string *(e.g., '#FF0000', '#F00', 'FF0000', 'F00')*.
|
|
28
28
|
* @param g Green component (0-255).
|
|
29
29
|
* @param b Blue component (0-255).
|
|
30
30
|
* @param a Alpha component (0-255).
|
|
@@ -40,7 +40,7 @@ export declare abstract class TextmodeFeatureConverter extends TextmodeConverter
|
|
|
40
40
|
/**
|
|
41
41
|
* Sets the cell color for all cells affected by the converter.
|
|
42
42
|
* This is only used when `cellColorMode` is set to `'fixed'`.
|
|
43
|
-
* @param r Red component (0-255) or hex string (e.g., '#FF0000', '#F00', 'FF0000', 'F00')
|
|
43
|
+
* @param r Red component (0-255) or hex string *(e.g., '#FF0000', '#F00', 'FF0000', 'F00')*.
|
|
44
44
|
* @param g Green component (0-255).
|
|
45
45
|
* @param b Blue component (0-255).
|
|
46
46
|
* @param a Alpha component (0-255).
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type { TextmodeCharacter
|
|
1
|
+
import type { TextmodeCharacter } from './types.ts';
|
|
2
|
+
import type { TyprFont } from './typr/types.ts';
|
|
2
3
|
/**
|
|
3
4
|
* Handles color generation and mapping for characters.
|
|
4
5
|
* This class manages the unique RGB color assignment for character identification.
|
|
5
6
|
*/
|
|
6
7
|
export declare class CharacterColorMapper {
|
|
8
|
+
private _fontTableReader;
|
|
9
|
+
constructor();
|
|
7
10
|
/**
|
|
8
11
|
* Creates TextmodeCharacter objects with unique color assignments.
|
|
9
12
|
* @param characters Array of character strings
|
|
@@ -11,14 +14,6 @@ export declare class CharacterColorMapper {
|
|
|
11
14
|
* @returns Array of TextmodeCharacter objects with colors
|
|
12
15
|
*/
|
|
13
16
|
createCharacterObjects(characters: string[], font: TyprFont): TextmodeCharacter[];
|
|
14
|
-
/**
|
|
15
|
-
* Gets the glyph index for a given Unicode code point in a Typr.js font
|
|
16
|
-
* This is a simplified version for advance width lookup only
|
|
17
|
-
* @param fontData The Typr.js font data
|
|
18
|
-
* @param codePoint The Unicode code point to look up
|
|
19
|
-
* @returns The glyph index, or 0 if not found
|
|
20
|
-
*/
|
|
21
|
-
private _getGlyphIndex;
|
|
22
17
|
/**
|
|
23
18
|
* Generates a unique RGB color for a character based on its index.
|
|
24
19
|
* @param index The index of the character
|
|
@@ -1,35 +1,17 @@
|
|
|
1
|
-
import type { TyprFont } from './types.ts';
|
|
1
|
+
import type { TyprFont } from './typr/types.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Handles extraction of characters from font cmap tables.
|
|
4
4
|
* This class encapsulates the complex logic for reading different cmap table formats.
|
|
5
5
|
*/
|
|
6
6
|
export declare class CharacterExtraction {
|
|
7
|
+
private _cmapParser;
|
|
8
|
+
constructor();
|
|
7
9
|
/**
|
|
8
10
|
* Extracts all available characters from a font's cmap tables.
|
|
9
11
|
* @param font The parsed font object from Typr
|
|
10
12
|
* @returns Array of unique character strings
|
|
11
13
|
*/
|
|
12
14
|
extractCharacters(font: TyprFont): string[];
|
|
13
|
-
/**
|
|
14
|
-
* Extracts characters from a Format 4 cmap table (Basic Multilingual Plane).
|
|
15
|
-
* @param table The Format 4 cmap table
|
|
16
|
-
* @returns Array of character strings
|
|
17
|
-
*/
|
|
18
|
-
private _extractCharactersFromFormat4Table;
|
|
19
|
-
/**
|
|
20
|
-
* Extracts characters from a Format 12 cmap table (Extended Unicode ranges).
|
|
21
|
-
* @param table The Format 12 cmap table
|
|
22
|
-
* @returns Array of character strings
|
|
23
|
-
*/
|
|
24
|
-
private _extractCharactersFromFormat12Table;
|
|
25
|
-
/**
|
|
26
|
-
* Calculates the glyph index for a character in a Format 4 cmap table.
|
|
27
|
-
* @param table The Format 4 cmap table
|
|
28
|
-
* @param codePoint The Unicode code point
|
|
29
|
-
* @param rangeIndex The index of the character range
|
|
30
|
-
* @returns The glyph index, or 0 if not found
|
|
31
|
-
*/
|
|
32
|
-
private _calculateGlyphIndexFormat4;
|
|
33
15
|
/**
|
|
34
16
|
* Filters out problematic characters that might cause rendering issues.
|
|
35
17
|
* @param characters Array of character strings to filter
|
|
@@ -37,9 +19,17 @@ export declare class CharacterExtraction {
|
|
|
37
19
|
*/
|
|
38
20
|
filterProblematicCharacters(characters: string[]): string[];
|
|
39
21
|
/**
|
|
40
|
-
* Checks if a character
|
|
41
|
-
* @param
|
|
42
|
-
* @
|
|
22
|
+
* Checks if a character exists in the font.
|
|
23
|
+
* @param font The parsed font object from Typr
|
|
24
|
+
* @param character The character to check
|
|
25
|
+
* @returns True if the character exists in the font
|
|
26
|
+
*/
|
|
27
|
+
characterExists(font: TyprFont, character: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if all characters in a string exist in the font.
|
|
30
|
+
* @param font The parsed font object from Typr
|
|
31
|
+
* @param text The text string to check
|
|
32
|
+
* @returns True if all characters exist in the font
|
|
43
33
|
*/
|
|
44
|
-
|
|
34
|
+
allCharactersExist(font: TyprFont, text: string): boolean;
|
|
45
35
|
}
|
|
@@ -1,22 +1,47 @@
|
|
|
1
1
|
import type { GlyphDimensions } from './types.ts';
|
|
2
|
+
import type { TyprFont } from './typr/types.ts';
|
|
2
3
|
/**
|
|
3
4
|
* Handles calculation of font metrics and glyph dimensions.
|
|
4
|
-
* This class encapsulates the logic for measuring text and calculating font properties
|
|
5
|
+
* This class encapsulates the logic for measuring text and calculating font properties
|
|
6
|
+
* directly from font data using Typr.ts, eliminating the need for Canvas-based measurement.
|
|
5
7
|
*/
|
|
6
8
|
export declare class FontMetricsCalculator {
|
|
7
|
-
private
|
|
8
|
-
private _tempContext;
|
|
9
|
+
private _tableReader;
|
|
9
10
|
/**
|
|
10
|
-
* Creates a new
|
|
11
|
+
* Creates a new FontMetricsCalculator instance.
|
|
11
12
|
*/
|
|
12
13
|
constructor();
|
|
13
14
|
/**
|
|
14
|
-
* Calculates the maximum glyph dimensions for a given set of characters
|
|
15
|
+
* Calculates the maximum glyph dimensions for a given set of characters
|
|
16
|
+
* using direct font metrics from the parsed font data.
|
|
15
17
|
* @param characters Array of character strings
|
|
16
|
-
* @param fontSize Font size to use for
|
|
17
|
-
* @param
|
|
18
|
-
* @param fontFace FontFace object (optional, for validation)
|
|
18
|
+
* @param fontSize Font size to use for scaling measurements
|
|
19
|
+
* @param font Parsed TyprFont object containing font data
|
|
19
20
|
* @returns Object containing width and height dimensions
|
|
20
21
|
*/
|
|
21
|
-
calculateMaxGlyphDimensions(characters: string[], fontSize: number,
|
|
22
|
+
calculateMaxGlyphDimensions(characters: string[], fontSize: number, font: TyprFont): GlyphDimensions;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the character advance width for a specific character and font size.
|
|
25
|
+
* @param character The character to measure
|
|
26
|
+
* @param fontSize Font size to use for scaling
|
|
27
|
+
* @param font Parsed TyprFont object
|
|
28
|
+
* @returns Advance width in pixels
|
|
29
|
+
*/
|
|
30
|
+
getCharacterAdvanceWidth(character: string, fontSize: number, font: TyprFont): number;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the font-level ascender, descender, and line gap values for a given font size.
|
|
33
|
+
* @param fontSize Font size to use for scaling
|
|
34
|
+
* @param font Parsed TyprFont object
|
|
35
|
+
* @returns Object containing ascender, descender, and lineGap in pixels
|
|
36
|
+
*/
|
|
37
|
+
getFontMetrics(fontSize: number, font: TyprFont): {
|
|
38
|
+
ascender: number;
|
|
39
|
+
descender: number;
|
|
40
|
+
lineGap: number;
|
|
41
|
+
lineHeight: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Clears internal caches. Useful for memory management.
|
|
45
|
+
*/
|
|
46
|
+
$clearCache(): void;
|
|
22
47
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GLRenderer } from '../../rendering/webgl/Renderer.ts';
|
|
2
2
|
import type { Framebuffer } from '../../rendering/webgl/Framebuffer.ts';
|
|
3
|
-
import type { TextmodeCharacter
|
|
3
|
+
import type { TextmodeCharacter } from './types.ts';
|
|
4
|
+
import type { TyprFont } from './typr/types.ts';
|
|
4
5
|
/**
|
|
5
6
|
* Manages the textmode font used for rendering characters.
|
|
6
7
|
*
|
|
@@ -78,7 +79,7 @@ export declare class TextmodeFont {
|
|
|
78
79
|
hasAllCharacters(str: string): boolean;
|
|
79
80
|
/**
|
|
80
81
|
* Dispose of all resources used by this font manager.
|
|
81
|
-
*
|
|
82
|
+
* @ignore
|
|
82
83
|
*/
|
|
83
84
|
$dispose(): void;
|
|
84
85
|
/**
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { TextmodeCharacter, GlyphDimensions } from './types.ts';
|
|
2
2
|
import type { GLRenderer } from '../../rendering/webgl/Renderer.ts';
|
|
3
3
|
import type { Framebuffer } from '../../rendering/webgl/Framebuffer.ts';
|
|
4
|
+
import type { TyprFont } from './typr/types.ts';
|
|
4
5
|
/**
|
|
5
6
|
* Handles creation of texture atlases for font rendering.
|
|
6
7
|
* This class manages the Canvas 2D rendering and WebGL framebuffer creation.
|
|
8
|
+
* Supports both Typr.js path-based rendering for uniform cross-browser text
|
|
9
|
+
* and fallback fillText rendering.
|
|
7
10
|
*/
|
|
8
11
|
export declare class TextureAtlasCreation {
|
|
9
12
|
private _textureCanvas;
|
|
10
13
|
private _textureContext;
|
|
11
14
|
private _renderer;
|
|
15
|
+
private _fontTableReader;
|
|
12
16
|
/**
|
|
13
17
|
* Creates a new TextureAtlasCreation instance.
|
|
14
18
|
* @param renderer The WebGL renderer instance
|
|
@@ -19,10 +23,10 @@ export declare class TextureAtlasCreation {
|
|
|
19
23
|
* @param characters Array of TextmodeCharacter objects
|
|
20
24
|
* @param maxGlyphDimensions Maximum dimensions of glyphs
|
|
21
25
|
* @param fontSize Font size for rendering
|
|
22
|
-
* @param
|
|
26
|
+
* @param fontDataOrFamilyName Either Typr.js font data object for path rendering, or font family name string for fillText rendering
|
|
23
27
|
* @returns Object containing framebuffer, columns, and rows
|
|
24
28
|
*/
|
|
25
|
-
createTextureAtlas(characters: TextmodeCharacter[], maxGlyphDimensions: GlyphDimensions, fontSize: number,
|
|
29
|
+
createTextureAtlas(characters: TextmodeCharacter[], maxGlyphDimensions: GlyphDimensions, fontSize: number, fontDataOrFamilyName: TyprFont | string): {
|
|
26
30
|
framebuffer: Framebuffer;
|
|
27
31
|
columns: number;
|
|
28
32
|
rows: number;
|
|
@@ -31,25 +35,37 @@ export declare class TextureAtlasCreation {
|
|
|
31
35
|
* Sets up the canvas for rendering.
|
|
32
36
|
* @param width Canvas buffer width
|
|
33
37
|
* @param height Canvas buffer height
|
|
34
|
-
* @param fontSize Font size
|
|
35
|
-
* @param fontFamilyName Font family name
|
|
36
|
-
* @param logicalWidth Logical width for scaling context
|
|
37
|
-
* @param logicalHeight Logical height for scaling context
|
|
38
38
|
*/
|
|
39
39
|
private _setupCanvas;
|
|
40
40
|
/**
|
|
41
|
-
* Renders all characters to the canvas in a grid layout.
|
|
41
|
+
* Renders all characters to the canvas in a grid layout using Typr.js paths.
|
|
42
42
|
* @param characters Array of characters to render
|
|
43
43
|
* @param maxGlyphDimensions Maximum glyph dimensions
|
|
44
44
|
* @param textureColumns Number of columns in the texture
|
|
45
45
|
* @param fontSize Font size
|
|
46
|
+
* @param fontData Typr.js font data
|
|
47
|
+
*/
|
|
48
|
+
private _renderCharacters;
|
|
49
|
+
/**
|
|
50
|
+
* Gets glyph data for a character using Typr.js
|
|
51
|
+
* @param fontData Typr.js font data
|
|
52
|
+
* @param character Character to get glyph data for
|
|
53
|
+
* @returns Parsed glyph data or null if not found
|
|
54
|
+
*/
|
|
55
|
+
private _getGlyphData;
|
|
56
|
+
/**
|
|
57
|
+
* Gets the advance width for a glyph
|
|
58
|
+
* @param fontData The Typr.js font data
|
|
59
|
+
* @param glyphIndex The glyph index
|
|
60
|
+
* @returns The advance width in font units
|
|
46
61
|
*/
|
|
47
|
-
private
|
|
62
|
+
private _getGlyphAdvanceWidth;
|
|
48
63
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @param
|
|
64
|
+
* Renders a glyph to the canvas using direct path rendering from glyph outline data.
|
|
65
|
+
* @param glyphData Glyph data from Typr.js
|
|
66
|
+
* @param x X position
|
|
67
|
+
* @param y Y position (baseline position)
|
|
68
|
+
* @param scale Scale factor
|
|
53
69
|
*/
|
|
54
|
-
private
|
|
70
|
+
private _renderGlyphToCanvas;
|
|
55
71
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { TextmodeFont } from './TextmodeFont.ts';
|
|
2
|
-
export type { TextmodeCharacter, GlyphDimensions
|
|
2
|
+
export type { TextmodeCharacter, GlyphDimensions } from './types.ts';
|
|
3
|
+
export type { TyprFont, CmapTable, CmapTableFormat4, CmapTableFormat12, HeadTable, HheaTable, HmtxTable, MaxpTable, CmapData, GlyphData, LocaTable, TyprStatic } from './typr/types.ts';
|
|
4
|
+
export { default as Typr } from './typr/Typr.ts';
|
|
3
5
|
export { CharacterExtraction } from './CharacterExtractor.ts';
|
|
4
6
|
export { TextureAtlasCreation } from './TextureAtlas.ts';
|
|
5
7
|
export { FontMetricsCalculator as MetricsCalculation } from './MetricsCalculator.ts';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Represents a single character in the
|
|
2
|
+
* Represents a single character in the {@link TextmodeFont.characters} array.
|
|
3
3
|
*/
|
|
4
4
|
export type TextmodeCharacter = {
|
|
5
5
|
/** The character itself. */
|
|
@@ -8,33 +8,9 @@ export type TextmodeCharacter = {
|
|
|
8
8
|
unicode: number;
|
|
9
9
|
/** The RGB color associated with the character for identification. */
|
|
10
10
|
color: [number, number, number];
|
|
11
|
-
/** The advance width of the character. */
|
|
11
|
+
/** The advance width of the character. @ignore */
|
|
12
12
|
advanceWidth: number;
|
|
13
13
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Interface for cmap table Format 4 (Basic Multilingual Plane)
|
|
16
|
-
*/
|
|
17
|
-
export interface CmapTableFormat4 {
|
|
18
|
-
format: 4;
|
|
19
|
-
startCount: number[];
|
|
20
|
-
endCount: number[];
|
|
21
|
-
idRangeOffset: number[];
|
|
22
|
-
idDelta: number[];
|
|
23
|
-
glyphIdArray?: number[];
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Interface for cmap table Format 12 (Extended Unicode ranges)
|
|
27
|
-
*/
|
|
28
|
-
export interface CmapTableFormat12 {
|
|
29
|
-
format: 12;
|
|
30
|
-
groups: number[];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Union type for supported cmap table formats
|
|
34
|
-
*/
|
|
35
|
-
export type CmapTable = CmapTableFormat4 | CmapTableFormat12 | {
|
|
36
|
-
format: number;
|
|
37
|
-
};
|
|
38
14
|
/**
|
|
39
15
|
* Font glyph dimensions
|
|
40
16
|
*/
|
|
@@ -42,113 +18,3 @@ export interface GlyphDimensions {
|
|
|
42
18
|
width: number;
|
|
43
19
|
height: number;
|
|
44
20
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Head table from OpenType/TrueType font
|
|
47
|
-
*/
|
|
48
|
-
export interface HeadTable {
|
|
49
|
-
fontRevision: number;
|
|
50
|
-
flags: number;
|
|
51
|
-
unitsPerEm: number;
|
|
52
|
-
created: number;
|
|
53
|
-
modified: number;
|
|
54
|
-
xMin: number;
|
|
55
|
-
yMin: number;
|
|
56
|
-
xMax: number;
|
|
57
|
-
yMax: number;
|
|
58
|
-
macStyle: number;
|
|
59
|
-
lowestRecPPEM: number;
|
|
60
|
-
fontDirectionHint: number;
|
|
61
|
-
indexToLocFormat: number;
|
|
62
|
-
glyphDataFormat: number;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Horizontal header table from OpenType/TrueType font
|
|
66
|
-
*/
|
|
67
|
-
export interface HheaTable {
|
|
68
|
-
ascender: number;
|
|
69
|
-
descender: number;
|
|
70
|
-
lineGap: number;
|
|
71
|
-
advanceWidthMax: number;
|
|
72
|
-
minLeftSideBearing: number;
|
|
73
|
-
minRightSideBearing: number;
|
|
74
|
-
xMaxExtent: number;
|
|
75
|
-
caretSlopeRise: number;
|
|
76
|
-
caretSlopeRun: number;
|
|
77
|
-
caretOffset: number;
|
|
78
|
-
res0: number;
|
|
79
|
-
res1: number;
|
|
80
|
-
res2: number;
|
|
81
|
-
res3: number;
|
|
82
|
-
metricDataFormat: number;
|
|
83
|
-
numberOfHMetrics: number;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Horizontal metrics table from OpenType/TrueType font
|
|
87
|
-
*/
|
|
88
|
-
export interface HmtxTable {
|
|
89
|
-
aWidth: number[];
|
|
90
|
-
lsBearing: number[];
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Maximum profile table from OpenType/TrueType font
|
|
94
|
-
*/
|
|
95
|
-
export interface MaxpTable {
|
|
96
|
-
numGlyphs: number;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Character map data from OpenType/TrueType font
|
|
100
|
-
*/
|
|
101
|
-
export interface CmapData {
|
|
102
|
-
tables: CmapTable[];
|
|
103
|
-
ids: Record<string, number>;
|
|
104
|
-
off: number;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Glyph data structure for parsed glyphs
|
|
108
|
-
*/
|
|
109
|
-
export interface GlyphData {
|
|
110
|
-
xs: number[];
|
|
111
|
-
ys: number[];
|
|
112
|
-
endPts: number[];
|
|
113
|
-
flags: number[];
|
|
114
|
-
xMin: number;
|
|
115
|
-
yMin: number;
|
|
116
|
-
xMax: number;
|
|
117
|
-
yMax: number;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Location table for glyph offsets
|
|
121
|
-
*/
|
|
122
|
-
export interface LocaTable {
|
|
123
|
-
[glyphIndex: number]: number;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Complete TyprFont interface representing a parsed OpenType/TrueType font
|
|
127
|
-
* This interface describes the structure returned by Typr.parse()
|
|
128
|
-
*/
|
|
129
|
-
export interface TyprFont {
|
|
130
|
-
/** Internal font data buffer */
|
|
131
|
-
_data: Uint8Array;
|
|
132
|
-
/** Font index in collection */
|
|
133
|
-
_index: number;
|
|
134
|
-
/** Font offset in data */
|
|
135
|
-
_offset: number;
|
|
136
|
-
/** Character map table */
|
|
137
|
-
cmap: CmapData;
|
|
138
|
-
/** Font header table */
|
|
139
|
-
head: HeadTable;
|
|
140
|
-
/** Horizontal header table */
|
|
141
|
-
hhea: HheaTable;
|
|
142
|
-
/** Horizontal metrics table */
|
|
143
|
-
hmtx: HmtxTable;
|
|
144
|
-
/** Maximum profile table */
|
|
145
|
-
maxp: MaxpTable;
|
|
146
|
-
/** Glyph location table (optional) */
|
|
147
|
-
loca?: LocaTable;
|
|
148
|
-
/** Glyph data table - stores parsed glyph data (optional, populated on demand) */
|
|
149
|
-
glyf?: {
|
|
150
|
-
[glyphIndex: number]: GlyphData | null;
|
|
151
|
-
};
|
|
152
|
-
/** Additional font tables that may be present */
|
|
153
|
-
[tableName: string]: any;
|
|
154
|
-
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typr.ts - TypeScript Font Parsing Library for textmode.js
|
|
3
|
+
*
|
|
4
|
+
* A comprehensive TypeScript implementation of font parsing capabilities
|
|
5
|
+
* for OpenType and TrueType fonts. Provides essential functionality including
|
|
6
|
+
* character mapping, glyph data extraction, and font metrics processing.
|
|
7
|
+
*
|
|
8
|
+
* Originally based on Typr.js by photopea (https://github.com/photopea/Typr.js)
|
|
9
|
+
* Rewritten in TypeScript with enhanced type safety and optimizations for textmode.js
|
|
10
|
+
*
|
|
11
|
+
* @license MIT
|
|
12
|
+
*/
|
|
13
|
+
import type { TyprStatic } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* Main Typr class implementation
|
|
16
|
+
*/
|
|
17
|
+
declare const Typr: TyprStatic;
|
|
18
|
+
export default Typr;
|