From 585ae66961cecf1e5876d5a6a870181ca1315af9 Mon Sep 17 00:00:00 2001 From: Denis <51781722+rycgar@users.noreply.github.com> Date: Thu, 14 Apr 2022 13:06:49 +0200 Subject: [PATCH] Fix review for text justify --- examples/vector-labels-justify-text.html | 6 ++---- src/ol/render/canvas/Executor.js | 1 - src/ol/render/canvas/Immediate.js | 2 -- src/ol/render/canvas/TextBuilder.js | 3 +-- src/ol/style/Text.js | 1 - 5 files changed, 3 insertions(+), 10 deletions(-) diff --git a/examples/vector-labels-justify-text.html b/examples/vector-labels-justify-text.html index 0047326081..ce4d261c97 100644 --- a/examples/vector-labels-justify-text.html +++ b/examples/vector-labels-justify-text.html @@ -5,10 +5,8 @@ shortdesc: Example of text justification within a label. docs: > This example showcases how the text can be justified within the label box. By default, the text is justified according to the `textAlign` option. - However, this option justifies the label itself according to the setting. - If one wants to change this behavior, it is possible to use the `justify` text style option. - For more information, see the discussion: - https://github.com/openlayers/openlayers/issues/13481 + However, this option justifies also the label itself according to `textAlign` setting. + To decouple the label placement from text placement (within the label box) use `justify`. tags: "vector, openstreetmap, label, rich-text" ---
diff --git a/src/ol/render/canvas/Executor.js b/src/ol/render/canvas/Executor.js index a5793d55b2..b424dfb7bd 100644 --- a/src/ol/render/canvas/Executor.js +++ b/src/ol/render/canvas/Executor.js @@ -239,7 +239,6 @@ class Executor { textState.scale[1] * pixelRatio, ]; const textIsArray = Array.isArray(text); - // See: https://github.com/openlayers/openlayers/issues/13481 const align = textState.justify ? TEXT_ALIGN[textState.justify] : horizontalTextAlign( diff --git a/src/ol/render/canvas/Immediate.js b/src/ol/render/canvas/Immediate.js index 543afdef10..ab7a55397a 100644 --- a/src/ol/render/canvas/Immediate.js +++ b/src/ol/render/canvas/Immediate.js @@ -946,8 +946,6 @@ class CanvasImmediateRenderer extends VectorContext { const textAlign = textState.textAlign ? textState.textAlign : defaultTextAlign; - // Ignore `textState.justify` here, - // since rich-text is not supported for the immediate rendering API. if (!contextTextState) { context.font = textState.font; context.textAlign = /** @type {CanvasTextAlign} */ (textAlign); diff --git a/src/ol/render/canvas/TextBuilder.js b/src/ol/render/canvas/TextBuilder.js index 5f23ee3c58..3e1bb4a45e 100644 --- a/src/ol/render/canvas/TextBuilder.js +++ b/src/ol/render/canvas/TextBuilder.js @@ -211,8 +211,7 @@ class CanvasTextBuilder extends CanvasBuilder { } this.beginGeometry(geometry, feature); const textAlign = textState.textAlign; - // Ignore `textState.justify` here, - // since rich-text and also `'\n'` make less sense for line placement. + // No `justify` support for line placement. let flatOffset = 0; let flatEnd; for (let o = 0, oo = ends.length; o < oo; ++o) { diff --git a/src/ol/style/Text.js b/src/ol/style/Text.js index 9acfd2a055..1337f88187 100644 --- a/src/ol/style/Text.js +++ b/src/ol/style/Text.js @@ -39,7 +39,6 @@ const DEFAULT_FILL_COLOR = '#333'; * If not set, text is justified towards the `textAlign` anchor. * Otherwise, use options `'left'`, `'center'`, or `'right'` to justify the text within the text box. * **Note:** `justify` is ignored for immediate rendering and also for `placement: 'line'`. - * See: https://github.com/openlayers/openlayers/issues/13481 * @property {string} [textBaseline='middle'] Text base line. Possible values: 'bottom', 'top', 'middle', 'alphabetic', * 'hanging', 'ideographic'. * @property {import("./Fill.js").default} [fill] Fill style. If none is provided, we'll use a dark fill-style (#333).