Skip to content

Vertical alignment in format expression#5043

Merged
HarelM merged 55 commits intomaplibre:mainfrom
tomtom-forks:vertical-alignment-in-format-expression
Jan 28, 2025
Merged

Vertical alignment in format expression#5043
HarelM merged 55 commits intomaplibre:mainfrom
tomtom-forks:vertical-alignment-in-format-expression

Conversation

@stanislawpuda-tomtom
Copy link
Copy Markdown
Contributor

@stanislawpuda-tomtom stanislawpuda-tomtom commented Nov 13, 2024

Related to issue: maplibre-style-spec

This PR introduces implementation of vertical align property in format expression. It enables to specify how each section should be positioned in relation to biggest element in line. There are three possible options:

  • "bottom" default: text baseline or image bottom are in line - this is current behaviour.
  • "center": image center or text center are in line.
  • "top": image top and text top are in

How to compare

To easily compare between current behaviour and new changes we build small comparison app. Please download test.zip, unpack and run eg. with VSC Live Server extension.

  • maplibre-gl-dev-MAIN.js file contains current maplibre-gl-js version. We've changed export variable to maplibreglMain.
  • maplibre-gl-dev.js contains maplibre-gl-js with changes from this PR.

Download test package:
test.zip

Visual comparison

Screen.Recording.2024-11-13.at.17.55.12.mov

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • 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.
  • Add an entry to CHANGELOG.md under the ## main section.

Authors: @zbigniewmatysek-tomtom @stanislawpuda-tomtom

…into vertical-alignment-in-format-expression
Comment thread src/symbol/shaping.ts Outdated
Comment thread src/symbol/shaping.ts Outdated
Comment thread src/symbol/shaping.ts Outdated
Comment thread src/symbol/shaping.ts Outdated
Comment thread src/symbol/shaping.ts
@HarelM
Copy link
Copy Markdown
Collaborator

HarelM commented Jan 27, 2025

Added a few nitpicking, otherwise looks good, thanks!

@stanislawpuda-tomtom
Copy link
Copy Markdown
Contributor Author

I checked performance benchmarks once again.
LayerSymbol
LayerSymbolWithIcons
LayerSymbolWithSortKey
LayerTextWithVariableAnchor

@stanislawpuda-tomtom stanislawpuda-tomtom marked this pull request as ready for review January 28, 2025 09:44
Comment thread src/symbol/shaping.ts
Comment thread src/symbol/shaping.ts
…into vertical-alignment-in-format-expression
Comment thread test/integration/render/tests/text-field/formatted-vertical-align/style.json Outdated
Comment thread test/integration/render/tests/text-field/formatted-vertical-align-line/style.json Outdated
@HarelM
Copy link
Copy Markdown
Collaborator

HarelM commented Jan 28, 2025

Did a last review and added a minor comment about the render test.
Looks good otherwise.

@HarelM HarelM merged commit b4035a7 into maplibre:main Jan 28, 2025
ToHold pushed a commit to ToHold/maplibre-gl-js that referenced this pull request Oct 31, 2025
* add support for `top` alingment

* add support for "center" alignment

* add comments

* render tests

* handle vertical text

* cleanout

* update top alignment

* cleanout

* refactor shaping

* Fix vertical alignment

* fix bbox size

* adjust line spacing

* vertical placement

* cleanout

* handle text offset

* minor fix

* const glyph height

* align when no big image

* use section.scale when multiplying on image

* fix big image case

* fix vertical

* simplify imageOffset calculation

* code simplification

* improve readability

* cleaning - removing dead code

* fix only images case

* cleaning + update render tests

* bump maplibre-style-spec version

* update bundle size

* use style spec type

* fix verticalAlign rendering tests

* improve justifyLine readabilty

* refactor getRectAndMetrics

* use switch in getVerticalAlignFactor

* split calculateLineContentSize fn to improve readability

* Revert "split calculateLineContentSize fn to improve readability"

This reverts commit b87ecdd.

* clearing

* improve calculateLineContentSize return type

* move isVertical outside shaping fn

* remove redundant imageName variable

* small shapeLines code simplification

* split shapeLines fn

* fix lint

* add tests for vertical align

* fix lint in test file

* move type definitions to the top of the file

* simplify shapeLines adding sectionAttributes object

* add return type to TaggedString.getMaxImageSize

* add changelog

* update render test files "baseline" -> "bottom"

---------

Co-authored-by: Zbigniew Matysek <zbigniew.matysek@tomtom.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants