signintech/gopdf

HIndi Rendering Problem

MayankFawkes opened this issue · 4 comments

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

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("الايام السبعة")))

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

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.

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 go-text/typesetting#159 lets see