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

Italic text alignment #4777

Open
3 tasks done
aplavin opened this issue Feb 11, 2025 · 4 comments
Open
3 tasks done

Italic text alignment #4777

aplavin opened this issue Feb 11, 2025 · 4 comments
Labels

Comments

@aplavin
Copy link
Contributor

aplavin commented Feb 11, 2025

I noticed that adding italic text to the legend moves the text down a bit compared to regular font – notice that the 2nd entry has a larger padding at the top and a smaller padding at the bottom:

with_theme(theme_latexfonts()) do
	scatter(rand(10), label="Abc")
	scatter!(rand(10), label=rich(rich("Def", font=:italic), "Def"))
	scatter!(rand(10), label="Xyz")
	axislegend()
	current_figure()
end

Image
The workaround I found for now is this:

let l = axislegend()
	# XXX: to fix italic text valign
	lab = content(l.grid[1,1][2,2])  # target label that has italic
	lab.padding[] = (0,0,0,-3)
	lab.tellheight[] = false
end

But would be great to align the text automatically so that both italic and regular fonts are consistent.

  • what version of Makie are you running? (]st -m Makie) 0.21
  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)
  • What platform + GPU are you on? any
@aplavin aplavin added the bug label Feb 11, 2025
@jkrumbiegel
Copy link
Member

jkrumbiegel commented Feb 11, 2025

That is not a bug, simply a consequence of the font metrics. You can see that the italic font has a much larger ascender than descender, so when vertically centered the visual result is not really centered.

I have actually made my own version of our default font TeX Gyre Heros because of this, I wanted good vertical centering so I adjusted the ascenders and descenders accordingly.

with_theme(theme_latexfonts()) do
    f = Figure(fontsize = 50)
    gl1 = GridLayout(f[1, 1], valign = :bottom)
    gl2 = GridLayout(f[1, 2], valign = :bottom)
    colgap!(f.layout, 0)
    Box(gl1[1, 1])
    Label(gl1[1, 1], "ABC", font = :italic)
    Box(gl2[1, 1])
    Label(gl2[1, 1], "ABC")
    f
end
Image

@aplavin
Copy link
Contributor Author

aplavin commented Feb 11, 2025

Thanks for the pointers! I'm not deeply familiar with fonts and their metrics, just looking for a nice workaround to get the uniform visual alignment (preferably without manually digging into legend/layout internals). Maybe a different default latex font then?

@jkrumbiegel
Copy link
Member

Yes if you find a different font variant that would be the easiest solution.

@aplavin
Copy link
Contributor Author

aplavin commented Feb 11, 2025

I wonder if a font-independent solution could work as well – for example, to constrain the rendered lineheight to be the same for all legend entries. Doesn't matter which one is chosen (probably the largest), just that it's consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants