Correct meaning of 'start' and 'end' text align for LTR text
This commit is contained in:
@@ -75,6 +75,20 @@ function getDeclutterBox(replayImageOrLabelArgs) {
|
||||
return replayImageOrLabelArgs[3].declutterBox;
|
||||
}
|
||||
|
||||
const rtlRegEx = /[\u0591-\u07FF]/;
|
||||
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @param {string} align Alignment.
|
||||
* @return {number} Text alignment.
|
||||
*/
|
||||
function horizontalTextAlign(text, align) {
|
||||
if ((align === 'start' || align === 'end') && !rtlRegEx.test(text)) {
|
||||
align = align === 'start' ? 'left' : 'right';
|
||||
}
|
||||
return TEXT_ALIGN[align];
|
||||
}
|
||||
|
||||
class Executor {
|
||||
/**
|
||||
* @param {number} resolution Resolution.
|
||||
@@ -205,7 +219,10 @@ class Executor {
|
||||
textState.scale[0] * pixelRatio,
|
||||
textState.scale[1] * pixelRatio,
|
||||
];
|
||||
const align = TEXT_ALIGN[textState.textAlign || defaultTextAlign];
|
||||
const align = horizontalTextAlign(
|
||||
text,
|
||||
textState.textAlign || defaultTextAlign
|
||||
);
|
||||
const strokeWidth =
|
||||
strokeKey && strokeState.lineWidth ? strokeState.lineWidth : 0;
|
||||
|
||||
@@ -541,7 +558,10 @@ class Executor {
|
||||
|
||||
const strokeState = this.strokeStates[strokeKey];
|
||||
const pixelRatio = this.pixelRatio;
|
||||
const align = TEXT_ALIGN[textState.textAlign || defaultTextAlign];
|
||||
const align = horizontalTextAlign(
|
||||
text,
|
||||
textState.textAlign || defaultTextAlign
|
||||
);
|
||||
const baseline = TEXT_ALIGN[textState.textBaseline || defaultTextBaseline];
|
||||
const strokeWidth =
|
||||
strokeState && strokeState.lineWidth ? strokeState.lineWidth : 0;
|
||||
|
||||
Reference in New Issue
Block a user