static void _cairo_quartz_path_apply_func (void *info, const CGPathElement *el) { cairo_path_fixed_t *path = (cairo_path_fixed_t *) info; cairo_status_t status; switch (el->type) { case kCGPathElementMoveToPoint: status = _cairo_path_fixed_move_to (path, _cairo_fixed_from_double(el->points[0].x), _cairo_fixed_from_double(el->points[0].y)); assert(!status); break; case kCGPathElementAddLineToPoint: status = _cairo_path_fixed_line_to (path, _cairo_fixed_from_double(el->points[0].x), _cairo_fixed_from_double(el->points[0].y)); assert(!status); break; case kCGPathElementAddQuadCurveToPoint: { cairo_fixed_t fx, fy; double x, y; if (!_cairo_path_fixed_get_current_point (path, &fx, &fy)) fx = fy = 0; x = _cairo_fixed_to_double (fx); y = _cairo_fixed_to_double (fy); status = _cairo_path_fixed_curve_to (path, _cairo_fixed_from_double((x + el->points[0].x * 2.0) / 3.0), _cairo_fixed_from_double((y + el->points[0].y * 2.0) / 3.0), _cairo_fixed_from_double((el->points[0].x * 2.0 + el->points[1].x) / 3.0), _cairo_fixed_from_double((el->points[0].y * 2.0 + el->points[1].y) / 3.0), _cairo_fixed_from_double(el->points[1].x), _cairo_fixed_from_double(el->points[1].y)); } assert(!status); break; case kCGPathElementAddCurveToPoint: status = _cairo_path_fixed_curve_to (path, _cairo_fixed_from_double(el->points[0].x), _cairo_fixed_from_double(el->points[0].y), _cairo_fixed_from_double(el->points[1].x), _cairo_fixed_from_double(el->points[1].y), _cairo_fixed_from_double(el->points[2].x), _cairo_fixed_from_double(el->points[2].y)); assert(!status); break; case kCGPathElementCloseSubpath: status = _cairo_path_fixed_close_path (path); assert(!status); break; } }
cairo_status_t _cairo_path_fixed_rel_curve_to (cairo_path_fixed_t *path, cairo_fixed_t dx0, cairo_fixed_t dy0, cairo_fixed_t dx1, cairo_fixed_t dy1, cairo_fixed_t dx2, cairo_fixed_t dy2) { cairo_fixed_t x0, y0; cairo_fixed_t x1, y1; cairo_fixed_t x2, y2; if (! path->has_current_point) return _cairo_error (CAIRO_STATUS_NO_CURRENT_POINT); x0 = path->current_point.x + dx0; y0 = path->current_point.y + dy0; x1 = path->current_point.x + dx1; y1 = path->current_point.y + dy1; x2 = path->current_point.x + dx2; y2 = path->current_point.y + dy2; return _cairo_path_fixed_curve_to (path, x0, y0, x1, y1, x2, y2); }
static cairo_status_t _cairo_default_context_curve_to (void *abstract_cr, double x1, double y1, double x2, double y2, double x3, double y3) { cairo_default_context_t *cr = abstract_cr; cairo_fixed_t x1_fixed, y1_fixed; cairo_fixed_t x2_fixed, y2_fixed; cairo_fixed_t x3_fixed, y3_fixed; _cairo_gstate_user_to_backend (cr->gstate, &x1, &y1); _cairo_gstate_user_to_backend (cr->gstate, &x2, &y2); _cairo_gstate_user_to_backend (cr->gstate, &x3, &y3); x1_fixed = _cairo_fixed_from_double (x1); y1_fixed = _cairo_fixed_from_double (y1); x2_fixed = _cairo_fixed_from_double (x2); y2_fixed = _cairo_fixed_from_double (y2); x3_fixed = _cairo_fixed_from_double (x3); y3_fixed = _cairo_fixed_from_double (y3); return _cairo_path_fixed_curve_to (cr->path, x1_fixed, y1_fixed, x2_fixed, y2_fixed, x3_fixed, y3_fixed); }
static cairo_status_t _append_curve_to (void *closure, cairo_point_t *p0, cairo_point_t *p1, cairo_point_t *p2) { cairo_path_fixed_t *path = (cairo_path_fixed_t *) closure; return _cairo_path_fixed_curve_to (path, p0->x, p0->y, p1->x, p1->y, p2->x, p2->y); }
IFACEMETHODIMP_(void) AddBeziers( const D2D1_BEZIER_SEGMENT *beziers, UINT beziersCount) { for (unsigned int i = 0; i < beziersCount; i++) { cairo_status_t status = _cairo_path_fixed_curve_to(mCairoPath, GetFixedX(beziers[i].point1), GetFixedY(beziers[i].point1), GetFixedX(beziers[i].point2), GetFixedY(beziers[i].point2), GetFixedX(beziers[i].point3), GetFixedY(beziers[i].point3)); } }
static cairo_status_t _scaled_glyph_path_curve_to (void *abstract_closure, cairo_point_t *p0, cairo_point_t *p1, cairo_point_t *p2) { cairo_scaled_glyph_path_closure_t *closure = abstract_closure; return _cairo_path_fixed_curve_to (closure->path, p0->x + closure->offset.x, p0->y + closure->offset.y, p1->x + closure->offset.x, p1->y + closure->offset.y, p2->x + closure->offset.x, p2->y + closure->offset.y); }
static OSStatus MyATSCubicCurveToCallback(const Float32Point * pt1, const Float32Point * pt2, const Float32Point * pt3, void *callBackDataPtr) { cairo_ATSUI_glyph_path_callback_info_t *info = callBackDataPtr; double scaledPt[2]; cairo_fixed_t x0, y0; cairo_fixed_t x1, y1; cairo_fixed_t x2, y2; scaledPt[0] = pt1->x; scaledPt[1] = pt1->y; cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]); x0 = _cairo_fixed_from_double(scaledPt[0]); y0 = _cairo_fixed_from_double(scaledPt[1]); scaledPt[0] = pt2->x; scaledPt[1] = pt2->y; cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]); x1 = _cairo_fixed_from_double(scaledPt[0]); y1 = _cairo_fixed_from_double(scaledPt[1]); scaledPt[0] = pt3->x; scaledPt[1] = pt3->y; cairo_matrix_transform_point(&info->scale, &scaledPt[0], &scaledPt[1]); x2 = _cairo_fixed_from_double(scaledPt[0]); y2 = _cairo_fixed_from_double(scaledPt[1]); _cairo_path_fixed_curve_to(info->path, x0, y0, x1, y1, x2, y2); return noErr; }
/** * _cairo_path_append_to_context: * @path: the path data to be appended * @cr: a cairo context * * Append @path to the current path within @cr. * * Return value: %CAIRO_STATUS_INVALID_PATH_DATA if the data in @path * is invalid, and %CAIRO_STATUS_SUCCESS otherwise. **/ cairo_status_t _cairo_path_append_to_context (const cairo_path_t *path, cairo_t *cr) { const cairo_path_data_t *p, *end; cairo_fixed_t x1_fixed, y1_fixed; cairo_fixed_t x2_fixed, y2_fixed; cairo_fixed_t x3_fixed, y3_fixed; cairo_matrix_t user_to_backend; cairo_status_t status; double x, y; user_to_backend = cr->gstate->ctm; cairo_matrix_multiply (&user_to_backend, &user_to_backend, &cr->gstate->target->device_transform); end = &path->data[path->num_data]; for (p = &path->data[0]; p < end; p += p->header.length) { switch (p->header.type) { case CAIRO_PATH_MOVE_TO: if (unlikely (p->header.length < 2)) return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); x = p[1].point.x, y = p[1].point.y; cairo_matrix_transform_point (&user_to_backend, &x, &y); x1_fixed = _cairo_fixed_from_double (x); y1_fixed = _cairo_fixed_from_double (y); status = _cairo_path_fixed_move_to (cr->path, x1_fixed, y1_fixed); break; case CAIRO_PATH_LINE_TO: if (unlikely (p->header.length < 2)) return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); x = p[1].point.x, y = p[1].point.y; cairo_matrix_transform_point (&user_to_backend, &x, &y); x1_fixed = _cairo_fixed_from_double (x); y1_fixed = _cairo_fixed_from_double (y); status = _cairo_path_fixed_line_to (cr->path, x1_fixed, y1_fixed); break; case CAIRO_PATH_CURVE_TO: if (unlikely (p->header.length < 4)) return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); x = p[1].point.x, y = p[1].point.y; cairo_matrix_transform_point (&user_to_backend, &x, &y); x1_fixed = _cairo_fixed_from_double (x); y1_fixed = _cairo_fixed_from_double (y); x = p[2].point.x, y = p[2].point.y; cairo_matrix_transform_point (&user_to_backend, &x, &y); x2_fixed = _cairo_fixed_from_double (x); y2_fixed = _cairo_fixed_from_double (y); x = p[3].point.x, y = p[3].point.y; cairo_matrix_transform_point (&user_to_backend, &x, &y); x3_fixed = _cairo_fixed_from_double (x); y3_fixed = _cairo_fixed_from_double (y); status = _cairo_path_fixed_curve_to (cr->path, x1_fixed, y1_fixed, x2_fixed, y2_fixed, x3_fixed, y3_fixed); break; case CAIRO_PATH_CLOSE_PATH: if (unlikely (p->header.length < 1)) return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); status = _cairo_path_fixed_close_path (cr->path); break; default: return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); } if (unlikely (status)) return status; } return CAIRO_STATUS_SUCCESS; }