Skip to content
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

Flow text into frames #499

Open
goyalyashpal opened this issue Jan 22, 2023 · 2 comments
Open

Flow text into frames #499

goyalyashpal opened this issue Jan 22, 2023 · 2 comments

Comments

@goyalyashpal
Copy link

goyalyashpal commented Jan 22, 2023

  • fantasizingly: this can be made non-constant to get some pretty dashing ASCII art flowing inside some particular shape like in inkscape. wow.

Textwrap takes a list of widths when wrapping text. This allows you to do things like cut out space for figures, but you also go further and wrap text inside circles, triangles and so on.
I don't think it's very well known since i haven't created any demos with this yet 🙂

Originally posted by @mgeisler in helix-editor/helix#136 (comment)

wowww, that's super nice. Exactly what i was thinking.

  • Do you have any idea how will you generate that list of widths?
  • I can think that it will require some sort of stepped interpolation of the required curve at fixed intervals.
  • Image editors likely do this inside.
  • But i don't know how would i do this?

Title inspired by inkscape: ddg 🔍 : inkscape flow text

@goyalyashpal
Copy link
Author

goyalyashpal commented Jan 22, 2023

OT:

while searching for possible duplicates, i stumbled upon this: #205 (comment) and wow, that can be used to implement typora like markup table source prettifier. nice.

@mgeisler
Copy link
Owner

Hi @goyalyashpal, thanks for writing! I'm glad you like this (mostly unknown) feature 😄

  • Do you have any idea how will you generate that list of widths?

I'm no expert on this, but I would imagine a desktop publishing (DTP) program would want to reserve a certain height and width for an embedded figure. So the program would do something like this

  • The figure is 24 mm in height and 40 mm in width.
  • The normal line width is 150 mm.
  • The line height is 6 mm.

Thus, we need to shrink 10 lines by 40 mm. If the picture starts on line 3, the DTP program would have to use [150, 150, 110, 110, 110, 110, 150] as the line widths (the last line width is repeated as necessary). This should allow the DTP program to format a single paragraph with a cut-out for the figure.

Note that Textwrap fundamentally likes to format paragraphs. It also works with multiple paragraphs, but that's just because it splits on \n and formats each line by itself. A program that anchors a figure to paragraph would definitely want to format that paragraph by itself.

In the example above, one could imagine that the formatted paragraph is not height enough to contain the full figure:

Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore  +--------+
magnam aliquam quaerat .        |        |
                                |        |
                                +--------+

The program can detect this because the wrapped paragraph has a height of 4 lines = 24 mm, but the picture started 2 lines down (12 mm) and it 24 mm tall. So the program knows that the picture sticks out by 12 mm or 2 lines. It can use this information to wrap the following paragraph appropriately (using [110, 150] as the line widths, assuming the paragraphs are spaced by 1 line of 6 mm).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants