@mlightcad/mtext-renderer 0.12.7 → 0.12.9

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.
@@ -13,8 +13,17 @@ export type DefaultFontsPreset =
13
13
  | 'modern'
14
14
  /** Western SHX fonts plus simsun and AMGDT; no CJK-specific SHX big fonts. */
15
15
  | 'international'
16
- /** Broad CJK coverage: simsun first, then GB big-font SHX files. */
17
- | 'cjk';
16
+ /**
17
+ * Broad CJK coverage: Chinese / Korean / Japanese mesh fonts plus matching
18
+ * SHX big fonts.
19
+ */
20
+ | 'cjk'
21
+ /** Simplified Chinese: simsun (TTF) plus GB big-font SHX. */
22
+ | 'chinese'
23
+ /** Korean: malgun / Noto Sans KR (TTF) plus Korean big-font SHX. */
24
+ | 'korean'
25
+ /** Japanese: MS Gothic (TTF) plus extfont2 / extfont SHX. */
26
+ | 'japanese';
18
27
  /**
19
28
  * Predefined text-font fallback chains (primary / big-font substitutes and CJK
20
29
  * mesh fallbacks). Symbol fonts such as `amgdt` are configured separately via
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Minimal opentype glyph fields used when deriving a mesh-font scale factor.
3
+ */
4
+ export interface MeshFontScaleGlyph {
5
+ yMax?: number;
6
+ advanceWidth?: number;
7
+ }
8
+ /**
9
+ * Minimal opentype font surface needed to compute {@link computeMeshFontScaleFactor}.
10
+ *
11
+ * Prefer {@link MeshFontScaleSource.charToGlyphIndex} over relying on
12
+ * {@link MeshFontScaleSource.charToGlyph} alone: opentype.js returns the
13
+ * `.notdef` glyph (index 0) for missing code points, so a truthy glyph object
14
+ * does not mean the face actually contains that character.
15
+ */
16
+ export interface MeshFontScaleSource {
17
+ unitsPerEm: number;
18
+ charToGlyph: (char: string) => MeshFontScaleGlyph | undefined;
19
+ charToGlyphIndex: (char: string) => number | null | undefined;
20
+ }
21
+ /**
22
+ * Threshold above which a Latin-'A'-based scale is treated as unsafe for fonts
23
+ * that also contain full-em CJK ideographs (SimSun / SimFang / etc.).
24
+ */
25
+ export declare const CJK_LATIN_SCALE_INFLATION_THRESHOLD = 1.15;
26
+ /**
27
+ * Fraction of the em square at which an ideograph advance is treated as a
28
+ * full-cell CJK design glyph.
29
+ */
30
+ export declare const CJK_FULL_EM_ADVANCE_RATIO = 0.9;
31
+ /**
32
+ * Computes the mesh-font scale that maps CAD text height onto glyph outlines.
33
+ *
34
+ * AutoCAD maps TrueType text height to the font design size. For Western faces,
35
+ * capital {@code A} height is a good proxy (`unitsPerEm / A.yMax`). For CJK
36
+ * faces, ideographs occupy the full em while Latin capitals are much shorter —
37
+ * using {@code A.yMax} then inflates both glyph size and advance (~1.4× for
38
+ * SimFang/SimSun), which falsely wraps MTEXT that AutoCAD keeps on one line.
39
+ *
40
+ * When the font has full-em ideographs and the Latin-based scale would inflate
41
+ * advances past {@link CJK_LATIN_SCALE_INFLATION_THRESHOLD}, return {@code 1}
42
+ * so text height maps to the em square (AutoCAD CJK TrueType behavior).
43
+ */
44
+ export declare function computeMeshFontScaleFactor(font: MeshFontScaleSource): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.12.7",
3
+ "version": "0.12.9",
4
4
  "description": "AutoCAD MText renderer based on Three.js",
5
5
  "license": "MIT",
6
6
  "author": "MLight Lee <mlight.lee@outlook.com>",