question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The space that is followed by CJK should not be a breaking space in TextMetrics

See original GitHub issue

Expected Behavior

The space that is followed by Chinese/Japanese/Korean should not be a breaking space. Like how it works in DOM as well: スクリーンショット 2020-11-03 15 50 50 export - 2020-11-03T160427 408

Current Behavior

The space will be a breaking space no matter what the following character is. The breaking space works correctly in English, but it is not correct with Chinese/Japanese/Korean. export - 2020-11-03T160407 935

Possible Solution

TextMetrics.isBreakingSpace may need to check the next character as well. If the character is CJK, the space should not be a breaking space.

let isUnbreakSpace = false;

if (typeof nextChar === 'string')
{
    const matchedAsCJK = nextChar.match(/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]/g);

    isUnbreakSpace = !!matchedAsCJK;
}

return (TextMetrics._breakingSpaces.indexOf(char.charCodeAt(0)) >= 0) && !isUnbreakSpace;

Steps to Reproduce

const style = new PIXI.TextStyle({
    breakWords: true,
    fontSize: 13,
    fontWeight: "bold",
    lineJoin: "bevel",
    stroke: "#896161",
    whiteSpace: "pre-line",
    wordWrap: true,
    wordWrapWidth: 285
});
const text = new PIXI.Text('テストテキスト テストテキスト テストテキスト テストテキスト ', style);

Environment

  • pixi.js version: _e.g. 5.1.6
  • Browser & Version: _e.g. Chrome 86
  • OS & Version: _e.g. Mac OS 10.15

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
huang-yuweicommented, Feb 23, 2021

@themoonrat Hi, I have just created a plugin for the CJK issue (sorry for my late notice), and would like to invite you to try on your games. I have tried it on my project, and seems great, but I hope it can work on almost all the cases in CJK. Therefore, sincerely hope you can try it when you have got time ☺️

BTW, I think my new way to determine the breakable-space/char uses less calculation and works in CJK than the current method. Do you think it is a good idea to contribute that feature to PIXI directly?

https://github.com/huang-yuwei/pixi-cjk

2reactions
themoonratcommented, Nov 3, 2020

CJK isn’t supported out of the box, atm, and there are a number of issues with it. I was going to make a plugin a long time ago to add support, and some refactor work for Text and TextMetrics allowed the easy addition, but it just never got done, as I suck. Not sure if it’d be something natively included in PixiJS itself, as its requires knowing what to do with certain symbols, for certain languages, via regex. I need to take another look. I have a method in my bespoke version of PixiJS, but there I just outright know what language hte game is in, so don’t have to be as smart about things

Read more comments on GitHub >

github_iconTop Results From Across the Web

The space that is followed by CJK should not be a breaking ...
It sounds like a great idea to allow adding additions to Text and TextMetrics. It is hard to perfectly resolve the problem in...
Read more >
When A Space Is Not A Space | Big Mess o' Wires
I think it would make more sense to have an HTML tag or CSS property for spans where spaces shouldn't be broken, instead...
Read more >
Word wrapping problem - lyx-devel@lists.lyx.org - narkive
It looks like this, huge space between mixture of CJK languages and ... I agree with the analysis, but I do not know...
Read more >
1102584 - Implement extended TextMetrics object
Currently, we are only implementing the width attribute of the TextMetrics object that is returned by ctx.measureText(). The canvas v5 API extended this ......
Read more >
CSS Inline Layout Module Level 3 - W3C
Line boxes that contain no text, no preserved white space, no inline boxes ... and do not end with a forced line break...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found