Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Justified Text not supporting RTL #534

Closed
Doragon-S opened this issue May 3, 2021 · 12 comments · Fixed by #539 or #540
Closed

Justified Text not supporting RTL #534

Doragon-S opened this issue May 3, 2021 · 12 comments · Fixed by #539 or #540
Labels
Milestone

Comments

@Doragon-S
Copy link

Doragon-S commented May 3, 2021

Describe the bug
When aligning a paragraph as "Justified", it changed to LTR. The hebrew letters were written backwards, like english. I thought I had broke something until I tried changing the alignment to "Right" and "Center".
I had written this in Kotlin, but since Kotlin is compatable with Java, I don't think there will be any difference between the two.

To Reproduce
Code to reproduce the issue

  1. Sample Code
    document.open()
    LayoutProcessor.enable(java.awt.Font.LAYOUT_RIGHT_TO_LEFT)
    val fontFileName = "Path\FrankRuehlCLM-Medium.ttf"
    FontFactory.register(fontFileName, "sans")
    val font: Font = FontFactory.getFont("sans", BaseFont.IDENTITY_H, 12f)
    val text = "שוב היתה זו שעת לילה. דממה שררה בפונדק אבן־הדרך, והיתה זו דממה בת שלושה חלקים." +
    "החלק המתבקש מאליו היה שקט חלול, מהדהד, עשוי מן הדברים שלא היו. אילו היתה רוח, כי" +
    "אז היתה נאנחת בעוברה בין העצים, מטלטלת את שלט הפונדק בחריקה על ציריו וסוחפת את" +
    "הדממה במורד הדרך, כפי שהיא גורפת עלי סתיו. אילו היה קהל בפונדק, אפילו קומץ אנשים, כי" +
    "אז היו ממלאים את הדממה בשיחה ובצחוק, בהמולה ובשאון שהיה מקום לצַפות להם במסבאה," +
    "בשעות הלילה החשוכות. אילו היתה מוסיקה... אבל לא , ודאי שלא היתה מוסיקה. למען האמת, אף" +
    "לא אחד מהדברים האלה היה שם, ולכן נותרה הדממה בעינה."
    var p1: Paragraph = Paragraph( Chunk(text, font) )
    p1.alignment = Element.ALIGN_JUSTIFIED
    document.add(p1)
    document.close()

  2. Unit-Test

Expected behavior
It should be justified, just like any LTR languages, but RTL

Screenshots
If applicable, add screenshots to help explain your problem.

System (please complete the following information):

  • OS: Windows 10
  • Used Font: FrankRuehlCLM

Additional context
Add any other context about the problem here.

@Doragon-S Doragon-S added the bug label May 3, 2021
@Doragon-S
Copy link
Author

This should probably also make the last line aligned right.
Also, is it possible to have options for the last line? for example: make the last line (or two?) centered instead of always being constrained to the side the words start from?

@Wugengxian
Copy link

@Doragon-S I know the reason, I will fixed it in this week.

@Doragon-S
Copy link
Author

Doragon-S commented May 10, 2021

@Doragon-S I know the reason, I will fixed it in this week.

Thank you so much!
Do you mind if I also ask you how to add text to a specific area on a page? I want to break the page up into different sections of different texts (not like columns, which I'd imagine is the same text spread over two columns, and filling the whole page top to bottom.) I was struggling to figure this out, and I didn't want to open an issue, since it isn't broken I just don't know, and I didn't know where I should ask, so maybe I can ask here... ?

@Wugengxian
Copy link

@Doragon-S I know the reason, I will fixed it in this week.

Thank you so much!
Do you mind if I also ask you how to add text to a specific area on a page? I want to break the page up into different sections of different texts (not like columns, which I'd imagine is the same text spread over two columns, and filling the whole page top to bottom.) I was struggling to figure this out, and I didn't want to open an issue, since it isn't broken I just don't know, and I didn't know where I should ask, so maybe I can ask here... ?

I don't know how how to do this, and maybe you can wait for others to help you.

@Doragon-S
Copy link
Author

@Doragon-S I know the reason, I will fixed it in this week.

Thank you so much!
Do you mind if I also ask you how to add text to a specific area on a page? I want to break the page up into different sections of different texts (not like columns, which I'd imagine is the same text spread over two columns, and filling the whole page top to bottom.) I was struggling to figure this out, and I didn't want to open an issue, since it isn't broken I just don't know, and I didn't know where I should ask, so maybe I can ask here... ?

I don't know how how to do this, and maybe you can wait for others to help you.

Do you know who I could ask? and how I would ask? (I'm new to GitHub)

@Wugengxian
Copy link

I think you can ask asturio, the maintainer of OpenPDF.

@arnthom
Copy link

arnthom commented May 12, 2021

Hi Dorago-S!

... how to add text to a specific area on a page?

In my case I want to set a specific header to document pages that are filled by the add method of the Document class.
I have managed this by using method writeSelectedRows of PdfPTable class.
In writeSelectedRows you can set the position, size and content.
Is this a method you could use?

@Doragon-S
Copy link
Author

Hi Dorago-S!

... how to add text to a specific area on a page?

In my case I want to set a specific header to document pages that are filled by the add method of the Document class.
I have managed this by using method writeSelectedRows of PdfPTable class.
In writeSelectedRows you can set the position, size and content.
Is this a method you could use?

I'm not sure. Would I need to make a whole table to use it?
I was planning on using multiple "textbox" objects to get the text into a certain shape (fitting comments around a base text - I was going to have the commentary be in a smaller font size and surround the base text kind of in an L shape). I had thought the best idea would be to make 3 textboxes - one for the base text, one for the part of the comments that would fit next to it, and a third for the spillover underneath it.
I'd guess that if I needed to make a whole table then it would mess that up? Or could you merge cells and mess with stuff like that?

@Wugengxian Wugengxian mentioned this issue May 13, 2021
1 task
@Wugengxian
Copy link

Wugengxian commented May 13, 2021

@Doragon-S I have fixed it. Hope it can help you. And Last Line is also alignment to "Right"

@asturio asturio linked a pull request May 13, 2021 that will close this issue
1 task
asturio added a commit that referenced this issue May 13, 2021
@asturio asturio linked a pull request May 13, 2021 that will close this issue
1 task
asturio added a commit that referenced this issue May 13, 2021
@asturio
Copy link
Member

asturio commented May 13, 2021

Hi @Doragon-S , can you take a look at the test whenLayoutRightToLeftHebrew_thenRevertCharOrder in https://github.com/LibrePDF/OpenPDF/blob/master/openpdf/src/test/java/com/lowagie/text/pdf/LayoutProcessor534Test.java, if it make some sense? I don't know hebrew, and my knowledge in RTL-languages is almost non-existent :-)

@Doragon-S
Copy link
Author

Hi @Doragon-S , can you take a look at the test whenLayoutRightToLeftHebrew_thenRevertCharOrder in https://github.com/LibrePDF/OpenPDF/blob/master/openpdf/src/test/java/com/lowagie/text/pdf/LayoutProcessor534Test.java, if it make some sense? I don't know hebrew, and my knowledge in RTL-languages is almost non-existent :-)

Hi! I'm new to coding, and I don't really know what to do, so I'll tell you what I tried doing and you tell me if it helped/what to actually do?

When I ran the code, I got a failed test of:

`INFO: Reading font-fallback/LiberationSans-Regular.ttf...

org.opentest4j.AssertionFailedError:
expected: ".ויה אלש םירבדה ןמ יושע ,דהדהמ ,לולח טקש היה וילאמ שקבתמה קלחה.םיקלח השולש תב הממד וז התיהו ,ךרדה־ןבא קדנופב הררש הממד .הליל תעש וז התיה בוש
וליא .ויתס ילע תפרוג איהש יפכ ,ךרדה דרומב הממדהתא תפחוסו ויריצ לע הקירחב קדנופה טלש תא תלטלטמ ,םיצעה ןיב הרבועב תחנאנ התיה זאיכ ,חור התיה וליא
וליא .תוכושחה הלילה תועשב,האבסמב םהל תופַצל םוקמ היהש ןואשבו הלומהב ,קוחצבו החישב הממדה תא םיאלממ ויה זאיכ ,םישנא ץמוק וליפא ,קדנופב להק היה
.הניעב הממדה הרתונ ןכלו ,םש היה הלאה םירבדהמ דחא אלףא ,תמאה ןעמל .הקיסומ התיה אלש יאדו , אל לבא ...הקיסומ התיה"
but was : ""

...`

I didn't see the first line about the font at first and so tried to save it as a pdf to view it there, but it came out written LTR (all the characters were printed the wrong direction).

I then saw the first line and thought maybe the test returned "" because LiberationSans is an English font (I think?) and tried adding in a Hebrew font, but then I realized that I didn't see any calls to any font, so I didn't know what to replace, and now I'm slightly confused about what I was supposed to do in the first place.

@asturio asturio added this to the 1.3.27 milestone May 24, 2021
@Doragon-S
Copy link
Author

@asturio
Hi, I'm trying to make a text wrap around other text, and I think the best way to do that is by making multiple textBox objects (or something similar) to set certain sections of text to specific places. Is this possible? What would be the best way to do this? arnthom had suggested making a PdfPTable, but I couldn't find an easy to follow documentation (or example) on how to use it properly. Do you know what would be the best way to learn how to use that? I'd appreciate any help you can give me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants