Wednesday, 15 September 2010

go - Aligning text in golang with Truetype -


I am trying to present some text on a PNG, which is using the FreeType / TrueType in the Galang project Used to be. As you can see from an attachment, I am trying to render 4 characters in the column - each letter is centered in the column. The truetype API is used to get the width and width of the glow but I can not be converted to give accurate offset for each glyph, for example with the O glyph, the font is used While I get the following dimensions:

Hertricks {Advance: 543 left sidebearing: 36} bounds {XMin: 0 YMin: -64 XMax: 512 YMax: 704} Advance width: 512 < / Code> <

Size: = 125.00 Tile Off Aet: = (int (TileWed): / p>

* I) + Int (tileWidth / 2) pt: = freetype.Pt (tileoffset, (IMGH -NightWhite) -Inter (size ))

How can I return the returning glyph dimension correctly to offset the characters truetype? I have tried to use AdvanceWidth as a detailed code (line 160) but it does not give me a consistent result in all the glyphs.

example of presentation

As suggested by Simon, using the correct solution AdvanceWidth:

Crude Example:

package main import ("flag" "FMT" "IO / Ioutil" "log" "image" "buffio" "picture / illustration" "image / png" "image / color" "github. Com / golang / freetype / truetype "" golang.org/x/image/font "" github ("dpi = flag.float64 (" dpi ", 72," screen resolution in dots per inch ") fontfile = flag.String ( "Fontfile", "/ usr / share / f Hinting = Flag String ("Hinting", "None", "None") Size = Flag. Float 64 ("Size", "T / F / Liberation Serif-Regular TTF", "Filename of TTF Font" , 125, "font size in digits") spacing = flag. Float64 ("difference", 1.5, "line difference (i.e., double meaning double 2)") wonb = flag.Bool ("whiteonblack", wrong, " White text on a black background ") text = string (" JOJO ")) func main () {flag.Parse () fmt.printf (" Fontfile% q \ n ", * fontfile loading) b, Err: = ioutil.ReadFile (* fontfile) If mistake! = Zero {log. The printline (mistake) returns} f, err: = truetype.Parse (b) if mistake! = Zero

No comments:

Post a Comment