Skip to content

Commit

Permalink
Break lines on com­mon­ly un­spaced punc­tu­a­tion
Browse files Browse the repository at this point in the history
Par­ti­cu­lar­ly hy­phens and soft hy­phens.

Fixes #1115.
  • Loading branch information
1ec5 committed Oct 13, 2015
1 parent e6daa14 commit 53b81da
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions js/symbol/shaping.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,23 @@ function shapeText(text, glyphs, maxWidth, lineHeight, horizontalAlign, vertical
return shaping;
}

var breakable = { 32: true }; // Currently only breaks at regular spaces
var invisible = {
0x20: true, // space
0x200b: true // zero-width space
};

var breakable = {
0x20: true, // space
0x26: true, // ampersand
0x2b: true, // plus sign
0x2d: true, // hyphen-minus
0x2f: true, // solidus
0xad: true, // soft hyphen
0xb7: true, // middle dot
0x200b: true, // zero-width space
0x2010: true, // hyphen
0x2013: true // en dash
};

function linewrap(shaping, glyphs, lineHeight, maxWidth, horizontalAlign, verticalAlign, justify) {
var lastSafeBreak = null;
Expand Down Expand Up @@ -83,7 +99,13 @@ function linewrap(shaping, glyphs, lineHeight, maxWidth, horizontalAlign, vertic
}

if (justify) {
justifyLine(positionedGlyphs, glyphs, lineStartIndex, lastSafeBreak - 1, justify);
// Collapse invisible characters.
var lineEnd = lastSafeBreak;
if (invisible[positionedGlyphs[lastSafeBreak].codePoint]) {
lineEnd--;
}

justifyLine(positionedGlyphs, glyphs, lineStartIndex, lineEnd, justify);
}

lineStartIndex = lastSafeBreak + 1;
Expand Down

0 comments on commit 53b81da

Please sign in to comment.