Handle invalidations

This commit is contained in:
Rob Napier
2020-01-01 17:42:12 -05:00
parent 7de452fa50
commit 363af726fa
2 changed files with 7 additions and 5 deletions

View File

@@ -99,22 +99,25 @@ struct PathTextLayoutManager {
return GlyphRun(run: run, locations: locations) return GlyphRun(run: run, locations: locations)
} }
updateGlyphPositions() needsGlyphGeneration = false
} }
private mutating func updateGlyphPositions() { private mutating func updateGlyphPositions() {
if needsGlyphGeneration { updateGlyphRuns() }
var tangents = TangentGenerator(path: path) var tangents = TangentGenerator(path: path)
glyphRuns = glyphRuns.map { glyphRuns = glyphRuns.map {
var glyphRun = $0 var glyphRun = $0
glyphRun.updatePositions(withTangents: &tangents) glyphRun.updatePositions(withTangents: &tangents)
return glyphRun return glyphRun
} }
needsLayout = false
} }
public mutating func draw(in context: CGContext) { public mutating func draw(in context: CGContext) {
// FIXME: Check if needed if needsLayout {
updateGlyphRuns() updateGlyphPositions()
updateGlyphPositions() }
// FIXME: Check if flip is needed (macos) // FIXME: Check if flip is needed (macos)
context.textMatrix = CGAffineTransform(translationX: 0, y:0).scaledBy(x: 1, y: -1) context.textMatrix = CGAffineTransform(translationX: 0, y:0).scaledBy(x: 1, y: -1)

View File

@@ -87,7 +87,6 @@ public class PathTextView: UIView {
public override func draw(_ rect: CGRect) { public override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()! let context = UIGraphicsGetCurrentContext()!
layoutManager.draw(in: context) layoutManager.draw(in: context)
} }
} }