void Path::apply(void* info, PathApplierFunction function) const { PathApplierInfo pinfo; pinfo.info = info; pinfo.function = function; CGPathApply(m_path, &pinfo, CGPathApplierToPathApplier); }
//----------------------------------------------------------------------------------- static void DrawTheMTView(CGContextRef ctx, MTViewData* data) { CGRect dstRect; #if CG_COORDINATES TransformHIViewToCG(ctx, data->theView); #endif // Draw the image first, before stroking the path; otherwise the path gets overwritten if (data->theImage != NULL) { dstRect = CGRectMake(0, 0, CGImageGetWidth(data->theImage), CGImageGetHeight(data->theImage)); #if CG_COORDINATES CGContextDrawImage(ctx, dstRect, data->theImage); #else HIViewDrawCGImage(ctx, &dstRect, data->theImage); #endif } if (data->thePath != NULL) { CGPathApply(data->thePath, (void*)ctx, MyCGPathApplier); CGContextStrokePath(ctx); } } // DrawTheMTView
static CGMutablePathRef copyCGPathClosingSubpaths(CGPathRef originalPath) { CGMutablePathRef path = CGPathCreateMutable(); CGPathApply(originalPath, path, copyClosingSubpathsApplierFunction); CGPathCloseSubpath(path); return path; }
already_AddRefed<PathBuilder> PathCG::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const { // 10.7 adds CGPathCreateMutableCopyByTransformingPath it might be faster than doing // this by hand struct TransformApplier { CGMutablePathRef path; CGAffineTransform transform; static void TranformCGPathApplierFunc(void *vinfo, const CGPathElement *element) { TransformApplier *info = reinterpret_cast<TransformApplier*>(vinfo); switch (element->type) { case kCGPathElementMoveToPoint: { CGPoint pt = element->points[0]; CGPathMoveToPoint(info->path, &info->transform, pt.x, pt.y); break; } case kCGPathElementAddLineToPoint: { CGPoint pt = element->points[0]; CGPathAddLineToPoint(info->path, &info->transform, pt.x, pt.y); break; } case kCGPathElementAddQuadCurveToPoint: { CGPoint cpt = element->points[0]; CGPoint pt = element->points[1]; CGPathAddQuadCurveToPoint(info->path, &info->transform, cpt.x, cpt.y, pt.x, pt.y); break; } case kCGPathElementAddCurveToPoint: { CGPoint cpt1 = element->points[0]; CGPoint cpt2 = element->points[1]; CGPoint pt = element->points[2]; CGPathAddCurveToPoint(info->path, &info->transform, cpt1.x, cpt1.y, cpt2.x, cpt2.y, pt.x, pt.y); break; } case kCGPathElementCloseSubpath: { CGPathCloseSubpath(info->path); break; } } } }; TransformApplier ta; ta.path = CGPathCreateMutable(); ta.transform = GfxMatrixToCGAffineTransform(aTransform); CGPathApply(mPath, &ta, TransformApplier::TranformCGPathApplierFunc); return MakeAndAddRef<PathBuilderCG>(ta.path, aFillRule); }
void Path::apply(void* info, PathApplierFunction function) const { if (isNull()) return; PathApplierInfo pinfo; pinfo.info = info; pinfo.function = function; CGPathApply(m_path, &pinfo, CGPathApplierToPathApplier); }
static CFStringRef CFStringFromCGPath(CGPathRef path) { if (!path) return 0; CFMutableStringRef string = CFStringCreateMutable(NULL, 0); CGPathApply(path, string, CGPathToCFStringApplierFunction); CFStringTrimWhitespace(string); return string; }
char *CGPathToCString(const CGPathRef p, const size_t capacity, const size_t increment) { if ( p == NULL ) return NULL; CGPathWriter_t t; t.allocated = MAX(0, capacity); t.increment = MAX(0, increment); t.buffer = malloc(t.allocated); if ( t.buffer != NULL ) t.buffer[0] = '\0'; t.used = 0; CGPathApply(p, &t, CGPathWriter_path_walker); return t.buffer; }
static cairo_int_status_t _cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font, cairo_scaled_glyph_t *scaled_glyph) { cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font); CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph); CGAffineTransform textMatrix; CGPathRef glyphPath; CTFontRef ctFont; cairo_path_fixed_t *path; if (glyph == INVALID_GLYPH) { _cairo_scaled_glyph_set_path (scaled_glyph, &font->base, _cairo_path_fixed_create()); return CAIRO_STATUS_SUCCESS; } /* scale(1,-1) * font->base.scale */ textMatrix = CGAffineTransformMake (font->base.scale.xx, font->base.scale.yx, -font->base.scale.xy, -font->base.scale.yy, 0, 0); // glyphPath = CGFontGetGlyphPathPtr (font_face->cgFont, &textMatrix, 0, glyph); ctFont = CTFontCreateWithGraphicsFont (font_face->cgFont, 0.0, NULL, NULL); glyphPath = CTFontCreatePathForGlyph (ctFont, glyph, &textMatrix); CFRelease (ctFont); if (!glyphPath) return CAIRO_INT_STATUS_UNSUPPORTED; path = _cairo_path_fixed_create (); if (!path) { CGPathRelease (glyphPath); return _cairo_error(CAIRO_STATUS_NO_MEMORY); } CGPathApply (glyphPath, path, _cairo_quartz_path_apply_func); CGPathRelease (glyphPath); _cairo_scaled_glyph_set_path (scaled_glyph, &font->base, path); return CAIRO_STATUS_SUCCESS; }
static cairo_int_status_t _cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font, cairo_scaled_glyph_t *scaled_glyph) { cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font); CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph); CGAffineTransform textMatrix; CGPathRef glyphPath; cairo_path_fixed_t *path; if (glyph == INVALID_GLYPH) { _cairo_scaled_glyph_set_path (scaled_glyph, &font->base, _cairo_path_fixed_create()); return CAIRO_STATUS_SUCCESS; } textMatrix = CGAffineTransformMake (font->base.scale.xx, -font->base.scale.yx, -font->base.scale.xy, font->base.scale.yy, font->base.scale.x0, font->base.scale.y0); textMatrix = CGAffineTransformConcat (textMatrix, CGAffineTransformMake (1.0, 0.0, 0.0, -1.0, 0.0, 0.0)); glyphPath = CGFontGetGlyphPathPtr (font_face->cgFont, &textMatrix, 0, glyph); if (!glyphPath) return CAIRO_INT_STATUS_UNSUPPORTED; path = _cairo_path_fixed_create (); if (!path) { CGPathRelease (glyphPath); return _cairo_error(CAIRO_STATUS_NO_MEMORY); } CGPathApply (glyphPath, path, _cairo_quartz_path_apply_func); CGPathRelease (glyphPath); _cairo_scaled_glyph_set_path (scaled_glyph, &font->base, path); return CAIRO_STATUS_SUCCESS; }
void PathCG::StreamToSink(PathSink *aSink) const { CGPathApply(mPath, aSink, StreamPathToSinkApplierFunc); }