Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Chinese labels should be wrapped by character with balanced lines #1223

Closed

Description

@barrycug

the font is "Unifont Medium” .The english is ok

Activity

  1. mikemorris commented on Apr 7, 2015

    @mikemorris
    Contributor

    @barrycug Can you please provide more details on what the expected result is versus what is actually rendered?

  2. barrycug commented on Apr 8, 2015

    @barrycug
    Author

    issure
    on the screenshot,you can find the English text have 2 lines,and the chinese text have 1 line.
    and i set the text-max-width =5;
    "text-max-width":5

  3. barrycug commented on Apr 8, 2015

    @barrycug
    Author

    I know ,the text wrapped line depend on space.But in chinese ,the text have not include the space.

  4. friedbunny commented on Apr 8, 2015

    @friedbunny
    Contributor

    Japanese has a similar issue, to a lesser degree because names tend to be shorter. The problem is that it would be difficult to determine where to break an un-spaced line — it would likely have to be specific to each language.

    Off the top of my head, Japanese could be split on certain characters (like ・ or other punctuation) or when switching character sets, e.g., syllabaries giving way to kanji like in カタカナ漢字 or alphabet to kanji ABC公園, etc.

    Here's a Yahoo Japan map, which is probably the best designed web map in Japan, if anyone is looking for inspriation. ;)

  5. barrycug commented on Apr 8, 2015

    @barrycug
    Author

    thank you very mach. I split the text by the size. It is the most simple solution。Mayby I can insert space into the data,this is the correct solution,because it can use the natural language broken。But it is a hard work。

    bool hasspace = false;
    uint32_t space = 32;
    if(!(string.find(space) ==std::string::npos))
    {
        hasspace = true;
    }
    long breakOffset=-1;
    if (!hasspace) {
        if (string.size() > maxWidth/24) {
            breakOffset = string.size()/2+1;
        }
    }
    
    int i=0;
    for (uint32_t chr : string) {
        if (!hasspace &&i==breakOffset) {
            shaping.emplace_back(space, x, y);
            auto metric = metrics.find(space);
            if (metric != metrics.end()) {
                x += metric->second.advance + spacing;
            }
        }
        shaping.emplace_back(chr, x, y);
        auto metric = metrics.find(chr);
        if (metric != metrics.end()) {
            x += metric->second.advance + spacing;
        }
        i++;
    }
    
  6. barrycug commented on Apr 8, 2015

    @barrycug
    Author

    the code only support 2 line wrapped.

  7. mikemorris commented on Apr 8, 2015

    @mikemorris
    Contributor

    Thanks for the detailed explanation @barrycug and @friedbunny! The "proper" way to implement this would probably be to use something like ICU's BreakIterator for boundary analysis, then calculate the width of glyph clusters similarly to Mapnik and split on the closest break point. A similar approach for complex scripts that require shaping is described at http://lists.freedesktop.org/archives/harfbuzz/2014-February/004140.html

  8. mikemorris commented on Apr 8, 2015

    @mikemorris
    Contributor
  9. friedbunny commented on Apr 8, 2015

    @friedbunny
    Contributor

    That's really interesting reading and looks like the ideal path to pursue, thanks @mikemorris. Do you have any idea how feasible it would be to do this properly/robustly in GL?

  10. mikemorris commented on Apr 8, 2015

    @mikemorris
    Contributor

    @friedbunny I think it should be pretty straightforward to implement in gl-native because of existing libraries like ICU and HarfBuzz; the challenge will mostly be avoiding performance slowdowns and minimizing bloat. I'd like to tackle this in conjunction with other render-time glyph issues like complex text shaping and RTL/bidirectional script support.

    What I expect will be difficult is implementing comparable functionality in mapbox-gl-js, as I'm not sure if it would be feasible to bundle (or request dynamically) contextual line-breaking support or shaping tables, and I don't know any existing JavaScript libraries that have already solved these problems.

  11. added this to the milestone on Apr 13, 2015
  12. mikemorris commented on Dec 9, 2015

    @mikemorris
    Contributor
  13. 1ec5 commented on Oct 19, 2016

    @1ec5
    Contributor

    CJK line breaking is orthogonal to complex text shaping. For example, the most cartographically sound way to wrap Chinese text (but not Japanese or Korean) would be character by character, keeping the lines balanced.

    Reopening.

  14. reopened this on Oct 19, 2016
  15. changed the title [-]Chinese Text can't support label wrapped[/-] [+]Line breaking by character for Chinese labels[/+] on Oct 19, 2016
  16. changed the title [-]Line breaking by character for Chinese labels[/-] [+]Chinese labels should be wrapped by character with balanced lines[/+] on Oct 19, 2016
  17. added 2 commits that reference this issue on Nov 12, 2016
    3c5445e
    c857312
  18. added a commit that references this issue on Nov 14, 2016
    dbd2235
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions