aya-dev icon indicating copy to clipboard operation
aya-dev copied to clipboard

Doc page width problem

Open imkiva opened this issue 2 years ago • 7 comments

Try the following case:

var d = Doc.english("You are right, but \"Genshin Impact\" is a brand new open world adventure game by MHY.");
System.out.println(d.renderToString(16, false));

Doc will be rendered as

You are right, but
"Genshin Impact"
is a brand new open
world adventure game
by MHY

There are lines exceeding the width of 16.

imkiva avatar Dec 11 '22 11:12 imkiva

I super, original

ice1000 avatar Dec 11 '22 12:12 ice1000

The doc printer checks whether to insert a line break or a space only in FlatAlt and Union, while Doc.english is a sequence of plain(), line(), plain(), line(), ... (line() is short for FlatAlt(a whitespace, a line break)).

imkiva avatar Dec 11 '22 12:12 imkiva

The sentence above is cut into

plain(You), line(), plain(are), line(), plain(right,), line(), plain(but), line()

When the doc printed "You are right," to output, there were 2 printable widths remaining. And now we are printing the line() after plain(right,). (As described, line() = FlatAlt(a whitespace, a line break)).

  • Doc printer checks if line remaining >= width of a whitespace, which evaluates to true.
  • So whitespace is printed, and now the line remains only 1 character.
  • Then we are printing plain(but), but this time we don't check the width.

imkiva avatar Dec 11 '22 12:12 imkiva

Not really fixed

imkiva avatar Dec 11 '22 14:12 imkiva

What about a plain(but) with page width 1 ?

HoshinoTented avatar Dec 12 '22 10:12 HoshinoTented

What about a plain(but) with page width 1 ?

It will be rendered as: (no line break is inserted)

but

imkiva avatar Dec 12 '22 16:12 imkiva

You can preview the result with WidthPreviewToy 😉

imkiva avatar Dec 12 '22 16:12 imkiva