Fix review for text justify

This commit is contained in:
Denis
2022-04-14 13:06:49 +02:00
parent 041b9a188a
commit 585ae66961
5 changed files with 3 additions and 10 deletions

View File

@@ -5,10 +5,8 @@ shortdesc: Example of text justification within a label.
docs: > docs: >
This example showcases how the text can be justified within the label box. This example showcases how the text can be justified within the label box.
By default, the text is justified according to the `textAlign` option. By default, the text is justified according to the `textAlign` option.
However, this option justifies the label itself according to the setting. However, this option justifies also the label itself according to `textAlign` setting.
If one wants to change this behavior, it is possible to use the `justify` text style option. To decouple the label placement from text placement (within the label box) use `justify`.
For more information, see the discussion:
https://github.com/openlayers/openlayers/issues/13481
tags: "vector, openstreetmap, label, rich-text" tags: "vector, openstreetmap, label, rich-text"
--- ---
<div id="map" class="map"></div> <div id="map" class="map"></div>

View File

@@ -239,7 +239,6 @@ class Executor {
textState.scale[1] * pixelRatio, textState.scale[1] * pixelRatio,
]; ];
const textIsArray = Array.isArray(text); const textIsArray = Array.isArray(text);
// See: https://github.com/openlayers/openlayers/issues/13481
const align = textState.justify const align = textState.justify
? TEXT_ALIGN[textState.justify] ? TEXT_ALIGN[textState.justify]
: horizontalTextAlign( : horizontalTextAlign(

View File

@@ -946,8 +946,6 @@ class CanvasImmediateRenderer extends VectorContext {
const textAlign = textState.textAlign const textAlign = textState.textAlign
? textState.textAlign ? textState.textAlign
: defaultTextAlign; : defaultTextAlign;
// Ignore `textState.justify` here,
// since rich-text is not supported for the immediate rendering API.
if (!contextTextState) { if (!contextTextState) {
context.font = textState.font; context.font = textState.font;
context.textAlign = /** @type {CanvasTextAlign} */ (textAlign); context.textAlign = /** @type {CanvasTextAlign} */ (textAlign);

View File

@@ -211,8 +211,7 @@ class CanvasTextBuilder extends CanvasBuilder {
} }
this.beginGeometry(geometry, feature); this.beginGeometry(geometry, feature);
const textAlign = textState.textAlign; const textAlign = textState.textAlign;
// Ignore `textState.justify` here, // No `justify` support for line placement.
// 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) {

View File

@@ -39,7 +39,6 @@ const DEFAULT_FILL_COLOR = '#333';
* If not set, text is justified towards the `textAlign` anchor. * 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. * 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'`. * **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', * @property {string} [textBaseline='middle'] Text base line. Possible values: 'bottom', 'top', 'middle', 'alphabetic',
* 'hanging', 'ideographic'. * 'hanging', 'ideographic'.
* @property {import("./Fill.js").default} [fill] Fill style. If none is provided, we'll use a dark fill-style (#333). * @property {import("./Fill.js").default} [fill] Fill style. If none is provided, we'll use a dark fill-style (#333).