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

format dual dialog #77

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

format dual dialog #77

wants to merge 4 commits into from

Conversation

Jacques-z
Copy link

Enabled dual dialog support for pdf export

@vilcans
Copy link
Owner

vilcans commented Sep 21, 2023

Thank you! That's been needed!

I think that dual dialog needs a different style, instead of Settings.dialog_style maybe Settings.dual_dialog_style that should have a smaller rightIndent. Otherwise there are only 12 characters per line in the dialog and lots of space between the two columns.

I also notice that the two table columns are bottom-aligned, so if the two lines of dialogue are of different length, the shortest one will start lower on the page than the other one.

BTW, have you checked what happens if one of the lines is very long, so it doesn't fit on the page?

@Jacques-z Jacques-z marked this pull request as draft September 21, 2023 13:16
@Jacques-z
Copy link
Author

Thanks for your response and I made some changes.

Added Settings.dual_dialog_style which has smaller leftIdent and rightIndent.

With TableStyle, now it's top-aligned.

If one of the lines is long, they will waste the remaining space on the page, showing at the top of a new page; if it's too long, then error occurs.
This should be a feature of cell of reportlab's Table. I could not find better ways to make columns
Maybe we could add a cell-split feature to reportlab?

Another thing is that the name of the characters in dual dialog seems a little right. I guess character_style should be adapted.

Finally, evil thoughts: why not offer an option to export to pdf by converting html?

@Jacques-z Jacques-z marked this pull request as ready for review September 21, 2023 13:58
@vilcans
Copy link
Owner

vilcans commented Oct 3, 2023

I can confirm that there's an error if the dual dialog is so long that it doesn't fit on a page:

Traceback (most recent call last):
  File "/home/vilcans/proj/screenplain/.venv/bin/screenplain", line 33, in <module>
    sys.exit(load_entry_point('screenplain', 'console_scripts', 'screenplain')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vilcans/proj/screenplain/screenplain/main.py", line 138, in cli
    main(sys.argv[1:])
  File "/home/vilcans/proj/screenplain/screenplain/main.py", line 130, in main
    pdf.to_pdf(screenplay, output, settings=settings)
  File "/home/vilcans/proj/screenplain/screenplain/export/pdf.py", line 412, in to_pdf
    doc.build(story)
  File "/home/vilcans/proj/screenplain/.venv/lib/python3.11/site-packages/reportlab/platypus/doctemplate.py", line 1082, in build
    self.handle_flowable(flowables)
  File "/home/vilcans/proj/screenplain/.venv/lib/python3.11/site-packages/reportlab/platypus/doctemplate.py", line 961, in handle_flowable
    raise LayoutError(ident)
reportlab.platypus.doctemplate.LayoutError: Flowable <Table@0x7F36ECD90250 1 rows x 2 cols(tallest row 786)> with cell(0,0) containing
'<Paragraph at 0x7f36ed1ea850>GIRL'(587.52 x 786), tallest cell 786.0 points,  too large on page 2 in frame 'title'(396.0 x 660.0*) of template 'title'

I don't know how common it is for dual dialog to be very long so I thought about having a limit on the number of lines in a dual dialog, and render them as normal dialog as a workaround. But it's Platypus that does the line wrapping, so our code doesn't even know the number of lines, so it's not that simple. There is the Paragraph.wrap function that possibly can be used to check for overflow.

BTW, another thing: There's less space between the action paragraph above and the character name on dual dialog than on normal dialog. Looks like half a line only.

@Jacques-z
Copy link
Author

Sorry for the late response, as this is quite beyond my scope.

Here's a table for the tools I can come up wit. Maybe it's up to you to weigh and decide which path to explore:

tool cross-page dual-dialogue non-roman character keep with next paragraph Courier font and fallbacks solution Advantage
reportlab Y ? contribute to add this feature already using this
typst Y Partial ? contribute to add this feature and convert superstring to typst format super fast, small, and is a new project
WeasyPrint Y Y Y I don't think HTML cares about the page thing uses HTML
$LaTeX$ Y Y Y Y use latex engine and convert superstring to latex format omitted

As for the paragraph.wrap method, well, I failed to find usable examples for that and actually the annoying unbreakable part is a table, so I guess this method is not the solution.

So, as long as you make a decision, giving up the keep-with-next feature, contributing to reportlab, etc., I'll follow that and try my best.

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

Successfully merging this pull request may close these issues.

2 participants