fschutt / printpdf

An easy-to-use library for writing PDF in Rust
https://docs.rs/printpdf/
MIT License
777 stars 95 forks source link

RTL support #126

Open pikhosh opened 1 year ago

pikhosh commented 1 year ago

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?

fschutt commented 1 year ago

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).

pikhosh commented 1 year ago

RTL - do you mean arabic / hebrew scripts?

Yeah!

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

Thanks! I will try genpdf!

fschutt commented 1 year ago

@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 commented 1 year ago

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.

pikhosh commented 1 year ago

@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 😅)

fschutt commented 1 year ago

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.

pikhosh commented 1 year ago

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...

fschutt commented 1 year ago

@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.

adals commented 1 year ago

for ref swash and demo it could help