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

Numbered lists: numbers rendered after text in RTL languages #645

Closed
johnnyaug opened this issue Feb 5, 2021 · 4 comments · Fixed by #655
Closed

Numbered lists: numbers rendered after text in RTL languages #645

johnnyaug opened this issue Feb 5, 2021 · 4 comments · Fixed by #655

Comments

@johnnyaug
Copy link
Contributor

johnnyaug commented Feb 5, 2021

Related to #270 - which dealt with a similar issue with bulleted lists, and was solved.

Reproduce:
Take the following html:

<html dir="rtl">
   <body dir="rtl">
   <ol>
      <li>דבר ראשון</li>
      <li>דבר שני</li>
      <li>דבר שלישי</li>
   </ol>
   </body>
</html>

And render it with the following code:

try (OutputStream os = new FileOutputStream("output.pdf")) {
    PdfRendererBuilder builder = new PdfRendererBuilder();
    builder.useUnicodeBidiSplitter(new ICUBidiSplitter.ICUBidiSplitterFactory());
    builder.useUnicodeBidiReorderer(new ICUBidiReorderer());
    builder.defaultTextDirection(BaseRendererBuilder.TextDirection.RTL);
    builder.withUri("file:///path/to/html");
    builder.toStream(os);
    builder.run();
} catch (URISyntaxException e) {
    e.printStackTrace();
}

Get the following PDF:
image

The numbers are expected to be to the right of the text, like so:
image

@johnnyaug
Copy link
Contributor Author

johnnyaug commented Feb 5, 2021

I can try to solve this issue with a little guidance: I tried to do it by simply calculating the width similar to what was done in #271. However this is not enough here: the order also needs to change. e.g. 1. should be rendered as .1

@syjer
Copy link
Contributor

syjer commented Feb 9, 2021

hi @johnnyaug ,

the "1. " is generated in the method makeTextMarker of BlockBox:

https://github.com/danfickle/openhtmltopdf/blob/open-dev-v1/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java#L372

The open point is: do we have the information that we are in a RTL context? :)

@syjer
Copy link
Contributor

syjer commented Feb 9, 2021

ok, you can get the direction by calling: getStyle().getDirection() inside the makeTextMarker method :)

@danfickle
Copy link
Owner

Technically, we should be doing BIDI on the list marker text.

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

Successfully merging a pull request may close this issue.

3 participants