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 overridable TextMetrics.isBreakingSpace for better CJK plugin support #7023

Merged
merged 7 commits into from Nov 23, 2020

Conversation

huang-yuwei
Copy link
Contributor

Description of change

As the discussion with @themoonrat in #6975, suggest allowing the isBreakingSpace to be able to receive the nextChar for solving the CJK issues in adding additions.

For example, the example plugin(https://codepen.io/huang-yuwei/pen/GRqbEmm) shows how we can solve the #6975 and #4447 via an adding addition.
However, I am not 100% sure whether the CJK related issues should be solved directly in PIXI.js itself.
Therefore, suggest applying the additional parameters for other developers can change via other plugins.

Pre-Merge Checklist
  • Tests and/or benchmarks are included
  • Lint process passed (npm run lint)
  • Tests passed (npm run test)

@codecov-io
Copy link

Codecov Report

Merging #7023 (1f3e564) into dev (425e494) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##               dev     #7023   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines          671       671           
=========================================
  Hits           671       671           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 425e494...1f3e564. Read the comment docs.

* @return {boolean} True if whitespace, False otherwise.
*/
private static isBreakingSpace(char: string): boolean
private static isBreakingSpace(char: string, _nextChar?: string): boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this public?

const reg = /[あいうえお]/;

// override breakingSpace
TextMetrics.isBreakingSpace = function (char, nextChar)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this test is over, can you reset isBreakingSpace to the default. Otherwise it may have unintended side effects for other tests.

@huang-yuwei
Copy link
Contributor Author

@bigtimebuddy thank you for the review. I have updated the code 😊

Copy link
Member

@bigtimebuddy bigtimebuddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code works for me! Thanks for the test too. I'll defer to @themoonrat to evaluate the utility of this.

Copy link
Member

@themoonrat themoonrat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only 1 minor jsdoc issue, otherwise lgtm. Non breaking change that allows greater plugin customising

packages/text/src/TextMetrics.ts Outdated Show resolved Hide resolved
@bigtimebuddy bigtimebuddy added the ✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t label Nov 23, 2020
@bigtimebuddy bigtimebuddy changed the title Overridable breaking space Add overridable TextMetrics.isBreakingSpace for better CJK plugin support Nov 23, 2020
@bigtimebuddy bigtimebuddy merged commit 13bf97a into pixijs:dev Nov 23, 2020
@bigtimebuddy
Copy link
Member

Thank you @huang-yuwei!

@huang-yuwei huang-yuwei deleted the overridable-breaking-space branch November 24, 2020 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants