00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SkPaint_DEFINED
00018 #define SkPaint_DEFINED
00019
00020 #include "SkColor.h"
00021 #include "SkMath.h"
00022 #include "SkXfermode.h"
00023
00024 class SkAutoGlyphCache;
00025 class SkColorFilter;
00026 class SkDescriptor;
00027 class SkFlattenableReadBuffer;
00028 class SkFlattenableWriteBuffer;
00029 struct SkGlyph;
00030 struct SkRect;
00031 class SkGlyphCache;
00032 class SkMaskFilter;
00033 class SkMatrix;
00034 class SkPath;
00035 class SkPathEffect;
00036 class SkRasterizer;
00037 class SkShader;
00038 class SkDrawLooper;
00039 class SkTypeface;
00040
00041 typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**,
00042 SkFixed x, SkFixed y);
00043
00044 typedef const SkGlyph& (*SkMeasureCacheProc)(SkGlyphCache*, const char**);
00045
00051 class SkPaint {
00052 public:
00053 SkPaint();
00054 SkPaint(const SkPaint& paint);
00055 ~SkPaint();
00056
00057 SkPaint& operator=(const SkPaint&);
00058
00059 friend int operator==(const SkPaint& a, const SkPaint& b);
00060 friend int operator!=(const SkPaint& a, const SkPaint& b)
00061 {
00062 return !(a == b);
00063 }
00064
00065 void flatten(SkFlattenableWriteBuffer&) const;
00066 void unflatten(SkFlattenableReadBuffer&);
00067
00070 void reset();
00071
00082 enum Hinting {
00083 kNo_Hinting = 0,
00084 kSlight_Hinting = 1,
00085 kNormal_Hinting = 2,
00086 kFull_Hinting = 3,
00087 };
00088
00089 Hinting getHinting() const
00090 {
00091 return static_cast<Hinting>(fHinting);
00092 }
00093
00094 void setHinting(Hinting hintingLevel)
00095 {
00096 fHinting = hintingLevel;
00097 }
00098
00101 enum Flags {
00102 kAntiAlias_Flag = 0x01,
00103 kFilterBitmap_Flag = 0x02,
00104 kDither_Flag = 0x04,
00105 kUnderlineText_Flag = 0x08,
00106 kStrikeThruText_Flag = 0x10,
00107 kFakeBoldText_Flag = 0x20,
00108 kLinearText_Flag = 0x40,
00109 kSubpixelText_Flag = 0x80,
00110 kDevKernText_Flag = 0x100,
00111 kLCDRenderText_Flag = 0x200,
00112
00113
00114
00115 kAllFlags = 0x3FF
00116 };
00117
00121 uint32_t getFlags() const { return fFlags; }
00122
00126 void setFlags(uint32_t flags);
00127
00131 bool isAntiAlias() const
00132 {
00133 return SkToBool(this->getFlags() & kAntiAlias_Flag);
00134 }
00135
00139 void setAntiAlias(bool aa);
00140
00144 bool isDither() const
00145 {
00146 return SkToBool(this->getFlags() & kDither_Flag);
00147 }
00148
00152 void setDither(bool dither);
00153
00157 bool isLinearText() const
00158 {
00159 return SkToBool(this->getFlags() & kLinearText_Flag);
00160 }
00161
00166 void setLinearText(bool linearText);
00167
00171 bool isSubpixelText() const
00172 {
00173 return SkToBool(this->getFlags() & kSubpixelText_Flag);
00174 }
00175
00180 void setSubpixelText(bool subpixelText);
00181
00182 bool isLCDRenderText() const
00183 {
00184 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
00185 }
00186
00191 void setLCDRenderText(bool subpixelRender);
00192
00196 bool isUnderlineText() const
00197 {
00198 return SkToBool(this->getFlags() & kUnderlineText_Flag);
00199 }
00200
00205 void setUnderlineText(bool underlineText);
00206
00210 bool isStrikeThruText() const
00211 {
00212 return SkToBool(this->getFlags() & kStrikeThruText_Flag);
00213 }
00214
00219 void setStrikeThruText(bool strikeThruText);
00220
00224 bool isFakeBoldText() const
00225 {
00226 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
00227 }
00228
00233 void setFakeBoldText(bool fakeBoldText);
00234
00238 bool isDevKernText() const
00239 {
00240 return SkToBool(this->getFlags() & kDevKernText_Flag);
00241 }
00242
00247 void setDevKernText(bool devKernText);
00248
00249 bool isFilterBitmap() const
00250 {
00251 return SkToBool(this->getFlags() & kFilterBitmap_Flag);
00252 }
00253
00254 void setFilterBitmap(bool filterBitmap);
00255
00265 enum Style {
00266 kFill_Style,
00267 kStroke_Style,
00268 kStrokeAndFill_Style,
00269
00270 kStyleCount,
00271 };
00272
00278 Style getStyle() const { return (Style)fStyle; }
00279
00285 void setStyle(Style style);
00286
00293 SkColor getColor() const { return fColor; }
00294
00300 void setColor(SkColor color);
00301
00305 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
00306
00311 void setAlpha(U8CPU a);
00312
00320 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
00321
00329 SkScalar getStrokeWidth() const { return fWidth; }
00330
00337 void setStrokeWidth(SkScalar width);
00338
00344 SkScalar getStrokeMiter() const { return fMiterLimit; }
00345
00352 void setStrokeMiter(SkScalar miter);
00353
00358 enum Cap {
00359 kButt_Cap,
00360 kRound_Cap,
00361 kSquare_Cap,
00362
00363 kCapCount,
00364 kDefault_Cap = kButt_Cap
00365 };
00366
00370 enum Join {
00371 kMiter_Join,
00372 kRound_Join,
00373 kBevel_Join,
00374
00375 kJoinCount,
00376 kDefault_Join = kMiter_Join
00377 };
00378
00384 Cap getStrokeCap() const { return (Cap)fCapType; }
00385
00390 void setStrokeCap(Cap cap);
00391
00396 Join getStrokeJoin() const { return (Join)fJoinType; }
00397
00402 void setStrokeJoin(Join join);
00403
00413 bool getFillPath(const SkPath& src, SkPath* dst) const;
00414
00419 bool canComputeFastBounds() const {
00420
00421 return (reinterpret_cast<uintptr_t>(this->getMaskFilter()) |
00422 reinterpret_cast<uintptr_t>(this->getLooper()) |
00423 reinterpret_cast<uintptr_t>(this->getRasterizer()) |
00424 reinterpret_cast<uintptr_t>(this->getPathEffect())) == 0;
00425 }
00426
00448 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
00449 return this->getStyle() == kFill_Style ? orig :
00450 this->computeStrokeFastBounds(orig, storage);
00451 }
00452
00458 SkShader* getShader() const { return fShader; }
00459
00469 SkShader* setShader(SkShader* shader);
00470
00475 SkColorFilter* getColorFilter() const { return fColorFilter; }
00476
00484 SkColorFilter* setColorFilter(SkColorFilter* filter);
00485
00491 SkXfermode* getXfermode() const { return fXfermode; }
00492
00503 SkXfermode* setXfermode(SkXfermode* xfermode);
00504
00509 SkXfermode* setXfermodeMode(SkXfermode::Mode);
00510
00516 SkPathEffect* getPathEffect() const { return fPathEffect; }
00517
00528 SkPathEffect* setPathEffect(SkPathEffect* effect);
00529
00535 SkMaskFilter* getMaskFilter() const { return fMaskFilter; }
00536
00547 SkMaskFilter* setMaskFilter(SkMaskFilter* maskfilter);
00548
00549
00550
00557 SkTypeface* getTypeface() const { return fTypeface; }
00558
00569 SkTypeface* setTypeface(SkTypeface* typeface);
00570
00576 SkRasterizer* getRasterizer() const { return fRasterizer; }
00577
00589 SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
00590
00591 SkDrawLooper* getLooper() const { return fLooper; }
00592 SkDrawLooper* setLooper(SkDrawLooper*);
00593
00594 enum Align {
00595 kLeft_Align,
00596 kCenter_Align,
00597 kRight_Align,
00598
00599 kAlignCount
00600 };
00604 Align getTextAlign() const { return (Align)fTextAlign; }
00608 void setTextAlign(Align align);
00609
00613 SkScalar getTextSize() const { return fTextSize; }
00614
00618 void setTextSize(SkScalar textSize);
00619
00624 SkScalar getTextScaleX() const { return fTextScaleX; }
00625
00632 void setTextScaleX(SkScalar scaleX);
00633
00638 SkScalar getTextSkewX() const { return fTextSkewX; }
00639
00644 void setTextSkewX(SkScalar skewX);
00645
00649 enum TextEncoding {
00650 kUTF8_TextEncoding,
00651 kUTF16_TextEncoding,
00652 kGlyphID_TextEncoding
00653 };
00654
00655 TextEncoding getTextEncoding() const
00656 {
00657 return (TextEncoding)fTextEncoding;
00658 }
00659
00660 void setTextEncoding(TextEncoding encoding);
00661
00662 struct FontMetrics {
00663 SkScalar fTop;
00664 SkScalar fAscent;
00665 SkScalar fDescent;
00666 SkScalar fBottom;
00667 SkScalar fLeading;
00668 SkScalar fAvgCharWidth;
00669 SkScalar fXMin;
00670 SkScalar fXMax;
00671 SkScalar fXHeight;
00672 };
00673
00685 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
00686
00690 SkScalar getFontSpacing() const { return this->getFontMetrics(NULL, 0); }
00691
00696 int textToGlyphs(const void* text, size_t byteLength,
00697 uint16_t glyphs[]) const;
00698
00704 int countText(const void* text, size_t byteLength) const
00705 {
00706 return this->textToGlyphs(text, byteLength, NULL);
00707 }
00708
00718 SkScalar measureText(const void* text, size_t length,
00719 SkRect* bounds, SkScalar scale = 0) const;
00720
00726 SkScalar measureText(const void* text, size_t length) const
00727 {
00728 return this->measureText(text, length, NULL, 0);
00729 }
00730
00733 enum TextBufferDirection {
00737 kForward_TextBufferDirection,
00741 kBackward_TextBufferDirection
00742 };
00743
00756 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
00757 SkScalar* measuredWidth = NULL,
00758 TextBufferDirection tbd = kForward_TextBufferDirection)
00759 const;
00760
00771 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
00772 SkRect bounds[] = NULL) const;
00773
00778 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
00779 SkPath* path) const;
00780
00781 private:
00782 SkTypeface* fTypeface;
00783 SkScalar fTextSize;
00784 SkScalar fTextScaleX;
00785 SkScalar fTextSkewX;
00786
00787 SkPathEffect* fPathEffect;
00788 SkShader* fShader;
00789 SkXfermode* fXfermode;
00790 SkMaskFilter* fMaskFilter;
00791 SkColorFilter* fColorFilter;
00792 SkRasterizer* fRasterizer;
00793 SkDrawLooper* fLooper;
00794
00795 SkColor fColor;
00796 SkScalar fWidth;
00797 SkScalar fMiterLimit;
00798 unsigned fFlags : 10;
00799 unsigned fTextAlign : 2;
00800 unsigned fCapType : 2;
00801 unsigned fJoinType : 2;
00802 unsigned fStyle : 2;
00803 unsigned fTextEncoding : 2;
00804 unsigned fHinting : 2;
00805
00806 SkDrawCacheProc getDrawCacheProc() const;
00807 SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,
00808 bool needFullMetrics) const;
00809
00810 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
00811 int* count, SkRect* bounds) const;
00812
00813 SkGlyphCache* detachCache(const SkMatrix*) const;
00814
00815 void descriptorProc(const SkMatrix* deviceMatrix,
00816 void (*proc)(const SkDescriptor*, void*),
00817 void* context) const;
00818
00819 const SkRect& computeStrokeFastBounds(const SkRect& orig,
00820 SkRect* storage) const;
00821
00822 enum {
00823 kCanonicalTextSizeForPaths = 64
00824 };
00825 friend class SkCanvas;
00826 friend class SkDraw;
00827 friend class SkAutoGlyphCache;
00828 friend class SkTextToPathIter;
00829 };
00830
00832
00833 #include "SkPathEffect.h"
00834
00842 class SkStrokePathEffect : public SkPathEffect {
00843 public:
00844 SkStrokePathEffect(const SkPaint&);
00845 SkStrokePathEffect(SkScalar width, SkPaint::Style, SkPaint::Join,
00846 SkPaint::Cap, SkScalar miterLimit = -1);
00847
00848
00849
00850 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
00851
00852
00853
00854 virtual void flatten(SkFlattenableWriteBuffer&);
00855
00856 virtual Factory getFactory();
00857
00858 private:
00859 SkScalar fWidth, fMiter;
00860 uint8_t fStyle, fJoin, fCap;
00861
00862 static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
00863 SkStrokePathEffect(SkFlattenableReadBuffer&);
00864
00865 typedef SkPathEffect INHERITED;
00866
00867
00868 SkStrokePathEffect(const SkStrokePathEffect&);
00869 SkStrokePathEffect& operator=(const SkStrokePathEffect&);
00870 };
00871
00872 #endif
00873