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

[QUESTION] Can we use it with gopdf #159

Open
MayankFawkes opened this issue Apr 8, 2024 · 2 comments
Open

[QUESTION] Can we use it with gopdf #159

MayankFawkes opened this issue Apr 8, 2024 · 2 comments

Comments

@MayankFawkes
Copy link

Hey i just wanted to know can we use this with gopdf cause i am having some rendering problem for hindi

Incorrent rendering Hindi fonts https://hindi-fonts.com/fonts/mangal-regular

pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4})
pdf.AddPage()
err := pdf.AddTTFFont("mangal", "mangal.ttf")
if err != nil {
    log.Print(err.Error())
    return
}

err = pdf.SetFont("mangal", "", 14)
if err != nil {
    log.Print(err.Error())
    return
}
pdf.Cell(nil, "नमस्ते")
pdf.WritePdf("hello.pdf")

If yes, then please help me fix this code.

Output

image

Expected

image

@MayankFawkes MayankFawkes changed the title Can we use it with gopdf [QUESTION] Can we use it with gopdf Apr 8, 2024
@andydotxyz
Copy link
Contributor

This may relate to locale info. The shaping needs to know how the glyph relationships should be interpreted, which can vary based on locale or other environment outside the font definition.

I can't recall immediately how it's passed in to GoText, but I have seen the same sort of challenges in writing the go-text/render component.

@benoitkugler
Copy link
Contributor

Hi @MayankFawkes,

Thank you for your question. As you might have guessed, you encounter a typical text shaping problem. Several languages/scripts, like Arabic or Hindi, require complex layout rules to properly display text. This is the issue Harfbuzz solves.

From what I've read, gopdf does not use such a shaper, and thus won't be able to display Hindi text.

The go-text/typesetting module provides the appropriate tooling to handle such complex scripts : the low level shaping is done in the harfbuzz package, and an higher level API is provided in shaping.
This library is definitively designed to be included in others projects, so, if there is some interest, we would be glad to collaborate with gopdf to help them leverage go-text.

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

No branches or pull requests

3 participants