Esempio n. 1
0
//-----------------------------------------------------------------------------
void CGDrawContext::lineTo (const CPoint& point)
{
	CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ());
	if (context)
	{
		applyLineStyle (context);

		if ((((int32_t)currentState.frameWidth) % 2))
			CGContextTranslateCTM (context, 0.5f, -0.5f);

		CGContextBeginPath (context);
		if (currentState.drawMode.integralMode ())
		{
			CGContextMoveToPoint (context, round (currentState.penLoc.h), round (currentState.penLoc.v));
			CGContextAddLineToPoint (context, round (point.h), round (point.v));
		}
		else
		{
			CGContextMoveToPoint (context, currentState.penLoc.h, currentState.penLoc.v);
			CGContextAddLineToPoint (context, point.h, point.v);
		}
		CGContextDrawPath (context, kCGPathStroke);
		releaseCGContext (context);
	}
	currentState.penLoc = point;
}
Esempio n. 2
0
void drawRoundedRect(CGContextRef context, CGRect rrect)
{
    // Drawing with a white stroke color
    CGContextSetRGBStrokeColor(context, 0.3, 0.3, 0.3, 1.0);
    CGContextSetRGBFillColor(context, 0.3, 0.3, 0.3, 1.0);
    
    // Add Rect to the current path, then stroke it
    //            CGContextAddRect(context, CGRectMake(10.0, 190.0, 290.0, 73.0));
    
    
    CGContextSetLineWidth(context, 1);
    CGFloat radius = 10.0;
    
    CGFloat minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect);
    CGFloat miny = CGRectGetMinY(rrect), midy = CGRectGetMidY(rrect), maxy = CGRectGetMaxY(rrect);
    
    // Next, we will go around the rectangle in the order given by the figure below.
    //       minx    midx    maxx
    // miny    2       3       4
    // midy   1 9              5
    // maxy    8       7       6
    // Which gives us a coincident start and end point, which is incidental to this technique, but still doesn't
    // form a closed path, so we still need to close the path to connect the ends correctly.
    // Thus we start by moving to point 1, then adding arcs through each pair of points that follows.
    // You could use a similar tecgnique to create any shape with rounded corners.
    
    // Start at 1
    CGContextMoveToPoint(context, minx, midy);
    // Add an arc through 2 to 3
    CGContextAddArcToPoint(context, minx, miny, midx, miny, radius);
    // Add an arc through 4 to 5
    CGContextAddArcToPoint(context, maxx, miny, maxx, midy, radius);
    // Add an arc through 6 to 7
    CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
    // Add an arc through 8 to 9
    CGContextAddArcToPoint(context, minx, maxy, minx, midy, radius);
    // Close the path
    CGContextClosePath(context);
    // Fill & stroke the path
    CGContextDrawPath(context, kCGPathFillStroke);
    
    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.0);
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
    
    CGContextMoveToPoint(context, minx, midy);
    // Add an arc through 2 to 3
    CGContextAddArcToPoint(context, minx, miny, midx, miny, radius);
    // Add an arc through 4 to 5
    CGContextAddArcToPoint(context, maxx, miny, maxx, midy, radius);
    // Add an arc through 6 to 7
    CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
    // Add an arc through 8 to 9
    CGContextAddArcToPoint(context, minx, maxy, minx, midy, radius);
    // Close the path
    CGContextClosePath(context);
    // Fill & stroke the path
    CGContextDrawPath(context, kCGPathFillStroke);
}
Esempio n. 3
0
void structGraphicsScreen :: v_fillArea (long numberOfPoints, double *xyDC) {
#if cairo
    if (our d_cairoGraphicsContext == NULL) return;
    // cairo_new_path (our d_cairoGraphicsContext); // move_to() automatically creates a new path
    cairo_move_to (our d_cairoGraphicsContext, xyDC [0], xyDC [1]);
    for (long i = 1; i < numberOfPoints; i ++)
        cairo_line_to (our d_cairoGraphicsContext, xyDC [i + i], xyDC [i + i + 1]);
    cairo_close_path (our d_cairoGraphicsContext);
    cairo_fill (our d_cairoGraphicsContext);
#elif win
    MY_BRUSH
    BeginPath (our d_gdiGraphicsContext);
    MoveToEx (our d_gdiGraphicsContext, xyDC [0], xyDC [1], NULL);
    for (long i = 1; i < numberOfPoints; i ++)
        LineTo (our d_gdiGraphicsContext, xyDC [i + i], xyDC [i + i + 1]);
    EndPath (our d_gdiGraphicsContext);
    FillPath (our d_gdiGraphicsContext);
    DEFAULT
#elif mac
    GraphicsQuartz_initDraw (this);
    quartzPrepareFill (this);
    CGContextBeginPath (our d_macGraphicsContext);
    CGContextMoveToPoint (our d_macGraphicsContext, xyDC [0], xyDC [1]);
    for (long i = 1; i < numberOfPoints; i ++) {
        CGContextAddLineToPoint (our d_macGraphicsContext, xyDC [i + i], xyDC [i + i + 1]);
    }
    CGContextFillPath (our d_macGraphicsContext);
    GraphicsQuartz_exitDraw (this);
#endif
}
Esempio n. 4
0
FX_BOOL CFX_QuartzDeviceDriver::DrawCosmeticLine(FX_FLOAT           x1,
        FX_FLOAT              y1,
        FX_FLOAT              x2,
        FX_FLOAT              y2,
        FX_DWORD              argb,
        int                   alphaFlag       ,
        void*                 iccTransform    ,
        int					blend_type )
{
    CGBlendMode mode = GetCGBlendMode(blend_type);
    if (mode != kCGBlendModeNormal) {
        CGContextSetBlendMode(_context, mode);
    }
    CGPoint pt = CGPointApplyAffineTransform(CGPointMake(x1, y1), _foxitDevice2User);
    x1 = pt.x;
    y1 = pt.y;
    pt = CGPointApplyAffineTransform(CGPointMake(x2, y2), _foxitDevice2User);
    x2 = pt.x;
    y2 = pt.y;
    FX_INT32 a, r, g, b;
    ArgbDecode(argb, a, r, g, b);
    CGContextSetRGBStrokeColor(_context,
                               r / 255.f,
                               g / 255.f,
                               b / 255.f,
                               a / 255.f);
    CGContextMoveToPoint(_context, x1, y1);
    CGContextAddLineToPoint(_context, x2, y2);
    CGContextStrokePath(_context);
    if (mode != kCGBlendModeNormal) {
        CGContextSetBlendMode(_context, kCGBlendModeNormal);
    }
    return TRUE;
}
Esempio n. 5
0
static void AddRoundedRectToPath(CGContextRef context, CGRect rect,
                                 float ovalWidth, float ovalHeight)
{
    float fw, fh;

    if (ovalWidth == 0 || ovalHeight == 0)
    {
        CGContextAddRect(context, rect);
        return;
    }

    CGContextSaveGState(context);

    CGContextTranslateCTM (context, CGRectGetMinX(rect),
                           CGRectGetMinY(rect));
    CGContextScaleCTM (context, ovalWidth, ovalHeight);
    fw = CGRectGetWidth (rect) / ovalWidth;
    fh = CGRectGetHeight (rect) / ovalHeight;

    CGContextMoveToPoint(context, fw, fh / 2);
    CGContextAddArcToPoint(context, fw, fh, fw / 2, fh, 1);
    CGContextAddArcToPoint(context, 0, fh, 0, fh / 2, 1);
    CGContextAddArcToPoint(context, 0, 0, fw / 2, 0, 1);
    CGContextAddArcToPoint(context, fw, 0, fw, fh / 2, 1);
    CGContextClosePath(context);

    CGContextRestoreGState(context);
}
Esempio n. 6
0
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);
        }
    }
}
Esempio n. 7
0
//-----------------------------------------------------------------------------
void CGDrawContext::drawLine (const LinePair& line)
{
    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        applyLineStyle (context);

        CGContextBeginPath (context);
        CGPoint first = CGPointFromCPoint (line.first);
        CGPoint second = CGPointFromCPoint (line.second);

        if (getDrawMode ().integralMode ())
        {
            first = pixelAlligned (first);
            second = pixelAlligned (second);

            int32_t frameWidth = static_cast<int32_t> (currentState.frameWidth);
            if (frameWidth % 2)
                CGContextTranslateCTM (context, 0.5, 0.5);
        }

        CGContextMoveToPoint (context, first.x, first.y);
        CGContextAddLineToPoint (context, second.x, second.y);

        CGContextDrawPath (context, kCGPathStroke);
        releaseCGContext (context);
    }
}
static void addRoundedRectToPath(CGContextRef context, CGRect rect,
										float ovalWidth,
										float ovalHeight)
{
	float fw, fh;
	// If either ovalWidth or ovalHeight is 0, draw a regular rectangle.
	if (ovalWidth == 0 || ovalHeight == 0) {
		CGContextAddRect(context, rect);
	}else{
        CGContextSaveGState(context);
		// Translate to lower-left corner of rectangle.
        CGContextTranslateCTM(context, CGRectGetMinX(rect),
										 CGRectGetMinY(rect));
		// Scale by the oval width and height so that
		// each rounded corner is 0.5 units in radius.
		CGContextScaleCTM(context, ovalWidth, ovalHeight);
		// Unscale the rectangle width by the amount of the X scaling.
		fw = CGRectGetWidth(rect) / ovalWidth;
		// Unscale the rectangle height by the amount of the Y scaling.
		fh = CGRectGetHeight(rect) / ovalHeight;
		// Start at the right edge of the rect, at the midpoint in Y.
		CGContextMoveToPoint(context, fw, fh/2);
		// Segment 1
		CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 0.5);
		// Segment 2
		CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 0.5);
		// Segment 3
		CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 0.5);
		// Segment 4
		CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 0.5);
		// Closing the path adds the last segment.
		CGContextClosePath(context);
		CGContextRestoreGState(context);
	}
}
Esempio n. 9
0
void drawRoundedRect(CGContextRef context, int x, int y){
    
    struct CGRect cgRect;
	struct CGPoint cgPoint;
	cgRect.size.width = 640;
	cgRect.size.height = y+30;
	cgPoint.x = 0;
	cgPoint.y = 5;
	cgRect.origin = cgPoint;
    
    
    //printf("Drawing %f, %f, %f, %f", cgPoint.x, cgPoint.y, cgRect.size.width, cgRect.size.height);
    
    
    CGContextBeginPath(context);
    
    float ovalWidth = 10;
    float ovalHeight = 10;
    
    float fw, fh;
    // If the width or height of the corner oval is zero, then it reduces to a right angle,
    // so instead of a rounded rectangle we have an ordinary one.
    if (ovalWidth == 0 || ovalHeight == 0) {
        CGContextAddRect(context, cgRect);
        return;
    }
    
    //  Save the context's state so that the translate and scale can be undone with a call
    //  to CGContextRestoreGState.
    CGContextSaveGState(context);
    
    //  Translate the origin of the contex to the lower left corner of the rectangle.
    CGContextTranslateCTM(context, CGRectGetMinX(cgRect), CGRectGetMinY(cgRect));
    
    //Normalize the scale of the context so that the width and height of the arcs are 1.0
    CGContextScaleCTM(context, ovalWidth, ovalHeight);
    
    // Calculate the width and height of the rectangle in the new coordinate system.
    fw = CGRectGetWidth(cgRect) / ovalWidth;
    fh = CGRectGetHeight(cgRect) / ovalHeight;
    
    // CGContextAddArcToPoint adds an arc of a circle to the context's path (creating the rounded
    // corners).  It also adds a line from the path's last point to the begining of the arc, making
    // the sides of the rectangle.
    CGContextMoveToPoint(context, fw, fh/2);  // Start at lower right corner
    CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);  // Top right corner
    CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner
    CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner
    CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right
    
    // Close the path
    CGContextClosePath(context);
    
    CGContextSetRGBFillColor (context, 1, 1, 1, 0.7);
    
    CGContextFillPath(context);
    
    CGContextRestoreGState(context);
    
}
Esempio n. 10
0
void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool shouldAntialias)
{
    if (paintingDisabled())
        return;

    if (npoints <= 1)
        return;

    CGContextRef context = platformContext();

    CGContextSaveGState(context);

    CGContextSetShouldAntialias(context, shouldAntialias);
    
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, points[0].x(), points[0].y());
    for (size_t i = 1; i < npoints; i++)
        CGContextAddLineToPoint(context, points[i].x(), points[i].y());
    CGContextClosePath(context);

    if (fillColor().alpha())
        CGContextEOFillPath(context);

    if (strokeStyle() != NoStroke)
        CGContextStrokePath(context);

    CGContextRestoreGState(context);
}
void doPixelAlignedFillAndStroke(CGContextRef context)
{
    CGPoint p1 = CGPointMake(16.7, 17.8);
    CGPoint p2 = CGPointMake(116.7, 17.8);
    CGRect r = CGRectMake(16.7, 20.8, 100.6, 100.6);
    CGSize s;
    
    CGContextSetLineWidth(context, 2);
    CGContextSetRGBFillColor(context, 1., 0., 0., 1.);
    CGContextSetRGBStrokeColor(context, 1., 0., 0., 1.);
    
    // Unaligned drawing.
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, p1.x, p1.y);
    CGContextAddLineToPoint(context, p2.x, p2.y);
    CGContextStrokePath(context);
    CGContextFillRect(context, r);
    
    // Translate to the right before drawing along
    // aligned coordinates.
    CGContextTranslateCTM(context, 106, 0);
    
    // Aligned drawing.
    
    // Compute the length of the line in user space.
    s = CGSizeMake(p2.x - p1.x, p2.y - p1.y);
    
    CGContextBeginPath(context);
    // Align the starting point to a device
    // pixel boundary.
    p1 = alignPointToUserSpace(context, p1);
    // Establish the starting point of the line.
    CGContextMoveToPoint(context, p1.x, p1.y);
    // Compute the line length as an integer
    // number of device pixels.
    s = alignSizeToUserSpace(context, s);
    CGContextAddLineToPoint(context, 
				p1.x + s.width, 
				p1.y + s.height);
    CGContextStrokePath(context);
    // Compute a rect that is aligned to device
    // space with a width that is an integer
    // number of device pixels.
    r = alignRectToUserSpace(context, r);
    CGContextFillRect(context, r);
}
Esempio n. 12
0
static void
gdk_quartz_draw_polygon (GdkDrawable *drawable,
			 GdkGC       *gc,
			 gboolean     filled,
			 GdkPoint    *points,
			 gint         npoints)
{
  CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
  int i;

  if (!context)
    return;

  if (!_gdk_quartz_gc_update_cg_context (gc, drawable, context,
					 filled ?
					 GDK_QUARTZ_CONTEXT_FILL :
					 GDK_QUARTZ_CONTEXT_STROKE))
    {
      gdk_quartz_drawable_release_context (drawable, context);
      return;
    }
  if (filled)
    {
      CGContextMoveToPoint (context, points[0].x, points[0].y);
      for (i = 1; i < npoints; i++)
	CGContextAddLineToPoint (context, points[i].x, points[i].y);

      CGContextClosePath (context);
      CGContextFillPath (context);
    }
  else
    {
      CGContextMoveToPoint (context, points[0].x + 0.5, points[0].y + 0.5);
      for (i = 1; i < npoints; i++)
	CGContextAddLineToPoint (context, points[i].x + 0.5, points[i].y + 0.5);

      CGContextClosePath (context);
      CGContextStrokePath (context);
    }

  gdk_quartz_drawable_release_context (drawable, context);
}
Esempio n. 13
0
static void quartzgen_polyline(GVJ_t *job, pointf *A, int n)
{
	/* convert polyline 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)
		CGContextAddLineToPoint(context, A[i].x, A[i].y);
	
	/* draw the ellipse */
	quartzgen_path(job, FALSE);
}
Esempio n. 14
0
static void quartzgen_polygon(GVJ_t *job, pointf *A, int n, int filled)
{
	/* convert polygon 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)
		CGContextAddLineToPoint(context, A[i].x, A[i].y);
	CGContextClosePath(context);

	/* draw the ellipse */
	quartzgen_path(job, filled);
}
Esempio n. 15
0
//-----------------------------------------------------------------------------
static void addOvalToPath (CGContextRef c, CPoint center, CGFloat a, CGFloat b, CGFloat start_angle, CGFloat end_angle)
{
	CGContextSaveGState (c);
	CGContextTranslateCTM (c, center.x, center.y);
	CGContextScaleCTM (c, a, b);
	CGContextRotateCTM (c, radians (-90.f));

	CGContextMoveToPoint (c, cos (radians (start_angle)), sin (radians (start_angle)));

	CGContextAddArc(c, 0, 0, 1, radians (start_angle), radians (end_angle), 1);

	CGContextRestoreGState(c);
}
Esempio n. 16
0
bool GiCanvasIos::rawLine(const GiContext* ctx, float x1, float y1, float x2, float y2)
{
    bool ret = m_draw->setPen(ctx);

    if (ret)
    {
        CGContextMoveToPoint(m_draw->getContext(), x1, y1);
        CGContextAddLineToPoint(m_draw->getContext(), x2, y2);
        CGContextStrokePath(m_draw->getContext());
    }

    return ret;
}
Esempio n. 17
0
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);
}
Esempio n. 18
0
bool GiCanvasIos::rawLines(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 < count; i++) {
            CGContextAddLineToPoint(m_draw->getContext(), pxs[i].x, pxs[i].y);
        }
        CGContextStrokePath(m_draw->getContext());
    }

    return ret;
}
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);
}
Esempio n. 20
0
void addRoundedRectToPath(CGContextRef context, CGRect rect, CGFloat radius) {
	CGFloat minX = CGRectGetMinX(rect);
	CGFloat minY = CGRectGetMinY(rect);
	CGFloat maxX = CGRectGetMaxX(rect);
	CGFloat maxY = CGRectGetMaxY(rect);
	CGFloat midX = CGRectGetMidX(rect);
	CGFloat midY = CGRectGetMidY(rect);

	CGContextBeginPath(context);
	CGContextMoveToPoint(context, maxX, midY);
	CGContextAddArcToPoint(context, maxX, maxY, midX, maxY, radius);
	CGContextAddArcToPoint(context, minX, maxY, minX, midY, radius);
	CGContextAddArcToPoint(context, minX, minY, midX, minY, radius);
	CGContextAddArcToPoint(context, maxX, minY, maxX, midY, radius);
	CGContextClosePath(context);
}
//-----------------------------------------------------------------------------------
// Called for each CGPathElement when scanning the CGPath in CGPathApply()
static void MyCGPathApplier(void* info, const CGPathElement* element)
{
    CGContextRef ctx = (CGContextRef)info;
    switch (element->type)
    {
	case kCGPathElementMoveToPoint:
	    CGContextMoveToPoint(ctx, element->points[0].x, element->points[0].y);
	    break;
		
	case kCGPathElementAddLineToPoint:
	    CGContextAddLineToPoint(ctx, element->points[0].x, element->points[0].y);
	    break;
	
	default:	// we know our path only contains line segments
	    break;
    }
}
Esempio n. 22
0
//-----------------------------------------------------------------------------
void CGDrawContext::drawEllipse (const CRect &rect, const CDrawStyle drawStyle)
{
	CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ());
	if (context)
	{
		CGPathDrawingMode m;
		switch (drawStyle)
		{
			case kDrawFilled : m = kCGPathFill; break;
			case kDrawFilledAndStroked : m = kCGPathFillStroke; break;
			default : m = kCGPathStroke; break;
		}
		applyLineStyle (context);

		if (rect.width () != rect.height ())
		{
			CGContextSaveGState (context);

			CGContextBeginPath (context);

			CGRect cgRect = CGRectMake (rect.left, rect.top, rect.width (), rect.height ());
			CGPoint center = CGPointMake (CGRectGetMidX (cgRect), CGRectGetMidY (cgRect));
			CGFloat a = CGRectGetWidth (cgRect) / 2.;
			CGFloat b = CGRectGetHeight (cgRect) / 2.;

		    CGContextTranslateCTM (context, center.x, center.y);
		    CGContextScaleCTM (context, a, b);
		    CGContextMoveToPoint (context, 1, 0);
		    CGContextAddArc (context, 0, 0, 1, radians (0), radians (360), 0);

			CGContextClosePath (context);
			CGContextRestoreGState (context);
			CGContextDrawPath (context, m);
		}
		else
		{
			CGFloat radius = rect.width () * 0.5;
			CGContextBeginPath (context);
			CGContextAddArc (context, rect.left + radius, rect.top + radius, radius, radians (0), radians (360), 0);
			CGContextClosePath (context);
			CGContextDrawPath (context, m);
		}
		releaseCGContext (context);
	}
}
Esempio n. 23
0
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;
}
Esempio n. 24
0
// Handles a pen move operation for cubic (Type 1 / Postscript) outlines
//
OSStatus MyCubicMoveToProc(const Float32Point *pt, void *callBackDataPtr)
{
    // Adjust the point according to the glyph origin
    float x = ((MyCurveCallbackData *)callBackDataPtr)->origin.x + pt->x;
    float y = ((MyCurveCallbackData *)callBackDataPtr)->origin.y + pt->y;

    // Move to the point
	y = ((MyCurveCallbackData *)callBackDataPtr)->windowHeight - y;
	CGContextMoveToPoint(((MyCurveCallbackData *)callBackDataPtr)->context, x, y);

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

    // Update counters and return
    if (gOutputNumOps) moveToCount++;
    return noErr;
}
void MacVegaPrinterListener::DrawLine(const OpPoint& from, const OpPoint& to, UINT32 width)
{
	if(width != 1)
	{
		CGContextSetLineWidth(m_ctx, width);
	}

	CGContextBeginPath(m_ctx);

	CGContextMoveToPoint(m_ctx, from.x, m_winHeight - from.y);
	CGContextAddLineToPoint(m_ctx, to.x, m_winHeight - to.y);

	CGContextStrokePath(m_ctx);

	if(width != 1)
	{
		CGContextSetLineWidth(m_ctx, 1);
	}
}
Esempio n. 26
0
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;
}
Esempio n. 27
0
void paintArc(CGContextRef context, CGRect r, int startAngle, int arcAngle)
{
    float start, end;
	
	// Signal the start of a path
    CGContextBeginPath(context);
	
	// Set the start of the path to the arcs focal point
    CGContextMoveToPoint(context, r.origin.x + r.size.width/2, r.origin.y + r.size.height/2);
	
	// Add to the path the arc of the oval that fits inside the rectangle.
	pathForArc(context,r,startAngle,arcAngle);

	// Complete the path closing the arc at the focal point
    CGContextClosePath(context);
	
	// Fill the path
    CGContextFillPath(context);
}
Esempio n. 28
0
bool GiCanvasIos::rawPolygon(const GiContext* ctx, const Point2d* pxs, int count)
{
    bool usepen = m_draw->setPen(ctx);
    bool usebrush = m_draw->setBrush(ctx);
    bool ret = count > 1 && (usepen || usebrush);

    if (ret)
    {
        CGContextMoveToPoint(m_draw->getContext(), pxs[0].x, pxs[0].y);
        for (int i = 1; i < count; i++) {
            CGContextAddLineToPoint(m_draw->getContext(), pxs[i].x, pxs[i].y);
        }
        CGContextClosePath(m_draw->getContext());
        
        CGContextDrawPath(m_draw->getContext(), usepen && usebrush ? kCGPathFillStroke
                          : usepen ? kCGPathStroke : kCGPathFill);
    }

    return ret;
}
Esempio n. 29
0
static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth,
						  float ovalHeight)
{
	float fw, fh;
	// If the width or height of the corner oval is zero, then it reduces to a right angle,
	// so instead of a rounded rectangle we have an ordinary one.
	if (ovalWidth == 0 || ovalHeight == 0) {
		CGContextAddRect(context, rect);
		return;
	}
	
	//  Save the context's state so that the translate and scale can be undone with a call
	//  to CGContextRestoreGState.
	CGContextSaveGState(context);
	
	//  Translate the origin of the contex to the lower left corner of the rectangle.
	CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
	
	//Normalize the scale of the context so that the width and height of the arcs are 1.0
	CGContextScaleCTM(context, ovalWidth, ovalHeight);
	
	// Calculate the width and height of the rectangle in the new coordinate system.
	fw = CGRectGetWidth(rect) / ovalWidth;
	fh = CGRectGetHeight(rect) / ovalHeight;
	
	// CGContextAddArcToPoint adds an arc of a circle to the context's path (creating the rounded
	// corners).  It also adds a line from the path's last point to the begining of the arc, making
	// the sides of the rectangle.
	CGContextMoveToPoint(context, fw, fh/2);  // Start at lower right corner
	CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);  // Top right corner
	CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner
	CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner
	CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right
	
	// Close the path
	CGContextClosePath(context);
	
	// Restore the context's state. This removes the translation and scaling
	// but leaves the path, since the path is not part of the graphics state.
	CGContextRestoreGState(context);
}
Esempio n. 30
0
//-----------------------------------------------------------------------------
void CGDrawContext::drawPolygon (const CPoint* pPoints, int32_t numberOfPoints, const CDrawStyle drawStyle)
{
	CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ());
	if (context)
	{
		CGPathDrawingMode m;
		switch (drawStyle)
		{
			case kDrawFilled : m = kCGPathFill; break;
			case kDrawFilledAndStroked : m = kCGPathFillStroke; break;
			default : m = kCGPathStroke; break;
		}
		applyLineStyle (context);

		CGContextBeginPath (context);
		CGContextMoveToPoint (context, pPoints[0].h, pPoints[0].v);
		for (int32_t i = 1; i < numberOfPoints; i++)
			CGContextAddLineToPoint (context, pPoints[i].h, pPoints[i].v);
		CGContextDrawPath (context, m);
		releaseCGContext (context);
	}
}