Attempting to recreate PKDrawing point-by-point using an existing drawing instance results in .pencil strokes being displayed with different (thinner) width than the original. Strokes with all other inks are restored fully visually identically to the original.
This can be observed from iOS 15.2 to iOS 18 beta 5.
Code used to remake the drawing:
let restoredDrawing = PKDrawing(strokes: drawing.strokes.map { stroke in
PKStroke(
ink: stroke.ink,
path: PKStrokePath(controlPoints: (0..<stroke.path.count).map { controlIndex in
// This could be replaced with stroke.path.map { point in }
let point = Array(stroke.path)[controlIndex]
// This does not result in the same presentation as the point
let restoredPoint: PKStrokePoint
if #available(iOS 17.0, *) {
restoredPoint = PKStrokePoint(
location: point.location,
timeOffset: point.timeOffset,
size: point.size,
opacity: point.opacity,
force: point.force,
azimuth: point.azimuth,
altitude: point.altitude,
secondaryScale: point.secondaryScale
)
} else {
restoredPoint = PKStrokePoint(
location: point.location,
timeOffset: point.timeOffset,
size: point.size,
opacity: point.opacity,
force: point.force,
azimuth: point.azimuth,
altitude: point.altitude
)
}
// Even this produces correct result:
// let restoredPoint = stroke.path.interpolatedPoint(at: CGFloat(controlIndex))
compare(point, restoredPoint)
return restoredPoint
},
creationDate: stroke.path.creationDate),
transform: stroke.transform,
mask: stroke.mask
)
})
Gist with ViewController with side-by-side to paste into new project: https://gist.github.com/ilevIO/a1dea60ab6cb16047de2b421897d30f1