Skip to content

Status of wrap-character option at 3.x #2333

Closed

Description

@springmeyer

At Mapnik 3.x we now support better text boundary handling (http://userguide.icu-project.org/boundaryanalysis) and line breaking is automatically done by the ICU BreakIterator::createLineInstance (btw, see #2072 too). This means that:

  • The wrap-character option is no longer respected and should be removed from the code base to avoid confusion.
  • Supporting breaking on a user provided character is no longer supported. In the future we could perhaps look into a custom RuleBasedBreakIterator to be able to re-introduce this support. However this is unlikely to work well.
  • Supporting language-specific breaking is more likely to become a future need, and this will be tricky. Currently we hardcode the default Locale:
    Locale locale; // TODO: Is the default constructor correct?
    UErrorCode status = U_ZERO_ERROR;
    BreakIterator *breakitr = BreakIterator::createLineInstance(locale, status);

Activity

  1. added this to the milestone on Aug 4, 2014
  2. springmeyer commented on Sep 4, 2014

    @springmeyer
    MemberAuthor

    re-opening to consider:

    • backwards compatibility shim so that load_map does not throw if parameter is present
    • what it would take to still support it

    /cc @ajashton

  3. artemp commented on Sep 8, 2014

    @artemp
    Member

    @springmeyer - we can force breaks by modifying itemizer:

    while ((start = text_.indexOf('\n', start)+1) > 0)
    . For example inserting new line character after 'wrap-char' if it's not '\n' ? But in this case if should really be called break-char. RuleBasedIterator, I think would be quite expensive to initialise per text line:
    BreakIterator *breakitr = BreakIterator::createLineInstance(locale, status);

    "...The setText() or the adoptText() method can be called more than once, allowing a single BreakIterator to be reused to analyze different pieces of text. Because the creation of a BreakIterator can be relatively time-consuming, it makes good sense to cache and reuse BreakIterators within an application. "

    ^^ Strangely, despite documentation stating that BreakIterator should be re-used I'm getting almost 2x slow down when creating it at:

    for (unsigned i = 0; i < num_lines; ++i)

    @ajashton - have you got a use case I can work with ?

  4. springmeyer commented on Sep 8, 2014

    @springmeyer
    MemberAuthor

    @ajashton - have you got a use case I can work with ?

    Open to ideas from @ajashton, but I think the usecase is just the way breaks worked before such that say you have a line of text line "this-is@a line@and another" and wrap-character="@" you'd get:

    this-is
    a line
    and another
    

    And the whitespace or hyphens would not be used to break. So, I'm thinking that when wrap-character is supplied we completely disable/ignore/stand-in-front of the ICU BreakIterator and don't let it do its smart things in the case where someone is asking for a manual break.

  5. ajashton commented on Sep 8, 2014

    @ajashton
    Member

    @springmeyer yes, that's basically the use case and enabling it would also have to mean disabling breaking on whitespace.

    However the wrap-character predates the implementation of the replace function in expressions which can cover the same use case ([text].replace('@', '\n')) and is actually more flexible. Given the major version bump I don't think we necessarily need to keep wrap-character around.

  6. pnorman commented on Sep 8, 2014

    @pnorman
    Contributor

    However the wrap-character predates the implementation of the replace function in expressions which can cover the same use case ([text].replace('@', '\n')) and is actually more flexible.

    Doesn't the wrap-character have the line break effects of a space, not a newline, while also preventing space from having its normal line break effects?

    e.g.I 50;I 51 will not be able to break on the spaces, but will on the ;?

  7. artemp commented on Sep 9, 2014

    @artemp
    Member

    b441586 - 'wrap-char' is back

    wrap-char=";" + wrap-width= -->

    I 50;
    I 51
    

    ^^ Is this what we're looking for ? I left wrap-char as part of the text - @ajashton ?

  8. Andrey-VI commented on Sep 10, 2014

    @Andrey-VI

    @artemp , great!
    But how to achieve this

    This-
    -is-
    -a-
    -test
    

    instead of

    This-
    is-
    a-
    test
    

    from This-is-a-test?

  9. artemp commented on Sep 10, 2014

    @artemp
    Member

    @Andrey-VI

    I just tried wrap-width="20" wrap-char="-" with text expression 'Mapnik-can do-fancy char wrap'.replace('-','--')

    char-wrap

    Note: this only works if wrap-width is forcing text breaks

    Is this kind of text-wrapping specific to cartographic text or is it used in general ?

  10. Andrey-VI commented on Sep 10, 2014

    @Andrey-VI

    Oh, my fault.

    This-
    -is-
    -a-
    -test
    

    is a very bad example. A good one

    This-
    -is-a-
    -test
    

    So, if you try 'Mapnik-can-do-fancy-char-wrap'.replace('-','--'), you get

    Mapnik-
    -can-
    -do-
    -fancy-
    -char-
    -wrap
    

    I believe.
    But I need something like

    Mapnik-can-do-
    -fancy-char-
    -wrap
    

    instead.

  11. artemp commented on Sep 10, 2014

    @artemp
    Member

    @Andrey-VI - I just added 'length(') function which is useful but perhaps not in your use-case

    <Filter>length([name]) > 10</Filter>

  12. artemp commented on Sep 10, 2014

    @artemp
    Member

    I will need to think how we can support this kind 'custom' text wrapping. We might need to add an extra parameter but at this moment I really need to understand if this is something really 'niche' or more common across international cartographic text.
    /cc @ajashton @springmeyer

  13. Andrey-VI commented on Sep 10, 2014

    @Andrey-VI

    I think this is a common practice to duplicate - on the new line after text wrapping.
    Just googled:
    swisstopo_bluemlisalp_50

    Blüemlisalp-
      -Rothorn
    

    Widely used on Russian maps:
    sw_braz

  14. artemp commented on Sep 10, 2014

    @artemp
    Member

    @Andrey-VI - I implemented repeat-wrap-char in f8dc7b0

    Input text 'Thisisatesta onea twoa three'
    wrap-char="~" wrap-width="100"

    repear-wrap-char

  15. Andrey-VI commented on Sep 10, 2014

    @Andrey-VI

    Thank you, Artem. Looks great!
    Unfortunately, I still can't test/use Mapnik 3.x due to incompatibility with mod_tile/renderd.

  16. springmeyer commented on Sep 14, 2014

    @springmeyer
    MemberAuthor

    Unfortunately, I still can't test/use Mapnik 3.x due to incompatibility with mod_tile/renderd.

    Use my branch: https://github.com/springmeyer/mod_tile

  17. changed the title [-]Remove wrap-character option at 3.x[/-] [+]Status of wrap-character option at 3.x[/+] on Sep 19, 2014
  18. springmeyer commented on Sep 22, 2014

    @springmeyer
    MemberAuthor

    wrap-character is now back, working, has basic tests, and a supports being an expression (#2424). Any followups can be made in new tickets like #2427

  19. yohanboniface commented on Nov 11, 2014

    @yohanboniface
    Member

    Thanks @artemp for the new repeat-wrap-character rule, very useful! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions