Skip to content

Instantly share code, notes, and snippets.

@lelit
Last active December 12, 2021 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lelit/f0e1ed1e2f9dec431463bec77a047362 to your computer and use it in GitHub Desktop.
Save lelit/f0e1ed1e2f9dec431463bec77a047362 to your computer and use it in GitHub Desktop.
RL hyphenation glitch
Display the source blob
Display the rendered blob
Raw
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()
@bbbart
Copy link

bbbart commented Dec 12, 2021

thanks for reporting this - I am currently facing the exact same issue as described in https://groups.google.com/g/reportlab-users/c/yEQi6Q495yA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment