I noticed that NSTextContainer.lineFragmentPadding value does not affect the NSTextLayoutManager.usageBoundsForTextContainer rectangle on both sizes.
Documentation of lineFragmentPadding says: "The padding appears at the beginning and end of the line fragment rectangles.", however the value of the usageBoundsForTextContainer
does not resize appropriately.
Let's see how a different value of lineFragmentPadding affect the text container rectangle:
for lineFragmentPadding = 5 usageBoundsForTextContainer = (x: 5.0, y: 0.0, width: 66.73828125, height: 14.0)
for lineFragmentPadding = 0 usageBoundsForTextContainer = (x: 0.0, y: 0.0, width: 66.73828125, height: 14.0)
as the "x" value updated as expected, the width did not change. The expected change would be to add (or substract) the value of lineFragmentPadding from the container width
the full sample code:
// Storage
let textContentManager = NSTextContentStorage()
// Layout
let textLayoutManager = NSTextLayoutManager()
textContentManager.addTextLayoutManager(textLayoutManager)
textContentManager.primaryTextLayoutManager = textLayoutManager
let textContainer = NSTextContainer()
textLayoutManager.textContainer = textContainer
textContentManager.attributedString = NSAttributedString(string: "01234567890123456789")
textContainer.lineFragmentPadding = 5
textLayoutManager.ensureLayout(for: textContentManager.documentRange)
print(textLayoutManager.usageBoundsForTextContainer) // (5.0, 0.0, 66.73828125, 14.0)
textContainer.lineFragmentPadding = 0
textLayoutManager.ensureLayout(for: textContentManager.documentRange)
print(textLayoutManager.usageBoundsForTextContainer) // (0.0, 0.0, 66.73828125, 14.0)