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

Multi lines TextSymbolizer upside down #3857

Open
NasH5169 opened this issue Feb 14, 2018 · 11 comments
Open

Multi lines TextSymbolizer upside down #3857

NasH5169 opened this issue Feb 14, 2018 · 11 comments

Comments

@NasH5169
Copy link

Hi Mapnik !

Sometimes with a TextSymbolizer and multilines text (Line1\nLine2\nLine3), the first line is near upside down, some rotation is applied, I don't understand why.

Please find the XML style code and an image to illustrate this.

Thanks for help.

issue_mapnik_text_on_his_back

<Rule>
	<TextSymbolizer
		face-name="DejaVu Sans Bold" size="16"
		fill="[POLYCOLOR]"
		halo-fill="white" halo-radius="2.0"
		placement="line"
		max-char-angle-delta="1"
		spacing="1750"
		clip="false"
		dy="-5">
		<![CDATA[[NAME]]]>
	</TextSymbolizer>
</Rule>
@talaj
Copy link
Member

talaj commented Feb 19, 2018

I cannot reproduce it. Can you make a simple test case I can run? Something like visual test.

@NasH5169
Copy link
Author

Yes you're right, I should write a test case and test it. Will do it. But, sorry for my silly question, how to render the .xml?

For example, I've done this py renderer but the image is empty.

#!/usr/bin/env python2.7

import mapnik
import sys, os, math

map = mapnik.Map(512, 512)
mapnik.load_map(map, "/home/me/polygon-placement-168.xml")
mapnik.render_to_file(map, '/home/me/polygon-placement-168.png', 'png')

@talaj
Copy link
Member

talaj commented Feb 20, 2018

You have to say which extent to render either by

map.zoom_all()

or by

bbox = mapnik.Envelope(-1, -1, 1, 1)
map.zoom_to_box(bbox)

@NasH5169
Copy link
Author

NasH5169 commented Feb 20, 2018

Yes ! That's it.

I think the poly is not big enough to enclose the multi lines text so the first line is rotated.

I will make further tests to workaround this issue.

Thanks again.

The .xml file

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
    <Layer name="layer" srs="+proj=latlong +datum=WGS84">
        <StyleName>lines</StyleName>
        <StyleName>text</StyleName>
        <Datasource>
            <Parameter name="type">csv</Parameter>
            <Parameter name="inline">
                wkt
                "POLYGON((5.793056 47.863056, 5.608333 47.741667, 6.003611 47.660000, 6.246944 47.611111, 6.445556 47.556944, 6.490000 47.605833, 6.486822 47.604866, 6.479822 47.602804, 6.472746 47.600863, 6.465599 47.599047, 6.458386 47.597355, 6.451111 47.595789, 6.443779 47.594351, 6.436389 47.593056, 6.284167 47.629722, 6.279210 47.630871, 6.272703 47.632563, 6.266269 47.634378, 6.259913 47.636315, 6.253611 47.638333, 6.253617 47.638671, 6.253514 47.640780, 6.253214 47.642880, 6.252719 47.644963, 6.252030 47.647021, 6.251150 47.649046, 6.250083 47.651029, 6.248832 47.652963, 6.247404 47.654839, 6.245802 47.656651, 6.244035 47.658391, 6.242109 47.660052, 6.240031 47.661627, 6.237810 47.663111, 6.235455 47.664497, 6.232975 47.665780, 6.230379 47.666954, 6.227680 47.668016, 6.224886 47.668960, 6.222010 47.669783, 6.219062 47.670482, 6.216055 47.671054, 6.213000 47.671496, 6.209910 47.671807, 6.206797 47.671986, 6.203674 47.672031, 6.200552 47.671944, 6.197446 47.671723, 6.194365 47.671370, 6.191324 47.670887, 6.188333 47.670278, 6.187380 47.670696, 6.182572 47.674118, 6.177908 47.677630, 6.173393 47.681229, 6.169029 47.684913, 6.164821 47.688679, 6.160771 47.692523, 6.156883 47.696443, 6.153160 47.700435, 6.149605 47.704497, 6.146220 47.708624, 6.143010 47.712815, 6.139975 47.717064, 6.137119 47.721370, 6.134444 47.725729, 6.131952 47.730136, 6.129645 47.734590, 6.127524 47.739085, 6.125593 47.743619, 6.123852 47.748188, 6.122303 47.752789, 6.120947 47.757417, 6.119784 47.762069, 6.118817 47.766741, 6.118046 47.771429, 6.117472 47.776131, 6.117095 47.780842, 6.116667 47.785556, 6.038611 47.775278, 5.793056 47.863056))"
            </Parameter>
        </Datasource>
    </Layer>
    <Style name="lines">
        <Rule>
            <LineSymbolizer
                stroke-width="12"
                stroke="rgb(255, 100, 100)" />
        </Rule>
    </Style>
    <Style name="text">
        <Rule>
            <TextSymbolizer
                face-name="DejaVu Sans Bold" size="28"
                fill="white"
                halo-fill="red" halo-radius="2.0"
                placement="line"
                spacing="300"
                clip="false"
                dy="-10">
                "First line\nSecond line"
            </TextSymbolizer>
        </Rule>
    </Style>
</Map>

The .py file

#!/usr/bin/env python2.7

import mapnik
import sys, os, math

map = mapnik.Map(2000, 2000)
mapnik.load_map(map, "/home/me/text-on-polygon.xml")
map.srs = '+proj=latlong +datum=WGS84'
map.zoom_all()
mapnik.render_to_file(map, '/home/me/text-on-polygon.png', 'png')

text-on-polygon

@talaj
Copy link
Member

talaj commented Feb 21, 2018

Thanks for the test case, I will try to take a look asap.

@talaj
Copy link
Member

talaj commented Feb 22, 2018

One more question, what is your version of Mapnik?

@NasH5169
Copy link
Author

My Mapnik version is 3.1.0. As far as i remember, i've always seen this issue.

@talaj
Copy link
Member

talaj commented Feb 23, 2018

It is strange that I cannot reproduce your rendering. Do you have some patches applied to your Mapnik? I have tried latest master, which is basically 3.1.0, and 3.0.18.

Anyway, I think the problem is related to #2952.

This is what I have got from the test case:
test-multiline-upside-down-2000-2000-1 0-agg

@NasH5169
Copy link
Author

Yes I forgot it. We just revert the vertex_cache.cpp to avoid the not well centered multi lines.

https://github.com/mapnik/mapnik/pull/2953/files

talaj added a commit to mapycz/mapnik that referenced this issue Feb 23, 2018
@talaj
Copy link
Member

talaj commented Feb 23, 2018

I have fixed it hopefully in mapycz@7721864. The problem is specific to your Mapnik with reverted #2953 so I cannot apply the fix to the upstream.

The problem was following. Individual lines of multi line text are placed on offset lines, like depicted in the image below. The algorithm finds starting positions for each line by finding closest position on offset line from original line. It happened in the narrow part of the polygon, that algorithm found closest position on part of the offset line that goes to the opposite direction. The fix controls that directions of offset and original line in starting positions are about the same.

test-multiline-upside-down-2000-2000-1 0-agg

@NasH5169
Copy link
Author

Wonderful ! I'll test your fix. Thanks you so much.

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

3 participants