Skip to content

Commit 066bf6b

Browse files
authored
Merge pull request #526 from wiztivi-framework/feature/rtl
feature: TextTexture handle right to left text direction
2 parents b25dcc1 + e491d82 commit 066bf6b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/textures/TextTexture.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,17 @@ export default class TextTexture extends Texture {
466466
return this._textIndent;
467467
}
468468

469+
set rtl(v) {
470+
if (this._rtl !== v) {
471+
this._rtl = v;
472+
this._changed();
473+
}
474+
}
475+
476+
get rtl() {
477+
return this._rtl;
478+
}
479+
469480
get precision() {
470481
return super.precision;
471482
}
@@ -620,6 +631,7 @@ export default class TextTexture extends Texture {
620631
if (this.highlightPaddingRight !== 0) nonDefaults["highlightPaddingRight"] = this.highlightPaddingRight;
621632
if (this.letterSpacing !== 0) nonDefaults["letterSpacing"] = this.letterSpacing;
622633
if (this.textIndent !== 0) nonDefaults["textIndent"] = this.textIndent;
634+
if (this.rtl !== 0) nonDefaults["rtl"] = this.rtl;
623635

624636
if (this.cutSx) nonDefaults["cutSx"] = this.cutSx;
625637
if (this.cutEx) nonDefaults["cutEx"] = this.cutEx;
@@ -667,6 +679,7 @@ export default class TextTexture extends Texture {
667679
obj.highlightPaddingRight = this._highlightPaddingRight;
668680
obj.letterSpacing = this._letterSpacing;
669681
obj.textIndent = this._textIndent;
682+
obj.rtl = this._rtl;
670683
obj.cutSx = this._cutSx;
671684
obj.cutEx = this._cutEx;
672685
obj.cutSy = this._cutSy;
@@ -714,6 +727,7 @@ proto._highlightPaddingLeft = 0;
714727
proto._highlightPaddingRight = 0;
715728
proto._letterSpacing = 0;
716729
proto._textIndent = 0;
730+
proto._rtl = 0;
717731
proto._cutSx = 0;
718732
proto._cutEx = 0;
719733
proto._cutSy = 0;

src/textures/TextTextureRenderer.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default class TextTextureRenderer {
4343
this._stage.getOption('defaultFontFace'),
4444
);
4545
this._context.textBaseline = this._settings.textBaseline;
46+
this._context.direction = this._settings.rtl ? "rtl" : "ltr";
4647
};
4748

4849
_load() {
@@ -306,6 +307,9 @@ export default class TextTextureRenderer {
306307
linePositionX += ((renderInfo.innerWidth - renderInfo.lineWidths[i]) / 2);
307308
}
308309
linePositionX += renderInfo.paddingLeft;
310+
if (this._settings.rtl) {
311+
linePositionX += renderInfo.lineWidths[i];
312+
}
309313

310314
drawLines.push({text: renderInfo.lines[i], x: linePositionX, y: linePositionY, w: renderInfo.lineWidths[i]});
311315
}

0 commit comments

Comments
 (0)