@mlightcad/mtext-renderer 0.6.4 → 0.7.0
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 +524 -0
- package/dist/index.js +14870 -3667
- package/dist/index.umd.cjs +13 -3
- package/dist/mtext-renderer-worker.js +19294 -8080
- package/lib/font/baseFont.d.ts +24 -2
- package/lib/font/baseTextShape.d.ts +0 -6
- package/lib/font/charGeometryCache.d.ts +9 -9
- package/lib/font/defaultFontLoader.d.ts +12 -2
- package/lib/font/font.d.ts +8 -1
- package/lib/font/fontFactory.d.ts +0 -10
- package/lib/font/fontLoader.d.ts +19 -4
- package/lib/font/fontManager.d.ts +13 -9
- package/lib/font/meshFont.d.ts +18 -4
- package/lib/font/meshTextShape.d.ts +1 -0
- package/lib/font/shxFont.d.ts +25 -1
- package/lib/font/shxTextShape.d.ts +3 -2
- package/lib/renderer/mtext.d.ts +11 -0
- package/lib/worker/baseRenderer.d.ts +5 -0
- package/lib/worker/mainThreadRenderer.d.ts +5 -0
- package/lib/worker/unifiedRenderer.d.ts +5 -0
- package/lib/worker/webWorkerRenderer.d.ts +14 -8
- package/package.json +12 -6
package/lib/font/baseFont.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseTextShape } from './baseTextShape';
|
|
2
2
|
import { CharGeometryCache } from './charGeometryCache';
|
|
3
|
-
import { FontType } from './font';
|
|
3
|
+
import { FontData, FontType } from './font';
|
|
4
4
|
/**
|
|
5
5
|
* Abstract base class for font implementations.
|
|
6
6
|
* Provides common functionality and interface for font handling.
|
|
@@ -14,17 +14,32 @@ export declare abstract class BaseFont {
|
|
|
14
14
|
* This data is used to render characters and calculate metrics.
|
|
15
15
|
*/
|
|
16
16
|
abstract readonly data: unknown;
|
|
17
|
+
/**
|
|
18
|
+
* Font names. One font may have multiple names.
|
|
19
|
+
*/
|
|
20
|
+
names: Set<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Encoding used by character code. Please refer to the following link for encoding name.
|
|
23
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings
|
|
24
|
+
*/
|
|
25
|
+
encoding?: string;
|
|
17
26
|
/**
|
|
18
27
|
* Caching of font character geometries to improve text rendering performance.
|
|
19
28
|
*/
|
|
20
29
|
cache: CharGeometryCache;
|
|
21
|
-
constructor();
|
|
30
|
+
constructor(fontData: FontData);
|
|
22
31
|
/**
|
|
23
32
|
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
24
33
|
* @param char - The character to check
|
|
25
34
|
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
26
35
|
*/
|
|
27
36
|
abstract hasChar(char: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Return true if this font contains glyph of the specified character code. Otherwise, return false.
|
|
39
|
+
* @param code - The character code to check
|
|
40
|
+
* @returns True if this font contains glyph of the specified character code. Otherwise, return false.
|
|
41
|
+
*/
|
|
42
|
+
abstract hasCode(code: number): boolean;
|
|
28
43
|
/**
|
|
29
44
|
* Record of characters that are not supported by this font.
|
|
30
45
|
* Maps character strings to their occurrence count.
|
|
@@ -38,6 +53,13 @@ export declare abstract class BaseFont {
|
|
|
38
53
|
* @returns The shape data for the character, or undefined if not found
|
|
39
54
|
*/
|
|
40
55
|
abstract getCharShape(char: string, size: number): BaseTextShape | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Gets the shape data for a specific character code at a given size.
|
|
58
|
+
* @param code - The character code to get the shape for
|
|
59
|
+
* @param size - The desired size of the character
|
|
60
|
+
* @returns The shape data for the character code, or undefined if not found
|
|
61
|
+
*/
|
|
62
|
+
abstract getCodeShape(code: number, size: number): BaseTextShape | undefined;
|
|
41
63
|
/**
|
|
42
64
|
* Gets the scale factor for this font.
|
|
43
65
|
* This is used to adjust the size of characters when rendering.
|
|
@@ -5,16 +5,10 @@ import * as THREE from 'three';
|
|
|
5
5
|
* This class defines the core interface that all text shape types must implement.
|
|
6
6
|
*/
|
|
7
7
|
export declare abstract class BaseTextShape extends THREE.Shape {
|
|
8
|
-
/** The character this shape represents */
|
|
9
|
-
readonly char: string;
|
|
10
8
|
/**
|
|
11
9
|
* Width used to render this character
|
|
12
10
|
*/
|
|
13
11
|
width: number;
|
|
14
|
-
/**
|
|
15
|
-
* Creates a new instance of BaseTextShape
|
|
16
|
-
* @param char - The character this shape represents */
|
|
17
|
-
constructor(char: string);
|
|
18
12
|
/**
|
|
19
13
|
* Converts the text shape to a THREE.js geometry
|
|
20
14
|
* @returns A THREE.js BufferGeometry representing the text shape
|
|
@@ -6,37 +6,37 @@ export declare class CharGeometryCache {
|
|
|
6
6
|
private cache;
|
|
7
7
|
constructor();
|
|
8
8
|
/**
|
|
9
|
-
* Returns true if the geometry of the specified character exists in the cache.
|
|
9
|
+
* Returns true if the geometry of the specified character code exists in the cache.
|
|
10
10
|
* Otherwise, returns false.
|
|
11
|
-
* @param
|
|
11
|
+
* @param code One character code.
|
|
12
12
|
* @param size The font size.
|
|
13
|
-
* @returns True if the geometry of the specified character exists in the cache.
|
|
13
|
+
* @returns True if the geometry of the specified character code exists in the cache.
|
|
14
14
|
* Otherwise, returns false.
|
|
15
15
|
*/
|
|
16
|
-
hasGeometry(
|
|
16
|
+
hasGeometry(code: number, size: number): boolean;
|
|
17
17
|
/**
|
|
18
18
|
* Get the geometry for a single character from cache if available.
|
|
19
|
-
* The cache key includes both character
|
|
20
|
-
* @param
|
|
19
|
+
* The cache key includes both character codeand size.
|
|
20
|
+
* @param code The character code to get geometry from cache.
|
|
21
21
|
* @param size The font size.
|
|
22
22
|
* @returns The geometry for a single character from cache if avaiable.
|
|
23
23
|
* Return undefined if the character not found in cache.
|
|
24
24
|
*/
|
|
25
|
-
getGeometry(
|
|
25
|
+
getGeometry(code: number, size: number): THREE.BufferGeometry | undefined;
|
|
26
26
|
/**
|
|
27
27
|
* Set the geometry to cache for a single character.
|
|
28
28
|
* @param char The character to set geometry for.
|
|
29
29
|
* @param size The font size.
|
|
30
30
|
* @param geometry The geometry to set.
|
|
31
31
|
*/
|
|
32
|
-
setGeometry(
|
|
32
|
+
setGeometry(code: number, size: number, geometry: THREE.BufferGeometry): void;
|
|
33
33
|
/**
|
|
34
34
|
* Dispose all cached geometries.
|
|
35
35
|
*/
|
|
36
36
|
dispose(): void;
|
|
37
37
|
/**
|
|
38
38
|
* Generates cache key by character and font size.
|
|
39
|
-
* @param char One character.
|
|
39
|
+
* @param char One character code.
|
|
40
40
|
* @param size The font size.
|
|
41
41
|
*/
|
|
42
42
|
private generateKey;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { FontInfo, FontLoader, FontLoadStatus } from './fontLoader';
|
|
2
2
|
/**
|
|
3
3
|
* Default implementation of the FontLoader interface.
|
|
4
|
-
* This class provides font loading functionality using
|
|
4
|
+
* This class provides font loading functionality using [this font repository](https://mlightcad.gitlab.io/cad-data/fonts/).
|
|
5
5
|
* It loads font metadata from a JSON file and provides access to available fonts.
|
|
6
6
|
*/
|
|
7
7
|
export declare class DefaultFontLoader implements FontLoader {
|
|
8
8
|
/** List of available fonts in the system */
|
|
9
9
|
private _avaiableFonts;
|
|
10
10
|
private _baseUrl;
|
|
11
|
+
private _avaiableFontMap;
|
|
11
12
|
/**
|
|
12
13
|
* Creates a new instance of DefaultFontLoader
|
|
13
14
|
*/
|
|
@@ -22,13 +23,18 @@ export declare class DefaultFontLoader implements FontLoader {
|
|
|
22
23
|
* @returns Array of FontInfo objects describing available fonts
|
|
23
24
|
*/
|
|
24
25
|
get avaiableFonts(): FontInfo[];
|
|
26
|
+
/**
|
|
27
|
+
* Triggered when font url changed
|
|
28
|
+
* @param url - New font url value
|
|
29
|
+
*/
|
|
30
|
+
onFontUrlChanged(url: string): void;
|
|
25
31
|
/**
|
|
26
32
|
* Retrieves information about all available fonts in the system.
|
|
27
33
|
* Loads font metadata from a CDN if not already loaded.
|
|
28
34
|
* @returns Promise that resolves to an array of FontInfo objects
|
|
29
35
|
* @throws {Error} If font metadata cannot be loaded from the CDN
|
|
30
36
|
*/
|
|
31
|
-
|
|
37
|
+
getAvailableFonts(): Promise<FontInfo[]>;
|
|
32
38
|
/**
|
|
33
39
|
* Loads the specified fonts into the system. If one font is already loaded,
|
|
34
40
|
* the font will not be loaded again. If no font names are provided, just loads
|
|
@@ -37,4 +43,8 @@ export declare class DefaultFontLoader implements FontLoader {
|
|
|
37
43
|
* @returns Promise that resolves to an array of FontLoadStatus objects
|
|
38
44
|
*/
|
|
39
45
|
load(fontNames: string[]): Promise<FontLoadStatus[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Build one font map. The key is font name. The value is font info.
|
|
48
|
+
*/
|
|
49
|
+
private buildFontMap;
|
|
40
50
|
}
|
package/lib/font/font.d.ts
CHANGED
|
@@ -9,10 +9,17 @@ export type FontType = 'shx' | 'mesh';
|
|
|
9
9
|
* This interface defines the structure of font data that is stored and retrieved from the cache.
|
|
10
10
|
*/
|
|
11
11
|
export interface FontData {
|
|
12
|
-
/** The name
|
|
12
|
+
/** The font name */
|
|
13
13
|
name: string;
|
|
14
|
+
/** The alias names of the font */
|
|
15
|
+
alias: string[];
|
|
14
16
|
/** The type of font (shx or mesh) */
|
|
15
17
|
type: FontType;
|
|
18
|
+
/**
|
|
19
|
+
* Encoding used by character code. Please refer to the following link for encoding name.
|
|
20
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings
|
|
21
|
+
*/
|
|
22
|
+
encoding?: string;
|
|
16
23
|
/** The parsed font data. Different types of fonts have different data structures. */
|
|
17
24
|
data: unknown;
|
|
18
25
|
}
|
|
@@ -28,14 +28,4 @@ export declare class FontFactory {
|
|
|
28
28
|
* @throws {Error} If the font data type is not supported
|
|
29
29
|
*/
|
|
30
30
|
createFont(data: FontData): BaseFont;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a font instance from a file name and its ArrayBuffer data.
|
|
33
|
-
* The type of font created is determined by the file extension.
|
|
34
|
-
*
|
|
35
|
-
* @param fileName - The name of the font file
|
|
36
|
-
* @param buffer - The ArrayBuffer containing the font data
|
|
37
|
-
* @returns A new instance of either ShxFont or MeshFont
|
|
38
|
-
* @throws {Error} If the file type is not supported
|
|
39
|
-
*/
|
|
40
|
-
createFontFromBuffer(fileName: string, buffer: ArrayBuffer): BaseFont;
|
|
41
31
|
}
|
package/lib/font/fontLoader.d.ts
CHANGED
|
@@ -7,9 +7,14 @@ export interface FontInfo {
|
|
|
7
7
|
/** Font file name */
|
|
8
8
|
file: string;
|
|
9
9
|
/** Type of the font - either mesh or shx format */
|
|
10
|
-
type: '
|
|
10
|
+
type: 'mesh' | 'shx';
|
|
11
11
|
/** URL where the font can be accessed */
|
|
12
12
|
url: string;
|
|
13
|
+
/**
|
|
14
|
+
* Encoding used by character code. Please refer to the following link for encoding name.
|
|
15
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings
|
|
16
|
+
*/
|
|
17
|
+
encoding?: string;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* Represents the status of a font loading operation
|
|
@@ -19,8 +24,13 @@ export interface FontLoadStatus {
|
|
|
19
24
|
fontName: string;
|
|
20
25
|
/** URL from which the font was loaded */
|
|
21
26
|
url: string;
|
|
22
|
-
/**
|
|
23
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The status to load font
|
|
29
|
+
* - Success
|
|
30
|
+
* - Font not found in font repository
|
|
31
|
+
* - Failed to load font from font repository
|
|
32
|
+
*/
|
|
33
|
+
status: 'Success' | 'NotFound' | 'FailedToLoad';
|
|
24
34
|
}
|
|
25
35
|
/**
|
|
26
36
|
* Interface that defines font loading functionality.
|
|
@@ -39,5 +49,10 @@ export interface FontLoader {
|
|
|
39
49
|
* Retrieves information about all available fonts in the system
|
|
40
50
|
* @returns Promise that resolves to an array of FontInfo objects containing details about available fonts
|
|
41
51
|
*/
|
|
42
|
-
|
|
52
|
+
getAvailableFonts(): Promise<FontInfo[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Base URL to load fonts
|
|
55
|
+
*/
|
|
56
|
+
get baseUrl(): string;
|
|
57
|
+
set baseUrl(value: string);
|
|
43
58
|
}
|
|
@@ -2,7 +2,7 @@ import { EventManager } from '../common';
|
|
|
2
2
|
import { BaseFont } from './baseFont';
|
|
3
3
|
import { BaseTextShape } from './baseTextShape';
|
|
4
4
|
import { FontType } from './font';
|
|
5
|
-
import { FontLoader, FontLoadStatus } from './fontLoader';
|
|
5
|
+
import { FontInfo, FontLoader, FontLoadStatus } from './fontLoader';
|
|
6
6
|
/**
|
|
7
7
|
* Font mappings configuration.
|
|
8
8
|
* Maps original font names to their replacement font names.
|
|
@@ -60,6 +60,11 @@ export declare class FontManager {
|
|
|
60
60
|
* @returns The FontManager instance
|
|
61
61
|
*/
|
|
62
62
|
static get instance(): FontManager;
|
|
63
|
+
/**
|
|
64
|
+
* Base URL to load fonts
|
|
65
|
+
*/
|
|
66
|
+
get baseUrl(): string;
|
|
67
|
+
set baseUrl(value: string);
|
|
63
68
|
/**
|
|
64
69
|
* Sets the font mapping configuration
|
|
65
70
|
* @param mapping - The font mapping to set
|
|
@@ -76,7 +81,7 @@ export declare class FontManager {
|
|
|
76
81
|
* @returns Promise that resolves to an array of FontInfo objects
|
|
77
82
|
* @throws {Error} If font metadata cannot be loaded from the CDN
|
|
78
83
|
*/
|
|
79
|
-
|
|
84
|
+
getAvailableFonts(): Promise<FontInfo[]>;
|
|
80
85
|
/**
|
|
81
86
|
* Return true if the default font was loaded.
|
|
82
87
|
* @returns True if the default font was loaded. False otherwise.
|
|
@@ -86,19 +91,19 @@ export declare class FontManager {
|
|
|
86
91
|
* Loads the default font
|
|
87
92
|
* @returns Promise that resolves to the font load statuses
|
|
88
93
|
*/
|
|
89
|
-
loadDefaultFont(): Promise<FontLoadStatus>;
|
|
94
|
+
loadDefaultFont(): Promise<FontLoadStatus[]>;
|
|
90
95
|
/**
|
|
91
96
|
* Loads the specified fonts from font names
|
|
92
97
|
* @param names - Font names to load.
|
|
93
98
|
* @returns Promise that resolves to an array of font load statuses
|
|
94
99
|
*/
|
|
95
|
-
loadFontsByNames(names: string | string[]): Promise<FontLoadStatus>;
|
|
100
|
+
loadFontsByNames(names: string | string[]): Promise<FontLoadStatus[]>;
|
|
96
101
|
/**
|
|
97
102
|
* Loads the specified fonts from URLs
|
|
98
103
|
* @param urls - URLs of font files to load.
|
|
99
104
|
* @returns Promise that resolves to an array of font load statuses
|
|
100
105
|
*/
|
|
101
|
-
|
|
106
|
+
loadFonts(fonts: FontInfo | FontInfo[]): Promise<FontLoadStatus[]>;
|
|
102
107
|
/**
|
|
103
108
|
* Tries to find the specified font. If not found, uses a replacement font and returns its name.
|
|
104
109
|
* @param fontName - The font name to find
|
|
@@ -116,8 +121,6 @@ export declare class FontManager {
|
|
|
116
121
|
/**
|
|
117
122
|
* Gets the first font which contains the specified character.
|
|
118
123
|
* @param char - The character to get the shape for
|
|
119
|
-
* @param fontName - The name of the font to use
|
|
120
|
-
* @param size - The size of the character
|
|
121
124
|
* @returns The text shape for the character, or undefined if not found
|
|
122
125
|
*/
|
|
123
126
|
getFontByChar(char: string): BaseFont | undefined;
|
|
@@ -159,10 +162,11 @@ export declare class FontManager {
|
|
|
159
162
|
*/
|
|
160
163
|
private recordMissedFonts;
|
|
161
164
|
/**
|
|
162
|
-
* Loads a single font
|
|
163
|
-
* @param
|
|
165
|
+
* Loads a single font
|
|
166
|
+
* @param fontInfo - The matadata of the font to be loaded
|
|
164
167
|
*/
|
|
165
168
|
private loadFont;
|
|
169
|
+
private fontInfoToFontData;
|
|
166
170
|
/**
|
|
167
171
|
* Loads all fonts from the cache
|
|
168
172
|
*/
|
package/lib/font/meshFont.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Font, FontData } from 'three/examples/jsm/loaders/FontLoader.js';
|
|
1
|
+
import { Font, FontData as ThreeFontData } from 'three/examples/jsm/loaders/FontLoader.js';
|
|
2
2
|
import { BaseFont } from './baseFont';
|
|
3
|
+
import { FontData } from './font';
|
|
3
4
|
import { MeshTextShape } from './meshTextShape';
|
|
4
5
|
/**
|
|
5
6
|
* Represents the data structure for mesh-based fonts.
|
|
6
|
-
* Extends the base
|
|
7
|
+
* Extends the base ThreeFontData interface with additional properties specific to mesh fonts.
|
|
7
8
|
*/
|
|
8
|
-
export interface MeshFontData extends
|
|
9
|
+
export interface MeshFontData extends ThreeFontData {
|
|
9
10
|
/** Scale factor used to adjust the size of characters when rendering */
|
|
10
11
|
scaleFactor: number;
|
|
11
12
|
}
|
|
@@ -27,13 +28,19 @@ export declare class MeshFont extends BaseFont {
|
|
|
27
28
|
* Creates a new instance of MeshFont.
|
|
28
29
|
* @param data - Either a MeshFontData object containing font information or an ArrayBuffer containing raw font data
|
|
29
30
|
*/
|
|
30
|
-
constructor(
|
|
31
|
+
constructor(fontData: FontData);
|
|
31
32
|
/**
|
|
32
33
|
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
33
34
|
* @param char - The character to check
|
|
34
35
|
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
35
36
|
*/
|
|
36
37
|
hasChar(char: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Return true if this font contains glyph of the specified character code. Otherwise, return false.
|
|
40
|
+
* @param code - The character code to check
|
|
41
|
+
* @returns True if this font contains glyph of the specified character code. Otherwise, return false.
|
|
42
|
+
*/
|
|
43
|
+
hasCode(code: number): boolean;
|
|
37
44
|
/**
|
|
38
45
|
* Generates shapes for a text string
|
|
39
46
|
* @param text - The text to generate shapes for
|
|
@@ -48,6 +55,13 @@ export declare class MeshFont extends BaseFont {
|
|
|
48
55
|
* @returns The shape data for the character, or undefined if not found
|
|
49
56
|
*/
|
|
50
57
|
getCharShape(char: string, size: number): MeshTextShape | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the shape data for a specific character unicode at a given size.
|
|
60
|
+
* @param code - The character unicode to get the shape for
|
|
61
|
+
* @param size - The desired size of the character
|
|
62
|
+
* @returns The shape data for the character unicode, or undefined if not found
|
|
63
|
+
*/
|
|
64
|
+
getCodeShape(code: number, size: number): MeshTextShape | undefined;
|
|
51
65
|
/**
|
|
52
66
|
* Gets the scale factor for this font.
|
|
53
67
|
* This is used to adjust the size of characters when rendering.
|
|
@@ -12,6 +12,7 @@ export declare class MeshTextShape extends BaseTextShape {
|
|
|
12
12
|
* Used to track if the character exists in the font's glyph set.
|
|
13
13
|
*/
|
|
14
14
|
isFound: boolean;
|
|
15
|
+
private readonly char;
|
|
15
16
|
private readonly font;
|
|
16
17
|
private readonly fontSize;
|
|
17
18
|
constructor(char: string, fontSize: number, font: MeshFont);
|
package/lib/font/shxFont.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ShxFontData } from '@mlightcad/shx-parser';
|
|
2
2
|
import { BaseFont } from './baseFont';
|
|
3
|
+
import { FontData } from './font';
|
|
3
4
|
import { ShxTextShape } from './shxTextShape';
|
|
4
5
|
/**
|
|
5
6
|
* ShxFont is a class that extends BaseFont and represents a SHX font.
|
|
@@ -10,13 +11,19 @@ export declare class ShxFont extends BaseFont {
|
|
|
10
11
|
private readonly font;
|
|
11
12
|
readonly type = "shx";
|
|
12
13
|
readonly data: ShxFontData;
|
|
13
|
-
constructor(
|
|
14
|
+
constructor(fontData: FontData);
|
|
14
15
|
/**
|
|
15
16
|
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
16
17
|
* @param char - The character to check
|
|
17
18
|
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
18
19
|
*/
|
|
19
20
|
hasChar(char: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Return true if this font contains glyph of the specified character code. Otherwise, return false.
|
|
23
|
+
* @param code - The character code to check
|
|
24
|
+
* @returns True if this font contains glyph of the specified character code. Otherwise, return false.
|
|
25
|
+
*/
|
|
26
|
+
hasCode(code: number): boolean;
|
|
20
27
|
generateShapes(text: string, size: number): ShxTextShape[];
|
|
21
28
|
/**
|
|
22
29
|
* SHX font always has fixed scale factor 1.
|
|
@@ -25,14 +32,31 @@ export declare class ShxFont extends BaseFont {
|
|
|
25
32
|
getScaleFactor(): number;
|
|
26
33
|
/**
|
|
27
34
|
* Gets the shape data for a specific character at a given size.
|
|
35
|
+
* If the font type is BIGFONT, please use getCodeShape to get the shape data
|
|
36
|
+
* because the character code for BIGFONT isn't unicode.
|
|
28
37
|
* @param char - The character to get the shape for
|
|
29
38
|
* @param size - The desired size of the character
|
|
30
39
|
* @returns The shape data for the character, or undefined if not found
|
|
31
40
|
*/
|
|
32
41
|
getCharShape(char: string, size: number): ShxTextShape | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the shape data for a specific character code at a given size.
|
|
44
|
+
* The passed code must the code stored in font instead of unicode.
|
|
45
|
+
* - Unicode shx font uses unicode as character code.
|
|
46
|
+
* - Bigfont uses a custom encoding for double-byte characters.
|
|
47
|
+
* @param code - The character code to get the shape for
|
|
48
|
+
* @param size - The desired size of the character
|
|
49
|
+
* @returns The shape data for the character code, or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
getCodeShape(code: number, size: number): ShxTextShape | undefined;
|
|
33
52
|
/**
|
|
34
53
|
* For an unsupported char, use "?" as a replacement.
|
|
35
54
|
*/
|
|
36
55
|
getNotFoundTextShape(size: number): ShxTextShape | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Gets encoded code of the specified character according to font character encoding
|
|
58
|
+
* @param char - The character to get its code
|
|
59
|
+
* @returns Returns encoded code of the specified character
|
|
60
|
+
*/
|
|
37
61
|
private getCode;
|
|
38
62
|
}
|
|
@@ -9,15 +9,16 @@ import * as THREE from 'three';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class ShxTextShape extends BaseTextShape {
|
|
11
11
|
/** The shape data for this character */
|
|
12
|
+
private readonly code;
|
|
12
13
|
private readonly shape;
|
|
13
14
|
private readonly font;
|
|
14
15
|
private readonly fontSize;
|
|
15
16
|
/**
|
|
16
17
|
* Creates a new instance of ShxTextShape
|
|
17
|
-
* @param
|
|
18
|
+
* @param code - The character code this shape represents
|
|
18
19
|
* @param shape - The shape data for this character
|
|
19
20
|
*/
|
|
20
|
-
constructor(
|
|
21
|
+
constructor(code: number, fontSize: number, shape: ShxShape, font: ShxFont);
|
|
21
22
|
protected calcWidth(): number;
|
|
22
23
|
offset(offset: Point): ShxTextShape;
|
|
23
24
|
/**
|
package/lib/renderer/mtext.d.ts
CHANGED
|
@@ -52,6 +52,11 @@ export declare class MText extends THREE.Object3D {
|
|
|
52
52
|
* @returns The FontManager instance
|
|
53
53
|
*/
|
|
54
54
|
get fontManager(): FontManager;
|
|
55
|
+
/**
|
|
56
|
+
* Remove the current object from its parent and release geometry and material resource used
|
|
57
|
+
* by the current object.
|
|
58
|
+
*/
|
|
59
|
+
dispose(): void;
|
|
55
60
|
/**
|
|
56
61
|
* Draw the MText object. This method loads required fonts on demand and builds the object graph.
|
|
57
62
|
*/
|
|
@@ -114,4 +119,10 @@ export declare class MText extends THREE.Object3D {
|
|
|
114
119
|
* @param boxes - Array to store the calculated bounding boxes
|
|
115
120
|
*/
|
|
116
121
|
private getBoxes;
|
|
122
|
+
/**
|
|
123
|
+
* Remove the specified object from its parent and release geometry and material resource used
|
|
124
|
+
* by the object.
|
|
125
|
+
* @param obj - Input object to dispose
|
|
126
|
+
*/
|
|
127
|
+
private disposeThreeObject;
|
|
117
128
|
}
|
|
@@ -67,6 +67,11 @@ export interface MTextBaseRenderer {
|
|
|
67
67
|
name: string[];
|
|
68
68
|
}>;
|
|
69
69
|
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Set URL to load fonts
|
|
72
|
+
* @param value - URL to load fonts
|
|
73
|
+
*/
|
|
74
|
+
setFontUrl(value: string): Promise<void>;
|
|
70
75
|
/**
|
|
71
76
|
* Release any resources owned by the renderer (e.g., terminate Web Workers).
|
|
72
77
|
*
|
|
@@ -9,6 +9,11 @@ export declare class MainThreadRenderer implements MTextBaseRenderer {
|
|
|
9
9
|
private styleManager;
|
|
10
10
|
private isInitialized;
|
|
11
11
|
constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Set URL to load fonts
|
|
14
|
+
* @param value - URL to load fonts
|
|
15
|
+
*/
|
|
16
|
+
setFontUrl(value: string): Promise<void>;
|
|
12
17
|
/**
|
|
13
18
|
* Render MText directly in the main thread asynchronously. It will ensure that default font
|
|
14
19
|
* is loaded. And fonts needed in mtext are loaded on demand.
|
|
@@ -23,6 +23,11 @@ export declare class UnifiedRenderer {
|
|
|
23
23
|
* @param mode The default rendering mode
|
|
24
24
|
*/
|
|
25
25
|
setDefaultMode(mode: RenderMode): void;
|
|
26
|
+
/**
|
|
27
|
+
* Set URL to load fonts
|
|
28
|
+
* @param value - URL to load fonts
|
|
29
|
+
*/
|
|
30
|
+
setFontUrl(value: string): Promise<void>;
|
|
26
31
|
/**
|
|
27
32
|
* Get the default rendering mode
|
|
28
33
|
*/
|
|
@@ -111,13 +111,25 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
|
|
|
111
111
|
private styleManager;
|
|
112
112
|
constructor(config?: WebWorkerRendererConfig);
|
|
113
113
|
private ensureInitialized;
|
|
114
|
+
/**
|
|
115
|
+
* Handles messages coming from any worker.
|
|
116
|
+
*/
|
|
114
117
|
private handleWorkerMessage;
|
|
118
|
+
/**
|
|
119
|
+
* Attaches message and error handlers to a worker.
|
|
120
|
+
*/
|
|
115
121
|
private attachWorkerHandlers;
|
|
116
122
|
private pickLeastLoadedWorker;
|
|
117
|
-
private
|
|
123
|
+
private sendMessageToAllWorkers;
|
|
124
|
+
private sendMessageToOneWorker;
|
|
118
125
|
private ensureTasksFinished;
|
|
119
126
|
/**
|
|
120
|
-
*
|
|
127
|
+
* Set URL to load fonts
|
|
128
|
+
* @param value - URL to load fonts
|
|
129
|
+
*/
|
|
130
|
+
setFontUrl(value: string): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Render MText in one worker and return serialized data asynchronously.
|
|
121
133
|
*/
|
|
122
134
|
asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
|
|
123
135
|
/**
|
|
@@ -125,15 +137,9 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
|
|
|
125
137
|
* Notes: It isn't supported yet.
|
|
126
138
|
*/
|
|
127
139
|
syncRenderMText(_mtextContent: MTextData, _textStyle: TextStyle, _colorSettings?: ColorSettings): MTextObject;
|
|
128
|
-
/**
|
|
129
|
-
* Load fonts in the worker
|
|
130
|
-
*/
|
|
131
140
|
loadFonts(fonts: string[]): Promise<{
|
|
132
141
|
loaded: string[];
|
|
133
142
|
}>;
|
|
134
|
-
/**
|
|
135
|
-
* Get available fonts from the worker
|
|
136
|
-
*/
|
|
137
143
|
getAvailableFonts(): Promise<{
|
|
138
144
|
fonts: Array<{
|
|
139
145
|
name: string[];
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/mtext-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "AutoCAD MText renderer based on Three.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MLight Lee <mlight.lee@outlook.com>",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://gitlab.com/mlightcad/mtext-renderer"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://gitlab.com/mlightcad/mtext-renderer",
|
|
8
13
|
"main": "./dist/index.umd.cjs",
|
|
9
14
|
"module": "./dist/index.js",
|
|
10
15
|
"types": "./lib/index.d.ts",
|
|
@@ -24,14 +29,15 @@
|
|
|
24
29
|
"mtext",
|
|
25
30
|
"three.js",
|
|
26
31
|
"renderer",
|
|
27
|
-
"
|
|
28
|
-
"text"
|
|
32
|
+
"webgl",
|
|
33
|
+
"3d-text"
|
|
29
34
|
],
|
|
30
35
|
"dependencies": {
|
|
31
36
|
"@mlightcad/mtext-parser": "^1.2.0",
|
|
32
|
-
"@mlightcad/shx-parser": "^1.
|
|
33
|
-
"
|
|
34
|
-
"idb": "^8.0.3"
|
|
37
|
+
"@mlightcad/shx-parser": "^1.3.0",
|
|
38
|
+
"iconv-lite": "^0.7.0",
|
|
39
|
+
"idb": "^8.0.3",
|
|
40
|
+
"opentype.js": "^1.3.4"
|
|
35
41
|
},
|
|
36
42
|
"devDependencies": {
|
|
37
43
|
"@types/opentype.js": "^1.3.8",
|