Comments (5)
I think if we switch to {textshaping} instead of using strwidth()
, we automatically get this taken care of in the y_offset
parameter. Plus, it should taking care of kerning so that text would look more natural.
library(textshaping)
txt <- "This is a perfectly\nflat label"
shape <- shape_text(txt)
cbind(shape$shape, letter = unlist(strsplit(txt, character())))
#> glyph index metric_id string_id x_offset y_offset x_midpoint letter
#> 1 0 55 1 1 0.000000 13.40625 3.656250 T
#> 2 1 75 1 1 7.328125 13.40625 3.328125 h
#> 3 2 76 1 1 14.000000 13.40625 1.328125 i
#> 4 3 86 1 1 16.671875 13.40625 3.000000 s
#> 5 4 3 1 1 22.671875 13.40625 1.656250
#> 6 5 76 1 1 26.000000 13.40625 1.328125 i
#> 7 6 86 1 1 28.671875 13.40625 3.000000 s
#> 8 7 3 1 1 34.671875 13.40625 1.656250
#> 9 8 68 1 1 38.000000 13.40625 3.328125 a
#> 10 9 3 1 1 44.671875 13.40625 1.656250
#> 11 10 83 1 1 48.000000 13.40625 3.328125 p
#> 12 11 72 1 1 54.671875 13.40625 3.328125 e
#> 13 12 85 1 1 61.343750 13.40625 2.000000 r
#> 14 13 73 1 1 65.343750 13.40625 1.656250 f
#> 15 14 72 1 1 68.671875 13.40625 3.328125 e
#> 16 15 70 1 1 75.343750 13.40625 3.000000 c
#> 17 16 87 1 1 81.343750 13.40625 1.656250 t
#> 18 17 79 1 1 84.671875 13.40625 1.328125 l
#> 19 18 92 1 1 87.343750 13.40625 3.000000 y
#> 20 19 0 1 1 93.343750 13.40625 4.500000 \n
#> 21 20 73 1 1 0.000000 0.00000 1.656250 f
#> 22 21 79 1 1 3.328125 0.00000 1.328125 l
#> 23 22 68 1 1 6.000000 0.00000 3.328125 a
#> 24 23 87 1 1 12.671875 0.00000 1.656250 t
#> 25 24 3 1 1 16.000000 0.00000 1.656250
#> 26 25 79 1 1 19.328125 0.00000 1.328125 l
#> 27 26 68 1 1 22.000000 0.00000 3.328125 a
#> 28 27 69 1 1 28.671875 0.00000 3.328125 b
#> 29 28 72 1 1 35.343750 0.00000 3.328125 e
#> 30 29 79 1 1 42.015625 0.00000 1.328125 l
Created on 2021-11-16 by the reprex package (v1.0.0)
from geomtextpath.
I'm keen to minimize dependencies, but this does look very useful. Getting kerning right will help , but our biggest issue is really "tracking" - i.e. making the general text spacing right. I don't think its possible to get this exactly right, since by definition if text is on a curve then the spacing between the tops of the letters will be different from the bottom of the letters. However, I think I more or less fixed the tracking on my previous merge - the spiral example on the readme looks much better now, with consistent spacing as the curvature changes along the path. Previously, the spacing was too large when the text was above a tight curve, and too small when it was below a tight curve.
from geomtextpath.
But yes, I'm happy to take a look at textshaping
to get the string positioning better.
from geomtextpath.
I just realised that textshaping::shape_text()
is as good as identical to systemfonts::shape_text()
, which seems like a more versatile dependency if we're to take one (it also has a tracking
argument, which we could expose to the user if they wish to fiddle with it). I generally agree that we should keep dependencies to a minimum (dependencies of ggplot2 excepted), but I also don't want to become a professional typographer to build/maintain custom kerning and tracking functions.
from geomtextpath.
This feature is now implemented, though not working perfectly. To keep focused on fixing specifics, I'm closing this as a specific issue at the moment.
from geomtextpath.
Related Issues (20)
- label border? HOT 2
- geom_textsmooth() doesn't choose method if not explicitly set HOT 2
- Request something like "dodge" along path HOT 3
- Chinese character support HOT 3
- geom_labelsf() not recognizing aesthetics HOT 5
- While working with ragg, minuses aren't drawn HOT 2
- geom_textpath() always draw a empty box when label is ""
- Ignoring unknown parameters: text_smoothing HOT 10
- Feature request - multiple labels per line HOT 7
- geom_textsmooth computation fails if method argument is not specified HOT 3
- ggplot2 is separating size and linewidth HOT 2
- Negative values in geom_textcontour not appearing HOT 2
- geom_textlinerange HOT 1
- Question on angle HOT 1
- text_only in geom_labelsegment
- Feature request - avoid text overlapping
- two labels on same curve HOT 5
- straight argument unknown in geom_textsf() HOT 2
- `label` aesthetic in `geom_textdensity2d` HOT 2
- R 4.3.0 and glyphs 👀 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geomtextpath.