You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed "sometimes" I had problems with text labels, compressing or expanding whitespace between words.
I also saw some issues here and on ggtext.
I may have found a reproducible test case!
My question: How can I track it down?
TL;DR
My spark: I noticed that calling gridtext::richtext_grob() would open a new graphics device if not already open.
I think the symptoms below are caused when the first graphics device is opened.
If that device opens "as expected by gridtext", font/kerning calculations are fine.
If that device opens "unexpectedly" then font/kerning is incorrect.
It seems to be cached.
It doesn't appear to happen with grid::textGrob().
Scenario 1.
Using gridtext within RStudio, or R console when the graphics device is already open.
Using gridtext on R console when the graphics device is not open.
(Same R code.)
(Admittedly, the wider spacing isn't super obvious, I promise it gets obvious.)
Scenario 3.
Using gridtext in an RMarkdown, with dev=c("png", "cairo_pdf")
(Same R code, but inside an RMarkdown.)
^^ Much more obvious.
This is the cool one, because it shows the whitespace isn't just incorrect, it's also inconsistent! Aha.
Also for RMarkdown:
Using dev=c("png", "cairo_pdf") causes both the PNG and PDF files to have the exact same weird spacing shown above.
In fact, using any combination of multiple output dev devices causes the same weird spacing to appear in all of them.
However, using any one dev such as dev="png" or dev="cairo_pdf" the font spacing seems fine... weirdly one exception is dev="jpeg" - that's always incorrect spacing. (I think rmarkdown:render() secretly adds "png" only for this case.)
Also when I try grid::textGrob() it always calculates proper spacing.
To be fair, it isn't doing the same work as richtext_grob(). But it isn't likely a grid issue.
Questions
Do you or others see the same behavior?
(Is it just me?)
Why and when does gridtext open a graphical device?
Maybe some call to par()?
Does gridtext cache the font metrics somewhere?
I think yes.
If I try Scenario 2 first, with no device open upfront, it creates the wrong spacing. If I close dev.off() then run dev.new() and repeat, in the same R session, it keeps using the same wrong spacing consistently.
If I try Scenario 1, open dev.new() upfront, then create the grob, the spacing is normal. If I close and open a new device, spacing is consistently normal in that R session.
The above are moot for rendering RMarkdown, since it creates its own session, or something.
Love the package, love your work. Big fan. ahem
I noticed "sometimes" I had problems with text labels, compressing or expanding whitespace between words.
I also saw some issues here and on ggtext.
I may have found a reproducible test case!
My question: How can I track it down?
TL;DR
My spark: I noticed that calling
gridtext::richtext_grob()
would open a new graphics device if not already open.I think the symptoms below are caused when the first graphics device is opened.
If that device opens "as expected by gridtext", font/kerning calculations are fine.
If that device opens "unexpectedly" then font/kerning is incorrect.
It seems to be cached.
It doesn't appear to happen with
grid::textGrob()
.Scenario 1.
Using
gridtext
within RStudio, or R console when the graphics device is already open.Falalalala lala la la. It looks great.
Scenario 2.
Using
gridtext
on R console when the graphics device is not open.(Same R code.)
(Admittedly, the wider spacing isn't super obvious, I promise it gets obvious.)
Scenario 3.
Using
gridtext
in an RMarkdown,with dev=c("png", "cairo_pdf")
(Same R code, but inside an RMarkdown.)
^^ Much more obvious.
This is the cool one, because it shows the whitespace isn't just incorrect, it's also inconsistent! Aha.
Also for RMarkdown:
Using
dev=c("png", "cairo_pdf")
causes both the PNG and PDF files to have the exact same weird spacing shown above.In fact, using any combination of multiple output
dev
devices causes the same weird spacing to appear in all of them.However, using any one
dev
such asdev="png"
ordev="cairo_pdf"
the font spacing seems fine... weirdly one exception isdev="jpeg"
- that's always incorrect spacing. (I thinkrmarkdown:render()
secretly adds "png" only for this case.)Also when I try
grid::textGrob()
it always calculates proper spacing.To be fair, it isn't doing the same work as
richtext_grob()
. But it isn't likely agrid
issue.Questions
Do you or others see the same behavior?
(Is it just me?)
Why and when does
gridtext
open a graphical device?Maybe some call to
par()
?Does
gridtext
cache the font metrics somewhere?I think yes.
dev.off()
then rundev.new()
and repeat, in the same R session, it keeps using the same wrong spacing consistently.dev.new()
upfront, then create the grob, the spacing is normal. If I close and open a new device, spacing is consistently normal in that R session.Can it be fixed?
Session Info
The text was updated successfully, but these errors were encountered: