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