gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.21k stars 69 forks source link

How to make Khmer language show correctly? #278

Closed kuyseng closed 8 months ago

kuyseng commented 8 months ago

Hi All;

I'm looking for help about render my native language (Khmer) on PDF. It's wrong in some how. I don't know whether the hexapdf library has option or tweak to make it work correctly. The text should be "ប្រទេសកម្ពុជា" but it shows up like in below image.

image

To type Khmer language, we need to choose Khmer Keyboard first and the font can get from Google font:

gettalong commented 8 months ago

This has most likely to do with the fact that the characters you write are combined to the correct glyphs by the browser font engine while HexaPDF outputs the characters as glyphs as is.

I'm not familiar with Khmer but if it is possible to pre-combine the characters HexaPDF should be able to output the correct version.

gettalong commented 8 months ago

For more information, see e.g. https://harfbuzz.github.io/why-do-i-need-a-shaping-engine.html, especially the third bullet point which may also apply to Khmer.

There is actually a harfbuzz-gem which you may wanna try to use because HarfBuzz is able to do what you want. Also see https://github.com/gettalong/hexapdf/issues/191.

kuyseng commented 8 months ago

thanks @gettalong for your direction. As I search Harfbuzz seem support my Khmer language in issue. Currently I try harfbuzz-gem but I still get wrong shaping for some cases. e.g. "កម្ពុជា" seem work fine. but wrong with "ប្រទេស" I will try to folk harfbuzz-gem to map some functions such hb_buffer_set_direction, hb_buffer_set_script & hb_buffer_set_language because hb_buffer_guess_segment_properties may not work well with my texts.

image

gettalong commented 8 months ago

@kuyseng I'm closing this issue for now since this can only be done using a fully-featured font layout engine like HarfBuzz.