Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: go-text rendering support #298

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

vantaboard
Copy link
Contributor

@vantaboard vantaboard commented Jun 9, 2024

A couple of months ago MayankFawkes posted about a rendering issue with Hindi #293 which prompted a discussion on font rendering go-text/typesetting#159.

Related Issues:
[QUESTION] Can we use it with gopdf go-text/typesetting#159
Support for Other languages 01walid/goarabic#8
I can not use Arabic language in pdf #50
Right to Left language support #96
Displaying proper malayalam text on PDF using Go lang gopdf #126
Print glyph #143
Incorrect Rendering of Devanagari #153
gopdf not support RTL and Persian (Farsi) language #178
how to get ttl file that support chinese charactor well? #251
Right to Left does not work properly on multicell, Works correctly on Text #291
HIndi Rendering Problem #293

I have created a draft pull request to explore integrating go-text as a separate renderer besides the gopdf one and would love some guidance on how to proceed in completing this feature.

Below is an image of a test implementation with go-text/render on the top and the typical rendering on the bottom. It only renders an image though, so the text cannot be selected as intended:

image

Edit:
The test file no longer renders with go-text/render, as it became apparent I needed to use the low-level typesetting core module instead, so my process now involves adapting the font.Face structure to update glyph positioning in the native font rendering.

@vantaboard
Copy link
Contributor Author

So far, I have go the glyph identifiers from the go-text/typesetting character map table to display on lookup of the runes when the font cache is being built, but I'm not sure how to proceed to use the glyph positioning or substitution table to modify the positioning of the glyphs in combination with the PDF text operators (which I assume is how I would do that).

image

@benoitkugler
Copy link

Hi,

I think you need to convert from runes to shaped glyphs first, using go-text/typesetting/shaping.HarfbuzzShaper.Shape (which calls the low level go-text/typesetting/harfbuzz shaper).

Then, you loop through the Output.Glyphs slice, using the Glyph.XOffset and Glyph.XAdvance to set the space around each glyph, as defined by the TJ pdf operator.

@vantaboard
Copy link
Contributor Author

vantaboard commented Jun 15, 2024

Hi,

I think you need to convert from runes to shaped glyphs first, using go-text/typesetting/shaping.HarfbuzzShaper.Shape (which calls the low level go-text/typesetting/harfbuzz shaper).

Then, you loop through the Output.Glyphs slice, using the Glyph.XOffset and Glyph.XAdvance to set the space around each glyph, as defined by the TJ pdf operator.

All right, I made adjustments but now I'm getting a weird issue where one of the glyphs do not appear.

image

Seems like it might be because it is https://en.wikipedia.org/wiki/Visarga which in Unicode is a "placeholder glyph character".

This is the PostScript that is generating the above image:

BT
10.00 814.62 TD
/F1 14 Tf 0 Tc
[43<0093>47<0098>37<00E8>43<008F>0<022F>] TJ
ET

I used go-text/typesetting/font.Face.GlyphName and it returned u0903 for one of the glyphs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants