Make Text options typesafe
This commit is contained in:
@@ -58,10 +58,10 @@ import {getFontParameters} from '../css.js';
|
||||
/**
|
||||
* @typedef {Object} TextState
|
||||
* @property {string} font Font.
|
||||
* @property {string} [textAlign] TextAlign.
|
||||
* @property {string} [justify] Justify.
|
||||
* @property {string} textBaseline TextBaseline.
|
||||
* @property {import('../style/Text.js').TextPlacement} [placement] Placement.
|
||||
* @property {CanvasTextAlign} [textAlign] TextAlign.
|
||||
* @property {import("../style/Text.js").TextJustify} [justify] Justify.
|
||||
* @property {CanvasTextBaseline} textBaseline TextBaseline.
|
||||
* @property {import("../style/Text.js").TextPlacement} [placement] Placement.
|
||||
* @property {number} [maxAngle] MaxAngle.
|
||||
* @property {boolean} [overflow] Overflow.
|
||||
* @property {import("../style/Fill.js").default} [backgroundFill] BackgroundFill.
|
||||
@@ -134,13 +134,13 @@ export const defaultStrokeStyle = '#000';
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
* @type {CanvasTextAlign}
|
||||
*/
|
||||
export const defaultTextAlign = 'center';
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
* @type {CanvasTextBaseline}
|
||||
*/
|
||||
export const defaultTextBaseline = 'middle';
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ const rtlRegEx = new RegExp(
|
||||
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @param {string} align Alignment.
|
||||
* @param {CanvasTextAlign} align Alignment.
|
||||
* @return {number} Text alignment.
|
||||
*/
|
||||
function horizontalTextAlign(text, align) {
|
||||
|
||||
@@ -947,10 +947,8 @@ class CanvasImmediateRenderer extends VectorContext {
|
||||
: defaultTextAlign;
|
||||
if (!contextTextState) {
|
||||
context.font = textState.font;
|
||||
context.textAlign = /** @type {CanvasTextAlign} */ (textAlign);
|
||||
context.textBaseline = /** @type {CanvasTextBaseline} */ (
|
||||
textState.textBaseline
|
||||
);
|
||||
context.textAlign = textAlign;
|
||||
context.textBaseline = textState.textBaseline;
|
||||
this.contextTextState_ = {
|
||||
font: textState.font,
|
||||
textAlign: textAlign,
|
||||
@@ -962,16 +960,12 @@ class CanvasImmediateRenderer extends VectorContext {
|
||||
context.font = textState.font;
|
||||
}
|
||||
if (contextTextState.textAlign != textAlign) {
|
||||
contextTextState.textAlign = /** @type {CanvasTextAlign} */ (textAlign);
|
||||
context.textAlign = /** @type {CanvasTextAlign} */ (textAlign);
|
||||
contextTextState.textAlign = textAlign;
|
||||
context.textAlign = textAlign;
|
||||
}
|
||||
if (contextTextState.textBaseline != textState.textBaseline) {
|
||||
contextTextState.textBaseline = /** @type {CanvasTextBaseline} */ (
|
||||
textState.textBaseline
|
||||
);
|
||||
context.textBaseline = /** @type {CanvasTextBaseline} */ (
|
||||
textState.textBaseline
|
||||
);
|
||||
contextTextState.textBaseline = textState.textBaseline;
|
||||
context.textBaseline = textState.textBaseline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user