Skip to content

Commit

Permalink
Adding zero-width space to Firefox SVG start of text working around #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Jul 10, 2024
1 parent 173ba99 commit 89da157
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions js/display/drawables/TextSVGDrawable.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class TextSVGDrawable extends TextStatefulDrawable( SVGSelfDrawable ) {
// @private {boolean}
this.hasLength = false;

// @private {'ltr' | 'rtl'}
this.direction = 'ltr';

if ( !this.svgElement ) {
const text = document.createElementNS( svgns, 'text' );

Expand Down Expand Up @@ -100,38 +97,8 @@ class TextSVGDrawable extends TextStatefulDrawable( SVGSelfDrawable ) {
let string = Utils.safariEmbeddingMarkWorkaround( this.node.renderedText );

// Workaround for Firefox handling of RTL embedding marks, https://github.com/phetsims/scenery/issues/1643
// We strip off outer containing embedding marks, and adjust the direction and text-anchor accordingly to match
// our normal behavior.
if ( platform.firefox ) {
let direction = 'ltr';

// While our string is long enough AND the last character is a POP embedding mark
while ( string.length > 2 && string[ string.length - 1 ] === '\u202c' ) {
const isLTR = string[ 0 ] === '\u202a';
const isRTL = string[ 0 ] === '\u202b';

if ( isLTR ) {
direction = 'ltr';
}
else if ( isRTL ) {
direction = 'rtl';
}
else {
break;
}

// Strip off the outer embedding marks
string = string.slice( 1, -1 );
}

if ( this.direction !== direction ) {
this.direction = direction;

text.setAttribute( 'direction', direction );

// To maintain the same positioning, we need to adjust the text-anchor
text.setAttribute( 'text-anchor', direction === 'rtl' ? 'end' : 'start' );
}
string = '\u200b' + string;
}

text.lastChild.nodeValue = string;
Expand Down

0 comments on commit 89da157

Please sign in to comment.