laymur 0.21.0 → 0.22.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/dist/core/elements/UIScene/UIScene.js +8 -1
- package/dist/core/elements/UIText/UIText.Bidi.d.ts +25 -0
- package/dist/core/elements/UIText/UIText.Bidi.js +133 -0
- package/dist/core/elements/UIText/UIText.Interfaces.d.ts +2 -0
- package/dist/core/elements/UIText/UIText.Internal.d.ts +12 -0
- package/dist/core/elements/UIText/UIText.Internal.js +12 -1
- package/dist/core/elements/UIText/UIText.Measuring.d.ts +10 -1
- package/dist/core/elements/UIText/UIText.Measuring.js +60 -43
- package/dist/core/elements/UIText/UIText.Rendering.d.ts +3 -1
- package/dist/core/elements/UIText/UIText.Rendering.js +30 -5
- package/dist/core/elements/UIText/UIText.d.ts +8 -2
- package/dist/core/elements/UIText/UIText.js +39 -14
- package/dist/core/index.d.ts +1 -1
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +4 -2
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.js +1 -1
- package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +3 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MathUtils, WebGLRenderTarget, UnsignedByteType, LinearFilter, RGBAFormat, Matrix3, Scene, PerspectiveCamera } from 'three';
|
|
1
|
+
import { Color, MathUtils, WebGLRenderTarget, UnsignedByteType, LinearFilter, RGBAFormat, Matrix3, Scene, PerspectiveCamera } from 'three';
|
|
2
2
|
import { assertValidPositiveNumber } from '../../miscellaneous/asserts.js';
|
|
3
3
|
import { UIColor } from '../../miscellaneous/color/UIColor.js';
|
|
4
4
|
import source from '../../shaders/UIImage.glsl.js';
|
|
@@ -6,6 +6,8 @@ import { DUMMY_DEFAULT_WIDTH, DUMMY_DEFAULT_HEIGHT } from '../UIDummy/UIDummy.In
|
|
|
6
6
|
import { UIElement } from '../UIElement/UIElement.js';
|
|
7
7
|
import { SCENE_DEFAULT_RESOLUTION_FACTOR, SCENE_MIN_RESOLUTION_FACTOR, SCENE_MAX_RESOLUTION_FACTOR, SCENE_DEFAULT_USE_DEPTH, SCENE_DEFAULT_CLEAR_COLOR, SCENE_DEFAULT_CAMERA_FOV, SCENE_DEFAULT_CAMERA_NEAR, SCENE_DEFAULT_CAMERA_FAR, SCENE_DEFAULT_UPDATE_MODE, UISceneUpdateMode } from './UIScene.Internal.js';
|
|
8
8
|
|
|
9
|
+
let previousClearColor = new Color();
|
|
10
|
+
let previousClearAlpha = 0;
|
|
9
11
|
/** Renders Three.js scene to texture */
|
|
10
12
|
class UIScene extends UIElement {
|
|
11
13
|
/**
|
|
@@ -143,10 +145,15 @@ class UIScene extends UIElement {
|
|
|
143
145
|
});
|
|
144
146
|
this._private_colorInternal.setDirtyFalse();
|
|
145
147
|
}
|
|
148
|
+
const previousRenderTarget = renderer.getRenderTarget();
|
|
149
|
+
previousClearColor = renderer.getClearColor(previousClearColor);
|
|
150
|
+
previousClearAlpha = renderer.getClearAlpha();
|
|
146
151
|
renderer.setClearColor(this._private_clearColorInternal.getHexRGB(), this._private_clearColorInternal.a);
|
|
147
152
|
renderer.setRenderTarget(this._private_renderTarget);
|
|
148
153
|
renderer.clear(true, true, false);
|
|
149
154
|
renderer.render(this._private_sceneInternal, this._private_cameraInternal);
|
|
155
|
+
renderer.setRenderTarget(previousRenderTarget);
|
|
156
|
+
renderer.setClearColor(previousClearColor, previousClearAlpha);
|
|
150
157
|
this._private_propertyDirty = false;
|
|
151
158
|
this._private_updateRequired = false;
|
|
152
159
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { UITextSpan } from "../../miscellaneous/text-span/UITextSpan";
|
|
2
|
+
import type { UITextChunk } from "./UIText.Interfaces";
|
|
3
|
+
/**
|
|
4
|
+
* Detects the directional class used to order a chunk among its neighbours.
|
|
5
|
+
* Digit only chunks are ordered left to right in both paragraph directions.
|
|
6
|
+
* @param text Chunk text
|
|
7
|
+
* @returns Directional class of the chunk
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectBidiClass(text: string): number;
|
|
10
|
+
/**
|
|
11
|
+
* Detects the paragraph direction of the content.
|
|
12
|
+
* Implements a simplified UAX#9 P2/P3: the first strong character of the content wins.
|
|
13
|
+
* @param textSpans Text spans in logical order
|
|
14
|
+
* @returns Whether the paragraph reads right to left
|
|
15
|
+
*/
|
|
16
|
+
export declare function detectIsRTL(textSpans: UITextSpan[]): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Reorders chunks from logical order into visual left to right order.
|
|
19
|
+
* Implements UAX#9 L2 at chunk granularity with simplified neutral resolution (N1/N2).
|
|
20
|
+
* Shaping and bidi inside a single chunk are handled by the canvas itself.
|
|
21
|
+
* @param textChunks Chunks of a single line in logical order
|
|
22
|
+
* @param isRTL Whether the paragraph reads right to left
|
|
23
|
+
* @returns Chunks in visual order, or the same array when reordering is not needed
|
|
24
|
+
*/
|
|
25
|
+
export declare function reorderChunksVisually(textChunks: UITextChunk[], isRTL: boolean): UITextChunk[];
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/** No strong directional character */
|
|
2
|
+
const BIDI_NEUTRAL = 0;
|
|
3
|
+
/** Resolves to left to right */
|
|
4
|
+
const BIDI_LTR = 1;
|
|
5
|
+
/** Resolves to right to left */
|
|
6
|
+
const BIDI_RTL = 2;
|
|
7
|
+
/** Hebrew, Arabic, Syriac, Thaana, NKo, Arabic Extended and presentation forms */
|
|
8
|
+
const RTL_PATTERN = /[\u0591-\u07FF\u0860-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/;
|
|
9
|
+
/** Latin, Greek, Cyrillic, Armenian, Indic, South East Asian, CJK, Hangul */
|
|
10
|
+
const LTR_PATTERN = /[A-Za-z\u00C0-\u058F\u0900-\u1FFF\u2C00-\uD7FF]/;
|
|
11
|
+
/** European digits, laid out left to right inside any paragraph */
|
|
12
|
+
const NUMBER_PATTERN = /[0-9]/;
|
|
13
|
+
/**
|
|
14
|
+
* Detects the strong directional class of a text.
|
|
15
|
+
* Implements a simplified UAX#9 P2: the first strong character wins.
|
|
16
|
+
* @param text Text to inspect
|
|
17
|
+
* @returns Directional class, neutral when no strong character is present
|
|
18
|
+
*/
|
|
19
|
+
function detectStrongClass(text) {
|
|
20
|
+
const rtlMatch = RTL_PATTERN.exec(text);
|
|
21
|
+
const ltrMatch = LTR_PATTERN.exec(text);
|
|
22
|
+
if (rtlMatch === null) {
|
|
23
|
+
return ltrMatch === null ? BIDI_NEUTRAL : BIDI_LTR;
|
|
24
|
+
}
|
|
25
|
+
if (ltrMatch === null) {
|
|
26
|
+
return BIDI_RTL;
|
|
27
|
+
}
|
|
28
|
+
return rtlMatch.index < ltrMatch.index ? BIDI_RTL : BIDI_LTR;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Finds the directional class of the closest non neutral chunk.
|
|
32
|
+
* @param textChunks Chunks of a single line
|
|
33
|
+
* @param index Index to start from
|
|
34
|
+
* @param step Search direction
|
|
35
|
+
* @param fallback Class returned when no strong chunk is found
|
|
36
|
+
* @returns Directional class of the closest strong chunk
|
|
37
|
+
*/
|
|
38
|
+
function findStrongNeighbourClass(textChunks, index, step, fallback) {
|
|
39
|
+
for (let i = index; i >= 0 && i < textChunks.length; i += step) {
|
|
40
|
+
if (textChunks[i].bidiClass !== BIDI_NEUTRAL) {
|
|
41
|
+
return textChunks[i].bidiClass;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return fallback;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Reverses a closed range of chunks in place.
|
|
48
|
+
* @param textChunks Chunks to modify
|
|
49
|
+
* @param from First index of the range
|
|
50
|
+
* @param to Last index of the range
|
|
51
|
+
*/
|
|
52
|
+
function reverseChunkRange(textChunks, from, to) {
|
|
53
|
+
while (from < to) {
|
|
54
|
+
const buffer = textChunks[from];
|
|
55
|
+
textChunks[from] = textChunks[to];
|
|
56
|
+
textChunks[to] = buffer;
|
|
57
|
+
from++;
|
|
58
|
+
to--;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Detects the directional class used to order a chunk among its neighbours.
|
|
63
|
+
* Digit only chunks are ordered left to right in both paragraph directions.
|
|
64
|
+
* @param text Chunk text
|
|
65
|
+
* @returns Directional class of the chunk
|
|
66
|
+
*/
|
|
67
|
+
function detectBidiClass(text) {
|
|
68
|
+
const strongClass = detectStrongClass(text);
|
|
69
|
+
if (strongClass !== BIDI_NEUTRAL) {
|
|
70
|
+
return strongClass;
|
|
71
|
+
}
|
|
72
|
+
return NUMBER_PATTERN.test(text) ? BIDI_LTR : BIDI_NEUTRAL;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Detects the paragraph direction of the content.
|
|
76
|
+
* Implements a simplified UAX#9 P2/P3: the first strong character of the content wins.
|
|
77
|
+
* @param textSpans Text spans in logical order
|
|
78
|
+
* @returns Whether the paragraph reads right to left
|
|
79
|
+
*/
|
|
80
|
+
function detectIsRTL(textSpans) {
|
|
81
|
+
for (const textSpan of textSpans) {
|
|
82
|
+
const strongClass = detectStrongClass(textSpan.text);
|
|
83
|
+
if (strongClass !== BIDI_NEUTRAL) {
|
|
84
|
+
return strongClass === BIDI_RTL;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Reorders chunks from logical order into visual left to right order.
|
|
91
|
+
* Implements UAX#9 L2 at chunk granularity with simplified neutral resolution (N1/N2).
|
|
92
|
+
* Shaping and bidi inside a single chunk are handled by the canvas itself.
|
|
93
|
+
* @param textChunks Chunks of a single line in logical order
|
|
94
|
+
* @param isRTL Whether the paragraph reads right to left
|
|
95
|
+
* @returns Chunks in visual order, or the same array when reordering is not needed
|
|
96
|
+
*/
|
|
97
|
+
function reorderChunksVisually(textChunks, isRTL) {
|
|
98
|
+
if (!isRTL && !textChunks.some((textChunk) => textChunk.bidiClass === BIDI_RTL)) {
|
|
99
|
+
return textChunks;
|
|
100
|
+
}
|
|
101
|
+
const baseClass = isRTL ? BIDI_RTL : BIDI_LTR;
|
|
102
|
+
const levels = [];
|
|
103
|
+
let maxLevel = 0;
|
|
104
|
+
for (let i = 0; i < textChunks.length; i++) {
|
|
105
|
+
let bidiClass = textChunks[i].bidiClass;
|
|
106
|
+
if (bidiClass === BIDI_NEUTRAL) {
|
|
107
|
+
const beforeClass = findStrongNeighbourClass(textChunks, i - 1, -1, baseClass);
|
|
108
|
+
const afterClass = findStrongNeighbourClass(textChunks, i + 1, 1, baseClass);
|
|
109
|
+
bidiClass = beforeClass === afterClass ? beforeClass : baseClass;
|
|
110
|
+
}
|
|
111
|
+
const level = bidiClass === BIDI_RTL ? 1 : isRTL ? 2 : 0;
|
|
112
|
+
levels.push(level);
|
|
113
|
+
maxLevel = Math.max(maxLevel, level);
|
|
114
|
+
}
|
|
115
|
+
const result = textChunks.slice();
|
|
116
|
+
for (let level = maxLevel; level >= 1; level--) {
|
|
117
|
+
let start = -1;
|
|
118
|
+
for (let i = 0; i <= levels.length; i++) {
|
|
119
|
+
if (i < levels.length && levels[i] >= level) {
|
|
120
|
+
if (start === -1) {
|
|
121
|
+
start = i;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else if (start !== -1) {
|
|
125
|
+
reverseChunkRange(result, start, i - 1);
|
|
126
|
+
start = -1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export { detectBidiClass, detectIsRTL, reorderChunksVisually };
|
|
@@ -24,6 +24,8 @@ export interface UITextChunk {
|
|
|
24
24
|
style: UITextStyleConfig;
|
|
25
25
|
/** Chunk metrics */
|
|
26
26
|
metrics: UIChunkMetrics;
|
|
27
|
+
/** Resolved bidirectional class used for visual reordering */
|
|
28
|
+
bidiClass: number;
|
|
27
29
|
}
|
|
28
30
|
/** Line of text chunks */
|
|
29
31
|
export interface UITextLine extends UIChunkMetrics {
|
|
@@ -2,6 +2,15 @@ import type { UIColorConfig } from "../../miscellaneous/color/UIColor.Internal";
|
|
|
2
2
|
import type { UIInsetsConfig } from "../../miscellaneous/insets/UIInsets.Internal";
|
|
3
3
|
import type { UITextStyleConfig } from "../../miscellaneous/text-style/UITextStyle.Internal";
|
|
4
4
|
import type { UIElementOptions } from "../UIElement/UIElement.Internal";
|
|
5
|
+
/** Base direction used for bidirectional text reordering */
|
|
6
|
+
export declare enum UITextDirection {
|
|
7
|
+
/** Detect from the first strong directional character of the content */
|
|
8
|
+
AUTO = 0,
|
|
9
|
+
/** Force left to right */
|
|
10
|
+
LTR = 1,
|
|
11
|
+
/** Force right to left */
|
|
12
|
+
RTL = 2
|
|
13
|
+
}
|
|
5
14
|
/** Controls how text adapts to element size */
|
|
6
15
|
export declare enum UITextResizeMode {
|
|
7
16
|
/** Break text into multiple lines when narrower than content*/
|
|
@@ -21,6 +30,9 @@ export interface UITextOptions extends UIElementOptions {
|
|
|
21
30
|
resizeMode: UITextResizeMode;
|
|
22
31
|
/** Maximum line width before wrapping in pixels */
|
|
23
32
|
maxLineWidth: number;
|
|
33
|
+
/** Base direction used for bidirectional text reordering */
|
|
34
|
+
direction: UITextDirection;
|
|
24
35
|
}
|
|
25
36
|
export declare const TEXT_DEFAULT_MAX_LINE_WIDTH = 1024;
|
|
26
37
|
export declare const TEXT_DEFAULT_RESIZE_MODE = UITextResizeMode.SCALE;
|
|
38
|
+
export declare const TEXT_DEFAULT_DIRECTION = UITextDirection.AUTO;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/** Base direction used for bidirectional text reordering */
|
|
2
|
+
var UITextDirection;
|
|
3
|
+
(function (UITextDirection) {
|
|
4
|
+
/** Detect from the first strong directional character of the content */
|
|
5
|
+
UITextDirection[UITextDirection["AUTO"] = 0] = "AUTO";
|
|
6
|
+
/** Force left to right */
|
|
7
|
+
UITextDirection[UITextDirection["LTR"] = 1] = "LTR";
|
|
8
|
+
/** Force right to left */
|
|
9
|
+
UITextDirection[UITextDirection["RTL"] = 2] = "RTL";
|
|
10
|
+
})(UITextDirection || (UITextDirection = {}));
|
|
1
11
|
/** Controls how text adapts to element size */
|
|
2
12
|
var UITextResizeMode;
|
|
3
13
|
(function (UITextResizeMode) {
|
|
@@ -8,5 +18,6 @@ var UITextResizeMode;
|
|
|
8
18
|
})(UITextResizeMode || (UITextResizeMode = {}));
|
|
9
19
|
const TEXT_DEFAULT_MAX_LINE_WIDTH = 1024;
|
|
10
20
|
const TEXT_DEFAULT_RESIZE_MODE = UITextResizeMode.SCALE;
|
|
21
|
+
const TEXT_DEFAULT_DIRECTION = UITextDirection.AUTO;
|
|
11
22
|
|
|
12
|
-
export { TEXT_DEFAULT_MAX_LINE_WIDTH, TEXT_DEFAULT_RESIZE_MODE, UITextResizeMode };
|
|
23
|
+
export { TEXT_DEFAULT_DIRECTION, TEXT_DEFAULT_MAX_LINE_WIDTH, TEXT_DEFAULT_RESIZE_MODE, UITextDirection, UITextResizeMode };
|
|
@@ -3,6 +3,13 @@ import type { UITextSpan } from "../../miscellaneous/text-span/UITextSpan";
|
|
|
3
3
|
import { UITextStyle } from "../../miscellaneous/text-style/UITextStyle";
|
|
4
4
|
import type { UITextStyleConfig } from "../../miscellaneous/text-style/UITextStyle.Internal";
|
|
5
5
|
import type { UIChunkMetrics, UITextChunk, UITextLine, UITextSize } from "./UIText.Interfaces";
|
|
6
|
+
/**
|
|
7
|
+
* Applies font of a resolved style to a canvas context.
|
|
8
|
+
* Shared by measuring and rendering so both stay in sync.
|
|
9
|
+
* @param context Canvas context to configure
|
|
10
|
+
* @param textStyle Resolved text style
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyFontStyle(context: UICanvasRenderingContext2D, textStyle: UITextStyleConfig): void;
|
|
6
13
|
/**
|
|
7
14
|
* Splits text into renderable chunks.
|
|
8
15
|
* @param text Text to split
|
|
@@ -26,6 +33,7 @@ export declare function measureTextChunk(context: UICanvasRenderingContext2D, te
|
|
|
26
33
|
export declare function buildTextLines(maxWidth: number, textChunks: UITextChunk[]): UITextLine[];
|
|
27
34
|
/**
|
|
28
35
|
* Calculates total text size from lines.
|
|
36
|
+
* The box spans from the ascent of the first line to the descent of the last one.
|
|
29
37
|
* @param lines Text lines
|
|
30
38
|
* @returns Total width and height
|
|
31
39
|
*/
|
|
@@ -35,9 +43,10 @@ export declare function calculateTextSize(lines: UITextLine[]): UITextSize;
|
|
|
35
43
|
* @param context Canvas context for measurement
|
|
36
44
|
* @param textSpans Text spans with styles
|
|
37
45
|
* @param commonStyle Fallback style
|
|
46
|
+
* @param isRTL Whether the paragraph reads right to left
|
|
38
47
|
* @returns Measured text chunks
|
|
39
48
|
*/
|
|
40
|
-
export declare function buildTextChunks(context: UICanvasRenderingContext2D, textSpans: UITextSpan[], commonStyle: UITextStyle): UITextChunk[];
|
|
49
|
+
export declare function buildTextChunks(context: UICanvasRenderingContext2D, textSpans: UITextSpan[], commonStyle: UITextStyle, isRTL: boolean): UITextChunk[];
|
|
41
50
|
/**
|
|
42
51
|
* Calculates text layout parameters.
|
|
43
52
|
* @param textChunks Measured text chunks
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { UITextStyle } from '../../miscellaneous/text-style/UITextStyle.js';
|
|
2
|
+
import { detectBidiClass } from './UIText.Bidi.js';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Applies font of a resolved style to a canvas context.
|
|
6
|
+
* Shared by measuring and rendering so both stay in sync.
|
|
7
|
+
* @param context Canvas context to configure
|
|
8
|
+
* @param textStyle Resolved text style
|
|
9
|
+
*/
|
|
10
|
+
function applyFontStyle(context, textStyle) {
|
|
11
|
+
context.font = `${textStyle.fontStyle} ${textStyle.fontWeight} ${textStyle.fontSize}px "${textStyle.fontFamily}"`;
|
|
12
|
+
}
|
|
3
13
|
/**
|
|
4
14
|
* Splits text into renderable chunks.
|
|
5
15
|
* @param text Text to split
|
|
@@ -16,25 +26,44 @@ function splitTextIntoChunks(text) {
|
|
|
16
26
|
* @returns Chunk metrics
|
|
17
27
|
*/
|
|
18
28
|
function measureTextChunk(context, text, textStyle) {
|
|
19
|
-
context
|
|
29
|
+
applyFontStyle(context, textStyle);
|
|
20
30
|
if (text === "\n") {
|
|
21
31
|
return {
|
|
22
|
-
width:
|
|
32
|
+
width: 1,
|
|
23
33
|
height: textStyle.lineHeight,
|
|
24
34
|
baseline: 0,
|
|
25
35
|
lineHeight: textStyle.lineHeight,
|
|
26
36
|
};
|
|
27
37
|
}
|
|
28
38
|
const metrics = context.measureText(text);
|
|
29
|
-
const
|
|
30
|
-
const
|
|
39
|
+
const ascent = Math.ceil(metrics.actualBoundingBoxAscent);
|
|
40
|
+
const descent = Math.ceil(metrics.actualBoundingBoxDescent);
|
|
31
41
|
return {
|
|
32
|
-
width,
|
|
33
|
-
height,
|
|
34
|
-
baseline:
|
|
42
|
+
width: Math.ceil(metrics.width),
|
|
43
|
+
height: ascent + descent,
|
|
44
|
+
baseline: ascent,
|
|
35
45
|
lineHeight: textStyle.lineHeight,
|
|
36
46
|
};
|
|
37
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Appends a line built from accumulated metrics.
|
|
50
|
+
* Ascent and descent are separate because the tallest and deepest chunks may differ.
|
|
51
|
+
* @param lines Lines to append to
|
|
52
|
+
* @param chunks Chunks of the line
|
|
53
|
+
* @param width Line width in pixels
|
|
54
|
+
* @param ascent Maximum chunk ascent in pixels
|
|
55
|
+
* @param descent Maximum chunk descent in pixels
|
|
56
|
+
* @param lineHeight Maximum chunk line height in pixels
|
|
57
|
+
*/
|
|
58
|
+
function pushTextLine(lines, chunks, width, ascent, descent, lineHeight) {
|
|
59
|
+
lines.push({
|
|
60
|
+
chunks,
|
|
61
|
+
width,
|
|
62
|
+
height: ascent + descent,
|
|
63
|
+
baseline: ascent,
|
|
64
|
+
lineHeight,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
38
67
|
/**
|
|
39
68
|
* Builds text lines with word wrapping.
|
|
40
69
|
* @param maxWidth Maximum line width in pixels
|
|
@@ -45,62 +74,47 @@ function buildTextLines(maxWidth, textChunks) {
|
|
|
45
74
|
const lines = [];
|
|
46
75
|
let currentLine = [];
|
|
47
76
|
let currentWidth = 0;
|
|
48
|
-
let
|
|
49
|
-
let
|
|
77
|
+
let currentAscent = 0;
|
|
78
|
+
let currentDescent = 0;
|
|
50
79
|
let currentLineHeight = 0;
|
|
51
80
|
for (const textChunk of textChunks) {
|
|
81
|
+
const ascent = textChunk.metrics.baseline;
|
|
82
|
+
const descent = textChunk.metrics.height - textChunk.metrics.baseline;
|
|
52
83
|
if (textChunk.text === "\n") {
|
|
53
84
|
if (currentLine.length > 0) {
|
|
54
|
-
lines
|
|
55
|
-
chunks: currentLine,
|
|
56
|
-
width: currentWidth,
|
|
57
|
-
height: currentHeight,
|
|
58
|
-
baseline: currentBaseline,
|
|
59
|
-
lineHeight: currentLineHeight,
|
|
60
|
-
});
|
|
85
|
+
pushTextLine(lines, currentLine, currentWidth, currentAscent, currentDescent, currentLineHeight);
|
|
61
86
|
}
|
|
62
87
|
currentLine = [];
|
|
63
88
|
currentWidth = 0;
|
|
64
|
-
|
|
65
|
-
|
|
89
|
+
currentAscent = 0;
|
|
90
|
+
currentDescent = 0;
|
|
66
91
|
currentLineHeight = 0;
|
|
67
92
|
continue;
|
|
68
93
|
}
|
|
69
94
|
if (currentLine.length === 0 || currentWidth + textChunk.metrics.width <= maxWidth) {
|
|
70
95
|
currentLine.push(textChunk);
|
|
71
96
|
currentWidth += textChunk.metrics.width;
|
|
72
|
-
|
|
73
|
-
|
|
97
|
+
currentAscent = Math.max(currentAscent, ascent);
|
|
98
|
+
currentDescent = Math.max(currentDescent, descent);
|
|
74
99
|
currentLineHeight = Math.max(currentLineHeight, textChunk.metrics.lineHeight);
|
|
75
100
|
}
|
|
76
101
|
else {
|
|
77
|
-
lines
|
|
78
|
-
chunks: currentLine,
|
|
79
|
-
width: currentWidth,
|
|
80
|
-
height: currentHeight,
|
|
81
|
-
baseline: currentBaseline,
|
|
82
|
-
lineHeight: currentLineHeight,
|
|
83
|
-
});
|
|
102
|
+
pushTextLine(lines, currentLine, currentWidth, currentAscent, currentDescent, currentLineHeight);
|
|
84
103
|
currentLine = [textChunk];
|
|
85
104
|
currentWidth = textChunk.metrics.width;
|
|
86
|
-
|
|
87
|
-
|
|
105
|
+
currentAscent = ascent;
|
|
106
|
+
currentDescent = descent;
|
|
88
107
|
currentLineHeight = textChunk.metrics.lineHeight;
|
|
89
108
|
}
|
|
90
109
|
}
|
|
91
110
|
if (currentLine.length > 0) {
|
|
92
|
-
lines
|
|
93
|
-
chunks: currentLine,
|
|
94
|
-
width: currentWidth,
|
|
95
|
-
height: currentHeight,
|
|
96
|
-
baseline: currentBaseline,
|
|
97
|
-
lineHeight: currentLineHeight,
|
|
98
|
-
});
|
|
111
|
+
pushTextLine(lines, currentLine, currentWidth, currentAscent, currentDescent, currentLineHeight);
|
|
99
112
|
}
|
|
100
113
|
return lines;
|
|
101
114
|
}
|
|
102
115
|
/**
|
|
103
116
|
* Calculates total text size from lines.
|
|
117
|
+
* The box spans from the ascent of the first line to the descent of the last one.
|
|
104
118
|
* @param lines Text lines
|
|
105
119
|
* @returns Total width and height
|
|
106
120
|
*/
|
|
@@ -109,21 +123,23 @@ function calculateTextSize(lines) {
|
|
|
109
123
|
return { width: 0, height: 0 };
|
|
110
124
|
}
|
|
111
125
|
const maxLineWidth = Math.max(...lines.map((line) => line.width));
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
totalHeight += i
|
|
126
|
+
const lastLine = lines[lines.length - 1];
|
|
127
|
+
let totalHeight = lines[0].baseline;
|
|
128
|
+
for (let i = 1; i < lines.length; i++) {
|
|
129
|
+
totalHeight += lines[i].lineHeight;
|
|
116
130
|
}
|
|
117
|
-
return { width: maxLineWidth, height: totalHeight };
|
|
131
|
+
return { width: maxLineWidth, height: totalHeight + lastLine.height - lastLine.baseline };
|
|
118
132
|
}
|
|
119
133
|
/**
|
|
120
134
|
* Builds measured text chunks from spans.
|
|
121
135
|
* @param context Canvas context for measurement
|
|
122
136
|
* @param textSpans Text spans with styles
|
|
123
137
|
* @param commonStyle Fallback style
|
|
138
|
+
* @param isRTL Whether the paragraph reads right to left
|
|
124
139
|
* @returns Measured text chunks
|
|
125
140
|
*/
|
|
126
|
-
function buildTextChunks(context, textSpans, commonStyle) {
|
|
141
|
+
function buildTextChunks(context, textSpans, commonStyle, isRTL) {
|
|
142
|
+
context.direction = isRTL ? "rtl" : "ltr";
|
|
127
143
|
const textChunks = [];
|
|
128
144
|
for (const textSpan of textSpans) {
|
|
129
145
|
const textStyle = UITextStyle.resolve(textSpan.style, commonStyle);
|
|
@@ -133,6 +149,7 @@ function buildTextChunks(context, textSpans, commonStyle) {
|
|
|
133
149
|
text: textChunk,
|
|
134
150
|
style: textStyle,
|
|
135
151
|
metrics: textChunkMetrics,
|
|
152
|
+
bidiClass: detectBidiClass(textChunk),
|
|
136
153
|
});
|
|
137
154
|
}
|
|
138
155
|
}
|
|
@@ -150,4 +167,4 @@ function calculateTextContentParameters(textChunks, maxLineWidth) {
|
|
|
150
167
|
return { lines, size };
|
|
151
168
|
}
|
|
152
169
|
|
|
153
|
-
export { buildTextChunks, buildTextLines, calculateTextContentParameters, calculateTextSize, measureTextChunk, splitTextIntoChunks };
|
|
170
|
+
export { applyFontStyle, buildTextChunks, buildTextLines, calculateTextContentParameters, calculateTextSize, measureTextChunk, splitTextIntoChunks };
|
|
@@ -12,9 +12,11 @@ import type { UITextLine } from "./UIText.Interfaces";
|
|
|
12
12
|
export declare function renderTextChunk(x: number, y: number, text: string, style: UITextStyleConfig, context: UICanvasRenderingContext2D): void;
|
|
13
13
|
/**
|
|
14
14
|
* Renders text lines to canvas.
|
|
15
|
+
* Chunks are laid out left to right after visual reordering, so x stays the left edge.
|
|
15
16
|
* @param paddingTop Top padding in pixels
|
|
16
17
|
* @param paddingLeft Left padding in pixels
|
|
17
18
|
* @param lines Text lines to render
|
|
19
|
+
* @param isRTL Whether the paragraph reads right to left
|
|
18
20
|
* @param context Canvas rendering context
|
|
19
21
|
*/
|
|
20
|
-
export declare function renderTextLines(paddingTop: number, paddingLeft: number, lines: UITextLine[], context: UICanvasRenderingContext2D): void;
|
|
22
|
+
export declare function renderTextLines(paddingTop: number, paddingLeft: number, lines: UITextLine[], isRTL: boolean, context: UICanvasRenderingContext2D): void;
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { TEXT_STYLE_DEFAULT_ALIGN } from '../../miscellaneous/text-style/UITextStyle.Internal.js';
|
|
2
|
+
import { reorderChunksVisually } from './UIText.Bidi.js';
|
|
3
|
+
import { applyFontStyle } from './UIText.Measuring.js';
|
|
2
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Resolves logical alignment into a physical one.
|
|
7
|
+
* @param align Alignment to resolve
|
|
8
|
+
* @param isRTL Whether the paragraph reads right to left
|
|
9
|
+
* @returns Physical alignment
|
|
10
|
+
*/
|
|
11
|
+
function resolveAlign(align, isRTL) {
|
|
12
|
+
if (align === "start") {
|
|
13
|
+
return isRTL ? "right" : "left";
|
|
14
|
+
}
|
|
15
|
+
if (align === "end") {
|
|
16
|
+
return isRTL ? "left" : "right";
|
|
17
|
+
}
|
|
18
|
+
return align;
|
|
19
|
+
}
|
|
3
20
|
/**
|
|
4
21
|
* Renders single text chunk.
|
|
5
22
|
* @param x X coordinate in pixels
|
|
@@ -9,13 +26,16 @@ import { TEXT_STYLE_DEFAULT_ALIGN } from '../../miscellaneous/text-style/UITextS
|
|
|
9
26
|
* @param context Canvas rendering context
|
|
10
27
|
*/
|
|
11
28
|
function renderTextChunk(x, y, text, style, context) {
|
|
12
|
-
context
|
|
29
|
+
applyFontStyle(context, style);
|
|
13
30
|
if (style.enableShadow) {
|
|
14
31
|
context.shadowOffsetX = style.shadowOffsetX;
|
|
15
32
|
context.shadowOffsetY = style.shadowOffsetY;
|
|
16
33
|
context.shadowBlur = style.shadowBlur;
|
|
17
34
|
context.shadowColor = style.shadowColor;
|
|
18
35
|
}
|
|
36
|
+
else {
|
|
37
|
+
context.shadowColor = "transparent";
|
|
38
|
+
}
|
|
19
39
|
if (style.enableStroke) {
|
|
20
40
|
context.strokeStyle = style.strokeColor;
|
|
21
41
|
context.lineWidth = style.strokeThickness;
|
|
@@ -26,12 +46,17 @@ function renderTextChunk(x, y, text, style, context) {
|
|
|
26
46
|
}
|
|
27
47
|
/**
|
|
28
48
|
* Renders text lines to canvas.
|
|
49
|
+
* Chunks are laid out left to right after visual reordering, so x stays the left edge.
|
|
29
50
|
* @param paddingTop Top padding in pixels
|
|
30
51
|
* @param paddingLeft Left padding in pixels
|
|
31
52
|
* @param lines Text lines to render
|
|
53
|
+
* @param isRTL Whether the paragraph reads right to left
|
|
32
54
|
* @param context Canvas rendering context
|
|
33
55
|
*/
|
|
34
|
-
function renderTextLines(paddingTop, paddingLeft, lines, context) {
|
|
56
|
+
function renderTextLines(paddingTop, paddingLeft, lines, isRTL, context) {
|
|
57
|
+
context.clearRect(0, 0, context.canvas.width, context.canvas.height);
|
|
58
|
+
context.direction = isRTL ? "rtl" : "ltr";
|
|
59
|
+
context.textAlign = "left";
|
|
35
60
|
let currentY = paddingTop;
|
|
36
61
|
let textWidth = 0;
|
|
37
62
|
for (const line of lines) {
|
|
@@ -41,7 +66,7 @@ function renderTextLines(paddingTop, paddingLeft, lines, context) {
|
|
|
41
66
|
const line = lines[i];
|
|
42
67
|
const firstAlign = line.chunks[0]?.style.align ?? TEXT_STYLE_DEFAULT_ALIGN;
|
|
43
68
|
const isUniformAlign = line.chunks.every((c) => c.style.align === firstAlign);
|
|
44
|
-
const lineAlign = isUniformAlign ? firstAlign : TEXT_STYLE_DEFAULT_ALIGN;
|
|
69
|
+
const lineAlign = resolveAlign(isUniformAlign ? firstAlign : TEXT_STYLE_DEFAULT_ALIGN, isRTL);
|
|
45
70
|
let offsetX = 0;
|
|
46
71
|
if (lineAlign === "center") {
|
|
47
72
|
offsetX = (textWidth - line.width) / 2;
|
|
@@ -50,8 +75,8 @@ function renderTextLines(paddingTop, paddingLeft, lines, context) {
|
|
|
50
75
|
offsetX = textWidth - line.width;
|
|
51
76
|
}
|
|
52
77
|
let currentX = paddingLeft + offsetX;
|
|
53
|
-
currentY += i === 0 ? line.
|
|
54
|
-
for (const chunk of line.chunks) {
|
|
78
|
+
currentY += i === 0 ? line.baseline : line.lineHeight;
|
|
79
|
+
for (const chunk of reorderChunksVisually(line.chunks, isRTL)) {
|
|
55
80
|
renderTextChunk(currentX, currentY, chunk.text, chunk.style, context);
|
|
56
81
|
currentX += chunk.metrics.width;
|
|
57
82
|
}
|
|
@@ -9,7 +9,7 @@ import { UITextStyle } from "../../miscellaneous/text-style/UITextStyle";
|
|
|
9
9
|
import { UIElement } from "../UIElement/UIElement";
|
|
10
10
|
import type { UITextContent } from "./UIText.Interfaces";
|
|
11
11
|
import type { UITextOptions } from "./UIText.Internal";
|
|
12
|
-
import { UITextResizeMode } from "./UIText.Internal";
|
|
12
|
+
import { UITextDirection, UITextResizeMode } from "./UIText.Internal";
|
|
13
13
|
/** Canvas-based text rendering element */
|
|
14
14
|
export declare class UIText extends UIElement {
|
|
15
15
|
/** Default style applied to all text spans */
|
|
@@ -25,10 +25,12 @@ export declare class UIText extends UIElement {
|
|
|
25
25
|
private maxLineWidthDirty;
|
|
26
26
|
private resizeModeInternal;
|
|
27
27
|
private resizeModeDirty;
|
|
28
|
+
private directionInternal;
|
|
29
|
+
private directionDirty;
|
|
30
|
+
private isRTL;
|
|
28
31
|
private lastWidth;
|
|
29
32
|
private lastHeight;
|
|
30
33
|
private textChunks;
|
|
31
|
-
private textChunksDirty;
|
|
32
34
|
/**
|
|
33
35
|
* Creates a new UIText instance.
|
|
34
36
|
*
|
|
@@ -47,6 +49,8 @@ export declare class UIText extends UIElement {
|
|
|
47
49
|
get padding(): UIInsets;
|
|
48
50
|
/** Controls how text adapts to element size */
|
|
49
51
|
get resizeMode(): UITextResizeMode;
|
|
52
|
+
/** Base direction used for bidirectional text reordering */
|
|
53
|
+
get direction(): UITextDirection;
|
|
50
54
|
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
51
55
|
set color(value: UIColorConfig);
|
|
52
56
|
/** Text content as string, span config, or array */
|
|
@@ -57,6 +61,8 @@ export declare class UIText extends UIElement {
|
|
|
57
61
|
set padding(value: UIInsetsConfig);
|
|
58
62
|
/** Controls how text adapts to size constraints */
|
|
59
63
|
set resizeMode(value: UITextResizeMode);
|
|
64
|
+
/** Base direction used for bidirectional text reordering */
|
|
65
|
+
set direction(value: UITextDirection);
|
|
60
66
|
/** Removes element and frees resources */
|
|
61
67
|
destroy(): void;
|
|
62
68
|
protected onWillRender(renderer: WebGLRenderer, deltaTime: number): void;
|
|
@@ -6,7 +6,8 @@ import { UITextSpan } from '../../miscellaneous/text-span/UITextSpan.js';
|
|
|
6
6
|
import { UITextStyle } from '../../miscellaneous/text-style/UITextStyle.js';
|
|
7
7
|
import source from '../../shaders/UIImage.glsl.js';
|
|
8
8
|
import { UIElement } from '../UIElement/UIElement.js';
|
|
9
|
-
import {
|
|
9
|
+
import { detectIsRTL } from './UIText.Bidi.js';
|
|
10
|
+
import { TEXT_DEFAULT_MAX_LINE_WIDTH, TEXT_DEFAULT_RESIZE_MODE, TEXT_DEFAULT_DIRECTION, UITextResizeMode, UITextDirection } from './UIText.Internal.js';
|
|
10
11
|
import { calculateTextContentParameters, buildTextChunks } from './UIText.Measuring.js';
|
|
11
12
|
import { renderTextLines } from './UIText.Rendering.js';
|
|
12
13
|
|
|
@@ -37,13 +38,15 @@ class UIText extends UIElement {
|
|
|
37
38
|
this._private_contentDirty = false;
|
|
38
39
|
this._private_maxLineWidthDirty = false;
|
|
39
40
|
this._private_resizeModeDirty = false;
|
|
41
|
+
this._private_directionDirty = false;
|
|
42
|
+
this._private_isRTL = false;
|
|
40
43
|
this._private_textChunks = [];
|
|
41
|
-
this._private_textChunksDirty = false;
|
|
42
44
|
this._private_colorInternal = color;
|
|
43
45
|
this._private_paddingInternal = new UIInsets(options.padding);
|
|
44
46
|
this.commonStyle = new UITextStyle(options.commonStyle);
|
|
45
47
|
this._private_maxLineWidthInternal = options.maxLineWidth ?? TEXT_DEFAULT_MAX_LINE_WIDTH;
|
|
46
48
|
this._private_resizeModeInternal = options.resizeMode ?? TEXT_DEFAULT_RESIZE_MODE;
|
|
49
|
+
this._private_directionInternal = options.direction ?? TEXT_DEFAULT_DIRECTION;
|
|
47
50
|
this._private_canvas = canvas;
|
|
48
51
|
this._private_context = context;
|
|
49
52
|
this._private_texture = texture;
|
|
@@ -82,6 +85,10 @@ class UIText extends UIElement {
|
|
|
82
85
|
get resizeMode() {
|
|
83
86
|
return this._private_resizeModeInternal;
|
|
84
87
|
}
|
|
88
|
+
/** Base direction used for bidirectional text reordering */
|
|
89
|
+
get direction() {
|
|
90
|
+
return this._private_directionInternal;
|
|
91
|
+
}
|
|
85
92
|
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
86
93
|
set color(value) {
|
|
87
94
|
this._private_colorInternal.set(value);
|
|
@@ -109,7 +116,6 @@ class UIText extends UIElement {
|
|
|
109
116
|
];
|
|
110
117
|
}
|
|
111
118
|
this._private_contentDirty = true;
|
|
112
|
-
this._private_textChunksDirty = true;
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
121
|
/** Maximum line width before wrapping in pixels */
|
|
@@ -130,6 +136,13 @@ class UIText extends UIElement {
|
|
|
130
136
|
this._private_resizeModeDirty = true;
|
|
131
137
|
}
|
|
132
138
|
}
|
|
139
|
+
/** Base direction used for bidirectional text reordering */
|
|
140
|
+
set direction(value) {
|
|
141
|
+
if (this._private_directionInternal !== value) {
|
|
142
|
+
this._private_directionInternal = value;
|
|
143
|
+
this._private_directionDirty = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
133
146
|
/** Removes element and frees resources */
|
|
134
147
|
destroy() {
|
|
135
148
|
this._private_texture.dispose();
|
|
@@ -149,6 +162,7 @@ class UIText extends UIElement {
|
|
|
149
162
|
_private_tryToRenderTextScaleMode() {
|
|
150
163
|
if (!this._private_colorInternal.dirty &&
|
|
151
164
|
!this._private_resizeModeDirty &&
|
|
165
|
+
!this._private_directionDirty &&
|
|
152
166
|
!this._private_maxLineWidthDirty &&
|
|
153
167
|
!this._private_paddingInternal.dirty &&
|
|
154
168
|
!(this.solverWrapper.dirty &&
|
|
@@ -165,14 +179,17 @@ class UIText extends UIElement {
|
|
|
165
179
|
this.width = desiredWidth;
|
|
166
180
|
this.height = (desiredHeight / desiredWidth) * Math.round(this.width);
|
|
167
181
|
this.width = (desiredWidth / desiredHeight) * Math.round(this.height);
|
|
168
|
-
const
|
|
182
|
+
const safeWidth = Math.max(Math.round(desiredWidth), 2);
|
|
183
|
+
const safeHeight = Math.max(Math.round(desiredHeight), 2);
|
|
184
|
+
const resolutionDirty = this._private_canvas.width !== safeWidth || this._private_canvas.height !== safeHeight;
|
|
169
185
|
if (resolutionDirty) {
|
|
170
|
-
this._private_canvas.
|
|
171
|
-
this._private_canvas.
|
|
186
|
+
this._private_canvas.width = safeWidth;
|
|
187
|
+
this._private_canvas.height = safeHeight;
|
|
172
188
|
}
|
|
173
|
-
renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, lines, this._private_context);
|
|
189
|
+
renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, lines, this._private_isRTL, this._private_context);
|
|
174
190
|
this._private_updateProperties(resolutionDirty);
|
|
175
191
|
this._private_resizeModeDirty = false;
|
|
192
|
+
this._private_directionDirty = false;
|
|
176
193
|
this._private_maxLineWidthDirty = false;
|
|
177
194
|
this._private_paddingInternal.setDirtyFalse();
|
|
178
195
|
this._private_setDimensionsDirtyFalse();
|
|
@@ -181,6 +198,7 @@ class UIText extends UIElement {
|
|
|
181
198
|
_private_tryToRenderTextBreakMode() {
|
|
182
199
|
if (!this._private_colorInternal.dirty &&
|
|
183
200
|
!this._private_resizeModeDirty &&
|
|
201
|
+
!this._private_directionDirty &&
|
|
184
202
|
!this._private_maxLineWidthDirty &&
|
|
185
203
|
!this._private_paddingInternal.dirty &&
|
|
186
204
|
!this._private_checkDimensionsDirty() &&
|
|
@@ -198,14 +216,15 @@ class UIText extends UIElement {
|
|
|
198
216
|
this.width = realTextSize.width + paddingH;
|
|
199
217
|
const safeWidth = Math.max(Math.round(this.width), 2);
|
|
200
218
|
const safeHeight = Math.max(Math.round(this.height), 2);
|
|
201
|
-
const resolutionDirty = this.
|
|
219
|
+
const resolutionDirty = this._private_canvas.width !== safeWidth || this._private_canvas.height !== safeHeight;
|
|
202
220
|
if (resolutionDirty) {
|
|
203
221
|
this._private_canvas.width = safeWidth;
|
|
204
222
|
this._private_canvas.height = safeHeight;
|
|
205
223
|
}
|
|
206
|
-
renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, realTextLines, this._private_context);
|
|
224
|
+
renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, realTextLines, this._private_isRTL, this._private_context);
|
|
207
225
|
this._private_updateProperties(resolutionDirty);
|
|
208
226
|
this._private_resizeModeDirty = false;
|
|
227
|
+
this._private_directionDirty = false;
|
|
209
228
|
this._private_maxLineWidthDirty = false;
|
|
210
229
|
this._private_paddingInternal.setDirtyFalse();
|
|
211
230
|
this._private_setDimensionsDirtyFalse();
|
|
@@ -221,18 +240,21 @@ class UIText extends UIElement {
|
|
|
221
240
|
if (resolutionDirty) {
|
|
222
241
|
this._private_texture.dispose();
|
|
223
242
|
this._private_texture = createCanvasTexture(this._private_canvas);
|
|
224
|
-
this._private_texture.needsUpdate = true;
|
|
225
243
|
properties ?? (properties = {});
|
|
226
244
|
properties["texture"] = this._private_texture;
|
|
227
245
|
}
|
|
246
|
+
this._private_texture.needsUpdate = true;
|
|
228
247
|
if (properties) {
|
|
229
248
|
this.sceneWrapper.setProperties(this.planeHandler, properties);
|
|
230
249
|
}
|
|
231
250
|
}
|
|
232
251
|
_private_buildTextChunks() {
|
|
233
|
-
if (this.
|
|
234
|
-
this.
|
|
235
|
-
|
|
252
|
+
if (this._private_directionDirty || this._private_checkContentDirty()) {
|
|
253
|
+
this._private_isRTL =
|
|
254
|
+
this._private_directionInternal === UITextDirection.AUTO
|
|
255
|
+
? detectIsRTL(this._private_contentInternal)
|
|
256
|
+
: this._private_directionInternal === UITextDirection.RTL;
|
|
257
|
+
this._private_textChunks = buildTextChunks(this._private_context, this._private_contentInternal, this.commonStyle, this._private_isRTL);
|
|
236
258
|
}
|
|
237
259
|
return this._private_textChunks;
|
|
238
260
|
}
|
|
@@ -245,10 +267,13 @@ class UIText extends UIElement {
|
|
|
245
267
|
this._private_lastHeight = Math.round(this.height);
|
|
246
268
|
}
|
|
247
269
|
_private_checkContentDirty() {
|
|
248
|
-
return this._private_contentDirty ||
|
|
270
|
+
return (this._private_contentDirty ||
|
|
271
|
+
this.commonStyle.dirty ||
|
|
272
|
+
this.content.some((span) => span.dirty));
|
|
249
273
|
}
|
|
250
274
|
_private_setContentDirtyFalse() {
|
|
251
275
|
this._private_contentDirty = false;
|
|
276
|
+
this.commonStyle.setDirtyFalse();
|
|
252
277
|
for (const span of this.content) {
|
|
253
278
|
span.setDirtyFalse();
|
|
254
279
|
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { UIProgress } from "./elements/UIProgress/UIProgress";
|
|
|
25
25
|
export { UIScene } from "./elements/UIScene/UIScene";
|
|
26
26
|
export { UISceneUpdateMode } from "./elements/UIScene/UIScene.Internal";
|
|
27
27
|
export { UIText } from "./elements/UIText/UIText";
|
|
28
|
-
export { UITextResizeMode } from "./elements/UIText/UIText.Internal";
|
|
28
|
+
export { UITextDirection, UITextResizeMode } from "./elements/UIText/UIText.Internal";
|
|
29
29
|
export { UIFullscreenLayer } from "./layers/UIFullscreenLayer/UIFullscreenLayer";
|
|
30
30
|
export type { UIFullscreenLayerInputEventData } from "./layers/UIFullscreenLayer/UIFullscreenLayer.Internal";
|
|
31
31
|
export { UILayer } from "./layers/UILayer/UILayer";
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/** Text alignment. `start` and `end` are resolved against the text direction. */
|
|
2
|
+
export type UITextAlign = "start" | "left" | "center" | "right" | "end";
|
|
1
3
|
/** Complete text style configuration with all properties resolved */
|
|
2
4
|
export interface UITextStyleConfig {
|
|
3
5
|
/** Text color */
|
|
4
6
|
color: string;
|
|
5
7
|
/** Text alignment */
|
|
6
|
-
align:
|
|
8
|
+
align: UITextAlign;
|
|
7
9
|
/** Font family name */
|
|
8
10
|
fontFamily: string;
|
|
9
11
|
/** Font size in pixels */
|
|
@@ -32,7 +34,7 @@ export interface UITextStyleConfig {
|
|
|
32
34
|
strokeThickness: number;
|
|
33
35
|
}
|
|
34
36
|
export declare const TEXT_STYLE_DEFAULT_COLOR = "#000000";
|
|
35
|
-
export declare const TEXT_STYLE_DEFAULT_ALIGN: "
|
|
37
|
+
export declare const TEXT_STYLE_DEFAULT_ALIGN: "start";
|
|
36
38
|
export declare const TEXT_STYLE_DEFAULT_FONT_FAMILY = "Arial";
|
|
37
39
|
export declare const TEXT_STYLE_DEFAULT_FONT_SIZE = 16;
|
|
38
40
|
export declare const TEXT_STYLE_DEFAULT_FONT_STYLE: "normal";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const TEXT_STYLE_DEFAULT_COLOR = "#000000";
|
|
2
|
-
const TEXT_STYLE_DEFAULT_ALIGN = "
|
|
2
|
+
const TEXT_STYLE_DEFAULT_ALIGN = "start";
|
|
3
3
|
const TEXT_STYLE_DEFAULT_FONT_FAMILY = "Arial";
|
|
4
4
|
const TEXT_STYLE_DEFAULT_FONT_SIZE = 16;
|
|
5
5
|
const TEXT_STYLE_DEFAULT_FONT_STYLE = "normal";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UITextStyleConfig } from "./UITextStyle.Internal";
|
|
1
|
+
import type { UITextAlign, UITextStyleConfig } from "./UITextStyle.Internal";
|
|
2
2
|
/** Text style configuration for UI text rendering */
|
|
3
3
|
export declare class UITextStyle {
|
|
4
4
|
private colorInternal?;
|
|
@@ -22,7 +22,7 @@ export declare class UITextStyle {
|
|
|
22
22
|
/** Text color */
|
|
23
23
|
get color(): string | undefined;
|
|
24
24
|
/** Text alignment */
|
|
25
|
-
get align():
|
|
25
|
+
get align(): UITextAlign | undefined;
|
|
26
26
|
/** Font family name */
|
|
27
27
|
get fontFamily(): string | undefined;
|
|
28
28
|
/** Font size in pixels */
|
|
@@ -50,7 +50,7 @@ export declare class UITextStyle {
|
|
|
50
50
|
/** Stroke thickness in pixels */
|
|
51
51
|
get strokeThickness(): number | undefined;
|
|
52
52
|
set color(value: string | undefined);
|
|
53
|
-
set align(value:
|
|
53
|
+
set align(value: UITextAlign | undefined);
|
|
54
54
|
set fontFamily(value: string | undefined);
|
|
55
55
|
set fontSize(value: number | undefined);
|
|
56
56
|
set fontStyle(value: "normal" | "italic" | "oblique" | undefined);
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ export { UIProgress } from './core/elements/UIProgress/UIProgress.js';
|
|
|
24
24
|
export { UIScene } from './core/elements/UIScene/UIScene.js';
|
|
25
25
|
export { UISceneUpdateMode } from './core/elements/UIScene/UIScene.Internal.js';
|
|
26
26
|
export { UIText } from './core/elements/UIText/UIText.js';
|
|
27
|
-
export { UITextResizeMode } from './core/elements/UIText/UIText.Internal.js';
|
|
27
|
+
export { UITextDirection, UITextResizeMode } from './core/elements/UIText/UIText.Internal.js';
|
|
28
28
|
export { UIFullscreenLayer } from './core/layers/UIFullscreenLayer/UIFullscreenLayer.js';
|
|
29
29
|
export { UILayer } from './core/layers/UILayer/UILayer.js';
|
|
30
30
|
export { UIAreaCircle } from './core/miscellaneous/area/UIAreaCircle.js';
|