CGContext.h
  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 <CoreGraphics/CoreGraphicsExport.h>
 21  #import <CoreFoundation/CFBase.h>
 22  
 23  typedef struct CF_BRIDGED_TYPE(id) O2Context *CGContextRef;
 24  
 25  #import <CoreGraphics/CGAffineTransform.h>
 26  #import <CoreGraphics/CGColor.h>
 27  #import <CoreGraphics/CGFont.h>
 28  #import <CoreGraphics/CGGeometry.h>
 29  #import <CoreGraphics/CGGradient.h>
 30  #import <CoreGraphics/CGImage.h>
 31  #import <CoreGraphics/CGLayer.h>
 32  #import <CoreGraphics/CGPDFPage.h>
 33  #import <CoreGraphics/CGPath.h>
 34  #import <CoreGraphics/CGPattern.h>
 35  #import <CoreGraphics/CGShading.h>
 36  
 37  CF_IMPLICIT_BRIDGING_ENABLED
 38  
 39  typedef enum {
 40      kCGEncodingFontSpecific,
 41      kCGEncodingMacRoman,
 42  } CGTextEncoding;
 43  
 44  typedef enum {
 45      kCGLineCapButt,
 46      kCGLineCapRound,
 47      kCGLineCapSquare,
 48  } CGLineCap;
 49  
 50  typedef enum {
 51      kCGLineJoinMiter,
 52      kCGLineJoinRound,
 53      kCGLineJoinBevel,
 54  } CGLineJoin;
 55  
 56  typedef enum {
 57      kCGPathFill,
 58      kCGPathEOFill,
 59      kCGPathStroke,
 60      kCGPathFillStroke,
 61      kCGPathEOFillStroke
 62  } CGPathDrawingMode;
 63  
 64  typedef enum {
 65      kCGInterpolationDefault,
 66      kCGInterpolationNone,
 67      kCGInterpolationLow,
 68      kCGInterpolationHigh,
 69  } CGInterpolationQuality;
 70  
 71  typedef enum {
 72      // seperable
 73      kCGBlendModeNormal,
 74      kCGBlendModeMultiply,
 75      kCGBlendModeScreen,
 76      kCGBlendModeOverlay,
 77      kCGBlendModeDarken,
 78      kCGBlendModeLighten,
 79      kCGBlendModeColorDodge,
 80      kCGBlendModeColorBurn,
 81      kCGBlendModeHardLight,
 82      kCGBlendModeSoftLight,
 83      kCGBlendModeDifference,
 84      kCGBlendModeExclusion,
 85      // nonseperable
 86      kCGBlendModeHue,
 87      kCGBlendModeSaturation,
 88      kCGBlendModeColor,
 89      kCGBlendModeLuminosity,
 90      // Porter-Duff
 91      kCGBlendModeClear,
 92      kCGBlendModeCopy,
 93      kCGBlendModeSourceIn,
 94      kCGBlendModeSourceOut,
 95      kCGBlendModeSourceAtop,
 96      kCGBlendModeDestinationOver,
 97      kCGBlendModeDestinationIn,
 98      kCGBlendModeDestinationOut,
 99      kCGBlendModeDestinationAtop,
100      kCGBlendModeXOR,
101      kCGBlendModePlusDarker,
102      kCGBlendModePlusLighter,
103  } CGBlendMode;
104  
105  typedef int CGTextDrawingMode;
106  
107  COREGRAPHICS_EXPORT CGContextRef CGContextRetain(CGContextRef context);
108  COREGRAPHICS_EXPORT void CGContextRelease(CGContextRef context);
109  
110  // context state
111  COREGRAPHICS_EXPORT void CGContextSetAllowsAntialiasing(CGContextRef context,
112                                                          bool yesOrNo);
113  
114  // layers
115  COREGRAPHICS_EXPORT void
116  CGContextBeginTransparencyLayer(CGContextRef context, CFDictionaryRef unused);
117  COREGRAPHICS_EXPORT void CGContextEndTransparencyLayer(CGContextRef context);
118  
119  // path
120  COREGRAPHICS_EXPORT bool CGContextIsPathEmpty(CGContextRef context);
121  COREGRAPHICS_EXPORT CGPoint CGContextGetPathCurrentPoint(CGContextRef context);
122  COREGRAPHICS_EXPORT CGRect CGContextGetPathBoundingBox(CGContextRef context);
123  COREGRAPHICS_EXPORT bool CGContextPathContainsPoint(CGContextRef context,
124                                                      CGPoint point,
125                                                      CGPathDrawingMode pathMode);
126  
127  COREGRAPHICS_EXPORT void CGContextBeginPath(CGContextRef context);
128  COREGRAPHICS_EXPORT void CGContextClosePath(CGContextRef context);
129  COREGRAPHICS_EXPORT void CGContextMoveToPoint(CGContextRef context, CGFloat x,
130                                                CGFloat y);
131  COREGRAPHICS_EXPORT void CGContextAddLineToPoint(CGContextRef context,
132                                                   CGFloat x, CGFloat y);
133  COREGRAPHICS_EXPORT void CGContextAddCurveToPoint(CGContextRef context,
134                                                    CGFloat cx1, CGFloat cy1,
135                                                    CGFloat cx2, CGFloat cy2,
136                                                    CGFloat x, CGFloat y);
137  COREGRAPHICS_EXPORT void CGContextAddQuadCurveToPoint(CGContextRef context,
138                                                        CGFloat cx1, CGFloat cy1,
139                                                        CGFloat x, CGFloat y);
140  
141  COREGRAPHICS_EXPORT void
142  CGContextAddLines(CGContextRef context, const CGPoint *points, unsigned count);
143  COREGRAPHICS_EXPORT void CGContextAddRect(CGContextRef context, CGRect rect);
144  COREGRAPHICS_EXPORT void CGContextAddRects(CGContextRef context,
145                                             const CGRect *rects, unsigned count);
146  
147  COREGRAPHICS_EXPORT void CGContextAddArc(CGContextRef context, CGFloat x,
148                                           CGFloat y, CGFloat radius,
149                                           CGFloat startRadian, CGFloat endRadian,
150                                           bool clockwise);
151  COREGRAPHICS_EXPORT void CGContextAddArcToPoint(CGContextRef context,
152                                                  CGFloat x1, CGFloat y1,
153                                                  CGFloat x2, CGFloat y2,
154                                                  CGFloat radius);
155  COREGRAPHICS_EXPORT void CGContextAddEllipseInRect(CGContextRef context,
156                                                     CGRect rect);
157  
158  COREGRAPHICS_EXPORT void CGContextAddPath(CGContextRef context, CGPathRef path);
159  
160  COREGRAPHICS_EXPORT void
161  CGContextReplacePathWithStrokedPath(CGContextRef context);
162  COREGRAPHICS_EXPORT CGPathRef CGContextCopyPath(CGContextRef context);
163  
164  // gstate
165  
166  COREGRAPHICS_EXPORT void CGContextSaveGState(CGContextRef context);
167  COREGRAPHICS_EXPORT void CGContextRestoreGState(CGContextRef context);
168  
169  COREGRAPHICS_EXPORT CGAffineTransform
170  CGContextGetUserSpaceToDeviceSpaceTransform(CGContextRef context);
171  COREGRAPHICS_EXPORT CGAffineTransform CGContextGetCTM(CGContextRef context);
172  COREGRAPHICS_EXPORT CGRect CGContextGetClipBoundingBox(CGContextRef context);
173  COREGRAPHICS_EXPORT CGAffineTransform
174  CGContextGetTextMatrix(CGContextRef context);
175  COREGRAPHICS_EXPORT CGInterpolationQuality
176  CGContextGetInterpolationQuality(CGContextRef context);
177  COREGRAPHICS_EXPORT CGPoint CGContextGetTextPosition(CGContextRef context);
178  
179  COREGRAPHICS_EXPORT CGPoint
180  CGContextConvertPointToDeviceSpace(CGContextRef context, CGPoint point);
181  COREGRAPHICS_EXPORT CGPoint
182  CGContextConvertPointToUserSpace(CGContextRef context, CGPoint point);
183  COREGRAPHICS_EXPORT CGSize
184  CGContextConvertSizeToDeviceSpace(CGContextRef context, CGSize size);
185  COREGRAPHICS_EXPORT CGSize CGContextConvertSizeToUserSpace(CGContextRef context,
186                                                             CGSize size);
187  COREGRAPHICS_EXPORT CGRect
188  CGContextConvertRectToDeviceSpace(CGContextRef context, CGRect rect);
189  COREGRAPHICS_EXPORT CGRect CGContextConvertRectToUserSpace(CGContextRef context,
190                                                             CGRect rect);
191  
192  COREGRAPHICS_EXPORT void CGContextConcatCTM(CGContextRef context,
193                                              CGAffineTransform matrix);
194  COREGRAPHICS_EXPORT void CGContextTranslateCTM(CGContextRef context,
195                                                 CGFloat translatex,
196                                                 CGFloat translatey);
197  COREGRAPHICS_EXPORT void CGContextScaleCTM(CGContextRef context, CGFloat scalex,
198                                             CGFloat scaley);
199  COREGRAPHICS_EXPORT void CGContextRotateCTM(CGContextRef context,
200                                              CGFloat radians);
201  
202  COREGRAPHICS_EXPORT void CGContextClip(CGContextRef context);
203  COREGRAPHICS_EXPORT void CGContextEOClip(CGContextRef context);
204  COREGRAPHICS_EXPORT void CGContextClipToMask(CGContextRef context, CGRect rect,
205                                               CGImageRef image);
206  COREGRAPHICS_EXPORT void CGContextClipToRect(CGContextRef context, CGRect rect);
207  COREGRAPHICS_EXPORT void
208  CGContextClipToRects(CGContextRef context, const CGRect *rects, unsigned count);
209  
210  COREGRAPHICS_EXPORT void
211  CGContextSetStrokeColorSpace(CGContextRef context, CGColorSpaceRef colorSpace);
212  COREGRAPHICS_EXPORT void CGContextSetFillColorSpace(CGContextRef context,
213                                                      CGColorSpaceRef colorSpace);
214  
215  COREGRAPHICS_EXPORT void CGContextSetStrokeColor(CGContextRef context,
216                                                   const CGFloat *components);
217  COREGRAPHICS_EXPORT void CGContextSetStrokeColorWithColor(CGContextRef context,
218                                                            CGColorRef color);
219  COREGRAPHICS_EXPORT void
220  CGContextSetGrayStrokeColor(CGContextRef context, CGFloat gray, CGFloat alpha);
221  COREGRAPHICS_EXPORT void CGContextSetRGBStrokeColor(CGContextRef context,
222                                                      CGFloat r, CGFloat g,
223                                                      CGFloat b, CGFloat alpha);
224  COREGRAPHICS_EXPORT void CGContextSetCMYKStrokeColor(CGContextRef context,
225                                                       CGFloat c, CGFloat m,
226                                                       CGFloat y, CGFloat k,
227                                                       CGFloat alpha);
228  COREGRAPHICS_EXPORT void
229  CGContextSetCalibratedRGBStrokeColor(CGContextRef context, CGFloat red,
230                                       CGFloat green, CGFloat blue,
231                                       CGFloat alpha);
232  COREGRAPHICS_EXPORT void
233  CGContextSetCalibratedGrayStrokeColor(CGContextRef context, CGFloat gray,
234                                        CGFloat alpha);
235  
236  COREGRAPHICS_EXPORT void CGContextSetFillColor(CGContextRef context,
237                                                 const CGFloat *components);
238  COREGRAPHICS_EXPORT void CGContextSetFillColorWithColor(CGContextRef context,
239                                                          CGColorRef color);
240  COREGRAPHICS_EXPORT void CGContextSetGrayFillColor(CGContextRef context,
241                                                     CGFloat gray, CGFloat alpha);
242  COREGRAPHICS_EXPORT void CGContextSetRGBFillColor(CGContextRef context,
243                                                    CGFloat r, CGFloat g,
244                                                    CGFloat b, CGFloat alpha);
245  COREGRAPHICS_EXPORT void CGContextSetCMYKFillColor(CGContextRef context,
246                                                     CGFloat c, CGFloat m,
247                                                     CGFloat y, CGFloat k,
248                                                     CGFloat alpha);
249  COREGRAPHICS_EXPORT void
250  CGContextSetCalibratedGrayFillColor(CGContextRef context, CGFloat gray,
251                                      CGFloat alpha);
252  COREGRAPHICS_EXPORT void
253  CGContextSetCalibratedRGBFillColor(CGContextRef context, CGFloat red,
254                                     CGFloat green, CGFloat blue, CGFloat alpha);
255  
256  COREGRAPHICS_EXPORT void CGContextSetAlpha(CGContextRef context, CGFloat alpha);
257  
258  COREGRAPHICS_EXPORT void CGContextSetPatternPhase(CGContextRef context,
259                                                    CGSize phase);
260  COREGRAPHICS_EXPORT void CGContextSetStrokePattern(CGContextRef context,
261                                                     CGPatternRef pattern,
262                                                     const CGFloat *components);
263  COREGRAPHICS_EXPORT void CGContextSetFillPattern(CGContextRef context,
264                                                   CGPatternRef pattern,
265                                                   const CGFloat *components);
266  
267  COREGRAPHICS_EXPORT void CGContextSetTextMatrix(CGContextRef context,
268                                                  CGAffineTransform matrix);
269  
270  COREGRAPHICS_EXPORT void CGContextSetTextPosition(CGContextRef context,
271                                                    CGFloat x, CGFloat y);
272  COREGRAPHICS_EXPORT void CGContextSetCharacterSpacing(CGContextRef context,
273                                                        CGFloat spacing);
274  COREGRAPHICS_EXPORT void
275  CGContextSetTextDrawingMode(CGContextRef context, CGTextDrawingMode textMode);
276  
277  COREGRAPHICS_EXPORT void CGContextSetFont(CGContextRef context, CGFontRef font);
278  COREGRAPHICS_EXPORT void CGContextSetFontSize(CGContextRef context,
279                                                CGFloat size);
280  COREGRAPHICS_EXPORT void CGContextSelectFont(CGContextRef context,
281                                               const char *name, CGFloat size,
282                                               CGTextEncoding encoding);
283  COREGRAPHICS_EXPORT void CGContextSetShouldSmoothFonts(CGContextRef context,
284                                                         bool yesOrNo);
285  
286  COREGRAPHICS_EXPORT void CGContextSetLineWidth(CGContextRef context,
287                                                 CGFloat width);
288  COREGRAPHICS_EXPORT void CGContextSetLineCap(CGContextRef context,
289                                               CGLineCap lineCap);
290  COREGRAPHICS_EXPORT void CGContextSetLineJoin(CGContextRef context,
291                                                CGLineJoin lineJoin);
292  COREGRAPHICS_EXPORT void CGContextSetMiterLimit(CGContextRef context,
293                                                  CGFloat miterLimit);
294  COREGRAPHICS_EXPORT void CGContextSetLineDash(CGContextRef context,
295                                                CGFloat phase,
296                                                const CGFloat *lengths,
297                                                unsigned count);
298  
299  COREGRAPHICS_EXPORT void
300  CGContextSetRenderingIntent(CGContextRef context,
301                              CGColorRenderingIntent renderingIntent);
302  COREGRAPHICS_EXPORT void CGContextSetBlendMode(CGContextRef context,
303                                                 CGBlendMode blendMode);
304  
305  COREGRAPHICS_EXPORT void CGContextSetFlatness(CGContextRef context,
306                                                CGFloat flatness);
307  
308  COREGRAPHICS_EXPORT void
309  CGContextSetInterpolationQuality(CGContextRef context,
310                                   CGInterpolationQuality quality);
311  
312  COREGRAPHICS_EXPORT void CGContextSetShadowWithColor(CGContextRef context,
313                                                       CGSize offset,
314                                                       CGFloat blur,
315                                                       CGColorRef color);
316  COREGRAPHICS_EXPORT void CGContextSetShadow(CGContextRef context, CGSize offset,
317                                              CGFloat blur);
318  
319  COREGRAPHICS_EXPORT void CGContextSetShouldAntialias(CGContextRef context,
320                                                       bool yesOrNo);
321  
322  // drawing
323  COREGRAPHICS_EXPORT void CGContextStrokeLineSegments(CGContextRef context,
324                                                       const CGPoint *points,
325                                                       unsigned count);
326  
327  COREGRAPHICS_EXPORT void CGContextStrokeRect(CGContextRef context, CGRect rect);
328  COREGRAPHICS_EXPORT void
329  CGContextStrokeRectWithWidth(CGContextRef context, CGRect rect, CGFloat width);
330  COREGRAPHICS_EXPORT void CGContextStrokeEllipseInRect(CGContextRef context,
331                                                        CGRect rect);
332  
333  COREGRAPHICS_EXPORT void CGContextFillRect(CGContextRef context, CGRect rect);
334  COREGRAPHICS_EXPORT void
335  CGContextFillRects(CGContextRef context, const CGRect *rects, unsigned count);
336  COREGRAPHICS_EXPORT void CGContextFillEllipseInRect(CGContextRef context,
337                                                      CGRect rect);
338  
339  COREGRAPHICS_EXPORT void CGContextDrawPath(CGContextRef context,
340                                             CGPathDrawingMode pathMode);
341  COREGRAPHICS_EXPORT void CGContextStrokePath(CGContextRef context);
342  COREGRAPHICS_EXPORT void CGContextFillPath(CGContextRef context);
343  COREGRAPHICS_EXPORT void CGContextEOFillPath(CGContextRef context);
344  
345  COREGRAPHICS_EXPORT void CGContextClearRect(CGContextRef context, CGRect rect);
346  
347  COREGRAPHICS_EXPORT void CGContextShowGlyphs(CGContextRef context,
348                                               const CGGlyph *glyphs,
349                                               unsigned count);
350  COREGRAPHICS_EXPORT void CGContextShowGlyphsAtPoint(CGContextRef context,
351                                                      CGFloat x, CGFloat y,
352                                                      const CGGlyph *glyphs,
353                                                      unsigned count);
354  COREGRAPHICS_EXPORT void CGContextShowGlyphsWithAdvances(CGContextRef context,
355                                                           const CGGlyph *glyphs,
356                                                           const CGSize *advances,
357                                                           unsigned count);
358  
359  COREGRAPHICS_EXPORT void CGContextShowText(CGContextRef context,
360                                             const char *text, unsigned count);
361  COREGRAPHICS_EXPORT void CGContextShowTextAtPoint(CGContextRef context,
362                                                    CGFloat x, CGFloat y,
363                                                    const char *text,
364                                                    unsigned count);
365  
366  COREGRAPHICS_EXPORT void CGContextDrawShading(CGContextRef context,
367                                                CGShadingRef shading);
368  COREGRAPHICS_EXPORT void CGContextDrawImage(CGContextRef context, CGRect rect,
369                                              CGImageRef image);
370  COREGRAPHICS_EXPORT void CGContextDrawLayerAtPoint(CGContextRef context,
371                                                     CGPoint point,
372                                                     CGLayerRef layer);
373  COREGRAPHICS_EXPORT void
374  CGContextDrawLayerInRect(CGContextRef context, CGRect rect, CGLayerRef layer);
375  COREGRAPHICS_EXPORT void CGContextDrawPDFPage(CGContextRef context,
376                                                CGPDFPageRef page);
377  
378  COREGRAPHICS_EXPORT void CGContextFlush(CGContextRef context);
379  COREGRAPHICS_EXPORT void CGContextSynchronize(CGContextRef context);
380  
381  // pagination
382  
383  COREGRAPHICS_EXPORT void CGContextBeginPage(CGContextRef context,
384                                              const CGRect *mediaBox);
385  COREGRAPHICS_EXPORT void CGContextEndPage(CGContextRef context);
386  
387  // **PRIVATE** These are private in Apple's implementation as well as ours.
388  
389  COREGRAPHICS_EXPORT void CGContextSetCTM(CGContextRef context,
390                                           CGAffineTransform matrix);
391  COREGRAPHICS_EXPORT void CGContextResetClip(CGContextRef context);
392  
393  // Temporary hacks
394  
395  COREGRAPHICS_EXPORT CFDataRef CGContextCaptureBitmap(CGContextRef context,
396                                                       CGRect rect);
397  COREGRAPHICS_EXPORT void CGContextCopyBits(CGContextRef context, CGRect rect,
398                                             CGPoint point, int gState);
399  COREGRAPHICS_EXPORT bool CGContextSupportsGlobalAlpha(CGContextRef context);
400  COREGRAPHICS_EXPORT bool CGContextIsBitmapContext(CGContextRef context);
401  COREGRAPHICS_EXPORT void
402  CGContextSetAllowsFontSmoothing(CGContextRef context, bool allowsFontSmoothing);
403  COREGRAPHICS_EXPORT void
404  CGContextSetAllowsFontSubpixelQuantization(CGContextRef context,
405                                             bool allowsFontSubpixelQuantization);
406  COREGRAPHICS_EXPORT void
407  CGContextSetShouldSubpixelQuantizeFonts(CGContextRef context,
408                                          bool shouldSubpixelQuantizeFonts);
409  COREGRAPHICS_EXPORT void
410  CGContextSetAllowsFontSubpixelPositioning(CGContextRef context,
411                                            bool allowsFontSubpixelPositioning);
412  COREGRAPHICS_EXPORT void
413  CGContextSetShouldSubpixelPositionFonts(CGContextRef context,
414                                          bool shouldSubpixelPositionFonts);
415  
416  COREGRAPHICS_EXPORT void
417  CGContextDrawLinearGradient(CGContextRef c,
418                              CGGradientRef gradient, CGPoint startPoint, CGPoint endPoint,
419                              CGGradientDrawingOptions options);
420  
421  COREGRAPHICS_EXPORT void
422  CGContextDrawRadialGradient(CGContextRef c,
423                              CGGradientRef gradient, CGPoint startCenter, CGFloat startRadius,
424                              CGPoint endCenter, CGFloat endRadius, CGGradientDrawingOptions options);
425  
426  COREGRAPHICS_EXPORT void CGContextDrawTiledImage(CGContextRef c, CGRect rect, CGImageRef image);
427  
428  COREGRAPHICS_EXPORT void
429  CGContextShowGlyphsAtPositions(CGContextRef c,
430                                 const CGGlyph * glyphs, const CGPoint * Lpositions,
431                                 size_t count);
432  
433  CF_IMPLICIT_BRIDGING_DISABLED