NSTextView ligature attribute overridden

45 views Asked by At

When setting the .ligature attribute on an NSTextView, it gets overridden when adding both a .paragraphStyle and .baselineOffset attribute at the same time. Here's the example, adding the below code

textView.textStorage?.setAttributes(
    [
        .ligature: 0,
        .font: NSFont(name: "FiraCode-Light", size: 12)!,
        .baselineOffset: 3.5,
        .paragraphStyle: {
            let p = NSParagraphStyle.default.mutableCopy()  as! NSMutableParagraphStyle
            p.lineHeightMultiple = 1.5
            p.lineSpacing = 10
            return p
        }()
    ],
    range: NSRange(location: 0, length: self.textView.string.count)
)

This should disable ligatures (see the .ligature: 0 line) on the FiraCode font which has ligatures. If the lines below the .font attribute are removed, ligatures get disabled.

Here's what it looks like with ligatures (incorrectly) enabled: bad, but with ligatures

And by disabling the .paragraphStyle and .baselineOffset the ligatures get disabled, but the needed line spacing is obviously gone.

bad, but without ligatures

Is this a bug with Apple's code? Or is there something I should be doing to disable this functionality.

0

There are 0 answers