Skip to content

Commit

Permalink
Disable letter-spacing for Arabic text (issue mapbox#4208)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLoer committed May 19, 2017
1 parent 18f7c51 commit a1f4938
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,11 @@ class SymbolBucket {
if (feature.text) {
const allowsVerticalWritingMode = scriptDetection.allowsVerticalWritingMode(feature.text);
const textOffset = this.layers[0].getLayoutValue('text-offset', {zoom: this.zoom}, feature.properties).map((t)=> t * oneEm);
const spacingIfAllowed = scriptDetection.allowsLetterSpacing(feature.text) ? spacing : 0;

shapedTextOrientations = {
[WritingMode.horizontal]: shapeText(feature.text, stacks[fontstack], maxWidth, lineHeight, horizontalAlign, verticalAlign, justify, spacing, textOffset, oneEm, WritingMode.horizontal),
[WritingMode.vertical]: allowsVerticalWritingMode && textAlongLine && shapeText(feature.text, stacks[fontstack], maxWidth, lineHeight, horizontalAlign, verticalAlign, justify, spacing, textOffset, oneEm, WritingMode.vertical)
[WritingMode.horizontal]: shapeText(feature.text, stacks[fontstack], maxWidth, lineHeight, horizontalAlign, verticalAlign, justify, spacingIfAllowed, textOffset, oneEm, WritingMode.horizontal),
[WritingMode.vertical]: allowsVerticalWritingMode && textAlongLine && shapeText(feature.text, stacks[fontstack], maxWidth, lineHeight, horizontalAlign, verticalAlign, justify, spacingIfAllowed, textOffset, oneEm, WritingMode.vertical)
};
} else {
shapedTextOrientations = {};
Expand Down
14 changes: 7 additions & 7 deletions src/util/is_char_in_unicode_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ const unicodeBlockLookup: UnicodeBlockLookup = {
// 'Cyrillic': (char) => char >= 0x0400 && char <= 0x04FF,
// 'Cyrillic Supplement': (char) => char >= 0x0500 && char <= 0x052F,
// 'Armenian': (char) => char >= 0x0530 && char <= 0x058F,
// 'Hebrew': (char) => char >= 0x0590 && char <= 0x05FF,
// 'Arabic': (char) => char >= 0x0600 && char <= 0x06FF,
// 'Syriac': (char) => char >= 0x0700 && char <= 0x074F,
// 'Arabic Supplement': (char) => char >= 0x0750 && char <= 0x077F,
//'Hebrew': (char) => char >= 0x0590 && char <= 0x05FF,
'Arabic': (char) => char >= 0x0600 && char <= 0x06FF,
//'Syriac': (char) => char >= 0x0700 && char <= 0x074F,
'Arabic Supplement': (char) => char >= 0x0750 && char <= 0x077F,
// 'Thaana': (char) => char >= 0x0780 && char <= 0x07BF,
// 'NKo': (char) => char >= 0x07C0 && char <= 0x07FF,
// 'Samaritan': (char) => char >= 0x0800 && char <= 0x083F,
// 'Mandaic': (char) => char >= 0x0840 && char <= 0x085F,
// 'Arabic Extended-A': (char) => char >= 0x08A0 && char <= 0x08FF,
'Arabic Extended-A': (char) => char >= 0x08A0 && char <= 0x08FF,
// 'Devanagari': (char) => char >= 0x0900 && char <= 0x097F,
// 'Bengali': (char) => char >= 0x0980 && char <= 0x09FF,
// 'Gurmukhi': (char) => char >= 0x0A00 && char <= 0x0A7F,
Expand Down Expand Up @@ -159,13 +159,13 @@ const unicodeBlockLookup: UnicodeBlockLookup = {
'Private Use Area': (char) => char >= 0xE000 && char <= 0xF8FF,
'CJK Compatibility Ideographs': (char) => char >= 0xF900 && char <= 0xFAFF,
// 'Alphabetic Presentation Forms': (char) => char >= 0xFB00 && char <= 0xFB4F,
// 'Arabic Presentation Forms-A': (char) => char >= 0xFB50 && char <= 0xFDFF,
'Arabic Presentation Forms-A': (char) => char >= 0xFB50 && char <= 0xFDFF,
// 'Variation Selectors': (char) => char >= 0xFE00 && char <= 0xFE0F,
'Vertical Forms': (char) => char >= 0xFE10 && char <= 0xFE1F,
// 'Combining Half Marks': (char) => char >= 0xFE20 && char <= 0xFE2F,
'CJK Compatibility Forms': (char) => char >= 0xFE30 && char <= 0xFE4F,
'Small Form Variants': (char) => char >= 0xFE50 && char <= 0xFE6F,
// 'Arabic Presentation Forms-B': (char) => char >= 0xFE70 && char <= 0xFEFF,
'Arabic Presentation Forms-B': (char) => char >= 0xFE70 && char <= 0xFEFF,
'Halfwidth and Fullwidth Forms': (char) => char >= 0xFF00 && char <= 0xFFEF
// 'Specials': (char) => char >= 0xFFF0 && char <= 0xFFFF,
// 'Linear B Syllabary': (char) => char >= 0x10000 && char <= 0x1007F,
Expand Down
17 changes: 17 additions & 0 deletions src/util/script_detection.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ module.exports.allowsVerticalWritingMode = function(chars) {
return false;
};

module.exports.allowsLetterSpacing = function(chars) {
for (const char of chars) {
if (!exports.charAllowsLetterSpacing(char.charCodeAt(0))) return false;
}
return true;
};

module.exports.charAllowsLetterSpacing = function(char) {
if (isChar['Arabic'](char)) return false;
if (isChar['Arabic Supplement'](char)) return false;
if (isChar['Arabic Extended-A'](char)) return false;
if (isChar['Arabic Presentation Forms-A'](char)) return false;
if (isChar['Arabic Presentation Forms-B'](char)) return false;

return true;
};

module.exports.charAllowsIdeographicBreaking = function(char) {
// Return early for characters outside all ideographic ranges.
if (char < 0x2E80) return false;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": 8,
"metadata": {
"test": {
"ignored": {
"native": "https://github.com/mapbox/mapbox-gl-native/issues/9057"
},
"width": 256,
"height": 256
}
},
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "name": "مجتمع آپارتمانهای مرتفع Not spaced" },
"geometry": {
"type": "Point",
"coordinates": [ 0, 0 ]
}
},
{
"type": "Feature",
"properties": { "name": "Spaced" },
"geometry": {
"type": "Point",
"coordinates": [ 0, 30 ]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "symbol",
"type": "symbol",
"source": "geojson",
"layout": {
"symbol-placement": "point",
"symbol-spacing": 20,
"text-allow-overlap": true,
"text-letter-spacing": 1,
"text-rotation-alignment": "auto",
"text-max-width": 5,
"text-field": "{name}",
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
]
}
}
]
}

0 comments on commit a1f4938

Please sign in to comment.