Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for rendering CJK glyphs top-to-bottom #3402

Closed
wants to merge 26 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
break evenly for now
  • Loading branch information
xrwang authored and jakepruitt committed Oct 14, 2016
commit cefde62e7259aa4c2ffe6e12788a848fc23dd6dd
75 changes: 72 additions & 3 deletions js/symbol/shaping.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,48 @@ function shapeText(text, glyphs, maxWidth, lineHeight, horizontalAlign, vertical

var invisible = {
0x20: true, // space
0x200b: false // zero-width space
0x200b: true // zero-width space
};

// var breakableCJK = [
// 0x0028, // dollar sign
// 0x24, // left parenthesis
// 0xA3, // english pound sign
// 0xA5, // rmb sign
// 0xB7, // dot
// 0x2018, // left single quotation
// 0x22, // quotation mark
// 0x3008, // left angle bracket
// 0x300A, // left angle double bracket
// 0x300C, // left corner bracket
// 0x300E,
// 0x3010,
// 0x3014,
// 0x3016,
// 0x301D,
// 0xFE59,
// 0xFE5B,
// 0xFF04,
// 0xFF08,
// 0xFF0E,
// 0xFF3B,
// 0xFF5B,
// 0xFFE1,
// 0xFFE5,
// 0x200b // zero-width space
// ];

var breakableCJK = {
0x20: true, // space
0x0028: true, // dollar sign
0x24: true, // left parenthesis
0x24: true,
0xA3: true, // english pound sign
0xA5: true, // rmb sign
0xB7: true, // dot
0x2018: true, // left single quotation
0x22: true, // quotation mark
0x3002: true,
65374: true,
0x3008: true, // left angle bracket
0x300A: true, // left angle double bracket
0x300C: true, // left corner bracket
Expand All @@ -89,7 +120,9 @@ var breakableCJK = {
0xFF5B: true,
0xFFE1: true,
0xFFE5: true,
0x200b: true // zero-width space
0x200b: true,
0x897F: true
// zero-width space
};

invisible[newLine] = breakable[newLine] = true;
Expand All @@ -108,6 +141,8 @@ function linewrap(shaping, glyphs, lineHeight, maxWidth, horizontalAlign, vertic

var wordLength = positionedGlyphs.length;

// lastSafeBreak = Math.round(wordLength/2);

for (var i = 0; i < positionedGlyphs.length; i++) {
var positionedGlyph = positionedGlyphs[i];

Expand Down Expand Up @@ -141,9 +176,43 @@ function linewrap(shaping, glyphs, lineHeight, maxWidth, horizontalAlign, vertic
line++;
}

// if (breakableCJK[positionedGlyph.codePoint]) {
// lastSafeBreak = i - 1;
// }
// lastSafeBreak = Math.round(wordLength / 3);

// if (!breakableCJK[positionedGlyph.codePoint]) {
// lastSafeBreak = Math.round(wordLength / 3);
// } else if (breakableCJK[positionedGlyph.codePoint]) {
// lastSafeBreak = i - 1;
// } else {
// lastSafeBreak = Math.round(wordLength / 4);
// }

if (breakableCJK[positionedGlyph.codePoint]) {
lastSafeBreak = i - 1;
}
if (!(breakableCJK[positionedGlyph.codePoint]) && positionedGlyph.codePoint > 19968) {
lastSafeBreak = Math.round(wordLength / 3);
}
// 16.95/31.24019/121.48622
// else {
// lastSafeBreak = (Math.round(wordLength / 3));
// }

// if (positionedGlyph.codePoint > 19968) {
// console.log(positionedGlyph.codePoint)
// lastSafeBreak = (Math.round(wordLength / 3));
// }

// console.log(typeof breakableCJK)
// if (breakableCJK.indexOf(positionedGlyph.codePoint) === 0) {
// lastSafeBreak = i - 1;
// }
//
// if (breakableCJK.indexOf(positionedGlyph.codePoint) !=== 0) {
// lastSafeBreak = Math.round(wordLength / 2);
// }

}

Expand Down