Implement text justify within the label box
See: https://github.com/openlayers/openlayers/issues/13481
This commit is contained in:
@@ -56,6 +56,7 @@ import {getFontParameters} from '../css.js';
|
|||||||
* @typedef {Object} TextState
|
* @typedef {Object} TextState
|
||||||
* @property {string} font Font.
|
* @property {string} font Font.
|
||||||
* @property {string} [textAlign] TextAlign.
|
* @property {string} [textAlign] TextAlign.
|
||||||
|
* @property {string} [justify] Justify.
|
||||||
* @property {string} textBaseline TextBaseline.
|
* @property {string} textBaseline TextBaseline.
|
||||||
* @property {string} [placement] Placement.
|
* @property {string} [placement] Placement.
|
||||||
* @property {number} [maxAngle] MaxAngle.
|
* @property {number} [maxAngle] MaxAngle.
|
||||||
|
|||||||
@@ -239,10 +239,13 @@ class Executor {
|
|||||||
textState.scale[1] * pixelRatio,
|
textState.scale[1] * pixelRatio,
|
||||||
];
|
];
|
||||||
const textIsArray = Array.isArray(text);
|
const textIsArray = Array.isArray(text);
|
||||||
const align = horizontalTextAlign(
|
// See: https://github.com/openlayers/openlayers/issues/13481
|
||||||
textIsArray ? text[0] : text,
|
const align = textState.justify
|
||||||
textState.textAlign || defaultTextAlign
|
? TEXT_ALIGN[textState.justify]
|
||||||
);
|
: horizontalTextAlign(
|
||||||
|
Array.isArray(text) ? text[0] : text,
|
||||||
|
textState.textAlign || defaultTextAlign
|
||||||
|
);
|
||||||
const strokeWidth =
|
const strokeWidth =
|
||||||
strokeKey && strokeState.lineWidth ? strokeState.lineWidth : 0;
|
strokeKey && strokeState.lineWidth ? strokeState.lineWidth : 0;
|
||||||
|
|
||||||
|
|||||||
@@ -946,6 +946,7 @@ class CanvasImmediateRenderer extends VectorContext {
|
|||||||
const textAlign = textState.textAlign
|
const textAlign = textState.textAlign
|
||||||
? textState.textAlign
|
? textState.textAlign
|
||||||
: defaultTextAlign;
|
: defaultTextAlign;
|
||||||
|
// Ignore justification here, since rich-text and also `'\n'` make less sense for line placement.
|
||||||
if (!contextTextState) {
|
if (!contextTextState) {
|
||||||
context.font = textState.font;
|
context.font = textState.font;
|
||||||
context.textAlign = /** @type {CanvasTextAlign} */ (textAlign);
|
context.textAlign = /** @type {CanvasTextAlign} */ (textAlign);
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ class CanvasTextBuilder extends CanvasBuilder {
|
|||||||
}
|
}
|
||||||
this.beginGeometry(geometry, feature);
|
this.beginGeometry(geometry, feature);
|
||||||
const textAlign = textState.textAlign;
|
const textAlign = textState.textAlign;
|
||||||
|
// Ignore justification here, since rich-text and also `'\n'` make less sense for line placement.
|
||||||
let flatOffset = 0;
|
let flatOffset = 0;
|
||||||
let flatEnd;
|
let flatEnd;
|
||||||
for (let o = 0, oo = ends.length; o < oo; ++o) {
|
for (let o = 0, oo = ends.length; o < oo; ++o) {
|
||||||
@@ -449,6 +450,7 @@ class CanvasTextBuilder extends CanvasBuilder {
|
|||||||
this.textStates[textKey] = {
|
this.textStates[textKey] = {
|
||||||
font: textState.font,
|
font: textState.font,
|
||||||
textAlign: textState.textAlign || defaultTextAlign,
|
textAlign: textState.textAlign || defaultTextAlign,
|
||||||
|
justify: textState.justify,
|
||||||
textBaseline: textState.textBaseline || defaultTextBaseline,
|
textBaseline: textState.textBaseline || defaultTextBaseline,
|
||||||
scale: textState.scale,
|
scale: textState.scale,
|
||||||
};
|
};
|
||||||
@@ -581,6 +583,7 @@ class CanvasTextBuilder extends CanvasBuilder {
|
|||||||
textState.maxAngle = textStyle.getMaxAngle();
|
textState.maxAngle = textStyle.getMaxAngle();
|
||||||
textState.placement = textStyle.getPlacement();
|
textState.placement = textStyle.getPlacement();
|
||||||
textState.textAlign = textStyle.getTextAlign();
|
textState.textAlign = textStyle.getTextAlign();
|
||||||
|
textState.justify = textStyle.getJustify();
|
||||||
textState.textBaseline =
|
textState.textBaseline =
|
||||||
textStyle.getTextBaseline() || defaultTextBaseline;
|
textStyle.getTextBaseline() || defaultTextBaseline;
|
||||||
textState.backgroundFill = textStyle.getBackgroundFill();
|
textState.backgroundFill = textStyle.getBackgroundFill();
|
||||||
@@ -617,6 +620,7 @@ class CanvasTextBuilder extends CanvasBuilder {
|
|||||||
textState.font +
|
textState.font +
|
||||||
textState.scale +
|
textState.scale +
|
||||||
(textState.textAlign || '?') +
|
(textState.textAlign || '?') +
|
||||||
|
(textState.justify || '?') +
|
||||||
(textState.textBaseline || '?');
|
(textState.textBaseline || '?');
|
||||||
this.fillKey_ = fillState
|
this.fillKey_ = fillState
|
||||||
? typeof fillState.fillStyle == 'string'
|
? typeof fillState.fillStyle == 'string'
|
||||||
|
|||||||
Reference in New Issue
Block a user