mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
Address PR comments.
This commit is contained in:
parent
5570b4d62b
commit
2ef0a38ef8
src
@ -78,6 +78,7 @@ var CONTEXT_PROPERTIES = [
|
||||
'shadowBlur',
|
||||
'shadowOffsetX',
|
||||
'shadowOffsetY',
|
||||
'letterSpacing',
|
||||
'lineCap',
|
||||
'lineDashOffset',
|
||||
'lineJoin',
|
||||
@ -94,8 +95,8 @@ var CONTEXT_PROPERTIES = [
|
||||
|
||||
const traceArrMax = 100;
|
||||
|
||||
interface CanvasRenderingContext2DFeatureDetection extends CanvasRenderingContext2D {
|
||||
letterSpacing: string | undefined;
|
||||
interface ExtendedCanvasRenderingContext2D extends CanvasRenderingContext2D {
|
||||
letterSpacing: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -712,21 +713,6 @@ export class Context {
|
||||
translate(x: number, y: number) {
|
||||
this._context.translate(x, y);
|
||||
}
|
||||
/**
|
||||
* Set letterSpacing if supported by browser.
|
||||
* @method
|
||||
* @name Konva.Context#trySetLetterSpacing
|
||||
* @returns true if successful, false if not supported.
|
||||
*/
|
||||
trySetLetterSpacing(letterSpacing: number): boolean {
|
||||
var context = this._context as CanvasRenderingContext2DFeatureDetection;
|
||||
var letterSpacingSupported = 'letterSpacing' in context;
|
||||
|
||||
if (letterSpacingSupported) {
|
||||
context.letterSpacing = letterSpacing + "px";
|
||||
}
|
||||
return letterSpacingSupported;
|
||||
}
|
||||
_enableTrace() {
|
||||
var that = this,
|
||||
len = CONTEXT_METHODS.length,
|
||||
@ -785,7 +771,7 @@ export class Context {
|
||||
|
||||
// supported context properties
|
||||
type CanvasContextProps = Pick<
|
||||
CanvasRenderingContext2D,
|
||||
ExtendedCanvasRenderingContext2D,
|
||||
(typeof CONTEXT_PROPERTIES)[number]
|
||||
>;
|
||||
|
||||
|
@ -207,7 +207,9 @@ export class Text extends Shape<TextConfig> {
|
||||
var lineTranslateX = 0;
|
||||
var lineTranslateY = 0;
|
||||
|
||||
context.setAttr('direction', direction);
|
||||
if (direction === RTL) {
|
||||
context.setAttr('direction', direction);
|
||||
}
|
||||
|
||||
context.setAttr('font', this._getContextFont());
|
||||
|
||||
@ -315,13 +317,14 @@ export class Text extends Shape<TextConfig> {
|
||||
lineTranslateX += this.measureSize(letter).width + letterSpacing;
|
||||
}
|
||||
} else {
|
||||
context.trySetLetterSpacing(letterSpacing);
|
||||
if (letterSpacing !== 0) {
|
||||
context.setAttr('letterSpacing', `${letterSpacing}px`);
|
||||
}
|
||||
this._partialTextX = lineTranslateX;
|
||||
this._partialTextY = translateY + lineTranslateY;
|
||||
this._partialText = text;
|
||||
|
||||
context.fillStrokeShape(this);
|
||||
context.trySetLetterSpacing(0);
|
||||
}
|
||||
context.restore();
|
||||
if (textArrLen > 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user