mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

Support right-to-left scripts without requiring plugin

Open ChrisLoer opened this issue 9 years ago • 2 comments

We use an Emscripten port of the ICU library to provide support for bidirectional text as well as shaping for Arabic text (https://github.com/mapbox/mapbox-gl-js/issues/3708). However, the Emscripten port ended up being so large that it would nearly double the size of the mapbox-gl.js bundle (see discussion in PR https://github.com/mapbox/mapbox-gl-js/pull/3758). Because right-to-left support wasn't critical to all of customers, we decided to split the RTL support out into a separate RTL text plugin.

This is a sub-optimal solution: we would prefer for RTL scripts to work out of the box. Possible solutions to this problem include:

  • Accepting the bundle size increase and pulling the Emscriptified code into the main bundle
  • Making and maintaining a (hopefully more lightweight) native JS implementation of both the bidirectional algorithm and arabic shaping. A recent PR to the iD editor points in the direction we could go, but would require significant expansion to implement all of the ICU functionality. We might be able to identify some subset of current ICU functionality that can be dropped.
  • Finding further ways to decrease size of the transpiled ICU code, perhaps by making modifications to Emscripten

The fix for this issue will be tightly coupled to whatever decisions we make as we implement further support for complex text rendering (indic scripts, ligatures, kerning, etc.). The current plan on mapbox-gl-native is to use Harfbuzz for client-side text shaping (https://github.com/mapbox/mapbox-gl-native/issues/7528). Directly porting those changes would require us to either double down on the Emscripten strategy or greatly expand the scope of any direct C++->JS port.

cc @1ec5 @lucaswoj @pveugen

ChrisLoer avatar Jan 18 '17 19:01 ChrisLoer

https://github.com/mapbox/mapbox-gl-js/pull/4847 brings the size of the plugin down from 396KB to 273KB: not enough to bundle it in, but going in the right direction. If/when we start using Web Assembly, we could get this down even further to around ~125KB.

ChrisLoer avatar Jun 16 '17 23:06 ChrisLoer

This issue was brought up today on the OSM forum: https://community.openstreetmap.org/t/vector-tiles-on-osmf-hardware/121501/83

I haven't really looked into it yet so this might be useless, but in case it turns out useful: https://github.com/lojjic/bidi-js

This is a pure JS implementation of the Unicode Bidirectional Algorithm. However, from a quick look I don't think it handles Arabic ligatures.

NeatNit avatar May 18 '25 16:05 NeatNit