Giter Club home page Giter Club logo

Comments (5)

teunbrand avatar teunbrand commented on July 24, 2024

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.

AllanCameron avatar AllanCameron commented on July 24, 2024

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.

AllanCameron avatar AllanCameron commented on July 24, 2024

But yes, I'm happy to take a look at textshaping to get the string positioning better.

from geomtextpath.

teunbrand avatar teunbrand commented on July 24, 2024

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.

AllanCameron avatar AllanCameron commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.