title: Aligning text in golang with Truetype
body: <p>I am trying to render some text on a png in a Golang project using freetype/truetype. As you can see from the attachment, I am trying to render 4 letters in columns - each letter centered in the column. Have used the truetype api to get bounds and widths of the glyphs but have been unable to convert these to give me an accurate offset for each glyph. For example with the <code>O</code> glyph, given the font I using. I get the following dimensions:</p>
  
  <p><code>Hmetric {AdvanceWidth:543 LeftSideBearing:36}
  Bounds {XMin:0 YMin:-64 XMax:512 YMax:704}
  Advance width: 512
  </code></p>
  
  <p>With the last dimension being returned from <a href="https://godoc.org/code.google.com/p/freetype-go/freetype/truetype#GlyphBuf" rel="noreferrer">GlyphBuf</a>.</p>
  
  <p>I rendered it using the following:</p>
  
  <p><code>size := 125.00
  tileOffset := (int(tileWidth) * i) + int(tileWidth/2)
  pt := freetype.Pt(tileOffset, (imgH-newCharHeight)-int(size))
  </code></p>
  
  <p>How can I use the glyph dimensions returned by truetype to offset the letters correctly? I have tried using the <code>AdvanceWidth</code> as detailed <a href="https://code.google.com/p/plotinum/source/browse/vg/font.go" rel="noreferrer">in this plotinum</a> code (line 160) but that does not give me a consistent result across all glyphs.</p>
  
  <p><img src="https://i.stack.imgur.com/B1Jxa.png" alt="Example of rendering"></p>