Skip to content
Open
Show file tree
Hide file tree
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
Binary file modified examples/Big-Fish.pdf
Binary file not shown.
Binary file modified examples/Brick-and-Steel.pdf
Binary file not shown.
Binary file modified examples/The-Last-Birthday-Card.pdf
Binary file not shown.
59 changes: 33 additions & 26 deletions screenplain/export/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def __init__(
self.parenthentical_style = ParagraphStyle(
'parenthentical', default_style,
leftIndent=13 * self.character_width,
rightIndent=self.frame_width - (38 * self.character_width),
keepWithNext=1,
)
self.action_style = ParagraphStyle(
Expand Down Expand Up @@ -265,13 +266,12 @@ def draw(self):
self.settings.font_size
)

# Left margin: Position to the left of frame
left_x = -0.75 * inch
canvas.drawString(left_x, 0, self.scene_number)

# Right margin: Right-aligned inside right margin area
right_x = self.settings.frame_width
canvas.drawRightString(right_x, 0, self.scene_number)
margin_offset = 0.75 * inch
right_edge = (
self.settings.page_width - margin_offset - self.settings.left_margin
)
canvas.drawString(-margin_offset, 0, self.scene_number)
canvas.drawRightString(right_edge, 0, self.scene_number)

canvas.restoreState()

Expand All @@ -298,12 +298,14 @@ def __init__(self, *args, **kwargs):
id='title',
leftPadding=0, topPadding=0, rightPadding=0, bottomPadding=0
)
pageTemplates = [
PageTemplate(id='title', frames=[title_frame]),
PageTemplate(id='standard', frames=[frame])
title_template = PageTemplate(id='title', frames=[title_frame])
standard_template = PageTemplate(id='standard', frames=[frame])
page_templates = [
*([title_template] if self.has_title_page else []),
standard_template,
]
BaseDocTemplate.__init__(
self, pageTemplates=pageTemplates, *args, **kwargs
self, pageTemplates=page_templates, *args, **kwargs
)

def handle_pageBegin(self):
Expand Down Expand Up @@ -351,29 +353,34 @@ def add_slug(story, para, settings):
story.append(paragraph)


def _scaled_style(style, name, proportion) -> ParagraphStyle:
"""Rebuild a style with both indents scaled to a narrower column.

Scaling every indent generically keeps a style's column intact: an
indent left unscaled would be measured against the full frame width
and swallow the narrower column.
"""
return ParagraphStyle(
name, style,
leftIndent=style.leftIndent * proportion,
rightIndent=style.rightIndent * proportion,
)


def _dialog_to_flowables(
dialog, settings: Settings, column_width=None
) -> list[Flowable]:
# If column_width is set, adjust indents proportionally
if column_width is not None:
proportion = column_width / settings.frame_width
character_left = settings.character_style.leftIndent * proportion
dialog_left = settings.dialog_style.leftIndent * proportion
parenthentical_left = (settings.parenthentical_style.leftIndent *
proportion)
dialog_right = settings.dialog_style.rightIndent * proportion
character_style = ParagraphStyle(
'character-dual', settings.character_style,
leftIndent=character_left
character_style = _scaled_style(
settings.character_style, 'character-dual', proportion
)
dialog_style = ParagraphStyle(
'dialog-dual', settings.dialog_style,
leftIndent=dialog_left,
rightIndent=dialog_right
dialog_style = _scaled_style(
settings.dialog_style, 'dialog-dual', proportion
)
parenthentical_style = ParagraphStyle(
'parenth-dual', settings.parenthentical_style,
leftIndent=parenthentical_left
parenthentical_style = _scaled_style(
settings.parenthentical_style, 'parenth-dual', proportion
)
else:
character_style = settings.character_style
Expand Down
7 changes: 7 additions & 0 deletions tests/files/dual-dialogue-parenthetical.fountain
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GIRL
(quietly)
Hello there friend.

GUY^
(loudly)
Hi back at you.
Binary file added tests/files/dual-dialogue-parenthetical.pdf
Binary file not shown.
Binary file modified tests/files/dual-dialogue.pdf
Binary file not shown.
Binary file modified tests/files/scene-numbers.pdf
Binary file not shown.