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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions screenplain/export/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
PageTemplate,
NextPageTemplate,
Spacer,
Table,
TableStyle,
)
from reportlab.lib import pagesizes
import sys
Expand All @@ -41,6 +43,7 @@ class Settings:
# Screenplay styles
character_style: ParagraphStyle
dialog_style: ParagraphStyle
dual_dialog_style: ParagraphStyle
parenthentical_style: ParagraphStyle
action_style: ParagraphStyle
centered_action_style: ParagraphStyle
Expand Down Expand Up @@ -126,6 +129,16 @@ def __init__(
leftIndent=9 * self.character_width,
rightIndent=self.frame_width - (45 * self.character_width),
)
self.dual_left_dialog_style = ParagraphStyle(
'dual_left_dialog', default_style,
leftIndent=4 * self.character_width,
rightIndent=self.frame_width - (56 * self.character_width),
)
self.dual_right_dialog_style = ParagraphStyle(
'dual_right_dialog', default_style,
leftIndent=0 * self.character_width,
rightIndent=self.frame_width - (52 * self.character_width),
)
self.parenthentical_style = ParagraphStyle(
'parenthentical', default_style,
leftIndent=13 * self.character_width,
Expand Down Expand Up @@ -226,6 +239,26 @@ def add_slug(story, para, style, is_strong):
story.append(Paragraph(html, style))


def dual_dialog_cont(dialog, settings: Settings, left: True):
cont = []
cont.append(
Paragraph(dialog.character.to_html(), settings.character_style)
)
for parenthetical, line in dialog.blocks:
if parenthetical:
cont.append(
Paragraph(line.to_html(), settings.parenthentical_style)
)
elif left:
cont.append(
Paragraph(line.to_html(), settings.dual_left_dialog_style)
)
else:
cont.append(
Paragraph(line.to_html(), settings.dual_right_dialog_style)
)
return cont

def add_dialog(story, dialog, settings: Settings):
story.append(
Paragraph(dialog.character.to_html(), settings.character_style)
Expand All @@ -240,12 +273,19 @@ def add_dialog(story, dialog, settings: Settings):
Paragraph(line.to_html(), settings.dialog_style)
)


def add_dual_dialog(story, dual, settings: Settings):
# TODO: format dual dialog
add_dialog(story, dual.left, settings)
add_dialog(story, dual.right, settings)

column_width = settings.page_width * 0.48 # I don't know why to put 10 here, just think it fine
paragraph_left = dual_dialog_cont(dual.left, settings, True)
paragraph_right = dual_dialog_cont(dual.right, settings, False)

table_data = []
table_data.append([paragraph_left, paragraph_right])
table_style = TableStyle([
('VALIGN', (0, 0), (-1, -1), 'TOP'),
])

table = Table(table_data, colWidths=[column_width, column_width], style=table_style)
story.append(table)

def get_title_page_story(screenplay, settings):
"""Get Platypus flowables for the title page
Expand Down
Loading