Timeline for Arabic text is revering lines in reportlab
Current License: CC BY-SA 4.0
Post Revisions
30 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 20, 2023 at 20:00 | vote | accept | Mounir | ||
| Jul 17, 2023 at 13:52 | vote | accept | Mounir | ||
| Jul 20, 2023 at 16:28 | |||||
| Jul 17, 2023 at 13:33 | comment | added | Andj | If you read through that thread, you will see that Moshe implemented initial fribidi support in reportlab. The key is to get fribidi installed. You may need to reinstall reportlab afterwards. If you have fribidi, try the code in my answer. | |
| Jul 17, 2023 at 13:03 | comment | added | Mounir | I am still phasing the same issue. Check this link. The problem remains the same I think. reportlab-users.reportlab.narkive.com/a9RYufEt/… | |
| Jul 17, 2023 at 12:09 | answer | added | Andj | timeline score: 1 | |
| Jul 17, 2023 at 11:42 | comment | added | Andj |
You need to have libfribidi installed, can be tested with pyfribidi.. Set your rtlSupport setting. Add wordWrap="RTL" to your ParagraphStyle and parse arabic_text to Paragraph() rather than parsing bidirectional_text. Paragraph() will process line by line using fribidi to handle the RTL rendering and swapping in presentational forms on each line.
|
|
| Jul 17, 2023 at 11:01 | comment | added | Mounir | This is not the ideal solution but I have to live with it until they fix this issue with RTL texts. | |
| Jul 17, 2023 at 11:00 | comment | added | Mounir | The rendering in the report lab for RTL starts from the bottom of the paragraph. I've created a text wrapper to split and reverse text lines. I need just a little time to work with a test library then I will share my solution. This is the signature def text_wrap(_text, _max_width, font_name, font_size): | |
| Jul 17, 2023 at 10:07 | comment | added | Andj | But reportlab RTL rendering is fairly simplistic, so likely to be far from ideal. | |
| Jul 17, 2023 at 10:05 | comment | added | Andj |
There is a reportlab setting rtlSupport, set this to 1. Section 1.8 of the reportlab user guide specifies where you can place override files. On linux and macos I just create a file ~/.reportlab_settings and enter a line rtlSupport=1. Then pass in standard Unicode Arabic text. Don't use python-bidi and arabic-reshaper. Also try to use a simple Naskh font, fonts with sophisticated rendering and typographic features are less likely to work.
|
|
| Jul 17, 2023 at 8:57 | comment | added | Mounir | Is there a way to calculate the paragraph with dynamically? | |
| Jul 17, 2023 at 8:56 | comment | added | Mounir | Thank you. What I am doing now is a similar solution with bidi. I am working on a text wrapper, but I have to provide the paragraph width so we have the desired output. Btw, pyfribidi results in the same problem. | |
| Jul 16, 2023 at 20:43 | comment | added | Andj | Going through some old threads on the reportlab list, it appears that python-bidi and arabic-reshaper will not work. The processing needs to occur on each line. In theory you'd pass plain Unicode, then within internal functions reportlab would use pyfribidi to reformat each line. Initial RTL work was done for Hebrew about 14 years ago. I am trying to ascertain the current status of RTL support, and how to enable it. | |
| Jul 16, 2023 at 14:10 | comment | added | Mounir | This is one of them I've tested. leading_text_style = ParagraphStyle( "ordinary_text_style", # border on parent=styles[ "Normal" ], ta="left", lineSpacing=-10, fontName="Arabic", # previously we named our custom font "Arabic" dir="rtl", ) | |
| Jul 16, 2023 at 8:46 | comment | added | Andj |
What is your paragraph_style?
|
|
| Jul 16, 2023 at 8:36 | comment | added | Andj |
arabic_reshaper converts Arabic Unicode characters into their equivalents in the presentation forms so U+0648 is converted to U+FEED, etc. bidi.algorithm.get_display coverts a RTL logically ordered string to a visually ordered string. This reverses the string and as a consequence changes the order of words. You pass this changed version of the string to the paragraph formatter. What you expect is based on a logically ordered string, but you pass a visually ordered string and that is used to generate your results.
|
|
| Jul 16, 2023 at 8:24 | comment | added | Andj |
arabic_text is U+0648 (و) U+062D (ح) U+062F (د) U+0629 (ة) U+0031 (1) U+0020( ) U+0648 (و) U+062D (ح) U+062F (د) U+0629 (ة) U+0032 (2). So first sub-string is U+0648 (و) U+062D (ح) U+062F (د) U+0629 (ة) U+0031 (1) while second is U+0648 (و) U+062D (ح) U+062F (د) U+0629 (ة) U+0032 (2). For bidirectional_text you have U+0032 (2) U+FE93 (ة) U+FEAA (د) U+FEA3 (ح) U+FEED (و) U+0020 ( ) U+0031 (1) U+FE93 (ة) U+FEAA (د) U+FEA3 (ح) U+FEED (و). So first sub-string is U+0032 (2) U+FE93 (ة) U+FEAA (د) U+FEA3 (ح) U+FEED (و) and 2nd: U+0031 (1) U+FE93 (ة) U+FEAA (د) U+FEA3 (ح) U+FEED (و).
|
|
| Jul 16, 2023 at 5:49 | comment | added | Andj | Converting it from logical to visual reverses the string, but that in itself automatically changes the word order. In Logical order first character in data should be the right most character in display. First word in data is word rendered right most on first line. Converting the string to visual order changes string so left most word is first word in string (but word is backwards). It's easier to observe when looking at the codepoints. | |
| Jul 16, 2023 at 5:37 | comment | added | Mounir | It does not reverse the word order. It reverses the lines by rendering the lines from the bottom of the paragraph. Hence, I think the problem is with the report lab and how it renders RTL text. Now, I'm working on a text wrapper to fix this problem. However, I would like to see if there is a stable solution. | |
| Jul 15, 2023 at 14:10 | comment | added | Andj |
bidi-algorithm converts the string from logical ordering to visual ordering, and in the process reverse the order of words within the string. First word in arabic_text is وحدة1 but first word after reorderng the string using bidi_algorithm is وحدة2. You would need to reverse the order of the words before return.
|
|
| S Jul 13, 2023 at 5:52 | history | suggested | TechyBenji | CC BY-SA 4.0 |
Improved grammar, formatting and spelling
|
| Jul 12, 2023 at 23:44 | review | Suggested edits | |||
| S Jul 13, 2023 at 5:52 | |||||
| Jul 12, 2023 at 20:06 | comment | added | Mounir | I have tried another library called pyfribidi. It seems that the problem with ReportLab staring Arabic paragraph from buttom. | |
| Jul 12, 2023 at 13:38 | history | edited | Mounir | CC BY-SA 4.0 |
added 2 characters in body
|
| Jul 12, 2023 at 13:37 | history | edited | Mounir | CC BY-SA 4.0 |
deleted 2 characters in body
|
| Jul 12, 2023 at 13:36 | history | edited | Mounir | CC BY-SA 4.0 |
added 61 characters in body
|
| Jul 12, 2023 at 13:35 | history | edited | Mounir | CC BY-SA 4.0 |
deleted 59 characters in body
|
| Jul 12, 2023 at 13:33 | history | edited | Mounir | CC BY-SA 4.0 |
deleted 16 characters in body
|
| S Jul 12, 2023 at 13:33 | review | First questions | |||
| Jul 12, 2023 at 23:44 | |||||
| S Jul 12, 2023 at 13:33 | history | asked | Mounir | CC BY-SA 4.0 | created from wizard |