Skip to content

Commit

Permalink
Allow breaking on all ideographic characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Wojciechowski committed Oct 25, 2016
1 parent e1eee1b commit 83a7aef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions js/symbol/shaping.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const breakable = {

invisible[newLine] = breakable[newLine] = true;

function linewrap(shaping, glyphs, lineHeight, maxWidth, horizontalAlign, verticalAlign, justify, translate, allowsIdeographicBreaking) {
function linewrap(shaping, glyphs, lineHeight, maxWidth, horizontalAlign, verticalAlign, justify, translate, useBalancedIdeographicBreaking) {
let lastSafeBreak = null;
let lengthBeforeCurrentLine = 0;
let lineStartIndex = 0;
Expand All @@ -92,7 +92,7 @@ function linewrap(shaping, glyphs, lineHeight, maxWidth, horizontalAlign, vertic
const positionedGlyphs = shaping.positionedGlyphs;

if (maxWidth) {
if (allowsIdeographicBreaking) {
if (useBalancedIdeographicBreaking) {
const lastPositionedGlyph = positionedGlyphs[positionedGlyphs.length - 1];
const estimatedLineCount = Math.max(1, Math.ceil(lastPositionedGlyph.x / maxWidth));
maxWidth = lastPositionedGlyph.x / estimatedLineCount;
Expand Down Expand Up @@ -131,7 +131,7 @@ function linewrap(shaping, glyphs, lineHeight, maxWidth, horizontalAlign, vertic
line++;
}

if (allowsIdeographicBreaking || breakable[positionedGlyph.codePoint]) {
if (useBalancedIdeographicBreaking || breakable[positionedGlyph.codePoint] || scriptDetection.charAllowsIdeographicBreaking(positionedGlyph.codePoint)) {
lastSafeBreak = i;
}
}
Expand Down
4 changes: 2 additions & 2 deletions js/util/script_detection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

module.exports.allowsIdeographicBreaking = function(input) {
for (let i = 0; i < input.length; i++) {
if (!charAllowsIdeographicBreaking(input.charCodeAt(i), input.charCodeAt(i + 1))) {
if (!exports.charAllowsIdeographicBreaking(input.charCodeAt(i), input.charCodeAt(i + 1))) {
return false;
}
}
return true;
};


function charAllowsIdeographicBreaking(char, nextChar) {
module.exports.charAllowsIdeographicBreaking = function(char, nextChar) {
// "一" to "鿌"
if (char >= 0x4E00 && char <= 0x9FCC) return true;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"highlight.js": "9.3.0",
"jsdom": "^9.4.2",
"lodash.template": "^4.4.0",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#16f7e8cdb73512ac723b7f4943e8464c930de066",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#4a508b6da9bad0fe267b0ccd4440fa061da3b4f8",
"minifyify": "^7.0.1",
"npm-run-all": "^3.0.0",
"nyc": "^8.3.0",
Expand Down

0 comments on commit 83a7aef

Please sign in to comment.