Added code to take glyph metrics into account