reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkScalerContext_DEFINED |
| 9 | #define SkScalerContext_DEFINED |
| 10 | |
| 11 | #include "SkMask.h" |
bungeman@google.com | 97efada | 2012-07-30 20:40:50 +0000 | [diff] [blame] | 12 | #include "SkMaskGamma.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkMatrix.h" |
| 14 | #include "SkPaint.h" |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 15 | #include "SkTypeface.h" |
bungeman@google.com | 6e502fe | 2012-07-24 21:18:54 +0000 | [diff] [blame] | 16 | |
herb | b69d0e0 | 2015-02-25 06:47:06 -0800 | [diff] [blame] | 17 | class SkGlyph; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | class SkDescriptor; |
| 19 | class SkMaskFilter; |
| 20 | class SkPathEffect; |
| 21 | class SkRasterizer; |
| 22 | |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 23 | struct SkScalerContextEffects { |
| 24 | SkScalerContextEffects() : fPathEffect(nullptr), fMaskFilter(nullptr), fRasterizer(nullptr) {} |
| 25 | SkScalerContextEffects(SkPathEffect* pe, SkMaskFilter* mf, SkRasterizer* ra) |
| 26 | : fPathEffect(pe), fMaskFilter(mf), fRasterizer(ra) {} |
| 27 | |
| 28 | SkPathEffect* fPathEffect; |
| 29 | SkMaskFilter* fMaskFilter; |
| 30 | SkRasterizer* fRasterizer; |
| 31 | }; |
| 32 | |
bungeman | 27876bc | 2016-02-29 11:22:55 -0800 | [diff] [blame] | 33 | enum SkAxisAlignment { |
| 34 | kNone_SkAxisAlignment, |
| 35 | kX_SkAxisAlignment, |
| 36 | kY_SkAxisAlignment |
| 37 | }; |
| 38 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 39 | /* |
| 40 | * To allow this to be forward-declared, it must be its own typename, rather |
| 41 | * than a nested struct inside SkScalerContext (where it started). |
| 42 | */ |
| 43 | struct SkScalerContextRec { |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 44 | uint32_t fFontID; |
| 45 | SkScalar fTextSize, fPreScaleX, fPreSkewX; |
| 46 | SkScalar fPost2x2[2][2]; |
| 47 | SkScalar fFrameWidth, fMiterLimit; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 48 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 49 | //These describe the parameters to create (uniquely identify) the pre-blend. |
| 50 | uint32_t fLumBits; |
| 51 | uint8_t fDeviceGamma; //2.6, (0.0, 4.0) gamma, 0.0 for sRGB |
| 52 | uint8_t fPaintGamma; //2.6, (0.0, 4.0) gamma, 0.0 for sRGB |
| 53 | uint8_t fContrast; //0.8+1, [0.0, 1.0] artificial contrast |
| 54 | uint8_t fReservedAlign; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 55 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 56 | SkScalar getDeviceGamma() const { |
| 57 | return SkIntToScalar(fDeviceGamma) / (1 << 6); |
| 58 | } |
| 59 | void setDeviceGamma(SkScalar dg) { |
| 60 | SkASSERT(0 <= dg && dg < SkIntToScalar(4)); |
| 61 | fDeviceGamma = SkScalarFloorToInt(dg * (1 << 6)); |
| 62 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 63 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 64 | SkScalar getPaintGamma() const { |
| 65 | return SkIntToScalar(fPaintGamma) / (1 << 6); |
| 66 | } |
| 67 | void setPaintGamma(SkScalar pg) { |
| 68 | SkASSERT(0 <= pg && pg < SkIntToScalar(4)); |
| 69 | fPaintGamma = SkScalarFloorToInt(pg * (1 << 6)); |
| 70 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 71 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 72 | SkScalar getContrast() const { |
| 73 | return SkIntToScalar(fContrast) / ((1 << 8) - 1); |
| 74 | } |
| 75 | void setContrast(SkScalar c) { |
| 76 | SkASSERT(0 <= c && c <= SK_Scalar1); |
| 77 | fContrast = SkScalarRoundToInt(c * ((1 << 8) - 1)); |
| 78 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 79 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 80 | /** |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 81 | * Causes the luminance color to be ignored, and the paint and device |
| 82 | * gamma to be effectively 1.0 |
| 83 | */ |
| 84 | void ignoreGamma() { |
| 85 | setLuminanceColor(SK_ColorTRANSPARENT); |
| 86 | setPaintGamma(SK_Scalar1); |
| 87 | setDeviceGamma(SK_Scalar1); |
| 88 | } |
| 89 | |
| 90 | /** |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 91 | * Causes the luminance color and contrast to be ignored, and the |
| 92 | * paint and device gamma to be effectively 1.0. |
| 93 | */ |
| 94 | void ignorePreBlend() { |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 95 | ignoreGamma(); |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 96 | setContrast(0); |
| 97 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 98 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 99 | uint8_t fMaskFormat; |
caryclark | d7ea92f | 2016-03-16 07:34:02 -0700 | [diff] [blame] | 100 | uint8_t fStrokeJoin : 4; |
| 101 | uint8_t fStrokeCap : 4; |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 102 | uint16_t fFlags; |
| 103 | // Warning: when adding members note that the size of this structure |
| 104 | // must be a multiple of 4. SkDescriptor requires that its arguments be |
| 105 | // multiples of four and this structure is put in an SkDescriptor in |
| 106 | // SkPaint::MakeRec. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 107 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 108 | void getMatrixFrom2x2(SkMatrix*) const; |
| 109 | void getLocalMatrix(SkMatrix*) const; |
| 110 | void getSingleMatrix(SkMatrix*) const; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 111 | |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 112 | /** The kind of scale which will be applied by the underlying port (pre-matrix). */ |
| 113 | enum PreMatrixScale { |
| 114 | kFull_PreMatrixScale, // The underlying port can apply both x and y scale. |
| 115 | kVertical_PreMatrixScale, // The underlying port can only apply a y scale. |
| 116 | kVerticalInteger_PreMatrixScale // The underlying port can only apply an integer y scale. |
| 117 | }; |
| 118 | /** |
| 119 | * Compute useful matrices for use with sizing in underlying libraries. |
| 120 | * |
| 121 | * There are two kinds of text size, a 'requested/logical size' which is like asking for size |
| 122 | * '12' and a 'real' size which is the size after the matrix is applied. The matrices produced |
| 123 | * by this method are based on the 'real' size. This method effectively finds the total device |
| 124 | * matrix and decomposes it in various ways. |
| 125 | * |
| 126 | * The most useful decomposition is into 'scale' and 'remaining'. The 'scale' is applied first |
| 127 | * and then the 'remaining' to fully apply the total matrix. This decomposition is useful when |
| 128 | * the text size ('scale') may have meaning apart from the total matrix. This is true when |
| 129 | * hinting, and sometimes true for other properties as well. |
| 130 | * |
| 131 | * The second (optional) decomposition is of 'remaining' into a non-rotational part |
| 132 | * 'remainingWithoutRotation' and a rotational part 'remainingRotation'. The 'scale' is applied |
| 133 | * first, then 'remainingWithoutRotation', then 'remainingRotation' to fully apply the total |
| 134 | * matrix. This decomposition is helpful when only horizontal metrics can be trusted, so the |
| 135 | * 'scale' and 'remainingWithoutRotation' will be handled by the underlying library, but |
| 136 | * the final rotation 'remainingRotation' will be handled manually. |
| 137 | * |
| 138 | * The 'total' matrix is also (optionally) available. This is useful in cases where the |
| 139 | * underlying library will not be used, often when working directly with font data. |
| 140 | * |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 141 | * The parameters 'scale' and 'remaining' are required, the other pointers may be nullptr. |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 142 | * |
| 143 | * @param preMatrixScale the kind of scale to extract from the total matrix. |
| 144 | * @param scale the scale extracted from the total matrix (both values positive). |
| 145 | * @param remaining apply after scale to apply the total matrix. |
| 146 | * @param remainingWithoutRotation apply after scale to apply the total matrix sans rotation. |
| 147 | * @param remainingRotation apply after remainingWithoutRotation to apply the total matrix. |
| 148 | * @param total the total matrix. |
bungeman | e55131c | 2016-08-24 12:01:31 -0700 | [diff] [blame] | 149 | * @return false if the matrix was singular. The output will be valid but not invertible. |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 150 | */ |
bungeman | 1f0e78d | 2016-08-23 13:19:01 -0700 | [diff] [blame] | 151 | bool computeMatrices(PreMatrixScale preMatrixScale, |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 152 | SkVector* scale, SkMatrix* remaining, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 153 | SkMatrix* remainingWithoutRotation = nullptr, |
| 154 | SkMatrix* remainingRotation = nullptr, |
| 155 | SkMatrix* total = nullptr); |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 156 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 157 | inline SkPaint::Hinting getHinting() const; |
| 158 | inline void setHinting(SkPaint::Hinting); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 159 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 160 | SkMask::Format getFormat() const { |
| 161 | return static_cast<SkMask::Format>(fMaskFormat); |
| 162 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 163 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 164 | SkColor getLuminanceColor() const { |
| 165 | return fLumBits; |
| 166 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 167 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 168 | void setLuminanceColor(SkColor c) { |
| 169 | fLumBits = c; |
| 170 | } |
| 171 | }; |
| 172 | |
bungeman@google.com | 97efada | 2012-07-30 20:40:50 +0000 | [diff] [blame] | 173 | //The following typedef hides from the rest of the implementation the number of |
| 174 | //most significant bits to consider when creating mask gamma tables. Two bits |
| 175 | //per channel was chosen as a balance between fidelity (more bits) and cache |
bungeman@google.com | fd668cf | 2012-08-24 17:46:11 +0000 | [diff] [blame] | 176 | //sizes (fewer bits). Three bits per channel was chosen when #303942; (used by |
| 177 | //the Chrome UI) turned out too green. |
| 178 | typedef SkTMaskGamma<3, 3, 3> SkMaskGamma; |
bungeman@google.com | 97efada | 2012-07-30 20:40:50 +0000 | [diff] [blame] | 179 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 180 | class SkScalerContext { |
| 181 | public: |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 182 | typedef SkScalerContextRec Rec; |
| 183 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 184 | enum Flags { |
reed@google.com | b6bb5cb | 2011-11-21 19:32:29 +0000 | [diff] [blame] | 185 | kFrameAndFill_Flag = 0x0001, |
| 186 | kDevKernText_Flag = 0x0002, |
| 187 | kEmbeddedBitmapText_Flag = 0x0004, |
| 188 | kEmbolden_Flag = 0x0008, |
| 189 | kSubpixelPositioning_Flag = 0x0010, |
bungeman@google.com | f6f5687 | 2014-01-23 19:01:36 +0000 | [diff] [blame] | 190 | kForceAutohinting_Flag = 0x0020, // Use auto instead of bytcode hinting if hinting. |
reed@google.com | b6bb5cb | 2011-11-21 19:32:29 +0000 | [diff] [blame] | 191 | kVertical_Flag = 0x0040, |
reed@google.com | ffe49f5 | 2011-11-22 19:42:41 +0000 | [diff] [blame] | 192 | |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 193 | // together, these two flags resulting in a two bit value which matches |
| 194 | // up with the SkPaint::Hinting enum. |
reed@google.com | ffe49f5 | 2011-11-22 19:42:41 +0000 | [diff] [blame] | 195 | kHinting_Shift = 7, // to shift into the other flags above |
reed@google.com | b6bb5cb | 2011-11-21 19:32:29 +0000 | [diff] [blame] | 196 | kHintingBit1_Flag = 0x0080, |
| 197 | kHintingBit2_Flag = 0x0100, |
reed@google.com | ffe49f5 | 2011-11-22 19:42:41 +0000 | [diff] [blame] | 198 | |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 199 | // Pixel geometry information. |
reed | d54d3fc | 2014-11-13 14:39:58 -0800 | [diff] [blame] | 200 | // only meaningful if fMaskFormat is kLCD16 |
reed@google.com | b6bb5cb | 2011-11-21 19:32:29 +0000 | [diff] [blame] | 201 | kLCD_Vertical_Flag = 0x0200, // else Horizontal |
| 202 | kLCD_BGROrder_Flag = 0x0400, // else RGB order |
reed@google.com | ffe49f5 | 2011-11-22 19:42:41 +0000 | [diff] [blame] | 203 | |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 204 | // Generate A8 from LCD source (for GDI and CoreGraphics). |
| 205 | // only meaningful if fMaskFormat is kA8 |
| 206 | kGenA8FromLCD_Flag = 0x0800, // could be 0x200 (bit meaning dependent on fMaskFormat) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 207 | }; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 208 | |
reed@google.com | ffe49f5 | 2011-11-22 19:42:41 +0000 | [diff] [blame] | 209 | // computed values |
reed@android.com | e2ca207 | 2009-07-27 16:39:38 +0000 | [diff] [blame] | 210 | enum { |
reed@google.com | ffe49f5 | 2011-11-22 19:42:41 +0000 | [diff] [blame] | 211 | kHinting_Mask = kHintingBit1_Flag | kHintingBit2_Flag, |
reed@android.com | e2ca207 | 2009-07-27 16:39:38 +0000 | [diff] [blame] | 212 | }; |
reed@google.com | ffe49f5 | 2011-11-22 19:42:41 +0000 | [diff] [blame] | 213 | |
bungeman | 7cfd46a | 2016-10-20 16:06:52 -0400 | [diff] [blame] | 214 | SkScalerContext(sk_sp<SkTypeface>, const SkScalerContextEffects&, const SkDescriptor*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 215 | virtual ~SkScalerContext(); |
| 216 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 217 | SkTypeface* getTypeface() const { return fTypeface.get(); } |
| 218 | |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 219 | SkMask::Format getMaskFormat() const { |
| 220 | return (SkMask::Format)fRec.fMaskFormat; |
| 221 | } |
| 222 | |
reed@google.com | abf00aa | 2012-01-03 19:43:20 +0000 | [diff] [blame] | 223 | bool isSubpixel() const { |
| 224 | return SkToBool(fRec.fFlags & kSubpixelPositioning_Flag); |
| 225 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 226 | |
bungeman | 4107806 | 2014-07-07 08:16:37 -0700 | [diff] [blame] | 227 | bool isVertical() const { |
| 228 | return SkToBool(fRec.fFlags & kVertical_Flag); |
| 229 | } |
| 230 | |
reed@android.com | a14ea0e | 2009-03-17 17:59:53 +0000 | [diff] [blame] | 231 | /** Return the corresponding glyph for the specified unichar. Since contexts |
| 232 | may be chained (under the hood), the glyphID that is returned may in |
| 233 | fact correspond to a different font/context. In that case, we use the |
| 234 | base-glyph-count to know how to translate back into local glyph space. |
| 235 | */ |
djsollen | 1b27704 | 2014-08-06 06:58:06 -0700 | [diff] [blame] | 236 | uint16_t charToGlyphID(SkUnichar uni) { |
| 237 | return generateCharToGlyph(uni); |
| 238 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 239 | |
reed@android.com | 9d3a985 | 2010-01-08 14:07:42 +0000 | [diff] [blame] | 240 | /** Map the glyphID to its glyph index, and then to its char code. Unmapped |
| 241 | glyphs return zero. |
| 242 | */ |
djsollen | 1b27704 | 2014-08-06 06:58:06 -0700 | [diff] [blame] | 243 | SkUnichar glyphIDToChar(uint16_t glyphID) { |
| 244 | return (glyphID < getGlyphCount()) ? generateGlyphToChar(glyphID) : 0; |
| 245 | } |
reed@android.com | 9d3a985 | 2010-01-08 14:07:42 +0000 | [diff] [blame] | 246 | |
ctguil@chromium.org | 0bc7bf5 | 2011-03-04 19:04:57 +0000 | [diff] [blame] | 247 | unsigned getGlyphCount() { return this->generateGlyphCount(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 248 | void getAdvance(SkGlyph*); |
| 249 | void getMetrics(SkGlyph*); |
| 250 | void getImage(const SkGlyph&); |
| 251 | void getPath(const SkGlyph&, SkPath*); |
reed@google.com | 0a01f5a | 2013-05-08 14:19:08 +0000 | [diff] [blame] | 252 | void getFontMetrics(SkPaint::FontMetrics*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 253 | |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 254 | /** Return the size in bytes of the associated gamma lookup table |
| 255 | */ |
| 256 | static size_t GetGammaLUTSize(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma, |
| 257 | int* width, int* height); |
| 258 | |
| 259 | /** Get the associated gamma lookup table. The 'data' pointer must point to pre-allocated |
| 260 | memory, with size in bytes greater than or equal to the return value of getGammaLUTSize(). |
| 261 | */ |
| 262 | static void GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma, |
| 263 | void* data); |
| 264 | |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 265 | static void MakeRec(const SkPaint&, const SkSurfaceProps* surfaceProps, |
commit-bot@chromium.org | eefd8a0 | 2014-04-08 20:14:32 +0000 | [diff] [blame] | 266 | const SkMatrix*, Rec* rec); |
bungeman@google.com | 97efada | 2012-07-30 20:40:50 +0000 | [diff] [blame] | 267 | static inline void PostMakeRec(const SkPaint&, Rec*); |
reed@google.com | 10d2d4d | 2012-03-01 22:32:51 +0000 | [diff] [blame] | 268 | |
bungeman@google.com | 97efada | 2012-07-30 20:40:50 +0000 | [diff] [blame] | 269 | static SkMaskGamma::PreBlend GetMaskPreBlend(const Rec& rec); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 270 | |
reed | 40dab98 | 2015-01-28 13:28:53 -0800 | [diff] [blame] | 271 | const Rec& getRec() const { return fRec; } |
| 272 | |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 273 | SkScalerContextEffects getEffects() const { |
| 274 | return { fPathEffect.get(), fMaskFilter.get(), fRasterizer.get() }; |
| 275 | } |
| 276 | |
bungeman | 27876bc | 2016-02-29 11:22:55 -0800 | [diff] [blame] | 277 | /** |
| 278 | * Return the axis (if any) that the baseline for horizontal text should land on. |
| 279 | * As an example, the identity matrix will return kX_SkAxisAlignment |
| 280 | */ |
| 281 | SkAxisAlignment computeAxisAlignmentForHText(); |
| 282 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 283 | protected: |
| 284 | Rec fRec; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 285 | |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 286 | /** Generates the contents of glyph.fAdvanceX and glyph.fAdvanceY. |
| 287 | * May call getMetrics if that would be just as fast. |
| 288 | */ |
| 289 | virtual void generateAdvance(SkGlyph* glyph) = 0; |
| 290 | |
| 291 | /** Generates the contents of glyph.fWidth, fHeight, fTop, fLeft, |
| 292 | * as well as fAdvanceX and fAdvanceY if not already set. |
| 293 | * |
| 294 | * TODO: fMaskFormat is set by getMetrics later; cannot be set here. |
| 295 | */ |
| 296 | virtual void generateMetrics(SkGlyph* glyph) = 0; |
| 297 | |
| 298 | /** Generates the contents of glyph.fImage. |
| 299 | * When called, glyph.fImage will be pointing to a pre-allocated, |
| 300 | * uninitialized region of memory of size glyph.computeImageSize(). |
| 301 | * This method may change glyph.fMaskFormat if the new image size is |
| 302 | * less than or equal to the old image size. |
| 303 | * |
| 304 | * Because glyph.computeImageSize() will determine the size of fImage, |
| 305 | * generateMetrics will be called before generateImage. |
| 306 | */ |
| 307 | virtual void generateImage(const SkGlyph& glyph) = 0; |
| 308 | |
| 309 | /** Sets the passed path to the glyph outline. |
| 310 | * If this cannot be done the path is set to empty; |
| 311 | * this is indistinguishable from a glyph with an empty path. |
| 312 | * This does not set glyph.fPath. |
| 313 | * |
| 314 | * TODO: path is always glyph.fPath, no reason to pass separately. |
| 315 | */ |
| 316 | virtual void generatePath(const SkGlyph& glyph, SkPath* path) = 0; |
| 317 | |
bungeman | 4107806 | 2014-07-07 08:16:37 -0700 | [diff] [blame] | 318 | /** Retrieves font metrics. */ |
| 319 | virtual void generateFontMetrics(SkPaint::FontMetrics*) = 0; |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 320 | |
| 321 | /** Returns the number of glyphs in the font. */ |
| 322 | virtual unsigned generateGlyphCount() = 0; |
| 323 | |
| 324 | /** Returns the glyph id for the given unichar. |
| 325 | * If there is no 1:1 mapping from the unichar to a glyph id, returns 0. |
| 326 | */ |
| 327 | virtual uint16_t generateCharToGlyph(SkUnichar unichar) = 0; |
| 328 | |
| 329 | /** Returns the unichar for the given glyph id. |
| 330 | * If there is no 1:1 mapping from the glyph id to a unichar, returns 0. |
| 331 | * The default implementation always returns 0, indicating failure. |
| 332 | */ |
| 333 | virtual SkUnichar generateGlyphToChar(uint16_t glyphId); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 334 | |
reed@google.com | a767fa0 | 2011-08-05 21:40:26 +0000 | [diff] [blame] | 335 | void forceGenerateImageFromPath() { fGenerateImageFromPath = true; } |
joshualitt | aa2f658 | 2015-07-29 10:14:58 -0700 | [diff] [blame] | 336 | void forceOffGenerateImageFromPath() { fGenerateImageFromPath = false; } |
reed@google.com | a767fa0 | 2011-08-05 21:40:26 +0000 | [diff] [blame] | 337 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 338 | private: |
joshualitt | 65e96b4 | 2015-07-31 11:45:22 -0700 | [diff] [blame] | 339 | friend class SkRandomScalerContext; // For debug purposes |
| 340 | |
reed@google.com | 0da4861 | 2013-03-19 16:06:52 +0000 | [diff] [blame] | 341 | // never null |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 342 | sk_sp<SkTypeface> fTypeface; |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 343 | |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 344 | // optional objects, which may be null |
| 345 | sk_sp<SkPathEffect> fPathEffect; |
| 346 | sk_sp<SkMaskFilter> fMaskFilter; |
| 347 | sk_sp<SkRasterizer> fRasterizer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 348 | |
reed@google.com | a767fa0 | 2011-08-05 21:40:26 +0000 | [diff] [blame] | 349 | // if this is set, we draw the image from a path, rather than |
| 350 | // calling generateImage. |
| 351 | bool fGenerateImageFromPath; |
| 352 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 353 | void internalGetPath(const SkGlyph& glyph, SkPath* fillPath, |
| 354 | SkPath* devPath, SkMatrix* fillToDevMatrix); |
| 355 | |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 356 | // SkMaskGamma::PreBlend converts linear masks to gamma correcting masks. |
| 357 | protected: |
| 358 | // Visible to subclasses so that generateImage can apply the pre-blend directly. |
| 359 | const SkMaskGamma::PreBlend fPreBlend; |
| 360 | private: |
| 361 | // When there is a filter, previous steps must create a linear mask |
| 362 | // and the pre-blend applied as a final step. |
| 363 | const SkMaskGamma::PreBlend fPreBlendForFilter; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 364 | }; |
| 365 | |
| 366 | #define kRec_SkDescriptorTag SkSetFourByteTag('s', 'r', 'e', 'c') |
| 367 | #define kPathEffect_SkDescriptorTag SkSetFourByteTag('p', 't', 'h', 'e') |
| 368 | #define kMaskFilter_SkDescriptorTag SkSetFourByteTag('m', 's', 'k', 'f') |
| 369 | #define kRasterizer_SkDescriptorTag SkSetFourByteTag('r', 'a', 's', 't') |
| 370 | |
reed@google.com | cb6ccdd | 2011-08-23 21:30:47 +0000 | [diff] [blame] | 371 | /////////////////////////////////////////////////////////////////////////////// |
| 372 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 373 | SkPaint::Hinting SkScalerContextRec::getHinting() const { |
| 374 | unsigned hint = (fFlags & SkScalerContext::kHinting_Mask) >> |
| 375 | SkScalerContext::kHinting_Shift; |
| 376 | return static_cast<SkPaint::Hinting>(hint); |
| 377 | } |
| 378 | |
| 379 | void SkScalerContextRec::setHinting(SkPaint::Hinting hinting) { |
| 380 | fFlags = (fFlags & ~SkScalerContext::kHinting_Mask) | |
| 381 | (hinting << SkScalerContext::kHinting_Shift); |
| 382 | } |
| 383 | |
| 384 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 385 | #endif |