Skip to content

Support text-writing-mode property for line placement symbols #10647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 21, 2021

Conversation

zmiao
Copy link
Contributor

@zmiao zmiao commented May 5, 2021

Launch Checklist

The line labels now can be configured with text-writing-mode as the following JSON shows:

      {
        "id": "lines-symbol",
        "type": "symbol",
        "source": "mapbox",
        "layout": {
          "text-field": "新华路12号A栋",
          "symbol-placement": "line",
          "text-writing-mode":["vertical"]
        }
      }

The text-writing-mode configuration can be added as an array, whose values are enumeration values from a ( horizontal | vertical ) set.
To keep the previous rendering behavior as much as possible, the default text-writing-mode configuration for line label would be either:

"text-writing-mode": ["horizontal", "vertical"]
or
"text-writing-mode": ["vertical", "horizontal"]

It means for line labels, the order of the writing modes in the array doesn’t affect the rendering behavior if both writing modes are provided. The decision is based on the assumption that the default map text-rotation-alignment is applied for the line labels.

The rendering result will keep almost the same as previous except that for vertical line labels, non-CJK characters along with CJK characters will also be upright. The following table shows the rendering effects with different text-writing-mode configs, to be aware that vertical writing mode will only be effective for text that is verticalizable, for pure Latin/numbers, the text will still be rendered horizontally with vertical writing mode:

'text-writing-mode' Effects
['horizontal'] Screen Shot 2021-06-08 at 4 51 25 PM
['vertical'] Screen Shot 2021-06-08 at 4 51 34 PM
default/['horizontal', 'veritcal']/['vertical', 'horizontal'] Screen Shot 2021-06-08 at 4 51 43 PM
  • briefly describe the changes in this PR
  • include before/after visuals or gifs if this PR includes visual changes
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page
  • tagged @mapbox/map-design-team @mapbox/static-apis if this PR includes style spec API or visual changes
  • tagged @mapbox/gl-native if this PR includes shader changes or needs a native port
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Support 'text-writing-mode' property for line symbol-placement text labels. Note: This change will bring following changes for CJK text block: 1. For vertical CJK text, all the characters including Latin and Numbers will be vertically placed now. Previously, Latin and Numbers are horizontally placed. 2. For horizontal CJK text, it may have a slight horizontal shift due to the anchor shift.</changelog>

Sorry, something went wrong.

@zmiao zmiao self-assigned this May 5, 2021
@zmiao zmiao force-pushed the zmiao-vertical-line-label branch 3 times, most recently from 8f636c7 to d0ee812 Compare May 14, 2021 11:13
@zmiao zmiao force-pushed the zmiao-vertical-line-label branch 2 times, most recently from bc50689 to b90ba0f Compare June 8, 2021 11:48
@zmiao zmiao marked this pull request as ready for review June 8, 2021 14:00
@zmiao
Copy link
Contributor Author

zmiao commented Jun 9, 2021

Benchmark result:
Screen Shot 2021-06-09 at 2 55 28 PM
Screen Shot 2021-06-09 at 2 56 20 PM

Copy link
Contributor

@ansis ansis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I asked a couple questions about things that were unclear to me but I didn't see any issues

if (symbolInstance.placedIconSymbolIndex >= 0) {
const horizontalOpacity = useHorizontal ? packedOpacity : PACKED_HIDDEN_OPACITY;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changed from !hasIconTextFit || !verticalPlacedIconSymbolIndex || !horizontalHidden to just !horizontalHidden. I understand why !verticalPlacedIconSymbolIndex would be dropped but I'm not sure about !hasIconTextFit. Do you know what the purpose of !hasIconTextFit was in the previous version?

Copy link
Contributor Author

@zmiao zmiao Jun 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quite sure why hiasIconTextFit is used for this case. I cross-compared with the gl-native parity code, it doesn't have this precondition. And one problem for only having useHorizontal check is it will disable either vertical or horizontal symbols, now this is not feasible for line label cases of having placedOrientation == undefined

const placedOrientation = this.placedOrientations[symbolInstance.crossTileID];  
const horizontalHidden = placedOrientation === WritingMode.vertical; 
const verticalHidden = placedOrientation === WritingMode.horizontal || placedOrientation === WritingMode.horizontalOnly;

@@ -175,6 +175,12 @@ function updateLineLabels(bucket: SymbolBucket,
for (let s = 0; s < placedSymbols.length; s++) {
const symbol: any = placedSymbols.get(s);

if (symbol.writingMode === WritingMode.vertical && !useVertical) {
if (s === 0 || placedSymbols.get(s - 1).writingMode !== WritingMode.horizontal) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this line is doing? especially the s - 1 part

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is a little confusing, I will add comment for it:

Normally, the 'Horizontal|Vertical' writing mode is followed by a 'Vertical' counterpart, 
this is not true for 'Vertical' only line labels. For this case, we'll have to overwrite the 
'useVertical' status before further checks.

@zmiao zmiao force-pushed the zmiao-vertical-line-label branch 2 times, most recently from 3dc4e4a to d271e93 Compare June 18, 2021 13:54
@zmiao zmiao force-pushed the zmiao-vertical-line-label branch from d271e93 to 756efbb Compare June 18, 2021 13:55
@zmiao zmiao merged commit c7e74bf into main Jun 21, 2021
@zmiao zmiao deleted the zmiao-vertical-line-label branch June 21, 2021 13:59
SnailBones pushed a commit to SnailBones/mapbox-gl-js that referenced this pull request Jul 15, 2021
…ox#10647)

* Remove Symbol placement checking when examing text writing modes

* Add default values of text-writing-mode for line labels

* Enable horizontal writing mode for vertical line label

* Add support for vertical only case for line label

* Fix lint errors

* Update render tests

* Update render tests

Add more render tests for line label text-writing-mode

* Add new render tests

Update render tests

* Fix vertical text shaping

* Fix punctuation verticalization

* Fix icon-text-fit

* Update comments

* Update style spec contents
zmiao added a commit that referenced this pull request Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants