ios - NSLayoutManager: Calling setLocation(_:forStartOfGlyphRange:) disables kerning in the whole string? -


i created simple nslayoutmanager subclass allows set custom layout location defined substrings:

class positionablelayoutmanager: nslayoutmanager {     var xoffsetsperglyphrange = [(nsrange, cgpoint)]()      override func invalidatelayoutforcharacterrange(charrange: nsrange, actualcharacterrange actualcharrange: nsrangepointer) {         super.invalidatelayoutforcharacterrange(charrange, actualcharacterrange: actualcharrange)         (range, offset) in xoffsetsperglyphrange {             setlocation(offset, forstartofglyphrange: range)         }     } } 

now, can define custom location of character range this:

let glyphrange = layoutmanager.glyphrangeforcharacterrange(charrange, actualcharacterrange: nil) layoutmanager.xoffsetsperglyphrange.append((glyphrange, custompointlocation)) layoutmanager.invalidatelayoutforcharacterrange(nsrange(location: 0, length: textstorage.length), actualcharacterrange: nil) 

it works fine, problem glyph range repositioned in way laid out , drawn without kerning. here example:

enter image description here

in green box there text drawn using positionablelayoutmanager without kerning, in pink box there same text kering drawn using uilabel comparison.

how can same thing proper kerning?


Comments