@codexo/exojs 0.6.8 → 0.6.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.
- package/CHANGELOG.md +68 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/rendering/index.d.ts +3 -0
- package/dist/esm/rendering/text/DynamicGlyphAtlas.d.ts +33 -0
- package/dist/esm/rendering/text/DynamicGlyphAtlas.js +140 -0
- package/dist/esm/rendering/text/DynamicGlyphAtlas.js.map +1 -0
- package/dist/esm/rendering/text/Text.d.ts +21 -17
- package/dist/esm/rendering/text/Text.js +93 -93
- package/dist/esm/rendering/text/Text.js.map +1 -1
- package/dist/esm/rendering/text/TextLayout.d.ts +13 -0
- package/dist/esm/rendering/text/TextLayout.js +63 -0
- package/dist/esm/rendering/text/TextLayout.js.map +1 -0
- package/dist/esm/rendering/text/TextStyle.d.ts +26 -3
- package/dist/esm/rendering/text/TextStyle.js +45 -0
- package/dist/esm/rendering/text/TextStyle.js.map +1 -1
- package/dist/esm/rendering/text/atlas-singleton.d.ts +7 -0
- package/dist/esm/rendering/text/atlas-singleton.js +17 -0
- package/dist/esm/rendering/text/atlas-singleton.js.map +1 -0
- package/dist/esm/rendering/text/types.d.ts +45 -0
- package/dist/esm/rendering/utils.js +1 -14
- package/dist/esm/rendering/utils.js.map +1 -1
- package/dist/exo.esm.js +344 -104
- package/dist/exo.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes per-glyph quad placements for the given text and style.
|
|
3
|
+
*
|
|
4
|
+
* Handles `\n` line breaks and left/center/right alignment. No word-wrap,
|
|
5
|
+
* no RTL, no ligature shaping — Unicode/diacritics are delegated to the
|
|
6
|
+
* browser's font engine via canvas `fillText`.
|
|
7
|
+
*
|
|
8
|
+
* Returns an empty array for empty text.
|
|
9
|
+
*/
|
|
10
|
+
function layoutText(text, style, atlas) {
|
|
11
|
+
if (text.length === 0) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const { fontSize, fontFamily, fontWeight, fontStyle, lineHeight, align } = style;
|
|
15
|
+
const computedLineHeight = fontSize * lineHeight;
|
|
16
|
+
const lines = text.split('\n');
|
|
17
|
+
// Pass 1: gather glyph info per line, track line widths
|
|
18
|
+
const linePlacements = [];
|
|
19
|
+
let maxLineWidth = 0;
|
|
20
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
21
|
+
const line = lines[lineIndex];
|
|
22
|
+
const y = lineIndex * computedLineHeight;
|
|
23
|
+
let cursorX = 0;
|
|
24
|
+
const placements = [];
|
|
25
|
+
for (const char of line) {
|
|
26
|
+
const info = atlas.getGlyph(char, fontFamily, fontSize, fontWeight, fontStyle);
|
|
27
|
+
placements.push({ info, x: cursorX, y });
|
|
28
|
+
cursorX += info.advance;
|
|
29
|
+
}
|
|
30
|
+
const lineWidth = cursorX;
|
|
31
|
+
if (lineWidth > maxLineWidth) {
|
|
32
|
+
maxLineWidth = lineWidth;
|
|
33
|
+
}
|
|
34
|
+
linePlacements.push({ placements, width: lineWidth });
|
|
35
|
+
}
|
|
36
|
+
// Pass 2: apply alignment and build final GlyphPlacement array
|
|
37
|
+
const result = [];
|
|
38
|
+
for (const line of linePlacements) {
|
|
39
|
+
let offsetX = 0;
|
|
40
|
+
if (align === 'right') {
|
|
41
|
+
offsetX = maxLineWidth - line.width;
|
|
42
|
+
}
|
|
43
|
+
else if (align === 'center') {
|
|
44
|
+
offsetX = (maxLineWidth - line.width) / 2;
|
|
45
|
+
}
|
|
46
|
+
for (const { info, x, y } of line.placements) {
|
|
47
|
+
result.push({
|
|
48
|
+
x: x + offsetX,
|
|
49
|
+
y,
|
|
50
|
+
width: info.width,
|
|
51
|
+
height: info.height,
|
|
52
|
+
uvLeft: info.uvLeft,
|
|
53
|
+
uvTop: info.uvTop,
|
|
54
|
+
uvRight: info.uvRight,
|
|
55
|
+
uvBottom: info.uvBottom,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { layoutText };
|
|
63
|
+
//# sourceMappingURL=TextLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextLayout.js","sources":["../../../../../src/rendering/text/TextLayout.ts"],"sourcesContent":[null],"names":[],"mappings":"AAaA;;;;;;;;AAQG;SACa,UAAU,CACtB,IAAY,EACZ,KAAgB,EAChB,KAAwB,EAAA;AAExB,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACnB,QAAA,OAAO,EAAE;IACb;AAEA,IAAA,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,KAAK;AAChF,IAAA,MAAM,kBAAkB,GAAG,QAAQ,GAAG,UAAU;IAChD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;;IAG9B,MAAM,cAAc,GAAyB,EAAE;IAC/C,IAAI,YAAY,GAAG,CAAC;AAEpB,IAAA,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;AAC3D,QAAA,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC;AAC7B,QAAA,MAAM,CAAC,GAAG,SAAS,GAAG,kBAAkB;QACxC,IAAI,OAAO,GAAG,CAAC;QACf,MAAM,UAAU,GAAgC,EAAE;AAElD,QAAA,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;AACrB,YAAA,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC;AAE9E,YAAA,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACxC,YAAA,OAAO,IAAI,IAAI,CAAC,OAAO;QAC3B;QAEA,MAAM,SAAS,GAAG,OAAO;AAEzB,QAAA,IAAI,SAAS,GAAG,YAAY,EAAE;YAC1B,YAAY,GAAG,SAAS;QAC5B;QAEA,cAAc,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IACzD;;IAGA,MAAM,MAAM,GAA0B,EAAE;AAExC,IAAA,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE;QAC/B,IAAI,OAAO,GAAG,CAAC;AAEf,QAAA,IAAI,KAAK,KAAK,OAAO,EAAE;AACnB,YAAA,OAAO,GAAG,YAAY,GAAG,IAAI,CAAC,KAAK;QACvC;AAAO,aAAA,IAAI,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;QAC7C;AAEA,QAAA,KAAK,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE;YAC1C,MAAM,CAAC,IAAI,CAAC;gBACR,CAAC,EAAE,CAAC,GAAG,OAAO;gBACd,CAAC;gBACD,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;AAC1B,aAAA,CAAC;QACN;IACJ;AAEA,IAAA,OAAO,MAAM;AACjB;;;;"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import { Color } from '@/core/Color';
|
|
2
|
+
import type { TextAlignment } from './types';
|
|
1
3
|
export type TextStyleColor = string | CanvasGradient | CanvasPattern;
|
|
2
4
|
export interface TextStyleOptions {
|
|
3
|
-
align?:
|
|
5
|
+
align?: TextAlignment;
|
|
4
6
|
fill?: TextStyleColor;
|
|
7
|
+
fillColor?: Color;
|
|
8
|
+
lineHeight?: number;
|
|
5
9
|
stroke?: TextStyleColor;
|
|
6
10
|
strokeThickness?: number;
|
|
7
11
|
fontSize?: number;
|
|
8
12
|
fontWeight?: string;
|
|
9
13
|
fontFamily?: string;
|
|
14
|
+
fontStyle?: 'normal' | 'italic';
|
|
10
15
|
wordWrap?: boolean;
|
|
11
16
|
wordWrapWidth?: number;
|
|
12
17
|
baseline?: CanvasTextBaseline;
|
|
@@ -17,11 +22,14 @@ export interface TextStyleOptions {
|
|
|
17
22
|
export declare class TextStyle {
|
|
18
23
|
private _align;
|
|
19
24
|
private _fill;
|
|
25
|
+
private _fillColor;
|
|
26
|
+
private _lineHeight;
|
|
20
27
|
private _stroke;
|
|
21
28
|
private _strokeThickness;
|
|
22
29
|
private _fontSize;
|
|
23
30
|
private _fontWeight;
|
|
24
31
|
private _fontFamily;
|
|
32
|
+
private _fontStyle;
|
|
25
33
|
private _wordWrap;
|
|
26
34
|
private _wordWrapWidth;
|
|
27
35
|
private _baseline;
|
|
@@ -30,10 +38,23 @@ export declare class TextStyle {
|
|
|
30
38
|
private _padding;
|
|
31
39
|
private _dirty;
|
|
32
40
|
constructor(options?: TextStyleOptions);
|
|
33
|
-
get align():
|
|
34
|
-
set align(align:
|
|
41
|
+
get align(): TextAlignment;
|
|
42
|
+
set align(align: TextAlignment);
|
|
35
43
|
get fill(): TextStyleColor;
|
|
36
44
|
set fill(fill: TextStyleColor);
|
|
45
|
+
/**
|
|
46
|
+
* Runtime fill color applied via `Mesh.tint`. Glyphs are always
|
|
47
|
+
* rasterized white; this color multiplies them at draw time so that
|
|
48
|
+
* changing the color never requires re-rasterizing cached glyphs.
|
|
49
|
+
*/
|
|
50
|
+
get fillColor(): Color;
|
|
51
|
+
set fillColor(color: Color);
|
|
52
|
+
/**
|
|
53
|
+
* Line-height multiplier applied to `fontSize` when computing vertical
|
|
54
|
+
* spacing between lines. Defaults to 1.2.
|
|
55
|
+
*/
|
|
56
|
+
get lineHeight(): number;
|
|
57
|
+
set lineHeight(lineHeight: number);
|
|
37
58
|
get stroke(): TextStyleColor;
|
|
38
59
|
set stroke(stroke: TextStyleColor);
|
|
39
60
|
get strokeThickness(): number;
|
|
@@ -44,6 +65,8 @@ export declare class TextStyle {
|
|
|
44
65
|
set fontWeight(fontWeight: string);
|
|
45
66
|
get fontFamily(): string;
|
|
46
67
|
set fontFamily(fontFamily: string);
|
|
68
|
+
get fontStyle(): 'normal' | 'italic';
|
|
69
|
+
set fontStyle(fontStyle: 'normal' | 'italic');
|
|
47
70
|
get wordWrap(): boolean;
|
|
48
71
|
set wordWrap(wordWrap: boolean);
|
|
49
72
|
get wordWrapWidth(): number;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { Color } from '../../core/Color.js';
|
|
2
|
+
|
|
1
3
|
class TextStyle {
|
|
2
4
|
_align;
|
|
3
5
|
_fill;
|
|
6
|
+
_fillColor;
|
|
7
|
+
_lineHeight;
|
|
4
8
|
_stroke;
|
|
5
9
|
_strokeThickness;
|
|
6
10
|
_fontSize;
|
|
7
11
|
_fontWeight;
|
|
8
12
|
_fontFamily;
|
|
13
|
+
_fontStyle;
|
|
9
14
|
_wordWrap;
|
|
10
15
|
_wordWrapWidth;
|
|
11
16
|
_baseline;
|
|
@@ -16,11 +21,14 @@ class TextStyle {
|
|
|
16
21
|
constructor(options = {}) {
|
|
17
22
|
this._align = options.align ?? 'left';
|
|
18
23
|
this._fill = options.fill ?? 'black';
|
|
24
|
+
this._fillColor = options.fillColor ?? Color.white.clone();
|
|
25
|
+
this._lineHeight = options.lineHeight ?? 1.2;
|
|
19
26
|
this._stroke = options.stroke ?? 'black';
|
|
20
27
|
this._strokeThickness = options.strokeThickness ?? 1;
|
|
21
28
|
this._fontSize = options.fontSize ?? 20;
|
|
22
29
|
this._fontWeight = options.fontWeight ?? 'bold';
|
|
23
30
|
this._fontFamily = options.fontFamily ?? 'Arial';
|
|
31
|
+
this._fontStyle = options.fontStyle ?? 'normal';
|
|
24
32
|
this._wordWrap = options.wordWrap ?? false;
|
|
25
33
|
this._wordWrapWidth = options.wordWrapWidth ?? 100;
|
|
26
34
|
this._baseline = options.baseline ?? 'alphabetic';
|
|
@@ -46,6 +54,31 @@ class TextStyle {
|
|
|
46
54
|
this._dirty = true;
|
|
47
55
|
}
|
|
48
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Runtime fill color applied via `Mesh.tint`. Glyphs are always
|
|
59
|
+
* rasterized white; this color multiplies them at draw time so that
|
|
60
|
+
* changing the color never requires re-rasterizing cached glyphs.
|
|
61
|
+
*/
|
|
62
|
+
get fillColor() {
|
|
63
|
+
return this._fillColor;
|
|
64
|
+
}
|
|
65
|
+
set fillColor(color) {
|
|
66
|
+
this._fillColor = color;
|
|
67
|
+
this._dirty = true;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Line-height multiplier applied to `fontSize` when computing vertical
|
|
71
|
+
* spacing between lines. Defaults to 1.2.
|
|
72
|
+
*/
|
|
73
|
+
get lineHeight() {
|
|
74
|
+
return this._lineHeight;
|
|
75
|
+
}
|
|
76
|
+
set lineHeight(lineHeight) {
|
|
77
|
+
if (this._lineHeight !== lineHeight) {
|
|
78
|
+
this._lineHeight = lineHeight;
|
|
79
|
+
this._dirty = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
49
82
|
get stroke() {
|
|
50
83
|
return this._stroke;
|
|
51
84
|
}
|
|
@@ -91,6 +124,15 @@ class TextStyle {
|
|
|
91
124
|
this._dirty = true;
|
|
92
125
|
}
|
|
93
126
|
}
|
|
127
|
+
get fontStyle() {
|
|
128
|
+
return this._fontStyle;
|
|
129
|
+
}
|
|
130
|
+
set fontStyle(fontStyle) {
|
|
131
|
+
if (this._fontStyle !== fontStyle) {
|
|
132
|
+
this._fontStyle = fontStyle;
|
|
133
|
+
this._dirty = true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
94
136
|
get wordWrap() {
|
|
95
137
|
return this._wordWrap;
|
|
96
138
|
}
|
|
@@ -168,11 +210,14 @@ class TextStyle {
|
|
|
168
210
|
if (style !== this) {
|
|
169
211
|
this.align = style.align;
|
|
170
212
|
this.fill = style.fill;
|
|
213
|
+
this._fillColor = style.fillColor.clone();
|
|
214
|
+
this.lineHeight = style.lineHeight;
|
|
171
215
|
this.stroke = style.stroke;
|
|
172
216
|
this.strokeThickness = style.strokeThickness;
|
|
173
217
|
this.fontSize = style.fontSize;
|
|
174
218
|
this.fontWeight = style.fontWeight;
|
|
175
219
|
this.fontFamily = style.fontFamily;
|
|
220
|
+
this.fontStyle = style.fontStyle;
|
|
176
221
|
this.wordWrap = style.wordWrap;
|
|
177
222
|
this.wordWrapWidth = style.wordWrapWidth;
|
|
178
223
|
this.baseline = style.baseline;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextStyle.js","sources":["../../../../../src/rendering/text/TextStyle.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TextStyle.js","sources":["../../../../../src/rendering/text/TextStyle.ts"],"sourcesContent":[null],"names":[],"mappings":";;MAwBa,SAAS,CAAA;AACV,IAAA,MAAM;AACN,IAAA,KAAK;AACL,IAAA,UAAU;AACV,IAAA,WAAW;AACX,IAAA,OAAO;AACP,IAAA,gBAAgB;AAChB,IAAA,SAAS;AACT,IAAA,WAAW;AACX,IAAA,WAAW;AACX,IAAA,UAAU;AACV,IAAA,SAAS;AACT,IAAA,cAAc;AACd,IAAA,SAAS;AACT,IAAA,SAAS;AACT,IAAA,WAAW;AACX,IAAA,QAAQ;IACR,MAAM,GAAG,IAAI;AAErB,IAAA,WAAA,CAAmB,UAA4B,EAAE,EAAA;QAC7C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM;QACrC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,IAAI,OAA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eAAe;AAC5C,YAAA,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ;AAC9B,YAAA,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU;AAClC,YAAA,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU;AAClC,YAAA,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS;AAChC,YAAA,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ;AAC9B,YAAA,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa;AACxC,YAAA,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ;AAC9B,YAAA,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ;AAC9B,YAAA,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU;AAClC,YAAA,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO;AAC5B,YAAA,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK;QAC5B;AAEA,QAAA,OAAO,IAAI;IACf;IAEO,KAAK,GAAA;QACR,OAAO,IAAI,SAAS,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;IACrC;AACH;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DynamicGlyphAtlas } from './DynamicGlyphAtlas';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the shared process-wide glyph atlas, creating it lazily on first
|
|
4
|
+
* call. All `Text` instances share this atlas so that identical glyph shapes
|
|
5
|
+
* (same char + family + size + weight + style) are rasterized only once.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getDefaultGlyphAtlas(): DynamicGlyphAtlas;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DynamicGlyphAtlas } from './DynamicGlyphAtlas.js';
|
|
2
|
+
|
|
3
|
+
let _defaultAtlas = null;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the shared process-wide glyph atlas, creating it lazily on first
|
|
6
|
+
* call. All `Text` instances share this atlas so that identical glyph shapes
|
|
7
|
+
* (same char + family + size + weight + style) are rasterized only once.
|
|
8
|
+
*/
|
|
9
|
+
function getDefaultGlyphAtlas() {
|
|
10
|
+
if (_defaultAtlas === null) {
|
|
11
|
+
_defaultAtlas = new DynamicGlyphAtlas();
|
|
12
|
+
}
|
|
13
|
+
return _defaultAtlas;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { getDefaultGlyphAtlas };
|
|
17
|
+
//# sourceMappingURL=atlas-singleton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atlas-singleton.js","sources":["../../../../../src/rendering/text/atlas-singleton.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA,IAAI,aAAa,GAA6B,IAAI;AAElD;;;;AAIG;SACa,oBAAoB,GAAA;AAChC,IAAA,IAAI,aAAa,KAAK,IAAI,EAAE;AACxB,QAAA,aAAa,GAAG,IAAI,iBAAiB,EAAE;IAC3C;AAEA,IAAA,OAAO,aAAa;AACxB;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type TextAlignment = 'left' | 'center' | 'right';
|
|
2
|
+
/**
|
|
3
|
+
* A key that uniquely identifies a glyph in the atlas cache.
|
|
4
|
+
* Format: `${char}:${family}:${size}:${weight}:${style}`
|
|
5
|
+
*/
|
|
6
|
+
export type GlyphKey = string;
|
|
7
|
+
/**
|
|
8
|
+
* Cached glyph data stored in the atlas after rasterization.
|
|
9
|
+
*/
|
|
10
|
+
export interface GlyphInfo {
|
|
11
|
+
/** Atlas X position (pixels, top-left of padded slot). */
|
|
12
|
+
readonly x: number;
|
|
13
|
+
/** Atlas Y position (pixels, top-left of padded slot). */
|
|
14
|
+
readonly y: number;
|
|
15
|
+
/** Glyph render width in pixels (excluding padding). */
|
|
16
|
+
readonly width: number;
|
|
17
|
+
/** Glyph render height in pixels (excluding padding). */
|
|
18
|
+
readonly height: number;
|
|
19
|
+
/** Horizontal advance in pixels (how far to move the cursor). */
|
|
20
|
+
readonly advance: number;
|
|
21
|
+
/** Distance from baseline to top of glyph in pixels. */
|
|
22
|
+
readonly ascent: number;
|
|
23
|
+
/** UV left edge (0..1, including padding). */
|
|
24
|
+
readonly uvLeft: number;
|
|
25
|
+
/** UV top edge (0..1, including padding). */
|
|
26
|
+
readonly uvTop: number;
|
|
27
|
+
/** UV right edge (0..1, including padding). */
|
|
28
|
+
readonly uvRight: number;
|
|
29
|
+
/** UV bottom edge (0..1, including padding). */
|
|
30
|
+
readonly uvBottom: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A single glyph's quad placement in local text space.
|
|
34
|
+
* Origin is the top-left of the first line.
|
|
35
|
+
*/
|
|
36
|
+
export interface GlyphPlacement {
|
|
37
|
+
readonly x: number;
|
|
38
|
+
readonly y: number;
|
|
39
|
+
readonly width: number;
|
|
40
|
+
readonly height: number;
|
|
41
|
+
readonly uvLeft: number;
|
|
42
|
+
readonly uvTop: number;
|
|
43
|
+
readonly uvRight: number;
|
|
44
|
+
readonly uvBottom: number;
|
|
45
|
+
}
|
|
@@ -21,19 +21,6 @@ const createCanvas = (options = {}) => {
|
|
|
21
21
|
context.fillRect(0, 0, newCanvas.width, newCanvas.height);
|
|
22
22
|
return newCanvas;
|
|
23
23
|
};
|
|
24
|
-
const heightCache = new Map();
|
|
25
|
-
const determineFontHeight = (font) => {
|
|
26
|
-
if (!heightCache.has(font)) {
|
|
27
|
-
const body = document.body;
|
|
28
|
-
const dummy = document.createElement('div');
|
|
29
|
-
dummy.appendChild(document.createTextNode('M'));
|
|
30
|
-
dummy.setAttribute('style', `font: ${font};position:absolute;top:0;left:0`);
|
|
31
|
-
body.appendChild(dummy);
|
|
32
|
-
heightCache.set(font, dummy.offsetHeight);
|
|
33
|
-
body.removeChild(dummy);
|
|
34
|
-
}
|
|
35
|
-
return heightCache.get(font);
|
|
36
|
-
};
|
|
37
24
|
|
|
38
|
-
export { createCanvas, createQuadIndices
|
|
25
|
+
export { createCanvas, createQuadIndices };
|
|
39
26
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/rendering/utils.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,iBAAiB,GAAG,CAAC,IAAY,KAAiB;IAC3D,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC,CAAC;AACtC,IAAA,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM;IAEvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,EAAE;AACtD,QAAA,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM;QAChB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC;QACxB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC;AACxB,QAAA,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM;QACpB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC;QACxB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC;IAC5B;AAEA,IAAA,OAAO,IAAI;AACf;MASa,YAAY,GAAG,CAAC,OAAA,GAA+B,EAAE,KAAuB;IACjF,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO;IAEpD,MAAM,SAAS,GAAG,MAAM,IAAI,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;IAC5D,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,IAAI,CAA6B;AAEtE,IAAA,SAAS,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE;AAC7B,IAAA,SAAS,CAAC,MAAM,GAAG,MAAM,IAAI,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