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

d.vect: label vertical alignment workaround #2857

Merged
merged 3 commits into from
Nov 21, 2023
Merged

Conversation

marisn
Copy link
Contributor

@marisn marisn commented Feb 24, 2023

Although more fine-grained control over label placement would be better, this PR at least makes labelling to work as intended.
Fixes #2854

@nilason
Copy link
Contributor

nilason commented Feb 24, 2023

This is the output with Cairo:
map

@nilason
Copy link
Contributor

nilason commented Feb 24, 2023

Using:

#!/bin/sh

# nc_spm_full_v2alpha2

echo "1|629880|222510|a
2|629882|222510|b
3|629884|222510|c
4|629886|222510|d
5|629888|222510|e
6|629890|222510|f
7|629892|222510|g
8|629894|222510|h
9|629896|222510|i
10|629898|222510|1
11|629900|222510|2
12|629902|222510|3
13|629904|222510|4
14|629906|222510|5
15|629908|222510|6
16|629910|222510|7
17|629912|222510|8
18|629914|222510|9" | v.in.ascii input=- output=labelmap cat=1 x=2 y=3 --overwrite

g.region e=629916 w=629879 s=222508 n=222512 res=1
d.mon start=cairo output=map.png --overwrite

d.vect map=labelmap color=0:29:57:255 width=1 \
    attribute_column=str_1 label_bcolor=13:0:200:255 \
    label_size=21 \
    yref=bottom xref=left

d.mon stop=cairo

@marisn
Copy link
Contributor Author

marisn commented Feb 24, 2023

That's strange as your example gives me (as expected):
image

@nilason
Copy link
Contributor

nilason commented Feb 24, 2023

Made another attempt with this PR, results are better (must have failed to build this PR correctly before), but centring doesn't work well (here top + center):

map

and with increased scale (greater region, larger distance between points):

map2

Script used, see in details:

#!/bin/sh

# nc_spm_full_v2alpha2

g.region e=629916 w=629879 s=222508 n=222512 res=1

echo "1|629880|222510|a
2|629882|222510|b
3|629884|222510|c
4|629886|222510|d
5|629888|222510|e
6|629890|222510|f
7|629892|222510|g
8|629894|222510|h
9|629896|222510|i
10|629898|222510|1
11|629900|222510|2
12|629902|222510|3
13|629904|222510|4
14|629906|222510|5
15|629908|222510|6
16|629910|222510|7
17|629912|222510|8
18|629914|222510|9" | v.in.ascii input=- output=labelmap cat=1 x=2 y=3 --overwrite

d.mon start=cairo output=map.png --overwrite

d.vect map=labelmap color=0:29:57:255 width=1 \
    attribute_column=str_1 label_bcolor=13:0:200:255 \
    label_size=17 \
    yref=top xref=center

d.mon stop=cairo

g.region raster=basin@PERMANENT res=100

echo "1|629880|222510|a
2|630000|222510|b
3|631000|222510|c
4|632000|222510|d
5|633000|222510|e
6|634000|222510|f
7|635000|222510|g
8|636000|222510|h
9|637000|222510|i
10|638000|222510|1
11|639000|222510|2
12|640000|222510|3
13|641000|222510|4
14|642000|222510|5
15|643000|222510|6
16|644000|222510|7
17|644500|222510|8
18|645000|222510|9" | v.in.ascii input=- output=labelmap2 cat=1 x=2 y=3 --overwrite

d.mon start=cairo output=map2.png --overwrite

d.vect map=labelmap2 color=0:29:57:255 width=1 \
    attribute_column=str_1 label_bcolor=13:0:200:255 \
    label_size=17 \
    yref=top xref=center

d.mon stop=cairo

@marisn
Copy link
Contributor Author

marisn commented Feb 24, 2023

I didn't touch the horizontal alignment code. It also seems to be in a need for a solution. Still I do not know how it should be made as vertical shift is easy movement of point of reference up/down by size * magic constant, then for horizontal it wouldn't work like that as length of string must be taken into account.

Note – vertical alignment seems to work fine as all letters seem to be aligned on the same baseline (note – „g“ letter goes below the line, „a“ doesn't and „b“, „f“ are taller than „g“ or „a“).

swap vertical alignment to match previous behaviour
@marisn
Copy link
Contributor Author

marisn commented Mar 23, 2023

@nilason can you, please, retest the PR if it is good now?

@neteler neteler added this to the 8.4.0 milestone Aug 16, 2023
Copy link
Member

@landam landam left a comment

Choose a reason for hiding this comment

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

I tested this PR (cairo 1.18).

map_before

PR applied:

map

Letter "G" is slightly shifted. But still PR brings significant improvement.

@marisn
Copy link
Contributor Author

marisn commented Nov 20, 2023

Letter "G" is slightly shifted. But still PR brings significant improvement.

@landam the "g" letter placement is intentional. Letters are aligned to baseline and not top or bottom. Note that "a", "c" and "e" are not as tall as "b", "d" and "f". And "g" does not jump up from its position as it goes below "a..f".

@landam
Copy link
Member

landam commented Nov 20, 2023

To my knowledge there is no request for change. @marisn So feel free to merge.

Copy link
Contributor

@nilason nilason left a comment

Choose a reason for hiding this comment

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

This is certainly an improvement. I was hoping to get some time to explore a "a proper fix" as you mentioned in the comment, perhaps with some input from e.g. https://wiki.inkscape.org/wiki/Text_Rendering_Notes#HarfBuzz, but in vain.
Looks good to me!

@landam
Copy link
Member

landam commented Nov 20, 2023

@marisn As you are marked as assignee, please consider merging this PR.

@marisn marisn merged commit d757e42 into OSGeo:main Nov 21, 2023
18 checks passed
@marisn marisn deleted the d_vect_label branch November 21, 2023 11:37
HuidaeCho pushed a commit to HuidaeCho/grass that referenced this pull request Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect label vertical alignment for certain font sizes
4 participants