OLD | NEW |
1 | 1 |
2 | 2 |
3 /* | 3 /* |
4 * Copyright 2006 The Android Open Source Project | 4 * Copyright 2006 The Android Open Source Project |
5 * | 5 * |
6 * Use of this source code is governed by a BSD-style license that can be | 6 * Use of this source code is governed by a BSD-style license that can be |
7 * found in the LICENSE file. | 7 * found in the LICENSE file. |
8 */ | 8 */ |
9 | 9 |
10 | 10 |
11 #ifndef SkPaint_DEFINED | 11 #ifndef SkPaint_DEFINED |
12 #define SkPaint_DEFINED | 12 #define SkPaint_DEFINED |
13 | 13 |
14 #include "SkColor.h" | 14 #include "SkColor.h" |
15 #include "SkDrawLooper.h" | 15 #include "SkDrawLooper.h" |
| 16 #include "SkMatrix.h" |
16 #include "SkXfermode.h" | 17 #include "SkXfermode.h" |
17 #ifdef SK_BUILD_FOR_ANDROID | 18 #ifdef SK_BUILD_FOR_ANDROID |
18 #include "SkPaintOptionsAndroid.h" | 19 #include "SkPaintOptionsAndroid.h" |
19 #endif | 20 #endif |
20 | 21 |
21 class SkAnnotation; | 22 class SkAnnotation; |
22 class SkAutoGlyphCache; | 23 class SkAutoGlyphCache; |
23 class SkColorFilter; | 24 class SkColorFilter; |
24 class SkDescriptor; | 25 class SkDescriptor; |
25 struct SkDeviceProperties; | 26 struct SkDeviceProperties; |
26 class SkFlattenableReadBuffer; | 27 class SkFlattenableReadBuffer; |
27 class SkFlattenableWriteBuffer; | 28 class SkFlattenableWriteBuffer; |
28 struct SkGlyph; | 29 struct SkGlyph; |
29 struct SkRect; | 30 struct SkRect; |
30 class SkGlyphCache; | 31 class SkGlyphCache; |
31 class SkImageFilter; | 32 class SkImageFilter; |
32 class SkMaskFilter; | 33 class SkMaskFilter; |
33 class SkMatrix; | |
34 class SkPath; | 34 class SkPath; |
35 class SkPathEffect; | 35 class SkPathEffect; |
36 struct SkPoint; | 36 struct SkPoint; |
37 class SkRasterizer; | 37 class SkRasterizer; |
38 class SkShader; | 38 class SkShader; |
39 class SkTypeface; | 39 class SkTypeface; |
40 | 40 |
41 typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**, | 41 typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**, |
42 SkFixed x, SkFixed y); | 42 SkFixed x, SkFixed y); |
43 | 43 |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 const SkRect& computeFastStrokeBounds(const SkRect& orig, | 928 const SkRect& computeFastStrokeBounds(const SkRect& orig, |
929 SkRect* storage) const { | 929 SkRect* storage) const { |
930 return this->doComputeFastBounds(orig, storage, kStroke_Style); | 930 return this->doComputeFastBounds(orig, storage, kStroke_Style); |
931 } | 931 } |
932 | 932 |
933 // Take the style explicitly, so the caller can force us to be stroked | 933 // Take the style explicitly, so the caller can force us to be stroked |
934 // without having to make a copy of the paint just to change that field. | 934 // without having to make a copy of the paint just to change that field. |
935 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage, | 935 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage, |
936 Style) const; | 936 Style) const; |
937 | 937 |
| 938 /** |
| 939 * Return a matrix that applies the paint's text values: size, scale, skew |
| 940 */ |
| 941 static SkMatrix* SetTextMatrix(SkMatrix* matrix, SkScalar size, |
| 942 SkScalar scaleX, SkScalar skewX) { |
| 943 matrix->setScale(size * scaleX, size); |
| 944 if (skewX) { |
| 945 matrix->postSkew(skewX, 0); |
| 946 } |
| 947 return matrix; |
| 948 } |
| 949 |
| 950 SkMatrix* setTextMatrix(SkMatrix* matrix) const { |
| 951 return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX); |
| 952 } |
| 953 |
938 SkDEVCODE(void toString(SkString*) const;) | 954 SkDEVCODE(void toString(SkString*) const;) |
939 | 955 |
940 private: | 956 private: |
941 SkTypeface* fTypeface; | 957 SkTypeface* fTypeface; |
942 SkScalar fTextSize; | 958 SkScalar fTextSize; |
943 SkScalar fTextScaleX; | 959 SkScalar fTextScaleX; |
944 SkScalar fTextSkewX; | 960 SkScalar fTextSkewX; |
945 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR | 961 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR |
946 SkScalar fHintingScaleFactor; | 962 SkScalar fHintingScaleFactor; |
947 #endif | 963 #endif |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 | 998 |
983 SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const
SkMatrix*) const; | 999 SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const
SkMatrix*) const; |
984 | 1000 |
985 void descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatr
ix* deviceMatrix, | 1001 void descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatr
ix* deviceMatrix, |
986 void (*proc)(SkTypeface*, const SkDescriptor*, void*), | 1002 void (*proc)(SkTypeface*, const SkDescriptor*, void*), |
987 void* context, bool ignoreGamma = false) const; | 1003 void* context, bool ignoreGamma = false) const; |
988 | 1004 |
989 static void Term(); | 1005 static void Term(); |
990 | 1006 |
991 enum { | 1007 enum { |
992 kCanonicalTextSizeForPaths = 64 | 1008 /* This is the size we use when we ask for a glyph's path. We then |
| 1009 * post-transform it as we draw to match the request. |
| 1010 * This is done to try to re-use cache entries for the path. |
| 1011 * |
| 1012 * This value is somewhat arbitrary. In theory, it could be 1, since |
| 1013 * we store paths as floats. However, we get the path from the font |
| 1014 * scaler, and it may represent its paths as fixed-point (or 26.6), |
| 1015 * so we shouldn't ask for something too big (might overflow 16.16) |
| 1016 * or too small (underflow 26.6). |
| 1017 * |
| 1018 * This value could track kMaxSizeForGlyphCache, assuming the above |
| 1019 * constraints, but since we ask for unhinted paths, the two values |
| 1020 * need not match per-se. |
| 1021 */ |
| 1022 kCanonicalTextSizeForPaths = 64, |
| 1023 |
| 1024 /* |
| 1025 * Above this size (taking into account CTM and textSize), we never use |
| 1026 * the cache for bits or metrics (we might overflow), so we just ask |
| 1027 * for a caononical size and post-transform that. |
| 1028 */ |
| 1029 kMaxSizeForGlyphCache = 256, |
993 }; | 1030 }; |
| 1031 |
| 1032 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM); |
| 1033 |
| 1034 bool tooBigToUseCache() const; |
| 1035 bool tooBigToUseCache(const SkMatrix& ctm) const; |
| 1036 |
| 1037 // Set flags/hinting/textSize up to use for drawing text as paths. |
| 1038 // Returns scale factor to restore the original textSize, since will will |
| 1039 // have change it to kCanonicalTextSizeForPaths. |
| 1040 SkScalar setupForAsPaths(); |
| 1041 |
| 1042 static SkScalar MaxCacheSize2() { |
| 1043 static const SkScalar kMaxSize = SkIntToScalar(kMaxSizeForGlyphCache); |
| 1044 static const SkScalar kMag2Max = kMaxSize * kMaxSize; |
| 1045 return kMag2Max; |
| 1046 } |
| 1047 |
994 friend class SkAutoGlyphCache; | 1048 friend class SkAutoGlyphCache; |
995 friend class SkCanvas; | 1049 friend class SkCanvas; |
996 friend class SkDraw; | 1050 friend class SkDraw; |
997 friend class SkGraphics; // So Term() can be called. | 1051 friend class SkGraphics; // So Term() can be called. |
998 friend class SkPDFDevice; | 1052 friend class SkPDFDevice; |
999 friend class SkTextToPathIter; | 1053 friend class SkTextToPathIter; |
| 1054 friend class SkCanonicalizePaint; |
1000 | 1055 |
1001 #ifdef SK_BUILD_FOR_ANDROID | 1056 #ifdef SK_BUILD_FOR_ANDROID |
1002 SkPaintOptionsAndroid fPaintOptionsAndroid; | 1057 SkPaintOptionsAndroid fPaintOptionsAndroid; |
1003 | 1058 |
1004 // In order for the == operator to work properly this must be the last field | 1059 // In order for the == operator to work properly this must be the last field |
1005 // in the struct so that we can do a memcmp to this field's offset. | 1060 // in the struct so that we can do a memcmp to this field's offset. |
1006 uint32_t fGenerationID; | 1061 uint32_t fGenerationID; |
1007 #endif | 1062 #endif |
1008 }; | 1063 }; |
1009 | 1064 |
1010 #endif | 1065 #endif |
OLD | NEW |