format dual dialog
Enabled dual dialog support for pdf export
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?
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?
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.
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.