Distrotech / reportlab

Mirror of https://bitbucket.org/rptlab/reportlab
Other
59 stars 42 forks source link

Space between words when using wordWrap='CJK' and alignment=TA_JUSTIFY #11

Open dn070017 opened 4 years ago

dn070017 commented 4 years ago

When using Asian characters with English/numbers, I expected the spaces will be added between the Asian characters and English/numbers for TA_JUSTIFY alignment (so the line alignment perfectly at the right side of the text). But instead, the spaces are added at the end of the line.

Expected: image

Result: image

Code:

from io import BytesIO
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics, ttfonts
from reportlab.lib.units import cm
from reportlab.lib.enums import TA_JUSTIFY, TA_LEFT, TA_CENTER
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import Paragraph, Frame, Table, TableStyle, Image

pdfmetrics.registerFont(ttfonts.TTFont('Noto-Light', './NotoSansCJKtc_ttf/NotoSansCJKtc-Light.ttf'))

styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='Content', fontName='Noto-Light', leading=19, alignment = TA_JUSTIFY, wordWrap = 'CJK', fontSize=13))

packet = BytesIO()
pdf_canvas = canvas.Canvas(packet, pagesize=(23.6 * cm, 32.3 * cm))

string = "測試測試測試測試測試測試測試測試測試測試123測試測試測試測試測試測試測試測試測試測試"

f = Frame(12 * cm, 9 * cm, 8.35 * cm, 2.7 * cm, showBoundary=1, leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0)
story = [Paragraph(string, styles['Content'])]
f.addFromList(story, pdf_canvas)
pdf_canvas.showPage()
pdf_canvas.save()

Version: 3.5.26