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

Doc page width problem #805

Open
imkiva opened this issue Dec 11, 2022 · 7 comments · Fixed by #806
Open

Doc page width problem #805

imkiva opened this issue Dec 11, 2022 · 7 comments · Fixed by #806

Comments

@imkiva
Copy link
Member

imkiva commented Dec 11, 2022

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 imkiva added this to the fridge milestone Dec 11, 2022
@ice1000
Copy link
Member

ice1000 commented Dec 11, 2022

I super, original

@imkiva
Copy link
Member Author

imkiva commented Dec 11, 2022

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
Copy link
Member Author

imkiva commented Dec 11, 2022

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
Copy link
Member Author

imkiva commented Dec 11, 2022

Not really fixed

@imkiva imkiva reopened this Dec 11, 2022
@HoshinoTented
Copy link
Contributor

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

@imkiva
Copy link
Member Author

imkiva commented Dec 12, 2022

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

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

but

@imkiva
Copy link
Member Author

imkiva commented Dec 12, 2022

You can preview the result with WidthPreviewToy 😉

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

Successfully merging a pull request may close this issue.

3 participants