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

Diacritic characters in generated PDFs? #35

Open
mckea opened this issue Feb 18, 2017 · 8 comments · May be fixed by #58
Open

Diacritic characters in generated PDFs? #35

mckea opened this issue Feb 18, 2017 · 8 comments · May be fixed by #58

Comments

@mckea
Copy link

mckea commented Feb 18, 2017

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?

@vilcans
Copy link
Owner

vilcans commented Feb 19, 2017

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.

@mckea
Copy link
Author

mckea commented Feb 19, 2017

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.
diacritic.fountain.txt

@vilcans
Copy link
Owner

vilcans commented Feb 20, 2017

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.

@mckea
Copy link
Author

mckea commented Feb 28, 2017

That's great! Thanks!

@mckea
Copy link
Author

mckea commented May 6, 2017

FWIW, I've modified my screenplain/export/pdf.py to use FreeMono instead of Courier, and it does render properly for my needs now.

@vilcans
Copy link
Owner

vilcans commented May 7, 2017

Awesome! I have started the work on supporting different fonts, and possibly using Courier Prime by default.

@lenormf
Copy link

lenormf commented May 12, 2020

Any progress on supporting other fonts?

@lenormf
Copy link

lenormf commented May 13, 2020

For the record, here is the patch I used, the font files were installed in ~/.fonts:

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?

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 a pull request may close this issue.

3 participants