mirror of
https://github.com/zhigang1992/CurvyText.git
synced 2026-03-26 10:14:20 +08:00
Support typographicBounds in demo
This commit is contained in:
@@ -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() }
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user