I'm drawing text within a CGPath
, in order to do hit-testing on the text, I'm using CTFrameGetLineOrigins
. Here's what the documentation says:
Each CGPoint is the origin of the corresponding line in the array of lines returned by CTFrameGetLines, relative to the origin of the frame's path.
How would I go about finding the origin of the frame's path? Examples I've found all save the origin of the path when the path is initially created. I have two problems with this:
CGPoint
in addition to the CGPath
. Ugly, but not insurmountable.You can use CGPathApply
to examine the full path:
typedef struct {
CGPoint origin;
BOOL found;
} MySearchData;
void MyApplierFunction (void* info, const CGPathElement* element) {
MySearchData* searchData = (MySearchData *) info;
if (! searchData->found) {
searchData->origin = element->points[0];
searchData->found = YES;
}
}
CGPoint GetPathOrigin (CGPathRef path) {
MySearchData searchData = { CGPointZero, NO };
CGPathApply(path, (void *) &searchData, &MyApplierFunction);
return searchData.origin;
}