fschutt / printpdf

A fully-featured PDF library for Rust, WASM-ready
https://fschutt.github.io/printpdf/
MIT License
832 stars 98 forks source link

RTL support #126

Open pikhosh opened 2 years ago

pikhosh commented 2 years 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 2 years 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 2 years 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 2 years 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 2 years 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 2 years 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 2 years 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 2 years 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 2 years 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 2 years ago

for ref swash and demo it could help

fschutt commented 3 weeks ago

In 0.8 there is now a text-shaping API using allsorts for glyph layout. Not sure if that will to RTL out-of-the-box but I hope.