printpdf icon indicating copy to clipboard operation
printpdf copied to clipboard

RTL support

Open pikhosh opened this issue 2 years ago • 9 comments

Hi! I wanted to know if this library supports RTL languages or not? In terms of writing and also in terms of layout and alignment.

If not, can you please tell me if there is a solution or if you know a library that has this feature?

pikhosh avatar Aug 25 '22 04:08 pikhosh

RTL - do you mean arabic / hebrew scripts? printpdf does not do text layout because that is way too complex for just PDF. Use https://crates.io/crates/azul-text-layout with inline_text_layout.align_children_horizontal(StyleTextAlignmentHorz::Right);

You can also try genpdf (which is built upon printpdf).

fschutt avatar Aug 25 '22 09:08 fschutt

RTL - do you mean arabic / hebrew scripts?

Yeah!

You can also try genpdf (which is built upon printpdf).

Thanks! I will try genpdf!

pikhosh avatar Aug 25 '22 10:08 pikhosh

@pikhosh RTL support is very difficult, I think I tried implementing it in azul-text-layout, but the only Rust crate that can reliably do it is allsorts, which is a very low-level font shaper.

fschutt avatar Aug 25 '22 10:08 fschutt

allsorts supports Arabic, Hindi, Hebrew, Pinyin and other scripts correctly. But it's very low level, so you have to position the glyphs manually. Doing that in a PDF library is simply out of the scope of this library, even though it would be nice to have.

fschutt avatar Aug 25 '22 10:08 fschutt

@pikhosh RTL support is very difficult, I think I tried implementing it in azul-text-layout, but the only Rust crate that can reliably do it is allsorts, which is a very low-level font shaper.

Yeah... it seems difficult! Even among JS libraries, RTL support is rare! (or maybe I just don't know how to use them 😅)

pikhosh avatar Aug 25 '22 10:08 pikhosh

I know I once supported Hebrew in azul-text-layout, I also tried supporting Japanese. But I'm not sure if that is still the case.

fschutt avatar Aug 25 '22 10:08 fschutt

I know I once supported Hebrew in azul-text-layout, I also tried supporting Japanese. But I'm not sure if that is still the case.

azul-text-layout is confusing for me! I've never coded in Rust and azul-text-layout seems to be for its own GUI library, which confuses me more about what it does to help create PDFs...

pikhosh avatar Aug 25 '22 10:08 pikhosh

@pikhosh you can use it without a GUI, it just does the text layouting: https://github.com/fschutt/printpdf/issues/39#issuecomment-559118743

Yeah, it's a lot of code to integrate, but allsorts is even more code. In short, I don't know of any "solid" text layouting API that does that.

fschutt avatar Aug 25 '22 13:08 fschutt

for ref swash and demo it could help

adals avatar Aug 25 '22 21:08 adals