Support typographicBounds in demo

This commit is contained in:
Rob Napier
2020-01-05 18:08:13 -05:00
parent 23cb2d4dbd
commit dd6ca46028
3 changed files with 11 additions and 1 deletions

View File

@@ -22,6 +22,11 @@ struct PathTextLayoutManager {
}
}
public var typographicBounds: CGRect {
// FIXME: ensureLayout? Maybe pre-calculate this?
glyphRuns.reduce(.null) { $0.union($1.typographicBounds) }
}
mutating func ensureGlyphs() {
if needsGlyphGeneration { updateGlyphRuns() }
}

View File

@@ -59,5 +59,10 @@ public class PathTextView: UIView {
context.textMatrix = CGAffineTransform(scaleX: 1, y: -1)
layoutManager.draw(in: context)
}
public var typographicBounds: CGRect {
layoutManager.ensureLayout()
return layoutManager.typographicBounds
}
}
#endif

View File

@@ -53,7 +53,7 @@ class ViewController: UIViewController {
var tightFrame = frame
tightFrame.origin.y = 400
let tightTextView = PathTextView(frame: tightFrame, text: text, path: path)
tightTextView.sizeToFit()
tightTextView.bounds = tightTextView.typographicBounds
tightTextView.layer.borderColor = UIColor.red.cgColor
tightTextView.layer.borderWidth = 1
view.addSubview(tightTextView)