@mlightcad/mtext-renderer 0.4.4 → 0.4.5
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/font/baseFont.d.ts +12 -0
- package/dist/font/charGeometryCache.d.ts +43 -0
- package/dist/font/fontManager.d.ts +16 -0
- package/dist/font/meshFont.d.ts +6 -0
- package/dist/font/shxFont.d.ts +6 -0
- package/dist/font/shxTextShape.d.ts +4 -1
- package/dist/index.js +667 -562
- package/dist/index.umd.cjs +3 -3
- package/package.json +2 -2
package/dist/font/baseFont.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseTextShape } from './baseTextShape';
|
|
2
|
+
import { CharGeometryCache } from './charGeometryCache';
|
|
2
3
|
import { FontType } from './font';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -14,6 +15,17 @@ export declare abstract class BaseFont {
|
|
|
14
15
|
* This data is used to render characters and calculate metrics.
|
|
15
16
|
*/
|
|
16
17
|
abstract readonly data: unknown;
|
|
18
|
+
/**
|
|
19
|
+
* Caching of font character geometries to improve text rendering performance.
|
|
20
|
+
*/
|
|
21
|
+
cache: CharGeometryCache;
|
|
22
|
+
constructor();
|
|
23
|
+
/**
|
|
24
|
+
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
25
|
+
* @param char - The character to check
|
|
26
|
+
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
27
|
+
*/
|
|
28
|
+
abstract hasChar(char: string): boolean;
|
|
17
29
|
/**
|
|
18
30
|
* Record of characters that are not supported by this font.
|
|
19
31
|
* Maps character strings to their occurrence count.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* Manages caching of font character geometries to improve text rendering performance.
|
|
4
|
+
*/
|
|
5
|
+
export declare class CharGeometryCache {
|
|
6
|
+
private cache;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Returns true if the geometry of the specified character exists in the cache.
|
|
10
|
+
* Otherwise, returns false.
|
|
11
|
+
* @param char One character.
|
|
12
|
+
* @param size The font size.
|
|
13
|
+
* @returns True if the geometry of the specified character exists in the cache.
|
|
14
|
+
* Otherwise, returns false.
|
|
15
|
+
*/
|
|
16
|
+
hasGeometry(char: string, size: number): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Get the geometry for a single character from cache if available.
|
|
19
|
+
* The cache key includes both character and size.
|
|
20
|
+
* @param char The character to get geometry from cache.
|
|
21
|
+
* @param size The font size.
|
|
22
|
+
* @returns The geometry for a single character from cache if avaiable.
|
|
23
|
+
* Return undefined if the character not found in cache.
|
|
24
|
+
*/
|
|
25
|
+
getGeometry(char: string, size: number): THREE.BufferGeometry | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Set the geometry to cache for a single character.
|
|
28
|
+
* @param char The character to set geometry for.
|
|
29
|
+
* @param size The font size.
|
|
30
|
+
* @param geometry The geometry to set.
|
|
31
|
+
*/
|
|
32
|
+
setGeometry(char: string, size: number, geometry: THREE.BufferGeometry): void;
|
|
33
|
+
/**
|
|
34
|
+
* Dispose all cached geometries.
|
|
35
|
+
*/
|
|
36
|
+
dispose(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Generates cache key by character and font size.
|
|
39
|
+
* @param char One character.
|
|
40
|
+
* @param size The font size.
|
|
41
|
+
*/
|
|
42
|
+
private generateKey;
|
|
43
|
+
}
|
|
@@ -76,6 +76,22 @@ export declare class FontManager {
|
|
|
76
76
|
* @returns The original font name if found, or the replacement font name if not found
|
|
77
77
|
*/
|
|
78
78
|
findAndReplaceFont(fontName: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Gets font by font name. Return undefined if not found.
|
|
81
|
+
* @param fontName - The font name to find
|
|
82
|
+
* @param recordMissedFonts - Record the font name to property `missedFonts` in this class
|
|
83
|
+
* if the specified font name not found.
|
|
84
|
+
* @returns The font with the specified font name, or undefined if not found
|
|
85
|
+
*/
|
|
86
|
+
getFontByName(fontName: string, recordMissedFonts?: boolean): BaseFont | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Gets the first font which contains the specified character.
|
|
89
|
+
* @param char - The character to get the shape for
|
|
90
|
+
* @param fontName - The name of the font to use
|
|
91
|
+
* @param size - The size of the character
|
|
92
|
+
* @returns The text shape for the character, or undefined if not found
|
|
93
|
+
*/
|
|
94
|
+
getFontByChar(char: string): BaseFont | undefined;
|
|
79
95
|
/**
|
|
80
96
|
* Gets the text shape for a specific character with the specified font and size
|
|
81
97
|
* @param char - The character to get the shape for
|
package/dist/font/meshFont.d.ts
CHANGED
|
@@ -29,6 +29,12 @@ export declare class MeshFont extends BaseFont {
|
|
|
29
29
|
* @param data - Either a MeshFontData object containing font information or an ArrayBuffer containing raw font data
|
|
30
30
|
*/
|
|
31
31
|
constructor(data: MeshFontData | ArrayBuffer);
|
|
32
|
+
/**
|
|
33
|
+
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
34
|
+
* @param char - The character to check
|
|
35
|
+
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
36
|
+
*/
|
|
37
|
+
hasChar(char: string): boolean;
|
|
32
38
|
/**
|
|
33
39
|
* Generates shapes for a text string
|
|
34
40
|
* @param text - The text to generate shapes for
|
package/dist/font/shxFont.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ export declare class ShxFont extends BaseFont {
|
|
|
12
12
|
readonly type = "shx";
|
|
13
13
|
readonly data: ShxFontData;
|
|
14
14
|
constructor(data: ShxFontData | ArrayBuffer);
|
|
15
|
+
/**
|
|
16
|
+
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
17
|
+
* @param char - The character to check
|
|
18
|
+
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
19
|
+
*/
|
|
20
|
+
hasChar(char: string): boolean;
|
|
15
21
|
generateShapes(text: string, size: number): ShxTextShape[];
|
|
16
22
|
/**
|
|
17
23
|
* SHX font always has fixed scale factor 1.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Point, ShxShape } from '@mlightcad/shx-parser';
|
|
2
2
|
import { BaseTextShape } from './baseTextShape';
|
|
3
|
+
import { ShxFont } from './shxFont';
|
|
3
4
|
|
|
4
5
|
import * as THREE from 'three';
|
|
5
6
|
/**
|
|
@@ -10,12 +11,14 @@ import * as THREE from 'three';
|
|
|
10
11
|
export declare class ShxTextShape extends BaseTextShape {
|
|
11
12
|
/** The shape data for this character */
|
|
12
13
|
private readonly shape;
|
|
14
|
+
private readonly font;
|
|
15
|
+
private readonly fontSize;
|
|
13
16
|
/**
|
|
14
17
|
* Creates a new instance of ShxTextShape
|
|
15
18
|
* @param char - The character this shape represents
|
|
16
19
|
* @param shape - The shape data for this character
|
|
17
20
|
*/
|
|
18
|
-
constructor(char: string, shape: ShxShape);
|
|
21
|
+
constructor(char: string, fontSize: number, shape: ShxShape, font: ShxFont);
|
|
19
22
|
protected calcWidth(): number;
|
|
20
23
|
offset(offset: Point): ShxTextShape;
|
|
21
24
|
/**
|