gg icon indicating copy to clipboard operation
gg copied to clipboard

Text drawn with DrawStringWrapped appears in discrete characters for Arabic

Open emad-elsaid opened this issue 7 years ago • 3 comments

When writing a text in arabic the characters are connected as follows :

عبد الفتاح السيسي

When I tried to use DrawStringWrapped it drawn the text in a descrete way, every character is not connected as follows: image

The code snippet that generated the text in that image is as follows:

func drawName(dc *gg.Context, name string) {
	const height = 250
	dc.SetRGB(0, 0, 0)
	dc.DrawRectangle(0, HEIGHT-height, WIDTH, height)
	dc.Fill()

	if err := dc.LoadFontFace("font.ttf", 70); err != nil {
		return
	}
	dc.SetRGB(1, 1, 1)
	dc.DrawStringWrapped(name, 100, HEIGHT-height+70, 0, 0, WIDTH-200, 1.5, gg.AlignLeft)
	dc.Fill()
}

emad-elsaid avatar Jan 06 '19 09:01 emad-elsaid

@nigeltao Is this something I'm doing wrong or does freetype have the same problem?

fogleman avatar Jan 14 '19 16:01 fogleman

Freetype-go has the same problem: it does not do text shaping. We'd need the Go equivalent of the Harfbuzz library, but that's a lot of work, and I don't have any spare time. Sorry.

nigeltao avatar Jan 15 '19 23:01 nigeltao

I've created a library to help fixing the text shaping issue for arabic: https://github.com/AbdullahDiaa/ar-golang

I hope it's helpful.

AbdullahDiaa avatar Jun 16 '21 23:06 AbdullahDiaa