00001 /* 00002 Copyright (c) 2010, The Barbarian Group 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that 00006 the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and 00009 the following disclaimer. 00010 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 00011 the following disclaimer in the documentation and/or other materials provided with the distribution. 00012 00013 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00014 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00015 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00016 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00017 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00018 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00019 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00020 POSSIBILITY OF SUCH DAMAGE. 00021 */ 00022 00023 #pragma once 00024 00025 #include "cinder/Cinder.h" 00026 #include "cinder/Surface.h" 00027 #include "cinder/Color.h" 00028 #include "cinder/Rect.h" 00029 #include "cinder/BSpline.h" 00030 #include "cinder/Shape2d.h" 00031 #include "cinder/Font.h" 00032 #include "cinder/ImageIo.h" 00033 00034 #if defined( CINDER_COCOA_TOUCH ) 00035 #include <CoreGraphics/CoreGraphics.h> 00036 #elif defined( CINDER_MAC ) 00037 #include <ApplicationServices/ApplicationServices.h> 00038 #endif 00039 00040 #include <string> 00041 #include <vector> 00042 00043 // Forward declarations used by our cairo wrappers 00044 struct _cairo_surface; 00045 typedef struct _cairo_surface cairo_surface_t; 00046 00047 struct _cairo; 00048 typedef struct _cairo cairo_t; 00049 00050 struct cairo_path; 00051 typedef struct cairo_path cairo_path_t; 00052 00053 struct _cairo_pattern; 00054 typedef struct _cairo_pattern cairo_pattern_t; 00055 00056 /* 00057 struct _cairo_rectangle; 00058 typedef struct _cairo_rectangle cairo_rectangle_t; 00059 00060 struct _cairo_rectangle_list; 00061 typedef struct _cairo_rectangle_list cairo_rectangle_list_t; 00062 */ 00063 00064 struct _cairo_font_options; 00065 typedef struct _cairo_font_options cairo_font_options_t; 00066 00067 struct _cairo_matrix; 00068 typedef struct _cairo_matrix cairo_matrix_t; 00069 00070 struct _cairo_font_face; 00071 typedef struct _cairo_font_face cairo_font_face_t; 00072 00073 struct _cairo_scaled_font; 00074 typedef struct _cairo_scaled_font cairo_scaled_font_t; 00075 00076 /*struct _cairo_glyph; 00077 typedef struct _cairo_glyph cairo_glyph_t;*/ 00078 00079 struct _cairo_text_extents; 00080 typedef struct _cairo_text_extents cairo_text_extents_t; 00081 00082 struct _cairo_font_extents; 00083 typedef struct _cairo_font_extents cairo_font_extents_t; 00084 00085 namespace cinder { namespace cairo { 00087 // SurfaceBase 00088 class SurfaceBase { 00089 public: 00090 SurfaceBase() : mCairoSurface( 0 ) {} 00091 SurfaceBase( const SurfaceBase &other ); 00092 SurfaceBase& operator=( const SurfaceBase &other ); 00093 00094 virtual ~SurfaceBase(); 00095 00096 cairo_surface_t* getCairoSurface() const { return mCairoSurface; } 00097 00098 int32_t getWidth() const { return mWidth; } 00099 int32_t getHeight() const { return mHeight; } 00100 float getAspectRatio() const { return getWidth() / (float)getHeight(); } 00101 Area getBounds() const { return Area( 0, 0, getWidth(), getHeight() ); } 00102 Vec2i getSize() const { return Vec2i( getWidth(), getHeight() ); } 00103 00104 void flush(); 00105 00106 protected: 00107 SurfaceBase( int32_t aWidth, int32_t aHeight ) : mWidth( aWidth ), mHeight( aHeight ), mCairoSurface( 0 ) {} 00108 00109 cairo_surface_t *mCairoSurface; 00110 int32_t mWidth, mHeight; 00111 }; 00112 00114 // SurfaceImage 00115 class SurfaceImage : public SurfaceBase { 00116 public: 00117 SurfaceImage() : SurfaceBase() {} 00118 SurfaceImage( int32_t width, int32_t height, bool hasAlpha = false ); 00119 SurfaceImage( const uint8_t *dataPtr, int32_t width, int32_t height, int32_t stride, bool hasAlpha = false ); 00121 SurfaceImage( cinder::Surface ciSurface ); 00122 SurfaceImage( ImageSourceRef imageSource ); 00123 SurfaceImage( const SurfaceImage &other ); 00124 00125 uint8_t* getData(); 00126 const uint8_t* getData() const { return getData(); } 00127 int32_t getStride() const; 00128 00129 cinder::Surface& getSurface(); 00130 const cinder::Surface& getSurface() const { return getSurface(); } 00131 00132 protected: 00133 void initCinderSurface( bool alpha, uint8_t *data, int32_t stride ); 00134 00135 cinder::Surface mCinderSurface; 00136 }; 00137 00139 // SurfaceSvg 00140 class SurfaceSvg : public SurfaceBase { 00141 public: 00142 SurfaceSvg() : SurfaceBase() {} 00143 SurfaceSvg( const std::string &filePath, uint32_t aWidth, uint32_t aHeight ); 00144 SurfaceSvg( const SurfaceSvg &other ); 00145 }; 00146 00148 // SurfacePdf 00149 class SurfacePdf : public SurfaceBase { 00150 public: 00151 SurfacePdf() : SurfaceBase() {} 00152 SurfacePdf( const std::string &filePath, double widthInPoints, double heightInPoints ); 00153 SurfacePdf( const SurfacePdf &other ); 00154 00155 void setSize( double widthInPoints, double heightInPoints ); 00156 }; 00157 00159 // SurfacePs 00160 class SurfacePs : public SurfaceBase { 00161 public: 00162 SurfacePs() : SurfaceBase() {} 00163 SurfacePs( const std::string &filePath, double widthInPoints, double heightInPoints, bool enableLevel3 = true ); 00164 SurfacePs( const SurfacePs &other ); 00165 00166 void setSize( double widthInPoints, double heightInPoints ); 00169 void dscBeginSetup();; 00172 void dscBeginPageSetup(); 00174 void dscComment( const std::string &comment ) { dscComment( comment.c_str() ); } 00176 void dscComment( const char *comment ); 00177 }; 00178 00180 // SurfaceEps 00181 class SurfaceEps : public SurfaceBase { 00182 public: 00183 SurfaceEps() : SurfaceBase() {} 00184 SurfaceEps( const std::string &filePath, double widthInPoints, double heightInPoints, bool enableLevel3 = true ); 00185 SurfaceEps( const SurfaceEps &other ); 00186 00187 void setSize( double widthInPoints, double heightInPoints ); 00190 void dscBeginSetup();; 00193 void dscBeginPageSetup(); 00195 void dscComment( const std::string &comment ) { dscComment( comment.c_str() ); } 00197 void dscComment( const char *comment ); 00198 }; 00199 00201 // SurfaceQuartz 00202 #if defined( CINDER_COCOA ) 00203 class SurfaceQuartz : public SurfaceBase { 00204 public: 00205 SurfaceQuartz() : SurfaceBase() {} 00206 SurfaceQuartz( CGContextRef cgContext, int32_t width, int32_t height ); 00207 SurfaceQuartz( const SurfaceQuartz &other ); 00208 00209 CGContextRef getCgContextRef(); 00210 00211 protected: 00212 CGContextRef mCgContextRef; 00213 }; 00214 00216 // SurfaceCgBitmapContext 00217 class SurfaceCgBitmapContext : public SurfaceBase { 00218 public: 00219 SurfaceCgBitmapContext() : SurfaceBase() {} 00220 SurfaceCgBitmapContext( int32_t width, int32_t height, bool alpha ); 00221 SurfaceCgBitmapContext( const SurfaceCgBitmapContext &other ); 00222 00223 cinder::Surface& getSurface() { return mSurface; } 00224 const cinder::Surface& getSurface() const { return getSurface(); } 00225 00226 CGContextRef getCgContextRef() { return mCgContextRef; } 00227 00228 protected: 00229 cinder::Surface mSurface; 00230 CGContextRef mCgContextRef; 00231 }; 00232 #endif // defined( CINDER_COCOA ) 00233 00235 // SurfaceGdi 00236 #if defined( CINDER_MSW ) 00237 class SurfaceGdi : public SurfaceBase { 00238 public: 00239 SurfaceGdi() : SurfaceBase() {} 00240 SurfaceGdi( HDC hdc ); 00241 SurfaceGdi( const SurfaceGdi &other ); 00242 00243 HDC getDc() const { return mDc; } 00244 00245 protected: 00246 HDC mDc; 00247 }; 00248 #endif // defined( CINDER_MSW ) 00249 00251 // Matrix 00252 class Matrix 00253 { 00254 public: 00255 Matrix(); 00256 Matrix( double xx, double yx, double xy, double yy, double x0, double y0 ); 00257 00258 // This is a sort of horrible technique, but we will replace this with the ci::Matrix32 that will exist one day 00259 cairo_matrix_t& getCairoMatrix() { return *reinterpret_cast<cairo_matrix_t*>( this ); } 00260 const cairo_matrix_t& getCairoMatrix() const { return *reinterpret_cast<const cairo_matrix_t*>( this ); } 00261 00262 void init( double xx, double yx, double xy, double yy, double x0, double y0 ); 00263 void initIdentity(); 00264 void initTranslate( double tx, double ty ); 00265 void initScale( double sx, double sy ); 00266 void initRotate( double radians ); 00267 void translate( double tx, double ty ); 00268 void scale( double sx, double sy ); 00269 void rotate( double radians ); 00270 int32_t invert(); 00271 00273 Vec2f transformPoint( const Vec2f &v ) const; 00275 Vec2f transformDistance( const Vec2f &v ) const; 00276 00277 // this is designed to mimic cairo_matrix_t exactly 00278 double xx; double yx; 00279 double xy; double yy; 00280 double x0; double y0; 00281 }; 00282 00283 class Pattern { 00284 public: 00286 Pattern( cairo_pattern_t *aPattern ) : mCairoPattern( aPattern ) {} 00287 Pattern( const Pattern &other ); 00288 ~Pattern(); 00289 00290 Pattern& operator=( const Pattern &other ); 00291 00292 cairo_pattern_t* getCairoPattern() { return mCairoPattern; } 00293 00294 void setExtend( int extend ); 00295 void setExtendNone(); 00296 void setExtendRepeat(); 00297 void setExtendReflect(); 00298 void setExtendPad(); 00299 int getExtend() const; 00300 00301 void setFilter( int filter ); 00302 int getFilter() const; 00303 00304 void setMatrix( const Matrix &matrix ); 00305 Matrix getMatrix() const; 00306 00307 protected: 00308 Pattern() : mCairoPattern( 0 ) {} 00309 00310 cairo_pattern_t *mCairoPattern; 00311 }; 00312 00313 class PatternSolid : public Pattern { 00314 public: 00315 PatternSolid( const ColorA &color ); 00316 PatternSolid( const Color &color ); 00317 }; 00318 00319 class PatternSurface : public Pattern { 00320 public: 00322 PatternSurface() : Pattern() {} 00323 PatternSurface( SurfaceBase &surface ); 00324 PatternSurface( ci::Surface cinderSurface ); 00325 PatternSurface( ImageSourceRef imageSource ); 00326 }; 00327 00328 class Gradient : public Pattern { 00329 public: 00330 void addColorStopRgb( double offset, double red, double green, double blue ); 00331 void addColorStopRgba( double offset, double red, double green, double blue, double alpha ); 00332 void addColorStop( double offset, const Color &color ) { addColorStopRgb( offset, (double)color.r, (double)color.g, (double)color.b ); } 00333 void addColorStop( double offset, const ColorA &color ) { addColorStopRgba( offset, (double)color.r, (double)color.g, (double)color.b, (double)color.a ); } 00335 int getColorStopCount(); 00336 void getColorStopRgba( int index, double *offset, double *red, double *green, double *blue, double *alpha ); 00337 00338 protected: 00339 Gradient( cairo_pattern_t *pattern ); 00340 }; 00341 00342 class GradientRadial : public Gradient { 00343 public: 00344 GradientRadial( double x0, double y0, double radius0, double x1, double y1, double radius1 ); 00345 GradientRadial( const Vec2f ¢er0, float radius0, const Vec2f ¢er1, float radius1 ); 00346 }; 00347 00348 class GradientLinear : public Gradient { 00349 public: 00350 GradientLinear( double x0, double y0, double x1, double y1 ); 00351 GradientLinear( Vec2f point0, Vec2f point1 ); 00352 }; 00353 00354 class FontOptions 00355 { 00356 public: 00357 FontOptions() { mCairoFontOptions = 0; } 00358 FontOptions( cairo_font_options_t *aCairoFontOptions ); 00359 virtual ~FontOptions(); 00360 00361 cairo_font_options_t* getCairoFontOptions() { return mCairoFontOptions; } 00362 00363 FontOptions* create(); 00364 00365 int32_t status(); 00366 void merge( const FontOptions *other ); 00367 unsigned long hash(); 00368 bool equal( const FontOptions *other ); 00369 void setAntiAlias( int32_t antialias ); 00370 int32_t getAntiAlias(); 00371 void setSubPixelOrder( int32_t subpixel_order ); 00372 int32_t getSubPixelOrder(); 00373 void setHintStyle( int32_t hint_style ); 00374 int32_t getHintStyle(); 00375 void setHintMetrics( int32_t hint_metrics ); 00376 int32_t getHintMetrics(); 00377 00378 private: 00379 cairo_font_options_t *mCairoFontOptions; 00380 }; 00381 00382 class FontFace 00383 { 00384 public: 00385 FontFace() { mCairoFontFace = 0; } 00386 FontFace( const std::string &fontName ); 00387 FontFace( cairo_font_face_t *aCairoFontFace ); 00388 virtual ~FontFace(); 00389 00390 cairo_font_face_t* getCairoFontFace() const { return mCairoFontFace; } 00391 00392 int32_t getType(); 00393 00394 private: 00395 cairo_font_face_t *mCairoFontFace; 00396 }; 00397 00398 class ScaledFont 00399 { 00400 public: 00401 ScaledFont() { mCairoScaledFont = 0; } 00402 ScaledFont( cairo_scaled_font_t *aCairoScaledFont ); 00403 virtual ~ScaledFont(); 00404 00405 cairo_scaled_font_t* getCairoScaledFont() { return mCairoScaledFont; } 00406 00407 int32_t status(); 00408 // void fontExtents( class FontExtents *extents ); 00409 // void textExtents( const char *utf8, class TextExtents *extents ); 00410 //void glyphExents( const class Glyph *glyphs, int32_t num_glyphs ); // Needs to change to accept arrays 00411 FontFace* getFontFace(); 00412 void getFontOptions( FontOptions *options ); 00413 void getFontMatrix( Matrix *font_matrix ); 00414 void getCtm( Matrix *ctm); 00415 int32_t getType(); 00416 00417 private: 00418 cairo_scaled_font_t *mCairoScaledFont; 00419 }; 00420 00421 /*class Glyph 00422 { 00423 public: 00424 Glyph(); 00425 Glyph( cairo_glyph_t *aCairoGlyph ); 00426 virtual ~Glyph(); 00427 00428 cairo_glyph_t* getCairoGlyph() { return mCairoGlyph.get(); } 00429 00430 const unsigned long& index() const; 00431 unsigned long& index(); 00432 const double& x() const; 00433 double& x(); 00434 const double& y() const; 00435 double& y(); 00436 00437 private: 00438 std::shared_ptr<cairo_glyph_t> mCairoGlyph; 00439 }; 00440 00441 // This stores a std::vector of cairo_glyph_t 00442 class GlyphArray 00443 { 00444 public: 00445 GlyphArray(); 00446 00447 Glyph getAtIndex( size_t idx ); 00448 void append( Glyph &aGlyph ); 00449 void clear(); 00450 00451 private: 00452 std::vector<cairo_glyph_t> mGlyphs; 00453 00454 friend class Context; 00455 }; 00456 */ 00457 class FontExtents 00458 { 00459 public: 00460 FontExtents(); 00461 FontExtents( cairo_font_extents_t *aCairoFontExtents ); 00462 virtual ~FontExtents(); 00463 00464 cairo_font_extents_t* getCairoFontExtents() { return mCairoFontExtents.get(); } 00465 00466 const double& ascent() const; 00467 double& ascent(); 00468 const double& descent() const; 00469 double& descent(); 00470 const double& height() const; 00471 double& height(); 00472 const double& maxXAdvance() const; 00473 double& maxXAdvance(); 00474 const double& maxYAdvance() const; 00475 double& maxYAdvance(); 00476 00477 private: 00478 std::shared_ptr<cairo_font_extents_t> mCairoFontExtents; 00479 }; 00480 00481 class TextExtents 00482 { 00483 public: 00484 TextExtents(); 00485 TextExtents( cairo_text_extents_t *aCairoTextExtents ); 00486 virtual ~TextExtents(); 00487 00488 cairo_text_extents_t* getCairoTextExtents() { return mCairoTextExtents.get(); } 00489 00490 const double& xBearing() const; 00491 double& xBearing(); 00492 const double& yBearing() const; 00493 double& yBearing(); 00494 const double& width() const; 00495 double& width(); 00496 const double& height() const; 00497 double& height(); 00498 const double& xAdvance() const; 00499 double& xAdvance(); 00500 const double& yAdvance() const; 00501 double& yAdvance(); 00502 00503 private: 00504 std::shared_ptr<cairo_text_extents_t> mCairoTextExtents; 00505 }; 00506 00508 // Context 00509 class Context 00510 { 00511 public: 00512 Context() : mCairo( 0 ) {} 00513 Context( const SurfaceBase &surface ); 00514 Context( const Context &other ); 00515 ~Context(); 00516 00517 Context& operator=( const Context &other ); 00518 00520 cairo_t* getCairo(); 00522 cairo_surface_t* getCairoSuface(); 00523 00524 void save(); 00525 void restore(); 00526 void flush(); 00527 00528 void pushGroup(); 00529 00530 void pushGroupWithContent( int32_t content ); 00531 Pattern* popGroup(); 00532 void popGroupToSource(); 00533 00534 void setSourceRgb( double red, double green, double blue ); 00535 void setSourceRgba( double red, double green, double blue, double alpha ); 00536 void setSource( const Color &col ) { setSourceRgb( col.r, col.g, col.b ); } 00537 void setSource( const ColorAf &col ) { setSourceRgba( col.r, col.g, col.b, col.a ); } 00538 void setSource( const Pattern &source ); 00539 void setSourceSurface( SurfaceBase &surface, double x, double y ); 00540 Pattern* getSource(); 00541 00542 void copySurface( const SurfaceBase &surface, const Area &srcArea, const Vec2i &dstOffset = Vec2i::zero() ); 00543 00544 void setAntiAlias( int32_t antialias ); 00545 int32_t getAntiAlias(); 00546 00547 void setDash( const double *dashes, int numDashes, double offset ); 00548 void setDash( const std::vector<double> &dashes, double offset = 0 ); 00549 void unsetDash(); 00550 int getDashCount() const; 00551 void getDash( double *dashes, double *offset ); 00552 00553 void setFillRule( int32_t fill_rule ); 00554 int32_t getFillRule(); 00555 void setLineCap( int32_t line_cap ); 00556 int32_t getLineCap(); 00557 void setLineJoin( int32_t line_join ); 00558 int32_t getLineJoin(); 00559 void setLineWidth( double width ); 00560 double getLineWidth() const; 00561 void setMiterLimit( double limit ); 00562 double getMiterLimit() const; 00563 00564 void setOperator( int32_t op ); 00565 int32_t getOperator(); 00566 00567 void setTolerance( double tolerance ); 00568 double getTolerance() const; 00569 void clip(); 00570 void clipPerserve(); 00571 void clipExtents( double *x1, double *y1, double *x2, double *y2 ); 00572 void resetClip(); 00573 00574 // TODO: This stuff needs to be reviewed before we implement. 00575 // enum cairo_rectangle_t; 00576 // enum cairo_rectangle_list_t; 00577 // void cairo_rectangle_list_destroy (cairo_rectangle_list_t *rectangle_list); 00578 // cairo_rectangle_list_t* cairo_copy_clip_rectangle_list(cairo_t *cr); 00579 00580 void fill(); 00581 void fillPreserve(); 00582 void fillExtents( double *x1, double *y1, double *x2, double *y2 ); 00583 bool inFill( double x, double y ); 00584 00585 // void cairo_mask (cairo_t *cr, cairo_pattern_t *pattern); 00586 // void cairo_mask_surface (cairo_t *cr, cairo_surface_t *surface, double surface_x, double surface_y); 00587 void mask( Pattern *pattern ); 00588 void maskSurface( SurfaceBase *surface, double surface_x, double surface_y ); 00589 00590 void paint(); 00591 void paintWithAlpha( double alpha ); 00592 void stroke(); 00593 void strokePreserve(); 00594 void strokeExtents( double *x1, double *y1, double *x2, double *y2 ); 00595 bool inStroke( double x, double y ); 00596 void copyPage(); 00597 void showPage(); 00598 00600 void copyPath( cinder::Shape2d *resultPath ); 00602 void copyPathFlat( cinder::Shape2d *resultPath ); 00603 /*void pathDestroy( class Path *path ); 00604 void appendPath( const class Path *path ); 00605 */ 00606 void getCurrentPoint( double *x, double *y ); 00607 void newPath(); 00608 void newSubPath(); 00609 void closePath(); 00610 void arc( double xc, double yc, double radius, double angle1, double angle2 ); 00611 void arc( const Vec2f ¢er, double radius, double angle1, double angle2 ) { arc( center.x, center.y, radius, angle1, angle2 ); } 00612 void arcNegative( double xc, double yc, double radius, double angle1, double angle2 ); 00613 void arcNegative( const Vec2f ¢er, double radius, double angle1, double angle2 ) { arcNegative( center.x, center.y, radius, angle1, angle2 ); } 00614 void quadTo( double x1, double y1, double x2, double y2 ); 00615 void quadTo( const Vec2f &v1, const Vec2f &v2 ) { quadTo( (double)v1.x, (double)v1.y, (double)v2.x, (double)v2.y ); } 00616 void curveTo( double x1, double y1, double x2, double y2, double x3, double y3 ); 00617 void curveTo( const Vec2f &v1, const Vec2f &v2, const Vec2f &v3 ) { curveTo( (double)v1.x, (double)v1.y, (double)v2.x, (double)v2.y, (double)v3.x, (double)v3.y ); } 00618 void line( const Vec2f &v1, const Vec2f &v2 ) { moveTo( v1 ); lineTo( v2 ); } 00619 void lineTo( double x, double y ); 00620 void lineTo( const Vec2f &v ) { lineTo( (double)v.x, (double)v.y ); } 00621 void moveTo( double x, double y ); 00622 void moveTo( const Vec2f &v ) { moveTo( (double)v.x, (double)v.y ); } 00623 void rectangle( double x, double y, double width, double height ); 00624 void rectangle( const Rectf &r ) { rectangle( r.x1, r.y1, r.getWidth(), r.getHeight() ); } 00625 void rectangle( const Vec2f &upperLeft, const Vec2f &lowerRight ); 00626 //void glyphPath( const cairo_glyph_t *glyphs, int num_glyphs ); 00627 void textPath( const char *utf8 ); 00628 void relCurveTo( double dx1, double dy1, double dx2, double dy2, double dx3, double dy3 ); 00629 void relLineTo( double dx, double dy ); 00630 void relMoveTo( double dx, double dy ); 00631 void appendPath( const cinder::Shape2d &path ); 00632 void appendPath( const cinder::Path2d &path ); 00633 void circle( double dx, double dy, double radius ); 00634 void circle( const Vec2f &v, double radius ) { circle( (double)v.x, (double)v.y, radius ); } 00635 00636 // Transformation functions 00637 void translate( double tx, double ty ); 00638 void translate( const Vec2f &v ) { translate( (double)v.x, (double)v.y ); } 00639 void scale( double sx, double sy ); 00640 void rotate( double angle ); 00641 void transform( const Matrix &aMatrix ); 00642 void setMatrix( const Matrix &aMatrix ); 00643 void getMatrix( Matrix *aMatrix ); 00644 void identityMatrix(); 00645 void userToDevice( double *x, double *y ); 00646 void userToDeviceDistance( double *dx, double *dy ); 00647 void deviceToUser( double *x, double *y ); 00648 void deviceToUserDistance( double *dx, double *dy ); 00649 00650 // Text/font functions 00651 void setFont( const cinder::Font &font ); 00652 void selectFontFace( const std::string &family, int32_t slant, int32_t weight ); 00653 void setFontSize( double size ); 00654 void setFontMatrix( const Matrix &matrix ); 00655 void getFontMatrix( Matrix *matrix ); 00656 void setFontOptions( const FontOptions *options ); 00657 void getFontOptions( FontOptions *options ); 00658 void setFontFace( const FontFace &font_face ); 00659 FontFace* getFontFace(); 00660 void setScaledFont( const ScaledFont *scaled_font ); 00661 ScaledFont* getScaledFont(); 00662 void showText( const std::string &s ); 00663 //void showGlyphs( const Glyph *glyphs, int num_glyphs ); // glyphs is an array of cairo_glyph_t 00664 //void showGlyphs( const GlyphArray &glyphs ); 00665 FontExtents fontExtents(); 00666 TextExtents textExtents( const std::string &s ); 00667 //void glyphExtents( const Glyph *glyphs, int num_glyphs, TextExtents *extents ); // glyphs is an array of cairo_glyph_t 00668 //void glyphExtents( const GlyphArray &glyphs, int num_glyphs, TextExtents *extents ); 00669 00670 protected: 00671 cairo_t *mCairo; 00672 cairo_surface_t *mCairoSurface; 00673 }; 00674 00675 #if defined( CINDER_COCOA ) 00676 SurfaceQuartz createWindowSurface(); 00677 #else 00678 SurfaceGdi createWindowSurface(); 00679 #endif 00680 00681 // CONSTANTS 00682 extern const int32_t FONT_SLANT_NORMAL; 00683 extern const int32_t FONT_SLANT_ITALIC; 00684 extern const int32_t FONT_SLANT_OBLIQUE; 00685 extern const int32_t FONT_WEIGHT_NORMAL; 00686 extern const int32_t FONT_WEIGHT_BOLD; 00687 00688 extern const int32_t FILL_RULE_WINDING; 00689 extern const int32_t FILL_RULE_EVEN_ODD; 00690 00691 extern const int32_t EXTEND_NONE; 00692 extern const int32_t EXTEND_REPEAT; 00693 extern const int32_t EXTEND_REFLECT; 00694 extern const int32_t EXTEND_PAD; 00695 00696 extern const int32_t LINE_CAP_BUTT; 00697 extern const int32_t LINE_CAP_ROUND; 00698 extern const int32_t LINE_CAP_SQUARE; 00699 00700 extern const int32_t LINE_JOIN_MITER; 00701 extern const int32_t LINE_JOIN_ROUND; 00702 extern const int32_t LINE_JOIN_BEVEL; 00703 00704 extern const int32_t HINT_METRICS_DEFAULT; 00705 extern const int32_t HINT_METRICS_OFF; 00706 extern const int32_t HINT_METRICS_ON; 00707 extern const int32_t HINT_STYLE_DEFAULT; 00708 extern const int32_t HINT_STYLE_NONE; 00709 extern const int32_t HINT_STYLE_SLIGHT; 00710 extern const int32_t HINT_STYLE_MEDIUM; 00711 extern const int32_t HINT_STYLE_FULL; 00712 00713 extern const int32_t ANTIALIAS_DEFAULT; 00714 extern const int32_t ANTIALIAS_NONE; 00715 extern const int32_t ANTIALIAS_GRAY; 00716 extern const int32_t ANTIALIAS_SUBPIXEL; 00717 00718 extern const int32_t SUBPIXEL_ORDER_DEFAULT; 00719 extern const int32_t SUBPIXEL_ORDER_RGB; 00720 extern const int32_t SUBPIXEL_ORDER_BGR; 00721 extern const int32_t SUBPIXEL_ORDER_VRGB; 00722 extern const int32_t SUBPIXEL_ORDER_VBGR; 00723 00724 extern const int32_t STATUS_SUCCESS; 00725 extern const int32_t STATUS_NO_AVAILABLE_MEMORY; 00726 extern const int32_t STATUS_INVALID_RESTORE; 00727 extern const int32_t STATUS_INVALID_POP_GROUP; 00728 extern const int32_t STATUS_NO_CURRENT_POINT; 00729 extern const int32_t STATUS_INVALID_MATRIX; 00730 extern const int32_t STATUS_INVALID_STATUS; 00731 extern const int32_t STATUS_NULL_POINTER; 00732 extern const int32_t STATUS_INVALID_STRING; 00733 extern const int32_t STATUS_INVALID_PATH_DATA; 00734 extern const int32_t STATUS_READ_ERROR; 00735 extern const int32_t STATUS_WRITE_ERROR; 00736 extern const int32_t STATUS_SURFACE_FINISHED; 00737 extern const int32_t STATUS_SURFACE_TYPE_MISMATCH; 00738 extern const int32_t STATUS_PATTERN_TYPE_MISMATCH; 00739 extern const int32_t STATUS_INVALID_CONTENT; 00740 extern const int32_t STATUS_INVALID_FORMAT; 00741 extern const int32_t STATUS_INVALID_VISUAL; 00742 extern const int32_t STATUS_FILE_NOT_FOUND; 00743 extern const int32_t STATUS_INVALID_DASH; 00744 extern const int32_t STATUS_INVALID_DSC_COMMENT; 00745 extern const int32_t STATUS_INVALID_INDEX; 00746 extern const int32_t STATUS_CLIP_NOT_REPRESENTABLE; 00747 00748 } } // namespace cinder::cairo 00749 00750 namespace cinder { 00751 00752 class SurfaceConstraintsCairo : public cinder::SurfaceConstraints { 00753 public: 00754 virtual SurfaceChannelOrder getChannelOrder( bool alpha ) const; 00755 virtual int32_t getRowBytes( int requestedWidth, const SurfaceChannelOrder &sco, int elementSize ) const; 00756 }; 00757 00758 } // namespace cinder