Last active
December 12, 2021 21:28
-
-
Save lelit/f0e1ed1e2f9dec431463bec77a047362 to your computer and use it in GitHub Desktop.
RL hyphenation glitch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from reportlab.pdfgen import canvas | |
from reportlab.platypus import Frame, ShowBoundaryValue, Paragraph | |
from reportlab.lib.styles import ParagraphStyle | |
from reportlab.pdfbase import pdfmetrics | |
from reportlab.pdfbase.ttfonts import TTFont | |
pdfmetrics.registerFont(TTFont('DINNextLTPro', 'DINNextLTPro-Regular.ttf')) | |
pagesize = (200+20, 400) | |
c = canvas.Canvas('hyphenation_glitch.pdf', pagesize=pagesize) | |
f = Frame(10, 0, 200, 400, | |
showBoundary=ShowBoundaryValue(dashArray=(1,1)), | |
leftPadding=0, | |
rightPadding=0, | |
topPadding=0, | |
bottomPadding=0) | |
style = ParagraphStyle('normal', | |
fontName='DINNextLTPro', | |
fontSize=10, | |
spaceBefore=20, | |
hyphenationLang='en-US', | |
alignment=4) | |
# This is rendered OK | |
text1 = """ | |
My recent use case was the preparation of a dictionary that was passed to a Jinja2 | |
template. Using a dictionary structure makes it easy to change the content sent to the template | |
but I don’t want the template to modify the contents as it renders it. | |
""" | |
# This is rendered OK | |
text2 = """ | |
My recent use case was the preparation of a dictionary that was passed to a "Jinja2" | |
template. Using a dictionary structure makes it easy to change the content sent to the template | |
but I don’t want the template to modify the contents as it renders it. | |
""" | |
# Replacing double quotes with corresponding HTML entities introduces glitches | |
text3 = """ | |
My recent use case was the preparation of a dictionary that was passed to a "Jinja2" | |
template. Using a dictionary structure makes it easy to change the content sent to the template | |
but I don’t want the template to modify the contents as it renders it. | |
""" | |
f.addFromList([Paragraph(text1, style), | |
Paragraph(text2, style), | |
Paragraph(text3, style)], | |
c) | |
c.showPage() | |
c.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for reporting this - I am currently facing the exact same issue as described in https://groups.google.com/g/reportlab-users/c/yEQi6Q495yA