-
Notifications
You must be signed in to change notification settings - Fork 24
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
vjust
is not respected on linux
#55
Comments
Hi @albert-ying. Thanks for using the package, and bringing this to our attention. It's not clear to me why this bug would show up on one system and not another. I'm assuming you have tried a new R session and the latest development version of If so, would you mind checking the behaviour of a slightly modified version of the code so that we can try to track this down? If you modify the function to plot_vjust <- function(vjust) {
ggplot(df, aes(x, y)) +
geom_textpath(aes(label = label, vjust = vjust)) +
geom_text(x = 2, y = 1, label = "geom_text", vjust = vjust) +
ggtitle(paste0("vjust = ", vjust)) +
scale_x_continuous(limits = c(-1, 3)) +
scale_vjust_identity()
} Do you still get the same behaviour? |
Yes. I tried your modified code, it gives me the same result. I noticed that when I save the plot as PDF, it gives the weird-looking font Might be related to the rendering of the text/font? updateThe font looks normal after I specify the
|
Thanks for trying that Albert. It looks to me as though the spacing is being increased between letters in the pdf version until you specify "family". Ultimately, both versions are drawn with the same font using Thanks again |
Not just Thank you for looking at it!
|
Strange, I get the following on Linux, where the textpath does seem responsive to library(ggplot2)
library(geomtextpath)
library(patchwork)
df <- data.frame(
x = seq(-0.5, 1.5, length.out = 10),
y = 1,
label = "geom_textpath"
)
plot_vjust <- function(vjust) {
ggplot(df, aes(x, y)) +
geom_textpath(aes(label = label), vjust = vjust) +
annotate(x = 2, y = 1, label = "geom_text", geom = "text", vjust = vjust) +
ggtitle(paste0("vjust = ", vjust)) +
scale_x_continuous(limits = c(-1, 3))
}
p = plot_vjust(-1) + plot_vjust(0) + plot_vjust(1) + plot_vjust(2) + plot_vjust(10) + plot_vjust(15)
p Created on 2022-01-13 by the reprex package (v2.0.0) But something seems off about vjust anyhow, it doesn't quite follow the vanilla text offsets. The text spacing looks weird as well. Update: text spacing issue seems device dependent (doesn't appear when using ragg). |
Hmm I'm on R 4.1.1, Ubuntuk 16.04.6. Is there any system-related dependency that might be related to this? |
I'm not aware that we'd have such dependencies, we don't have any compiled code in geomtextpath. geomtextpath:::measure_label("AB\nCD")[[1]]
#> glyph ymin xmin xmid xmax substring y_id
#> 1 A 0.1116536 0.009331597 0.06488715 0.1204427 1 2
#> 2 B 0.1116536 0.120442708 0.17599826 0.2315538 1 2
#> 3 C -0.1116536 0.000000000 0.06011285 0.1202257 1 3
#> 4 D -0.1116536 0.120442708 0.18055556 0.2406684 1 3 Created on 2022-01-13 by the reprex package (v2.0.1) The exact values can vary slightly due to the fonts available (this was Arial on windows), but I'm interested to see if the |
I have tracked down part of the problem. You'll notice that the geomtextpath position is wrong when vjust == 1. This is actually due to a bug in one of the dependencies (textshaping), which gives the wrong y position when vjust is exactly 1: textshaping::shape_text('hello', vjust = 1)
#> $shape
#> # A tibble: 5 x 7
#> glyph index metric_id string_id x_offset y_offset x_midpoint
#> <int> <int> <int> <int> <dbl> <dbl> <dbl>
#> 1 0 75 1 1 0 0 3.33
#> 2 1 72 1 1 6.67 0 3.33
#> 3 2 79 1 1 13.3 0 1.33
#> 4 3 79 1 1 16.0 0 1.33
#> 5 4 82 1 1 18.7 0 3.33
#>
#> $metrics
#> # A tibble: 1 x 11
#> string width height left_bearing right_bearing top_bearing bottom_bearing
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 hello 25.4 24.3 0.797 0.438 2.27 2.41
#> # ... with 4 more variables: left_border <dbl>, top_border <dbl>, pen_x <dbl>,
#> # pen_y <dbl>
textshaping::shape_text('hello', vjust = 1 + .Machine$double.eps)
#> $shape
#> # A tibble: 5 x 7
#> glyph index metric_id string_id x_offset y_offset x_midpoint
#> <int> <int> <int> <int> <dbl> <dbl> <dbl>
#> 1 0 75 1 1 0 -10.9 3.33
#> 2 1 72 1 1 6.67 -10.9 3.33
#> 3 2 79 1 1 13.3 -10.9 1.33
#> 4 3 79 1 1 16.0 -10.9 1.33
#> 5 4 82 1 1 18.7 -10.9 3.33
#>
#> $metrics
#> # A tibble: 1 x 11
#> string width height left_bearing right_bearing top_bearing bottom_bearing
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 hello 25.4 24.3 0.797 0.438 2.27 2.41
#> # ... with 4 more variables: left_border <dbl>, top_border <dbl>, pen_x <dbl>,
#> # pen_y <dbl>
textshaping::shape_text('hello', vjust = 1 - .Machine$double.eps)
#> $shape
#> # A tibble: 5 x 7
#> glyph index metric_id string_id x_offset y_offset x_midpoint
#> <int> <int> <int> <int> <dbl> <dbl> <dbl>
#> 1 0 75 1 1 0 -10.8 3.33
#> 2 1 72 1 1 6.67 -10.8 3.33
#> 3 2 79 1 1 13.3 -10.8 1.33
#> 4 3 79 1 1 16.0 -10.8 1.33
#> 5 4 82 1 1 18.7 -10.8 3.33
#>
#> $metrics
#> # A tibble: 1 x 11
#> string width height left_bearing right_bearing top_bearing bottom_bearing
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 hello 25.4 24.3 0.797 0.438 2.27 2.41
#> # ... with 4 more variables: left_border <dbl>, top_border <dbl>, pen_x <dbl>,
#> # pen_y <dbl> I'm guessing that the bug is further-reaching on some systems? Created on 2022-01-13 by the reprex package (v2.0.1) |
Yeah I defensively coded against that bug previously: Lines 44 to 45 in 616d6b5
But this I forgot to catch that bug when I refactored the code at some point. I've already included it in my local version, so it'll be fixed after the next PR. AFAIK, it shouldn't affect any other vjust values. |
Here is my output, the ymin indeed does not vary
|
Thanks! That narrows it down to a particular part of the code. |
Is this perhaps a problem with @albert-ying -In a fresh R session with your normal default settings, the following function will return the value of the y offset (in pixels) for different values of vjust, given default font values: f <- function(x) textshaping::shape_text('x', vjust = x)$shape$y_offset For example, I get f(0)
#> [1] 0
f(0.5)
#> [1] -5.421875 The symptoms you describe suggest that there is a problem with If I am right about this, then it suggests that on your system, every glyph height is somehow being measured as 0. This would happen, for example, if you passed a font size of 0, or if your device height was 0. We know that the font size is not 0, since the x measurements are correct. The most likely cause I can see for this is that the device height is somehow being registered as 0 in the |
Yes, you are right! @AllanCameron
|
Thanks for trying that @albert-ying From looking at the |
Thank you for helping and figuring out the root cause! Although I failed to link the new version of HarfBuzz to |
Hi, thank you for this amazing package! I noticed that for some reason the
geomtextpath
doesn't respond tovjust
value on my linux machine. This bug doesn't appear on my macOS machine thoHere is the code I copyed from a previous issue
And this is my output on Linux machine: you can see the
geom_textpath
does not respond tovjust
value likegeom_text
Here is my sessionInfo
Thank you!
The text was updated successfully, but these errors were encountered: