fschutt / printpdf

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

How to get information about length/heigth of a string you're printing to a pdf #123

Closed astrale-sharp closed 2 years ago

astrale-sharp commented 2 years ago

Hi!

I'm toying with the idea of writing an alternative to tex/latex, i want to keep the idea of boxes and glue (if you are familiar)

so i would like to know the rectangle in which a text you want to put on the pdf will be contained with.

I also would like to be able to align these boxes in a way that the text flows naturally, explanation : the characters 'an' and 'd' don't have the same height, so the resulting boxes don't have the same height but i would like to known where to align them so we can read 'and' naturally.

Is it even possible? what do you think? Do you have advice ? Thanks!

If something is unclear, i can rephrase it, I'm not an English speaker

Thank you for this library and possibly your answer :heart:

fschutt commented 2 years ago

See issue https://github.com/fschutt/printpdf/issues/49 - you can use either my crate https://crates.io/crates/azul-text-layout or some other crate to calculate that. Your problem is called "font shaping" and it's very complex, so I didn't want to integrate it into a library

If you don't want to deal with that, use https://crates.io/crates/genpdf/0.2.0 (which is built on printpdf) instead

astrale-sharp commented 2 years ago

thank you so much for your answer! i'm going to explore :)