mirror of
https://github.com/zhigang1992/CurvyText.git
synced 2026-04-30 18:32:34 +08:00
Handle invalidations
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user