/ CoreGraphics / CGContext.m
CGContext.m
  1  /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
  2  
  3  Permission is hereby granted,free of charge,to any person obtaining a copy of
  4  this software and associated documentation files (the "Software"),to deal in the
  5  Software without restriction,including without limitation the rights to
  6  use,copy,modify,merge,publish,distribute,sublicense,and/or sell copies of the
  7  Software,and to permit persons to whom the Software is furnished to do
  8  so,subject to the following conditions:
  9  
 10  The above copyright notice and this permission notice shall be included in all
 11  copies or substantial portions of the Software.
 12  
 13  THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS OR
 14  IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS
 15  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 16  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY,WHETHER IN
 17  AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM,OUT OF OR IN CONNECTION
 18  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
 19  
 20  #import "CGConversions.h"
 21  #import <CoreGraphics/CGContext.h>
 22  #import <Onyx2D/O2Context.h>
 23  #import <Onyx2D/O2MutablePath.h>
 24  
 25  CGContextRef CGContextRetain(CGContextRef context) {
 26      return O2ContextRetain(context);
 27  }
 28  
 29  void CGContextRelease(CGContextRef context) {
 30      O2ContextRelease(context);
 31  }
 32  
 33  void CGContextSetAllowsAntialiasing(CGContextRef context, bool yesOrNo) {
 34      O2ContextSetAllowsAntialiasing(context, yesOrNo);
 35  }
 36  
 37  void CGContextBeginTransparencyLayer(CGContextRef context,
 38                                       CFDictionaryRef unused)
 39  {
 40      O2ContextBeginTransparencyLayer(context, (NSDictionary *) unused);
 41  }
 42  
 43  void CGContextEndTransparencyLayer(CGContextRef context) {
 44      O2ContextEndTransparencyLayer(context);
 45  }
 46  
 47  bool CGContextIsPathEmpty(CGContextRef context) {
 48      return O2ContextIsPathEmpty(context);
 49  }
 50  
 51  CGPoint CGContextGetPathCurrentPoint(CGContextRef context) {
 52      return O2ContextGetPathCurrentPoint(context);
 53  }
 54  
 55  CGRect CGContextGetPathBoundingBox(CGContextRef context) {
 56      return O2ContextGetPathBoundingBox(context);
 57  }
 58  
 59  bool CGContextSupportsGlobalAlpha(CGContextRef context) {
 60      return O2ContextSupportsGlobalAlpha(context);
 61  }
 62  
 63  bool CGContextIsBitmapContext(CGContextRef context) {
 64      return O2ContextIsBitmapContext(context);
 65  }
 66  
 67  bool CGContextPathContainsPoint(CGContextRef context, CGPoint point,
 68                                  CGPathDrawingMode pathMode)
 69  {
 70      return O2ContextPathContainsPoint(context, point, pathMode);
 71  }
 72  
 73  void CGContextBeginPath(CGContextRef context) {
 74      O2ContextBeginPath(context);
 75  }
 76  
 77  void CGContextClosePath(CGContextRef context) {
 78      O2ContextClosePath(context);
 79  }
 80  
 81  void CGContextMoveToPoint(CGContextRef context, CGFloat x, CGFloat y) {
 82      O2ContextMoveToPoint(context, x, y);
 83  }
 84  
 85  void CGContextAddLineToPoint(CGContextRef context, CGFloat x, CGFloat y) {
 86      O2ContextAddLineToPoint(context, x, y);
 87  }
 88  
 89  void CGContextAddCurveToPoint(CGContextRef context, CGFloat cx1, CGFloat cy1,
 90                                CGFloat cx2, CGFloat cy2, CGFloat x, CGFloat y)
 91  {
 92      O2ContextAddCurveToPoint(context, cx1, cy1, cx2, cy2, x, y);
 93  }
 94  
 95  void CGContextAddQuadCurveToPoint(CGContextRef context, CGFloat cx1,
 96                                    CGFloat cy1, CGFloat x, CGFloat y)
 97  {
 98      O2ContextAddQuadCurveToPoint(context, cx1, cy1, x, y);
 99  }
100  
101  void CGContextAddLines(CGContextRef context, const CGPoint *points,
102                         unsigned count)
103  {
104      O2ContextAddLines(context, points, count);
105  }
106  
107  void CGContextAddRect(CGContextRef context, CGRect rect) {
108      O2ContextAddRect(context, rect);
109  }
110  
111  void CGContextAddRects(CGContextRef context, const CGRect *rects,
112                         unsigned count)
113  {
114      O2ContextAddRects(context, rects, count);
115  }
116  
117  void CGContextAddArc(CGContextRef context, CGFloat x, CGFloat y, CGFloat radius,
118                       CGFloat startRadian, CGFloat endRadian, bool clockwise)
119  {
120      O2ContextAddArc(context, x, y, radius, startRadian, endRadian, clockwise);
121  }
122  
123  void CGContextAddArcToPoint(CGContextRef context, CGFloat x1, CGFloat y1,
124                              CGFloat x2, CGFloat y2, CGFloat radius)
125  {
126      O2ContextAddArcToPoint(context, x1, y1, x2, y2, radius);
127  }
128  
129  void CGContextAddEllipseInRect(CGContextRef context, CGRect rect) {
130      O2ContextAddEllipseInRect(context, rect);
131  }
132  
133  void CGContextAddPath(CGContextRef context, CGPathRef path) {
134      O2ContextAddPath(context, path);
135  }
136  
137  void CGContextReplacePathWithStrokedPath(CGContextRef context) {
138      O2ContextReplacePathWithStrokedPath(context);
139  }
140  
141  CGPathRef CGContextCopyPath(CGContextRef context) {
142      return O2ContextCopyPath(context);
143  }
144  
145  void CGContextSaveGState(CGContextRef context) {
146      O2ContextSaveGState(context);
147  }
148  
149  void CGContextRestoreGState(CGContextRef context) {
150      O2ContextRestoreGState(context);
151  }
152  
153  CGAffineTransform
154  CGContextGetUserSpaceToDeviceSpaceTransform(CGContextRef context)
155  {
156      return CGAffineTransformFromO2(
157              O2ContextGetUserSpaceToDeviceSpaceTransform(context));
158  }
159  
160  CGAffineTransform CGContextGetCTM(CGContextRef context) {
161      return CGAffineTransformFromO2(O2ContextGetCTM(context));
162  }
163  
164  CGRect CGContextGetClipBoundingBox(CGContextRef context) {
165      return O2ContextGetClipBoundingBox(context);
166  }
167  
168  CGAffineTransform CGContextGetTextMatrix(CGContextRef context) {
169      return CGAffineTransformFromO2(O2ContextGetTextMatrix(context));
170  }
171  
172  CGInterpolationQuality CGContextGetInterpolationQuality(CGContextRef context) {
173      return O2ContextGetInterpolationQuality(context);
174  }
175  
176  CGPoint CGContextGetTextPosition(CGContextRef context) {
177      return O2ContextGetTextPosition(context);
178  }
179  
180  CGPoint CGContextConvertPointToDeviceSpace(CGContextRef context, CGPoint point)
181  {
182      return O2ContextConvertPointToDeviceSpace(context, point);
183  }
184  
185  CGPoint CGContextConvertPointToUserSpace(CGContextRef context, CGPoint point) {
186      return O2ContextConvertPointToUserSpace(context, point);
187  }
188  
189  CGSize CGContextConvertSizeToDeviceSpace(CGContextRef context, CGSize size) {
190      return O2ContextConvertSizeToDeviceSpace(context, size);
191  }
192  
193  CGSize CGContextConvertSizeToUserSpace(CGContextRef context, CGSize size) {
194      return O2ContextConvertSizeToUserSpace(context, size);
195  }
196  
197  CGRect CGContextConvertRectToDeviceSpace(CGContextRef context, CGRect rect) {
198      return O2ContextConvertRectToDeviceSpace(context, rect);
199  }
200  
201  CGRect CGContextConvertRectToUserSpace(CGContextRef context, CGRect rect) {
202      return O2ContextConvertRectToUserSpace(context, rect);
203  }
204  
205  void CGContextSetCTM(CGContextRef context, CGAffineTransform matrix) {
206      O2ContextSetCTM(context, O2AffineTransformFromCG(matrix));
207  }
208  
209  void CGContextConcatCTM(CGContextRef context, CGAffineTransform matrix) {
210      O2ContextConcatCTM(context, O2AffineTransformFromCG(matrix));
211  }
212  
213  void CGContextTranslateCTM(CGContextRef context, CGFloat tx, CGFloat ty) {
214      O2ContextTranslateCTM(context, tx, ty);
215  }
216  
217  void CGContextScaleCTM(CGContextRef context, CGFloat scalex, CGFloat scaley) {
218      O2ContextScaleCTM(context, scalex, scaley);
219  }
220  
221  void CGContextRotateCTM(CGContextRef context, CGFloat radians) {
222      O2ContextRotateCTM(context, radians);
223  }
224  
225  void CGContextClip(CGContextRef context) {
226      O2ContextClip(context);
227  }
228  
229  void CGContextEOClip(CGContextRef context) {
230      O2ContextEOClip(context);
231  }
232  
233  void CGContextClipToMask(CGContextRef context, CGRect rect, CGImageRef image) {
234      O2ContextClipToMask(context, rect, image);
235  }
236  
237  void CGContextClipToRect(CGContextRef context, CGRect rect) {
238      O2ContextClipToRect(context, rect);
239  }
240  
241  void CGContextClipToRects(CGContextRef context, const CGRect *rects,
242                            unsigned count)
243  {
244      O2ContextClipToRects(context, rects, count);
245  }
246  
247  void CGContextSetStrokeColorSpace(CGContextRef context,
248                                    CGColorSpaceRef colorSpace)
249  {
250      O2ContextSetStrokeColorSpace(context, colorSpace);
251  }
252  
253  void CGContextSetFillColorSpace(CGContextRef context,
254                                  CGColorSpaceRef colorSpace)
255  {
256      O2ContextSetFillColorSpace(context, colorSpace);
257  }
258  
259  void CGContextSetStrokeColor(CGContextRef context, const CGFloat *components) {
260      O2ContextSetStrokeColor(context, components);
261  }
262  
263  void CGContextSetStrokeColorWithColor(CGContextRef context, CGColorRef color) {
264      O2ContextSetStrokeColorWithColor(context, color);
265  }
266  
267  void CGContextSetGrayStrokeColor(CGContextRef context, CGFloat gray,
268                                   CGFloat alpha)
269  {
270      O2ContextSetGrayStrokeColor(context, gray, alpha);
271  }
272  
273  void CGContextSetRGBStrokeColor(CGContextRef context, CGFloat r, CGFloat g,
274                                  CGFloat b, CGFloat alpha)
275  {
276      O2ContextSetRGBStrokeColor(context, r, g, b, alpha);
277  }
278  
279  void CGContextSetCMYKStrokeColor(CGContextRef context, CGFloat c, CGFloat m,
280                                   CGFloat y, CGFloat k, CGFloat alpha)
281  {
282      O2ContextSetCMYKStrokeColor(context, c, m, y, k, alpha);
283  }
284  
285  void CGContextSetFillColor(CGContextRef context, const CGFloat *components) {
286      O2ContextSetFillColor(context, components);
287  }
288  
289  void CGContextSetFillColorWithColor(CGContextRef context, CGColorRef color) {
290      O2ContextSetFillColorWithColor(context, color);
291  }
292  
293  void CGContextSetGrayFillColor(CGContextRef context, CGFloat gray,
294                                 CGFloat alpha)
295  {
296      O2ContextSetGrayFillColor(context, gray, alpha);
297  }
298  
299  void CGContextSetRGBFillColor(CGContextRef context, CGFloat r, CGFloat g,
300                                CGFloat b, CGFloat alpha)
301  {
302      O2ContextSetRGBFillColor(context, r, g, b, alpha);
303  }
304  
305  void CGContextSetCMYKFillColor(CGContextRef context, CGFloat c, CGFloat m,
306                                 CGFloat y, CGFloat k, CGFloat alpha)
307  {
308      O2ContextSetCMYKFillColor(context, c, m, y, k, alpha);
309  }
310  
311  void CGContextSetAlpha(CGContextRef context, CGFloat alpha) {
312      O2ContextSetAlpha(context, alpha);
313  }
314  
315  void CGContextSetPatternPhase(CGContextRef context, CGSize phase) {
316      O2ContextSetPatternPhase(context, phase);
317  }
318  
319  void CGContextSetStrokePattern(CGContextRef context, CGPatternRef pattern,
320                                 const CGFloat *components)
321  {
322      O2ContextSetStrokePattern(context, pattern, components);
323  }
324  
325  void CGContextSetFillPattern(CGContextRef context, CGPatternRef pattern,
326                               const CGFloat *components)
327  {
328      O2ContextSetFillPattern(context, pattern, components);
329  }
330  
331  void CGContextSetTextMatrix(CGContextRef context, CGAffineTransform matrix) {
332      O2ContextSetTextMatrix(context, O2AffineTransformFromCG(matrix));
333  }
334  
335  void CGContextSetTextPosition(CGContextRef context, CGFloat x, CGFloat y) {
336      O2ContextSetTextPosition(context, x, y);
337  }
338  
339  void CGContextSetCharacterSpacing(CGContextRef context, CGFloat spacing) {
340      O2ContextSetCharacterSpacing(context, spacing);
341  }
342  
343  void CGContextSetTextDrawingMode(CGContextRef context,
344                                   CGTextDrawingMode textMode)
345  {
346      O2ContextSetTextDrawingMode(context, textMode);
347  }
348  
349  void CGContextSetFont(CGContextRef context, CGFontRef font) {
350      O2ContextSetFont(context, font);
351  }
352  
353  void CGContextSetFontSize(CGContextRef context, CGFloat size) {
354      O2ContextSetFontSize(context, size);
355  }
356  
357  void CGContextSelectFont(CGContextRef context, const char *name, CGFloat size,
358                           CGTextEncoding encoding)
359  {
360      O2ContextSelectFont(context, name, size, encoding);
361  }
362  
363  void CGContextSetShouldSmoothFonts(CGContextRef context, bool yesOrNo) {
364      O2ContextSetShouldSmoothFonts(context, yesOrNo);
365  }
366  
367  void CGContextSetLineWidth(CGContextRef context, CGFloat width) {
368      O2ContextSetLineWidth(context, width);
369  }
370  
371  void CGContextSetLineCap(CGContextRef context, CGLineCap lineCap) {
372      O2ContextSetLineCap(context, lineCap);
373  }
374  
375  void CGContextSetLineJoin(CGContextRef context, CGLineJoin lineJoin) {
376      O2ContextSetLineJoin(context, lineJoin);
377  }
378  
379  void CGContextSetMiterLimit(CGContextRef context, CGFloat miterLimit) {
380      O2ContextSetMiterLimit(context, miterLimit);
381  }
382  
383  void CGContextSetLineDash(CGContextRef context, CGFloat phase,
384                            const CGFloat *lengths, unsigned count)
385  {
386      O2ContextSetLineDash(context, phase, lengths, count);
387  }
388  
389  void CGContextSetRenderingIntent(CGContextRef context,
390                                   CGColorRenderingIntent renderingIntent)
391  {
392      O2ContextSetRenderingIntent(context, renderingIntent);
393  }
394  
395  void CGContextSetBlendMode(CGContextRef context, CGBlendMode blendMode) {
396      O2ContextSetBlendMode(context, blendMode);
397  }
398  
399  void CGContextSetFlatness(CGContextRef context, CGFloat flatness) {
400      O2ContextSetFlatness(context, flatness);
401  }
402  
403  void CGContextSetInterpolationQuality(CGContextRef context,
404                                        CGInterpolationQuality quality)
405  {
406      O2ContextSetInterpolationQuality(context, quality);
407  }
408  
409  void CGContextSetShadowWithColor(CGContextRef context, CGSize offset,
410                                   CGFloat blur, CGColorRef color)
411  {
412      O2ContextSetShadowWithColor(context, offset, blur, color);
413  }
414  
415  void CGContextSetShadow(CGContextRef context, CGSize offset, CGFloat blur) {
416      O2ContextSetShadow(context, offset, blur);
417  }
418  
419  void CGContextSetShouldAntialias(CGContextRef context, bool yesOrNo) {
420      O2ContextSetShouldAntialias(context, yesOrNo);
421  }
422  
423  void CGContextStrokeLineSegments(CGContextRef context, const CGPoint *points,
424                                   unsigned count)
425  {
426      O2ContextStrokeLineSegments(context, points, count);
427  }
428  
429  void CGContextStrokeRect(CGContextRef context, CGRect rect) {
430      O2ContextStrokeRect(context, rect);
431  }
432  
433  void CGContextStrokeRectWithWidth(CGContextRef context, CGRect rect,
434                                    CGFloat width)
435  {
436      O2ContextStrokeRectWithWidth(context, rect, width);
437  }
438  
439  void CGContextStrokeEllipseInRect(CGContextRef context, CGRect rect) {
440      O2ContextStrokeEllipseInRect(context, rect);
441  }
442  
443  void CGContextFillRect(CGContextRef context, CGRect rect) {
444      O2ContextFillRect(context, rect);
445  }
446  
447  void CGContextFillRects(CGContextRef context, const CGRect *rects,
448                          unsigned count)
449  {
450      O2ContextFillRects(context, rects, count);
451  }
452  
453  void CGContextFillEllipseInRect(CGContextRef context, CGRect rect) {
454      O2ContextFillEllipseInRect(context, rect);
455  }
456  
457  void CGContextDrawPath(CGContextRef context, CGPathDrawingMode pathMode) {
458      O2ContextDrawPath(context, pathMode);
459  }
460  
461  void CGContextStrokePath(CGContextRef context) {
462      O2ContextStrokePath(context);
463  }
464  
465  void CGContextFillPath(CGContextRef context) {
466      O2ContextFillPath(context);
467  }
468  
469  void CGContextEOFillPath(CGContextRef context) {
470      O2ContextEOFillPath(context);
471  }
472  
473  void CGContextClearRect(CGContextRef context, CGRect rect) {
474      O2ContextClearRect(context, rect);
475  }
476  
477  void CGContextShowGlyphs(CGContextRef context, const CGGlyph *glyphs,
478                           unsigned count)
479  {
480      O2ContextShowGlyphs(context, glyphs, count);
481  }
482  
483  void CGContextShowGlyphsAtPoint(CGContextRef context, CGFloat x, CGFloat y,
484                                  const CGGlyph *glyphs, unsigned count)
485  {
486      O2ContextShowGlyphsAtPoint(context, x, y, glyphs, count);
487  }
488  
489  void CGContextShowGlyphsWithAdvances(CGContextRef context,
490                                       const CGGlyph *glyphs,
491                                       const CGSize *advances, unsigned count)
492  {
493      O2ContextShowGlyphsWithAdvances(context, glyphs, advances, count);
494  }
495  
496  void CGContextShowText(CGContextRef context, const char *text, unsigned count) {
497      O2ContextShowText(context, text, count);
498  }
499  
500  void CGContextShowTextAtPoint(CGContextRef context, CGFloat x, CGFloat y,
501                                const char *text, unsigned count)
502  {
503      O2ContextShowTextAtPoint(context, x, y, text, count);
504  }
505  
506  void CGContextDrawShading(CGContextRef context, CGShadingRef shading) {
507      O2ContextDrawShading(context, shading);
508  }
509  
510  void CGContextDrawImage(CGContextRef context, CGRect rect, CGImageRef image) {
511      O2ContextDrawImage(context, rect, image);
512  }
513  
514  void CGContextDrawLayerAtPoint(CGContextRef context, CGPoint point,
515                                 CGLayerRef layer)
516  {
517      O2ContextDrawLayerAtPoint(context, point, layer);
518  }
519  
520  void CGContextDrawLayerInRect(CGContextRef context, CGRect rect,
521                                CGLayerRef layer)
522  {
523      O2ContextDrawLayerInRect(context, rect, layer);
524  }
525  
526  void CGContextDrawPDFPage(CGContextRef context, CGPDFPageRef page) {
527      O2ContextDrawPDFPage(context, page);
528  }
529  
530  void CGContextFlush(CGContextRef context) {
531      O2ContextFlush(context);
532  }
533  
534  void CGContextSynchronize(CGContextRef context) {
535      O2ContextSynchronize(context);
536  }
537  
538  void CGContextBeginPage(CGContextRef context, const CGRect *mediaBox) {
539      O2ContextBeginPage(context, mediaBox);
540  }
541  
542  void CGContextEndPage(CGContextRef context) {
543      O2ContextEndPage(context);
544  }
545  
546  /// temporary hacks
547  
548  void CGContextResetClip(CGContextRef context) {
549      O2ContextResetClip(context);
550  }
551  
552  void CGContextCopyBits(CGContextRef context, CGRect rect, CGPoint point,
553                         int gState)
554  {
555      O2ContextCopyBits(context, rect, point, gState);
556  }
557  
558  CFDataRef CGContextCaptureBitmap(CGContextRef context, CGRect rect) {
559      return (CFDataRef) O2ContextCaptureBitmap(context, rect);
560  }
561  
562  void CGContextSetAllowsFontSmoothing(CGContextRef context,
563                                       bool allowsFontSmoothing)
564  {
565      O2ContextSetAllowsFontSmoothing((O2ContextRef) context,
566                                      allowsFontSmoothing);
567  }
568  
569  void CGContextSetAllowsFontSubpixelQuantization(
570          CGContextRef context, bool allowsFontSubpixelQuantization)
571  {
572      O2ContextSetAllowsFontSubpixelQuantization((O2ContextRef) context,
573                                                 allowsFontSubpixelQuantization);
574  }
575  
576  void CGContextSetShouldSubpixelQuantizeFonts(CGContextRef context,
577                                               bool shouldSubpixelQuantizeFonts)
578  {
579      O2ContextSetShouldSubpixelQuantizeFonts((O2ContextRef) context,
580                                              shouldSubpixelQuantizeFonts);
581  }
582  
583  void CGContextSetAllowsFontSubpixelPositioning(
584          CGContextRef context, bool allowsFontSubpixelPositioning)
585  {
586      O2ContextSetAllowsFontSubpixelPositioning((O2ContextRef) context,
587                                                allowsFontSubpixelPositioning);
588  }
589  
590  void CGContextSetShouldSubpixelPositionFonts(CGContextRef context,
591                                               bool shouldSubpixelPositionFonts)
592  {
593      O2ContextSetShouldSubpixelPositionFonts((O2ContextRef) context,
594                                              shouldSubpixelPositionFonts);
595  }
596  
597  void CGContextDrawLinearGradient(CGContextRef c,
598                                   CGGradientRef gradient, CGPoint startPoint, CGPoint endPoint,
599                                   CGGradientDrawingOptions options)
600  {
601      printf("STUB %s\n", __PRETTY_FUNCTION__);
602  }
603  
604  void CGContextDrawRadialGradient(CGContextRef c,
605                                   CGGradientRef gradient, CGPoint startCenter, CGFloat startRadius,
606                                   CGPoint endCenter, CGFloat endRadius, CGGradientDrawingOptions options)
607  {
608      printf("STUB %s\n", __PRETTY_FUNCTION__);
609  }
610  
611  void CGContextDrawTiledImage(CGContextRef c, CGRect rect, CGImageRef image)
612  {
613      printf("STUB %s\n", __PRETTY_FUNCTION__);
614  }
615  
616  void CGContextShowGlyphsAtPositions(CGContextRef c,
617                                      const CGGlyph * glyphs, const CGPoint * Lpositions,
618                                      size_t count)
619  {
620      printf("STUB %s\n", __PRETTY_FUNCTION__);
621  }