[reportlab-users] JustifyRight in ParagraphStyle

1,234 views
Skip to first unread message

Moshe Uminer

unread,
Mar 17, 2021, 8:50:00 AM3/17/21
to reportl...@lists2.reportlab.com
Hi, I'm enjoying reportlab, but I've run into an issue. 
Currently, when using TA_JUSTIFY in ParagraphStyle, the last line is aligned to the left. This is problematic when using an RTL language together with justify, as the last line of the paragraph should be aligned right.
I don't know how complex it would be to add this option, but I would definitely appreciate it :).

(I sent this email once before, but I'm sending it again because I think it wasn't sent to the mailing list because I had not yet subscribed to the list).

Robin Becker

unread,
Mar 17, 2021, 4:34:57 PM3/17/21
to reportlab-users, Moshe Uminer
Hi Moshe,

I'll take a look at this; can you provide a simple example of the code that you useto demonstrate the problem. If
possible I need to use the same text, style, width and font. Also if possible what reportlab version and I guess fribidi
etc etc if you are using that.


On 17/03/2021 12:48, Moshe Uminer wrote:
> Hi, I'm enjoying reportlab, but I've run into an issue.
> Currently, when using TA_JUSTIFY in ParagraphStyle, the last line is
> aligned to the left. This is problematic when using an RTL language
> together with justify, as the last line of the paragraph should be aligned
> right.
> I don't know how complex it would be to add this option, but I would
> definitely appreciate it :).
.......

--
Robin Becker
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
https://pairlist2.pair.net/mailman/listinfo/reportlab-users

Moshe Uminer

unread,
Mar 17, 2021, 5:26:45 PM3/17/21
to Robin Becker, reportlab-users
Hi Robin,

Thanks for taking a look!

Package versions:
reportlab==3.5.65
pyfribidi==0.12.0

The font used in the repro is Libre David (though the behavior is the same with other fonts as well). Downloadable from google fonts here https://fonts.google.com/specimen/David+Libre

Reproduction code:

```
from reportlab.platypus import Paragraph

from reportlab.lib.enums import TA_JUSTIFY

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib.pagesizes import LETTER
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet

from reportlab.platypus.doctemplate import SimpleDocTemplate

pdfmetrics.registerFont(TTFont("David", "DavidLibre-Regular.ttf"))


text = "שלום! זו תהיה פסקה שהשורה האחרונה שלה לא תוצדק כהלכה. "
text = text * 2

doc = SimpleDocTemplate(
    "repro.pdf",
    pagesize=LETTER,
    rightMargin=72,
    leftMargin=72,
    topMargin=72,
    bottomMargin=72,
)
styles = getSampleStyleSheet()
normal_hebrew = ParagraphStyle(
    parent=styles["Normal"],
    name="NormalHebrew",
    wordWrap="RTL",
    alignment=TA_JUSTIFY,
    fontName="David",
    fontSize=14,
)

flowables = [Paragraph(text, normal_hebrew)]

doc.build(flowables)

```

Thank you for looking into this!

(Sorry, I accidentally sent my reply only to you, hence I am resending).

Robin Becker

unread,
Mar 18, 2021, 7:23:25 AM3/18/21
to Moshe Uminer, reportlab-users
Thanks Moshe,

I am sure this ought to be regarded as a bug. The only question is how to fix it and under what circumstance. I assume
that if we have RTL in the style we ought to deal with the change of direction for the various left oriented things.

I guess we need to deal with enddots, links and underlines for the special case(s), but can I confirm that 'trailing
dots' in LTR would become leading dots in RTL


so LTR

Robin Becker ...........

would be RTL

........... rekceB niboR

On 17/03/2021 21:25, Moshe Uminer wrote:
> Hi Robin,
>
> Thanks for taking a look!
>
> Package versions:
> reportlab==3.5.65
> pyfribidi==0.12.0
>
> The font used in the repro is Libre David (though the behavior is the same
> with other fonts as well). Downloadable from google fonts here
> https://fonts.google.com/specimen/David+Libre
>
> Reproduction code:
>
...........--

Robin Becker

unread,
Mar 18, 2021, 4:02:30 PM3/18/21
to Moshe Uminer, reportlab-users
Hi Moshe,

I made some progress on this issue and can now get the right sort of behaviour for RTL text.

I will try and send you the files I changed and a test script based on your example. A couple of minor bugs appeared
during testing and those are also fixed.

I would be glad if you can install the three reportlab files into your test environment and see if they work for your
purposes. The last line problem was easy, but endDots and strike/underline were harder.


On 17/03/2021 21:25, Moshe Uminer wrote:
> Hi Robin,
>
> Thanks for taking a look!
........

Moshe Uminer

unread,
Mar 18, 2021, 4:22:05 PM3/18/21
to Robin Becker, reportlab-users
Hi Robin,

It looks great now, thank you! Works on my documents, and with your test and the repro, of course. I really appreciate it.

If I may ask, about how long will it be until the fix is released to PyPI?

Robin Becker

unread,
Mar 18, 2021, 4:30:00 PM3/18/21
to Moshe Uminer, reportlab-users
On 18/03/2021 20:20, Moshe Uminer wrote:
> Hi Robin,
>
> It looks great now, thank you! Works on my documents, and with your test
> and the repro, of course. I really appreciate it.
>
> If I may ask, about how long will it be until the fix is released to PyPI?
..........

I will try and put out the fix tomorrow, but certainly it will go out before Monday.

Moshe Uminer

unread,
Mar 18, 2021, 4:50:33 PM3/18/21
to Robin Becker, reportlab-users
Thank you very much! 

Robin Becker

unread,
Mar 19, 2021, 7:13:35 AM3/19/21
to Moshe Uminer, reportlab-users
On 18/03/2021 20:49, Moshe Uminer wrote:
> Thank you very much!
Thank you Moshe, credits in latest version 3.5.66 now uploading to pypi

https://pypi.org/project/reportlab/3.5.66/
Reply all
Reply to author
Forward
0 new messages