signintech / gopdf

A simple library for generating PDF written in Go lang
MIT License
2.54k stars 273 forks source link

HIndi Rendering Problem #293

Open MayankFawkes opened 6 months ago

MayankFawkes commented 6 months ago

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")

Output

image

Expected

image

oneplus1000 commented 6 months ago

I'm not 100% sure, but I think this problem is caused by combine 2 letters in to one letters. This problem is more specific to the language than the gopdf lib that tries to act as a simple library for generating PDF will do.

And I've seen a similar solution in Arabic: they take the string through a conversion function before sending it to gopdf.

pdf.Text(reverseString(goarabic.ToGlyph("الايام السبعة")))
MayankFawkes commented 6 months ago

I don't think do that Arabic thing work with Hindi both are completely different

oneplus1000 commented 6 months ago

I don't mean that goarabic can be used in Hindi. What I mean is that the problem arises the same way as in Arabic, where letters are changed or combined depending on the preceding letter. What you should do is write a character converter similar to goarabic but in hindi.

MayankFawkes commented 6 months ago

yeah i am looking for something like that i found go-text/typesetting but not sure if we can use it or not or how can we use it so i made issue there https://github.com/go-text/typesetting/issues/159 lets see