vandeseer / easytable

Small table drawing library built upon Apache PDFBox
MIT License
239 stars 91 forks source link

Arabic line splitting #77

Open chahinehamila opened 4 years ago

chahinehamila commented 4 years ago

We're trying to use easytable with Arabic text (right to left). The text (String) is rearranged with IBM ICU and java.text.bidi then passed to easytable. The text is correctly displayed (with right align) and correctly ordered within each line, but lines must be read from bottom to top. A bit like:

each line, but lines must be read from bottom to top. displayed (with right align), and correctly ordered within The text is correctly

I'd be quite happy to provide the code needed to correctly process Arabic text, and submit it as a pull request. I just need some guidance. A quick look suggests the work is mostly done in PdfUtil and/or TextCellDrawer. Essentially, I would need to split the lines in a way that would, for Latin text: 1- output lines in the Pdf from bottom to top, 2- and make the residual line out of the beginning of the paragraph, as opposed to its end.

That approach, applied to Arabic text, would display it correctly. Thanks!

vandeseer commented 4 years ago

I will have a closer look soon, generally speaking I think the way to go is to create a cell type of its own and then just override the necessary methods.

Will keep you posted, and I am always happy to accept pull requests :)

Best Stefan

chahinehamila commented 4 years ago

Thanks Stefan, looking forward to hearing from you.

vandeseer commented 4 years ago

I created a branch for it: feature/arabic-line-splitting – just check it out and try to run the test that has been added. If I wasn't mistaken this should do the trick.

Please let me know if it works.

Hope this helps, Stefan

chahinehamila commented 4 years ago

Fantastic, will revert soon

chahinehamila commented 4 years ago

Dear Stefan, we tested it and it looks great. As mentioned in the issue of #80, there are edge cases where this is glitchy, and which would require other means, but this fix does the job in most cases. Any chance of integrating it in the master branch for next releases? (e.g. 0.6.5?) Thanks again, sincerely appreciated!

vandeseer commented 4 years ago

Happy it worked for you :+1:

I think I will include it in the next release but I don't know yet when this will go out ;) When it's released I will close this ticket.

Cheers, Stefan