-
Notifications
You must be signed in to change notification settings - Fork 30
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
Diacritic characters in generated PDFs? #35
Comments
First make sure that the file is in utf-8 format. It may be a setting in your editor when you save the file. Also check if those characters work if you convert to HTML instead of PDF, because then we know it's a PDF problem. If so, please send me a file that reproduces the problem so I can have a look at it. |
I'm using vim - encoding and fileencoding are both set to "utf-8". The characters do render correctly in vim. I have attached a sample file. |
Thanks, I've found the problem. It's that the default Courier font doesn't include those characters. I've started working on support for other fonts. |
That's great! Thanks! |
FWIW, I've modified my screenplain/export/pdf.py to use FreeMono instead of Courier, and it does render properly for my needs now. |
Awesome! I have started the work on supporting different fonts, and possibly using Courier Prime by default. |
Any progress on supporting other fonts? |
For the record, here is the patch I used, the font files were installed in diff --git a/screenplain/export/pdf.py b/screenplain/export/pdf.py
index 6955616..86d7a00 100644
--- a/screenplain/export/pdf.py
+++ b/screenplain/export/pdf.py
@@ -23,6 +23,8 @@ from reportlab import platypus
from reportlab.lib.units import inch
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.enums import TA_CENTER, TA_RIGHT
+from reportlab.pdfbase import pdfmetrics
+from reportlab.pdfbase.ttfonts import TTFont
from screenplain.types import (
Action, Dialog, DualDialog, Transition, Slug
@@ -46,7 +48,7 @@ bottom_margin = page_height - top_margin - frame_height
default_style = ParagraphStyle(
'default',
- fontName='Courier',
+ fontName='Courier Prime',
fontSize=font_size,
leading=line_height,
spaceBefore=0,
@@ -126,7 +128,7 @@ class DocTemplate(BaseDocTemplate):
)
def handle_pageBegin(self):
- self.canv.setFont('Courier', font_size, leading=line_height)
+ self.canv.setFont('Courier Prime', font_size, leading=line_height)
if self.has_title_page:
page = self.page # self.page is 0 on first page
else:
@@ -246,6 +248,11 @@ def to_pdf(
template_constructor=DocTemplate,
is_strong=False,
):
+ pdfmetrics.registerFont(TTFont('Courier Prime', 'courier-prime.ttf'))
+ pdfmetrics.registerFont(TTFont('Courier Prime Bold', 'courier-prime-bold.ttf'))
+ pdfmetrics.registerFont(TTFont('Courier Prime Italic', 'courier-prime-italic.ttf'))
+ pdfmetrics.registerFont(TTFont('Courier Prime Bold Italic', 'courier-prime-bold-italic.ttf'))
+
story = get_title_page_story(screenplay)
has_title_page = bool(story)
I could create a PR to allow users to select a font from a configuration file, if needed? |
I have some scripts that contain some diacritic characters (with circumflexes etc.). These render as a black box in the PDF file. Possible to fix?
The text was updated successfully, but these errors were encountered: