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

Support counting Asian characters double for line-breaking purposes #21

Closed
remkop opened this issue Feb 6, 2017 · 3 comments
Closed

Comments

@remkop
Copy link
Owner

remkop commented Feb 6, 2017

See argparse4j

enable if { "ja", "zh", "ko" }.contains(Locale.getDefault().getLanguage())

Apply to Unicode characters having East Asian Width property Wide/Full/Ambiguous.

@remkop remkop modified the milestone: 0.2.0 usage online help Feb 6, 2017
@remkop remkop modified the milestones: 0.3.0 usage online help, 0.5.0 advanced option parsing Mar 18, 2017
@remkop remkop modified the milestones: 0.5.0 advanced option parsing, 0.6.0 polishing Mar 31, 2017
@remkop remkop modified the milestones: 0.5.0 advanced option parsing, 0.6.0 polishing Apr 12, 2017
@remkop remkop modified the milestones: backlog, 4.0 Mar 19, 2019
@remkop
Copy link
Owner Author

remkop commented Mar 19, 2019

From lanterna TerminalTextUtils:

    /**
     * Given a character, is this character considered to be a CJK character?
     * Shamelessly stolen from
     * <a href="http://stackoverflow.com/questions/1499804/how-can-i-detect-japanese-text-in-a-java-string">StackOverflow</a>
     * where it was contributed by user Rakesh N
     * @param c Character to test
     * @return {@code true} if the character is a CJK character
     *
     */
    public static boolean isCharCJK(final char c) {
        Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(c);
        return (unicodeBlock == Character.UnicodeBlock.HIRAGANA)
                || (unicodeBlock == Character.UnicodeBlock.KATAKANA)
                || (unicodeBlock == Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS)
                || (unicodeBlock == Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO)
                || (unicodeBlock == Character.UnicodeBlock.HANGUL_JAMO)
                || (unicodeBlock == Character.UnicodeBlock.HANGUL_SYLLABLES)
                || (unicodeBlock == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS)
                || (unicodeBlock == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A)
                || (unicodeBlock == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B)
                || (unicodeBlock == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS)
                || (unicodeBlock == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS)
                || (unicodeBlock == Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT)
                || (unicodeBlock == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION)
                || (unicodeBlock == Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS)
                || (unicodeBlock == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS && c < 0xFF61);    //The magic number here is the separating index between full-width and half-width
    }

    /**
     * Checks if a character is expected to be taking up two columns if printed to a terminal. This will generally be
     * {@code true} for CJK (Chinese, Japanese and Korean) characters.
     * @param c Character to test if it's double-width when printed to a terminal
     * @return {@code true} if this character is expected to be taking up two columns when printed to the terminal,
     * otherwise {@code false}
     */
    public static boolean isCharDoubleWidth(final char c) {
        return isCharCJK(c);
    }

@remkop remkop modified the milestones: 4.0, 4.0-alpha-2 Apr 12, 2019
@remkop remkop closed this as completed in e7cbd3d Apr 12, 2019
@remkop
Copy link
Owner Author

remkop commented Apr 13, 2019

Should add a setting to switch this off.

  • doubleCountCJKCharacters
  • detectWideCJKCharacters
  • adjustLineBreaksForWideCJKCharacters

@remkop remkop reopened this Apr 13, 2019
@remkop remkop closed this as completed in e55f62f Apr 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant