4

I'd like to flow text into a region defined by a curve, such as:

pts = {{0, 0}, {1, 1}, {2, -1}, {3, 0}, {5, 2}, {6, -1}, {7, 3}, {0, 1}, {0, 0}};
Graphics[BezierCurve[pts]]

enter image description here

The text must flow so that every character appears, as shown here.

Here is an example from this page.

enter image description here

(It is unacceptable to use the contour to produce a mask and "hide" some characters outside the contour.)

I could put in new line characters by hand, but this is unacceptable as the regions are quite complex, and every time I adjust the font size I'd have to go back and alter every new line character by hand.

It is also important that the final figure be in .eps (or .pdf), so some pixel-based methods simply will not work.

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
David G. Stork
  • 41,180
  • 3
  • 34
  • 96
  • Could you be more explicit about what flow means? – Greg Hurst Oct 19 '19 at 19:04
  • Simply fill the region with the letters in sequence order: https://www.istudiopublisher.com/help-pages/pgs/text-flow-tool.html – David G. Stork Oct 19 '19 at 19:48
  • a Y problem (that may well be as difficult as the X problem): Can we keep the original ordering of the words/characters in input string and suppress randomization of positions in WordCloud? If we knew how to solve the Y problem we could use something like WordCloud[MapIndexed[DynamicWrapper] @StringSplit[strng," "|"\n"|","],Graphics[{White,FilledCurve[{BezierCurve[pts]}]}, Background->Black],FontSize->{Scaled[.01],Scaled[.01]},ImageSize->Large,PreprocessingRules->None, WordSelectionFunction->(True&),ColorFunction->(Black&),WordSpacings->{15,15}] – kglr Oct 19 '19 at 23:19
  • @kglr: Thanks. Can you modify your code to work on just a paragraph or two of given text? – David G. Stork Oct 19 '19 at 23:20
  • David, I used the first argument in the 4th example in WordCloud >> Scope >> Data as strng. – kglr Oct 19 '19 at 23:25
  • @kglr: Oh gee... it works! Post this as a solution and I'll accept it. Again, you solve the subtle, hard problems and prove again an unsurpassed knowledge of Mathematica. – David G. Stork Oct 19 '19 at 23:38
  • 2
    David, on v12.0.0 on Wolfram Cloud front-end the ordering of characters is not preserved and the vertical positions of words are jittered (they are not on a straight line). Do you not get the same issue on desktop version? (thank you again for the kind words btw) – kglr Oct 19 '19 at 23:45
  • 1
    @kglr: Ah... I had just realized that word order is not preserved, so no... this doesn't quite work. I'm v. 11.3.0 on a Mac. – David G. Stork Oct 19 '19 at 23:49
  • 1
    the approaches in the q/a's How can I wrap text around a circle? and Movable text on a curve also look promising as a first step. – kglr Oct 20 '19 at 00:01

0 Answers0