1

I created simple NSLayoutManager subclass that allows to set custom layout location for defined substrings:

class PositionableLayoutManager: NSLayoutManager {
    var xOffsetsPerGlyphRange = [(NSRange, CGPoint)]()

    override func invalidateLayoutForCharacterRange(charRange: NSRange, actualCharacterRange actualCharRange: NSRangePointer) {
        super.invalidateLayoutForCharacterRange(charRange, actualCharacterRange: actualCharRange)
        for (range, offset) in xOffsetsPerGlyphRange {
            setLocation(offset, forStartOfGlyphRange: range)
        }
    }
}

Now, I can define custom location of any character range like 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, the only problem is that any glyph range repositioned in this way is laid out and drawn without kerning. Here is an example:

enter image description here

In green box there is text drawn using my PositionableLayoutManager with without kerning, in pink box there is same text with kering drawn using UILabel for comparison.

How can I do the same thing but with proper kerning?

Rasto
  • 17,204
  • 47
  • 154
  • 245
  • You are overriding the kerning values. I am not sure about how to do this, but try with a subclass to NSTypesetter. override the method setLocation(...) in typesetter and work there, may be this is helpfull – ion Jan 26 '16 at 12:40

0 Answers0