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