コード例 #1
0
void doEgg(CGContextRef context)
{
	CGPoint p0 = {0., 0.}, p1 = {0., 200.};
	CGPoint c1 = {140., 5.}, c2 = {80., 198.};
	CGContextTranslateCTM(context, 100., 5.);
	CGContextBeginPath(context);
	
	CGContextMoveToPoint(context, p0.x, p0.y);
	// Create the BŽzier path segment for the right side of the egg.
	CGContextAddCurveToPoint(context, c1.x, c1.y, c2.x, c2.y, p1.x, p1.y);
	// Create the BŽzier path segment for the left side of the egg.
	CGContextAddCurveToPoint(context, -c2.x, c2.y, -c1.x, c1.y, p0.x, p0.y);
	CGContextClosePath(context);
	CGContextSetLineWidth(context, 2);
	CGContextDrawPath(context, kCGPathStroke);
}
コード例 #2
0
// Handles a curve drawing operation for cubic (Type 1 / Postscript) outlines
//
// The curve is a Bezier patch defined by two off-curve control points (pt1 and pt2), and an endpoint (pt3).
// The starting point is whatever the current pen position is.
//
OSStatus MyCubicCurveToProc(const Float32Point *pt1, const Float32Point *pt2, const Float32Point *pt3, void *callBackDataPtr)
{
    // Adjust the points according to the glyph origin
    float x1 = ((MyCurveCallbackData *)callBackDataPtr)->origin.x + pt1->x;
    float y1 = ((MyCurveCallbackData *)callBackDataPtr)->origin.y + pt1->y;
    float x2 = ((MyCurveCallbackData *)callBackDataPtr)->origin.x + pt2->x;
    float y2 = ((MyCurveCallbackData *)callBackDataPtr)->origin.y + pt2->y;
    float x3 = ((MyCurveCallbackData *)callBackDataPtr)->origin.x + pt3->x;
    float y3 = ((MyCurveCallbackData *)callBackDataPtr)->origin.y + pt3->y;

    // Draw a curve according to the points
	y1 = ((MyCurveCallbackData *)callBackDataPtr)->windowHeight - y1;
	y2 = ((MyCurveCallbackData *)callBackDataPtr)->windowHeight - y2;
	y3 = ((MyCurveCallbackData *)callBackDataPtr)->windowHeight - y3;
	CGContextAddCurveToPoint(((MyCurveCallbackData *)callBackDataPtr)->context, x1, y1, x2, y2, x3, y3);

    // Keep track of the current pen position (used to filter degenerate cases)
    ((MyCurveCallbackData *)callBackDataPtr)->current.x = x3;
    ((MyCurveCallbackData *)callBackDataPtr)->current.y = y3;

    // Update counters and return
    if (gOutputNumSegments) segmentCount++;
    if (gOutputNumOps) curveToCount++;
    return noErr;
}
コード例 #3
0
ファイル: fx_quartz_device.cpp プロジェクト: 151706061/PDFium
void CFX_QuartzDeviceDriver::setPathToContext(const CFX_PathData* pathData)
{
    FX_INT32 count = pathData->GetPointCount();
    FX_PATHPOINT* points = pathData->GetPoints();
    CGContextBeginPath(_context);
    for (FX_INT32 i = 0; i < count; i ++) {
        switch (points[i].m_Flag & FXPT_TYPE) {
            case FXPT_MOVETO:
                CGContextMoveToPoint(_context, points[i].m_PointX, points[i].m_PointY);
                break;
            case FXPT_LINETO:
                CGContextAddLineToPoint(_context, points[i].m_PointX, points[i].m_PointY);
                break;
            case FXPT_BEZIERTO: {
                    CGContextAddCurveToPoint(_context,
                                             points[i].m_PointX, points[i].m_PointY,
                                             points[i + 1].m_PointX, points[i + 1].m_PointY,
                                             points[i + 2].m_PointX, points[i + 2].m_PointY);
                    i += 2;
                }
        }
        if (points[i].m_Flag & FXPT_CLOSEFIGURE) {
            CGContextClosePath(_context);
        }
    }
}
コード例 #4
0
ファイル: gvrender_quartz.c プロジェクト: nyue/graphviz-cmake
static void
quartzgen_bezier(GVJ_t *job, pointf *A, int n, int arrow_at_start,
	     int arrow_at_end, int filled)
{
	/* convert bezier into the current path */
	CGContextRef context = (CGContextRef)job->context;
	CGContextMoveToPoint(context, A[0].x, A[0].y);
	int i;
	for (i = 1; i < n; i += 3)
		CGContextAddCurveToPoint(context, A[i].x, A[i].y, A[i+1].x, A[i+1].y, A[i+2].x, A[i+2].y);
	
	/* draw the ellipse */
	quartzgen_path(job, filled);
}
コード例 #5
0
ファイル: ioscanvas.cpp プロジェクト: fanliugen/touchvg
bool GiCanvasIos::rawBezierTo(const Point2d* pxs, int count)
{
    bool ret = pxs && count > 2;

    for (int i = 0; i + 2 < count; i += 3)
    {
        CGContextAddCurveToPoint(m_draw->getContext(), 
            pxs[i+0].x, pxs[i+0].y,
            pxs[i+1].x, pxs[i+1].y,
            pxs[i+2].x, pxs[i+2].y);
    }

    return ret;
}
コード例 #6
0
ファイル: ioscanvas.cpp プロジェクト: fanliugen/touchvg
bool GiCanvasIos::rawPath(const GiContext* ctx, 
                          int count, const Point2d* pxs, const UInt8* types)
{
    CGContextBeginPath(m_draw->getContext());
    
    for (int i = 0; i < count; i++)
    {
        switch (types[i] & ~kGiCloseFigure)
        {
        case kGiMoveTo:
            CGContextMoveToPoint(m_draw->getContext(), pxs[i].x, pxs[i].y);
            break;

        case kGiLineTo:
            CGContextAddLineToPoint(m_draw->getContext(), pxs[i].x, pxs[i].y);
            break;

        case kGiBeziersTo:
            if (i + 2 >= count)
                return false;
            CGContextAddCurveToPoint(m_draw->getContext(), 
                pxs[i+0].x, pxs[i+0].y,
                pxs[i+1].x, pxs[i+1].y,
                pxs[i+2].x, pxs[i+2].y);
            i += 2;
            break;

        default:
            return false;
        }
        if (types[i] & kGiCloseFigure)
            CGContextClosePath(m_draw->getContext());
    }

    bool usepen = m_draw->setPen(ctx);
    bool usebrush = m_draw->setBrush(ctx);
    bool ret = count > 1 && (usepen || usebrush);
    
    if (ret) {
        CGContextDrawPath(m_draw->getContext(), usepen && usebrush ? kCGPathFillStroke
                          : usepen ? kCGPathStroke : kCGPathFill);
    }

    return ret;
}
コード例 #7
0
ファイル: ioscanvas.cpp プロジェクト: huangzongwu/touchvg
bool GiCanvasIos::rawBeziers(const GiContext* ctx, const Point2d* pxs, int count)
{
    bool ret = m_draw->setPen(ctx) && count > 1;

    if (ret)
    {
        CGContextMoveToPoint(m_draw->getContext(), pxs[0].x, pxs[0].y);
        for (int i = 1; i + 2 < count; i += 3)
        {
            CGContextAddCurveToPoint(m_draw->getContext(), 
                pxs[i+0].x, pxs[i+0].y,
                pxs[i+1].x, pxs[i+1].y,
                pxs[i+2].x, pxs[i+2].y);
        }
        CGContextStrokePath(m_draw->getContext());
    }

    return ret;
}
コード例 #8
0
ファイル: ioscanvas.cpp プロジェクト: huangzongwu/touchvg
bool GiCanvasIos::rawBezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y)
{
    CGContextAddCurveToPoint(m_draw->getContext(), c1x, c1y, c2x, c2y, x, y);
    return true;
}