blob: 11208fec599bad1ca0dfeef7f3bab9c23f00dc96 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
10#include "SkScalerContext.h"
agl@chromium.org309485b2009-07-21 17:41:32 +000011#include "SkColorPriv.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkDescriptor.h"
13#include "SkDraw.h"
14#include "SkFontHost.h"
bungeman@google.combbe50132012-07-24 20:33:21 +000015#include "SkGlyph.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000016#include "SkMaskFilter.h"
bungeman@google.com97efada2012-07-30 20:40:50 +000017#include "SkMaskGamma.h"
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000018#include "SkReadBuffer.h"
19#include "SkWriteBuffer.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000020#include "SkPathEffect.h"
21#include "SkRasterizer.h"
reed@google.com045e62d2011-10-24 12:19:46 +000022#include "SkRasterClip.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023#include "SkStroke.h"
24#include "SkThread.h"
25
Derek Sollenbergerda7a9442014-08-06 16:34:40 -040026#ifdef SK_BUILD_FOR_ANDROID
27 #include "SkTypeface_android.h"
28#endif
29
reed@android.com8a1c16f2008-12-17 15:59:43 +000030#define ComputeBWRowBytes(width) (((unsigned)(width) + 7) >> 3)
31
reed@android.com8a1c16f2008-12-17 15:59:43 +000032void SkGlyph::toMask(SkMask* mask) const {
33 SkASSERT(mask);
34
35 mask->fImage = (uint8_t*)fImage;
36 mask->fBounds.set(fLeft, fTop, fLeft + fWidth, fTop + fHeight);
37 mask->fRowBytes = this->rowBytes();
reed@android.com6c14b432009-03-23 20:11:11 +000038 mask->fFormat = static_cast<SkMask::Format>(fMaskFormat);
reed@android.com8a1c16f2008-12-17 15:59:43 +000039}
40
41size_t SkGlyph::computeImageSize() const {
agl@chromium.org309485b2009-07-21 17:41:32 +000042 const size_t size = this->rowBytes() * fHeight;
43
44 switch (fMaskFormat) {
reed@google.com7db9fe62011-04-11 11:57:54 +000045 case SkMask::k3D_Format:
46 return 3 * size;
47 default:
48 return size;
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000050}
51
reed@android.com62900b42009-02-11 15:07:19 +000052void SkGlyph::zeroMetrics() {
53 fAdvanceX = 0;
54 fAdvanceY = 0;
55 fWidth = 0;
56 fHeight = 0;
57 fTop = 0;
58 fLeft = 0;
59 fRsbDelta = 0;
60 fLsbDelta = 0;
61}
62
63///////////////////////////////////////////////////////////////////////////////
64
reed@android.com8a1c16f2008-12-17 15:59:43 +000065#ifdef SK_DEBUG
66 #define DUMP_RECx
67#endif
68
reed@google.com35348222013-10-16 13:05:06 +000069static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag,
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +000070 SkFlattenable::Type ft) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 SkFlattenable* obj = NULL;
72 uint32_t len;
73 const void* data = desc->findEntry(tag, &len);
skia.committer@gmail.com583b18a2013-10-24 07:01:59 +000074
reed@android.com8a1c16f2008-12-17 15:59:43 +000075 if (data) {
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000076 SkReadBuffer buffer(data, len);
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +000077 obj = buffer.readFlattenable(ft);
reed@android.com8a1c16f2008-12-17 15:59:43 +000078 SkASSERT(buffer.offset() == buffer.size());
79 }
80 return obj;
81}
82
reed@google.com0da48612013-03-19 16:06:52 +000083SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
bungeman@google.com97efada2012-07-30 20:40:50 +000084 : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, NULL)))
bungeman@google.coma76de722012-10-26 19:35:54 +000085
reed@google.com0da48612013-03-19 16:06:52 +000086 , fTypeface(SkRef(typeface))
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +000087 , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag,
88 SkFlattenable::kSkPathEffect_Type)))
89 , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_SkDescriptorTag,
90 SkFlattenable::kSkMaskFilter_Type)))
91 , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_SkDescriptorTag,
92 SkFlattenable::kSkRasterizer_Type)))
bungeman@google.coma76de722012-10-26 19:35:54 +000093 // Initialize based on our settings. Subclasses can also force this.
bungeman@google.com97efada2012-07-30 20:40:50 +000094 , fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != NULL || fRasterizer != NULL)
bungeman@google.coma76de722012-10-26 19:35:54 +000095
bungeman@google.coma76de722012-10-26 19:35:54 +000096 , fPreBlend(fMaskFilter ? SkMaskGamma::PreBlend() : SkScalerContext::GetMaskPreBlend(fRec))
97 , fPreBlendForFilter(fMaskFilter ? SkScalerContext::GetMaskPreBlend(fRec)
98 : SkMaskGamma::PreBlend())
reed@android.com8a1c16f2008-12-17 15:59:43 +000099{
reed@android.com8a1c16f2008-12-17 15:59:43 +0000100#ifdef DUMP_REC
101 desc->assertChecksum();
commit-bot@chromium.org34abef12014-02-17 15:28:55 +0000102 SkDebugf("SkScalerContext checksum %x count %d length %d\n",
reed@google.com7db9fe62011-04-11 11:57:54 +0000103 desc->getChecksum(), desc->getCount(), desc->getLength());
reed@android.com8a1c16f2008-12-17 15:59:43 +0000104 SkDebugf(" textsize %g prescale %g preskew %g post [%g %g %g %g]\n",
105 rec->fTextSize, rec->fPreScaleX, rec->fPreSkewX, rec->fPost2x2[0][0],
106 rec->fPost2x2[0][1], rec->fPost2x2[1][0], rec->fPost2x2[1][1]);
107 SkDebugf(" frame %g miter %g hints %d framefill %d format %d join %d\n",
108 rec->fFrameWidth, rec->fMiterLimit, rec->fHints, rec->fFrameAndFill,
109 rec->fMaskFormat, rec->fStrokeJoin);
reed@google.com7db9fe62011-04-11 11:57:54 +0000110 SkDebugf(" pathEffect %x maskFilter %x\n",
111 desc->findEntry(kPathEffect_SkDescriptorTag, NULL),
reed@android.com8a1c16f2008-12-17 15:59:43 +0000112 desc->findEntry(kMaskFilter_SkDescriptorTag, NULL));
113#endif
Derek Sollenbergerda7a9442014-08-06 16:34:40 -0400114#ifdef SK_BUILD_FOR_ANDROID
115 uint32_t len;
116 const void* data = desc->findEntry(kAndroidOpts_SkDescriptorTag, &len);
117 if (data) {
118 SkReadBuffer buffer(data, len);
119 fPaintOptionsAndroid.unflatten(buffer);
120 SkASSERT(buffer.offset() == buffer.size());
121 }
122#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000123}
124
125SkScalerContext::~SkScalerContext() {
reed@google.com82065d62011-02-07 15:30:46 +0000126 SkSafeUnref(fPathEffect);
127 SkSafeUnref(fMaskFilter);
128 SkSafeUnref(fRasterizer);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000129}
130
reed@android.com8a1c16f2008-12-17 15:59:43 +0000131void SkScalerContext::getAdvance(SkGlyph* glyph) {
132 // mark us as just having a valid advance
133 glyph->fMaskFormat = MASK_FORMAT_JUST_ADVANCE;
134 // we mark the format before making the call, in case the impl
135 // internally ends up calling its generateMetrics, which is OK
136 // albeit slower than strictly necessary
djsollen1b277042014-08-06 06:58:06 -0700137 generateAdvance(glyph);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000138}
139
140void SkScalerContext::getMetrics(SkGlyph* glyph) {
djsollen1b277042014-08-06 06:58:06 -0700141 generateMetrics(glyph);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000142
143 // for now we have separate cache entries for devkerning on and off
144 // in the future we might share caches, but make our measure/draw
145 // code make the distinction. Thus we zap the values if the caller
146 // has not asked for them.
147 if ((fRec.fFlags & SkScalerContext::kDevKernText_Flag) == 0) {
148 // no devkern, so zap the fields
149 glyph->fLsbDelta = glyph->fRsbDelta = 0;
150 }
151
152 // if either dimension is empty, zap the image bounds of the glyph
153 if (0 == glyph->fWidth || 0 == glyph->fHeight) {
154 glyph->fWidth = 0;
155 glyph->fHeight = 0;
156 glyph->fTop = 0;
157 glyph->fLeft = 0;
158 glyph->fMaskFormat = 0;
159 return;
160 }
reed@google.com82065d62011-02-07 15:30:46 +0000161
reed@google.coma767fa02011-08-05 21:40:26 +0000162 if (fGenerateImageFromPath) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000163 SkPath devPath, fillPath;
164 SkMatrix fillToDevMatrix;
165
166 this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix);
167
168 if (fRasterizer) {
169 SkMask mask;
170
171 if (fRasterizer->rasterize(fillPath, fillToDevMatrix, NULL,
172 fMaskFilter, &mask,
173 SkMask::kJustComputeBounds_CreateMode)) {
174 glyph->fLeft = mask.fBounds.fLeft;
175 glyph->fTop = mask.fBounds.fTop;
176 glyph->fWidth = SkToU16(mask.fBounds.width());
177 glyph->fHeight = SkToU16(mask.fBounds.height());
178 } else {
senorblanco@chromium.org7767cd82009-11-25 17:14:32 +0000179 goto SK_ERROR;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000180 }
181 } else {
182 // just use devPath
reed@android.com8a1c16f2008-12-17 15:59:43 +0000183 SkIRect ir;
reed@android.comd252db02009-04-01 18:31:44 +0000184 devPath.getBounds().roundOut(&ir);
reed@google.com82065d62011-02-07 15:30:46 +0000185
reed@android.comb757f8d2009-12-08 22:02:26 +0000186 if (ir.isEmpty() || !ir.is16Bit()) {
senorblanco@chromium.org7767cd82009-11-25 17:14:32 +0000187 goto SK_ERROR;
reed@android.comd4577752009-11-21 02:48:11 +0000188 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000189 glyph->fLeft = ir.fLeft;
190 glyph->fTop = ir.fTop;
191 glyph->fWidth = SkToU16(ir.width());
192 glyph->fHeight = SkToU16(ir.height());
bungeman@google.com0abbff92013-07-27 20:37:56 +0000193
194 if (glyph->fWidth > 0) {
rmistry@google.comd6bab022013-12-02 13:50:38 +0000195 switch (fRec.fMaskFormat) {
196 case SkMask::kLCD16_Format:
197 case SkMask::kLCD32_Format:
198 glyph->fWidth += 2;
199 glyph->fLeft -= 1;
200 break;
201 default:
202 break;
203 }
bungeman@google.com0abbff92013-07-27 20:37:56 +0000204 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000205 }
206 }
207
robertphillips@google.coma22e2112012-08-16 14:58:06 +0000208 if (SkMask::kARGB32_Format != glyph->fMaskFormat) {
209 glyph->fMaskFormat = fRec.fMaskFormat;
210 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000211
reed@google.com5bdfb332013-05-02 18:55:44 +0000212 // If we are going to create the mask, then we cannot keep the color
213 if ((fGenerateImageFromPath || fMaskFilter) &&
214 SkMask::kARGB32_Format == glyph->fMaskFormat) {
215 glyph->fMaskFormat = SkMask::kA8_Format;
216 }
217
reed@android.com8a1c16f2008-12-17 15:59:43 +0000218 if (fMaskFilter) {
219 SkMask src, dst;
220 SkMatrix matrix;
221
222 glyph->toMask(&src);
223 fRec.getMatrixFrom2x2(&matrix);
224
225 src.fImage = NULL; // only want the bounds from the filter
226 if (fMaskFilter->filterMask(&dst, src, matrix, NULL)) {
reed@google.com8136d582012-09-21 17:38:06 +0000227 if (dst.fBounds.isEmpty() || !dst.fBounds.is16Bit()) {
228 goto SK_ERROR;
229 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000230 SkASSERT(dst.fImage == NULL);
231 glyph->fLeft = dst.fBounds.fLeft;
232 glyph->fTop = dst.fBounds.fTop;
233 glyph->fWidth = SkToU16(dst.fBounds.width());
234 glyph->fHeight = SkToU16(dst.fBounds.height());
235 glyph->fMaskFormat = dst.fFormat;
236 }
237 }
reed@android.comd4577752009-11-21 02:48:11 +0000238 return;
reed@google.com82065d62011-02-07 15:30:46 +0000239
senorblanco@chromium.org7767cd82009-11-25 17:14:32 +0000240SK_ERROR:
reed@android.comd4577752009-11-21 02:48:11 +0000241 // draw nothing 'cause we failed
242 glyph->fLeft = 0;
243 glyph->fTop = 0;
244 glyph->fWidth = 0;
245 glyph->fHeight = 0;
reed@android.comb757f8d2009-12-08 22:02:26 +0000246 // put a valid value here, in case it was earlier set to
247 // MASK_FORMAT_JUST_ADVANCE
248 glyph->fMaskFormat = fRec.fMaskFormat;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000249}
250
bungeman@google.com0abbff92013-07-27 20:37:56 +0000251#define SK_SHOW_TEXT_BLIT_COVERAGE 0
bungeman@google.coma76de722012-10-26 19:35:54 +0000252
253static void applyLUTToA8Mask(const SkMask& mask, const uint8_t* lut) {
254 uint8_t* SK_RESTRICT dst = (uint8_t*)mask.fImage;
255 unsigned rowBytes = mask.fRowBytes;
256
257 for (int y = mask.fBounds.height() - 1; y >= 0; --y) {
258 for (int x = mask.fBounds.width() - 1; x >= 0; --x) {
259 dst[x] = lut[dst[x]];
260 }
261 dst += rowBytes;
262 }
263}
264
bungeman@google.com97efada2012-07-30 20:40:50 +0000265template<bool APPLY_PREBLEND>
bungeman@google.com0abbff92013-07-27 20:37:56 +0000266static void pack4xHToLCD16(const SkBitmap& src, const SkMask& dst,
bungeman@google.coma76de722012-10-26 19:35:54 +0000267 const SkMaskGamma::PreBlend& maskPreBlend) {
bungeman@google.com0abbff92013-07-27 20:37:56 +0000268#define SAMPLES_PER_PIXEL 4
269#define LCD_PER_PIXEL 3
reed@google.com900ecf22014-02-20 20:55:37 +0000270 SkASSERT(kAlpha_8_SkColorType == src.colorType());
reed@google.comcf598b12011-08-22 21:13:23 +0000271 SkASSERT(SkMask::kLCD16_Format == dst.fFormat);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000272
bungeman@google.com0abbff92013-07-27 20:37:56 +0000273 const int sample_width = src.width();
274 const int height = src.height();
275
reed@google.comcf598b12011-08-22 21:13:23 +0000276 uint16_t* dstP = (uint16_t*)dst.fImage;
277 size_t dstRB = dst.fRowBytes;
bungeman@google.com0abbff92013-07-27 20:37:56 +0000278 // An N tap FIR is defined by
279 // out[n] = coeff[0]*x[n] + coeff[1]*x[n-1] + ... + coeff[N]*x[n-N]
280 // or
281 // out[n] = sum(i, 0, N, coeff[i]*x[n-i])
282
283 // The strategy is to use one FIR (different coefficients) for each of r, g, and b.
284 // This means using every 4th FIR output value of each FIR and discarding the rest.
285 // The FIRs are aligned, and the coefficients reach 5 samples to each side of their 'center'.
286 // (For r and b this is technically incorrect, but the coeffs outside round to zero anyway.)
skia.committer@gmail.com27e21fe2013-07-28 07:01:03 +0000287
bungeman@google.com0abbff92013-07-27 20:37:56 +0000288 // These are in some fixed point repesentation.
289 // Adding up to more than one simulates ink spread.
290 // For implementation reasons, these should never add up to more than two.
291
292 // Coefficients determined by a gausian where 5 samples = 3 std deviations (0x110 'contrast').
293 // Calculated using tools/generate_fir_coeff.py
294 // With this one almost no fringing is ever seen, but it is imperceptibly blurry.
295 // The lcd smoothed text is almost imperceptibly different from gray,
296 // but is still sharper on small stems and small rounded corners than gray.
297 // This also seems to be about as wide as one can get and only have a three pixel kernel.
298 // TODO: caculate these at runtime so parameters can be adjusted (esp contrast).
299 static const unsigned int coefficients[LCD_PER_PIXEL][SAMPLES_PER_PIXEL*3] = {
300 //The red subpixel is centered inside the first sample (at 1/6 pixel), and is shifted.
301 { 0x03, 0x0b, 0x1c, 0x33, 0x40, 0x39, 0x24, 0x10, 0x05, 0x01, 0x00, 0x00, },
302 //The green subpixel is centered between two samples (at 1/2 pixel), so is symetric
303 { 0x00, 0x02, 0x08, 0x16, 0x2b, 0x3d, 0x3d, 0x2b, 0x16, 0x08, 0x02, 0x00, },
304 //The blue subpixel is centered inside the last sample (at 5/6 pixel), and is shifted.
305 { 0x00, 0x00, 0x01, 0x05, 0x10, 0x24, 0x39, 0x40, 0x33, 0x1c, 0x0b, 0x03, },
306 };
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000307
reed@google.comcf598b12011-08-22 21:13:23 +0000308 for (int y = 0; y < height; ++y) {
309 const uint8_t* srcP = src.getAddr8(0, y);
bungeman@google.com0abbff92013-07-27 20:37:56 +0000310
311 // TODO: this fir filter implementation is straight forward, but slow.
312 // It should be possible to make it much faster.
313 for (int sample_x = -4, pixel_x = 0; sample_x < sample_width + 4; sample_x += 4, ++pixel_x) {
314 int fir[LCD_PER_PIXEL] = { 0 };
315 for (int sample_index = SkMax32(0, sample_x - 4), coeff_index = sample_index - (sample_x - 4)
316 ; sample_index < SkMin32(sample_x + 8, sample_width)
317 ; ++sample_index, ++coeff_index)
318 {
319 int sample_value = srcP[sample_index];
320 for (int subpxl_index = 0; subpxl_index < LCD_PER_PIXEL; ++subpxl_index) {
321 fir[subpxl_index] += coefficients[subpxl_index][coeff_index] * sample_value;
322 }
323 }
324 for (int subpxl_index = 0; subpxl_index < LCD_PER_PIXEL; ++subpxl_index) {
325 fir[subpxl_index] /= 0x100;
326 fir[subpxl_index] = SkMin32(fir[subpxl_index], 255);
327 }
328
329 U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>(fir[0], maskPreBlend.fR);
330 U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>(fir[1], maskPreBlend.fG);
331 U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>(fir[2], maskPreBlend.fB);
332#if SK_SHOW_TEXT_BLIT_COVERAGE
333 r = SkMax32(r, 10); g = SkMax32(g, 10); b = SkMax32(b, 10);
334#endif
335 dstP[pixel_x] = SkPack888ToRGB16(r, g, b);
reed@google.coma767fa02011-08-05 21:40:26 +0000336 }
reed@google.comcf598b12011-08-22 21:13:23 +0000337 dstP = (uint16_t*)((char*)dstP + dstRB);
338 }
339}
340
bungeman@google.com97efada2012-07-30 20:40:50 +0000341template<bool APPLY_PREBLEND>
bungeman@google.com0abbff92013-07-27 20:37:56 +0000342static void pack4xHToLCD32(const SkBitmap& src, const SkMask& dst,
bungeman@google.coma76de722012-10-26 19:35:54 +0000343 const SkMaskGamma::PreBlend& maskPreBlend) {
reed@google.com900ecf22014-02-20 20:55:37 +0000344 SkASSERT(kAlpha_8_SkColorType == src.colorType());
reed@google.comcf598b12011-08-22 21:13:23 +0000345 SkASSERT(SkMask::kLCD32_Format == dst.fFormat);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000346
reed@google.comcf598b12011-08-22 21:13:23 +0000347 const int width = dst.fBounds.width();
348 const int height = dst.fBounds.height();
349 SkPMColor* dstP = (SkPMColor*)dst.fImage;
350 size_t dstRB = dst.fRowBytes;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000351
reed@google.comcf598b12011-08-22 21:13:23 +0000352 for (int y = 0; y < height; ++y) {
353 const uint8_t* srcP = src.getAddr8(0, y);
bungeman@google.com0abbff92013-07-27 20:37:56 +0000354
355 // TODO: need to use fir filter here as well.
reed@google.comcf598b12011-08-22 21:13:23 +0000356 for (int x = 0; x < width; ++x) {
bungeman@google.coma76de722012-10-26 19:35:54 +0000357 U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>(*srcP++, maskPreBlend.fR);
358 U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>(*srcP++, maskPreBlend.fG);
359 U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>(*srcP++, maskPreBlend.fB);
bungeman@google.com97efada2012-07-30 20:40:50 +0000360 dstP[x] = SkPackARGB32(0xFF, r, g, b);
reed@google.comcf598b12011-08-22 21:13:23 +0000361 }
reed@google.coma767fa02011-08-05 21:40:26 +0000362 dstP = (SkPMColor*)((char*)dstP + dstRB);
363 }
364}
365
rmistry@google.comd6bab022013-12-02 13:50:38 +0000366static inline int convert_8_to_1(unsigned byte) {
367 SkASSERT(byte <= 0xFF);
368 return byte >> 7;
369}
370
371static uint8_t pack_8_to_1(const uint8_t alpha[8]) {
372 unsigned bits = 0;
373 for (int i = 0; i < 8; ++i) {
374 bits <<= 1;
375 bits |= convert_8_to_1(alpha[i]);
376 }
377 return SkToU8(bits);
378}
379
380static void packA8ToA1(const SkMask& mask, const uint8_t* src, size_t srcRB) {
381 const int height = mask.fBounds.height();
382 const int width = mask.fBounds.width();
383 const int octs = width >> 3;
384 const int leftOverBits = width & 7;
385
386 uint8_t* dst = mask.fImage;
387 const int dstPad = mask.fRowBytes - SkAlign8(width)/8;
388 SkASSERT(dstPad >= 0);
389
commit-bot@chromium.orgf1177812014-04-23 19:19:44 +0000390 SkASSERT(width >= 0);
391 SkASSERT(srcRB >= (size_t)width);
392 const size_t srcPad = srcRB - width;
rmistry@google.comd6bab022013-12-02 13:50:38 +0000393
394 for (int y = 0; y < height; ++y) {
395 for (int i = 0; i < octs; ++i) {
396 *dst++ = pack_8_to_1(src);
397 src += 8;
398 }
399 if (leftOverBits > 0) {
400 unsigned bits = 0;
401 int shift = 7;
402 for (int i = 0; i < leftOverBits; ++i, --shift) {
robertphillips@google.comc932c9f2013-12-02 15:43:39 +0000403 bits |= convert_8_to_1(*src++) << shift;
rmistry@google.comd6bab022013-12-02 13:50:38 +0000404 }
405 *dst++ = bits;
406 }
407 src += srcPad;
408 dst += dstPad;
409 }
410}
411
bungeman@google.coma76de722012-10-26 19:35:54 +0000412static void generateMask(const SkMask& mask, const SkPath& path,
413 const SkMaskGamma::PreBlend& maskPreBlend) {
rmistry@google.comd6bab022013-12-02 13:50:38 +0000414 SkPaint paint;
reed@google.comcf598b12011-08-22 21:13:23 +0000415
416 int srcW = mask.fBounds.width();
417 int srcH = mask.fBounds.height();
418 int dstW = srcW;
419 int dstH = srcH;
420 int dstRB = mask.fRowBytes;
421
422 SkMatrix matrix;
423 matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft),
424 -SkIntToScalar(mask.fBounds.fTop));
425
rmistry@google.comd6bab022013-12-02 13:50:38 +0000426 paint.setAntiAlias(SkMask::kBW_Format != mask.fFormat);
427 switch (mask.fFormat) {
428 case SkMask::kBW_Format:
429 dstRB = 0; // signals we need a copy
430 break;
431 case SkMask::kA8_Format:
432 break;
433 case SkMask::kLCD16_Format:
434 case SkMask::kLCD32_Format:
435 // TODO: trigger off LCD orientation
436 dstW = 4*dstW - 8;
437 matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft + 1),
438 -SkIntToScalar(mask.fBounds.fTop));
439 matrix.postScale(SkIntToScalar(4), SK_Scalar1);
440 dstRB = 0; // signals we need a copy
441 break;
442 default:
443 SkDEBUGFAIL("unexpected mask format");
reed@google.comcf598b12011-08-22 21:13:23 +0000444 }
445
reed@google.com045e62d2011-10-24 12:19:46 +0000446 SkRasterClip clip;
447 clip.setRect(SkIRect::MakeWH(dstW, dstH));
reed@google.comcf598b12011-08-22 21:13:23 +0000448
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +0000449 const SkImageInfo info = SkImageInfo::MakeA8(dstW, dstH);
reed@google.comcf598b12011-08-22 21:13:23 +0000450 SkBitmap bm;
reed@google.comcf598b12011-08-22 21:13:23 +0000451
452 if (0 == dstRB) {
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +0000453 if (!bm.allocPixels(info)) {
reed@google.com9be57272012-12-17 14:21:38 +0000454 // can't allocate offscreen, so empty the mask and return
455 sk_bzero(mask.fImage, mask.computeImageSize());
456 return;
457 }
reed@google.comcf598b12011-08-22 21:13:23 +0000458 } else {
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +0000459 bm.installPixels(info, mask.fImage, dstRB);
reed@google.comcf598b12011-08-22 21:13:23 +0000460 }
461 sk_bzero(bm.getPixels(), bm.getSafeSize());
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000462
reed@google.comcf598b12011-08-22 21:13:23 +0000463 SkDraw draw;
reed@google.com045e62d2011-10-24 12:19:46 +0000464 draw.fRC = &clip;
465 draw.fClip = &clip.bwRgn();
reed@google.comcf598b12011-08-22 21:13:23 +0000466 draw.fMatrix = &matrix;
467 draw.fBitmap = &bm;
468 draw.drawPath(path, paint);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000469
bungeman@google.com0c5f3762012-10-26 20:48:54 +0000470 switch (mask.fFormat) {
rmistry@google.comd6bab022013-12-02 13:50:38 +0000471 case SkMask::kBW_Format:
472 packA8ToA1(mask, bm.getAddr8(0, 0), bm.rowBytes());
473 break;
bungeman@google.com0c5f3762012-10-26 20:48:54 +0000474 case SkMask::kA8_Format:
475 if (maskPreBlend.isApplicable()) {
476 applyLUTToA8Mask(mask, maskPreBlend.fG);
477 }
478 break;
479 case SkMask::kLCD16_Format:
480 if (maskPreBlend.isApplicable()) {
bungeman@google.com0abbff92013-07-27 20:37:56 +0000481 pack4xHToLCD16<true>(bm, mask, maskPreBlend);
bungeman@google.com0c5f3762012-10-26 20:48:54 +0000482 } else {
bungeman@google.com0abbff92013-07-27 20:37:56 +0000483 pack4xHToLCD16<false>(bm, mask, maskPreBlend);
bungeman@google.com0c5f3762012-10-26 20:48:54 +0000484 }
485 break;
486 case SkMask::kLCD32_Format:
487 if (maskPreBlend.isApplicable()) {
bungeman@google.com0abbff92013-07-27 20:37:56 +0000488 pack4xHToLCD32<true>(bm, mask, maskPreBlend);
bungeman@google.com0c5f3762012-10-26 20:48:54 +0000489 } else {
bungeman@google.com0abbff92013-07-27 20:37:56 +0000490 pack4xHToLCD32<false>(bm, mask, maskPreBlend);
bungeman@google.com0c5f3762012-10-26 20:48:54 +0000491 }
492 break;
493 default:
494 break;
reed@google.comcf598b12011-08-22 21:13:23 +0000495 }
496}
497
reed@google.com5bdfb332013-05-02 18:55:44 +0000498static void extract_alpha(const SkMask& dst,
499 const SkPMColor* srcRow, size_t srcRB) {
500 int width = dst.fBounds.width();
501 int height = dst.fBounds.height();
502 int dstRB = dst.fRowBytes;
503 uint8_t* dstRow = dst.fImage;
504
505 for (int y = 0; y < height; ++y) {
506 for (int x = 0; x < width; ++x) {
507 dstRow[x] = SkGetPackedA32(srcRow[x]);
508 }
509 // zero any padding on each row
510 for (int x = width; x < dstRB; ++x) {
511 dstRow[x] = 0;
512 }
513 dstRow += dstRB;
514 srcRow = (const SkPMColor*)((const char*)srcRow + srcRB);
515 }
516}
517
reed@android.com8a1c16f2008-12-17 15:59:43 +0000518void SkScalerContext::getImage(const SkGlyph& origGlyph) {
519 const SkGlyph* glyph = &origGlyph;
520 SkGlyph tmpGlyph;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000521
reed@google.com5bdfb332013-05-02 18:55:44 +0000522 // in case we need to call generateImage on a mask-format that is different
523 // (i.e. larger) than what our caller allocated by looking at origGlyph.
524 SkAutoMalloc tmpGlyphImageStorage;
525
526 // If we are going to draw-from-path, then we cannot generate color, since
527 // the path only makes a mask. This case should have been caught up in
528 // generateMetrics().
529 SkASSERT(!fGenerateImageFromPath ||
530 SkMask::kARGB32_Format != origGlyph.fMaskFormat);
531
reed@android.com8a1c16f2008-12-17 15:59:43 +0000532 if (fMaskFilter) { // restore the prefilter bounds
reed@google.comce2b1af2011-02-18 13:00:40 +0000533 tmpGlyph.init(origGlyph.fID);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000534
535 // need the original bounds, sans our maskfilter
536 SkMaskFilter* mf = fMaskFilter;
537 fMaskFilter = NULL; // temp disable
538 this->getMetrics(&tmpGlyph);
539 fMaskFilter = mf; // restore
540
reed@android.com8a1c16f2008-12-17 15:59:43 +0000541 // we need the prefilter bounds to be <= filter bounds
542 SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth);
543 SkASSERT(tmpGlyph.fHeight <= origGlyph.fHeight);
reed@google.com5bdfb332013-05-02 18:55:44 +0000544
545 if (tmpGlyph.fMaskFormat == origGlyph.fMaskFormat) {
546 tmpGlyph.fImage = origGlyph.fImage;
547 } else {
548 tmpGlyphImageStorage.reset(tmpGlyph.computeImageSize());
549 tmpGlyph.fImage = tmpGlyphImageStorage.get();
550 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000551 glyph = &tmpGlyph;
552 }
553
reed@google.coma767fa02011-08-05 21:40:26 +0000554 if (fGenerateImageFromPath) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000555 SkPath devPath, fillPath;
556 SkMatrix fillToDevMatrix;
reed@google.comcf598b12011-08-22 21:13:23 +0000557 SkMask mask;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000558
559 this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix);
reed@google.comcf598b12011-08-22 21:13:23 +0000560 glyph->toMask(&mask);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000561
562 if (fRasterizer) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000563 mask.fFormat = SkMask::kA8_Format;
reed@android.com4516f472009-06-29 16:25:36 +0000564 sk_bzero(glyph->fImage, mask.computeImageSize());
reed@google.com82065d62011-02-07 15:30:46 +0000565
reed@android.com8a1c16f2008-12-17 15:59:43 +0000566 if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, NULL,
567 fMaskFilter, &mask,
568 SkMask::kJustRenderImage_CreateMode)) {
569 return;
570 }
bungeman@google.coma76de722012-10-26 19:35:54 +0000571 if (fPreBlend.isApplicable()) {
572 applyLUTToA8Mask(mask, fPreBlend.fG);
bungeman@google.com97efada2012-07-30 20:40:50 +0000573 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000574 } else {
reed@google.com5bdfb332013-05-02 18:55:44 +0000575 SkASSERT(SkMask::kARGB32_Format != mask.fFormat);
bungeman@google.coma76de722012-10-26 19:35:54 +0000576 generateMask(mask, devPath, fPreBlend);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000577 }
578 } else {
djsollen1b277042014-08-06 06:58:06 -0700579 generateImage(*glyph);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000580 }
581
582 if (fMaskFilter) {
583 SkMask srcM, dstM;
584 SkMatrix matrix;
585
586 // the src glyph image shouldn't be 3D
587 SkASSERT(SkMask::k3D_Format != glyph->fMaskFormat);
reed@google.com5bdfb332013-05-02 18:55:44 +0000588
589 SkAutoSMalloc<32*32> a8storage;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000590 glyph->toMask(&srcM);
reed@google.com5bdfb332013-05-02 18:55:44 +0000591 if (SkMask::kARGB32_Format == srcM.fFormat) {
592 // now we need to extract the alpha-channel from the glyph's image
593 // and copy it into a temp buffer, and then point srcM at that temp.
594 srcM.fFormat = SkMask::kA8_Format;
595 srcM.fRowBytes = SkAlign4(srcM.fBounds.width());
596 size_t size = srcM.computeImageSize();
597 a8storage.reset(size);
598 srcM.fImage = (uint8_t*)a8storage.get();
599 extract_alpha(srcM,
600 (const SkPMColor*)glyph->fImage, glyph->rowBytes());
601 }
skia.committer@gmail.com2fd42c42013-05-03 07:01:00 +0000602
reed@android.com8a1c16f2008-12-17 15:59:43 +0000603 fRec.getMatrixFrom2x2(&matrix);
604
605 if (fMaskFilter->filterMask(&dstM, srcM, matrix, NULL)) {
606 int width = SkFastMin32(origGlyph.fWidth, dstM.fBounds.width());
607 int height = SkFastMin32(origGlyph.fHeight, dstM.fBounds.height());
608 int dstRB = origGlyph.rowBytes();
609 int srcRB = dstM.fRowBytes;
reed@google.com82065d62011-02-07 15:30:46 +0000610
reed@android.com8a1c16f2008-12-17 15:59:43 +0000611 const uint8_t* src = (const uint8_t*)dstM.fImage;
612 uint8_t* dst = (uint8_t*)origGlyph.fImage;
613
614 if (SkMask::k3D_Format == dstM.fFormat) {
615 // we have to copy 3 times as much
616 height *= 3;
617 }
618
619 // clean out our glyph, since it may be larger than dstM
reed@android.com4516f472009-06-29 16:25:36 +0000620 //sk_bzero(dst, height * dstRB);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000621
622 while (--height >= 0) {
623 memcpy(dst, src, width);
624 src += srcRB;
625 dst += dstRB;
626 }
627 SkMask::FreeImage(dstM.fImage);
bungeman@google.com97efada2012-07-30 20:40:50 +0000628
bungeman@google.coma76de722012-10-26 19:35:54 +0000629 if (fPreBlendForFilter.isApplicable()) {
630 applyLUTToA8Mask(srcM, fPreBlendForFilter.fG);
631 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000632 }
633 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000634}
635
reed@google.com7db9fe62011-04-11 11:57:54 +0000636void SkScalerContext::getPath(const SkGlyph& glyph, SkPath* path) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000637 this->internalGetPath(glyph, NULL, path, NULL);
638}
639
reed@google.com0a01f5a2013-05-08 14:19:08 +0000640void SkScalerContext::getFontMetrics(SkPaint::FontMetrics* fm) {
bungeman41078062014-07-07 08:16:37 -0700641 this->generateFontMetrics(fm);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000642}
643
reed@android.com9d3a9852010-01-08 14:07:42 +0000644SkUnichar SkScalerContext::generateGlyphToChar(uint16_t glyph) {
645 return 0;
646}
647
reed@google.com7db9fe62011-04-11 11:57:54 +0000648///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000649
reed@google.com7db9fe62011-04-11 11:57:54 +0000650void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath,
651 SkPath* devPath, SkMatrix* fillToDevMatrix) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000652 SkPath path;
djsollen1b277042014-08-06 06:58:06 -0700653 generatePath(glyph, &path);
reed@google.com82065d62011-02-07 15:30:46 +0000654
reed@google.comcf598b12011-08-22 21:13:23 +0000655 if (fRec.fFlags & SkScalerContext::kSubpixelPositioning_Flag) {
656 SkFixed dx = glyph.getSubXFixed();
657 SkFixed dy = glyph.getSubYFixed();
658 if (dx | dy) {
659 path.offset(SkFixedToScalar(dx), SkFixedToScalar(dy));
660 }
661 }
662
reed@google.com7db9fe62011-04-11 11:57:54 +0000663 if (fRec.fFrameWidth > 0 || fPathEffect != NULL) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000664 // need the path in user-space, with only the point-size applied
665 // so that our stroking and effects will operate the same way they
666 // would if the user had extracted the path themself, and then
667 // called drawPath
668 SkPath localPath;
669 SkMatrix matrix, inverse;
670
671 fRec.getMatrixFrom2x2(&matrix);
bungeman@google.com9575fb82012-04-09 20:49:03 +0000672 if (!matrix.invert(&inverse)) {
673 // assume fillPath and devPath are already empty.
674 return;
675 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000676 path.transform(inverse, &localPath);
677 // now localPath is only affected by the paint settings, and not the canvas matrix
678
reed@google.comfd4be262012-05-25 01:04:12 +0000679 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000680
reed@google.comfd4be262012-05-25 01:04:12 +0000681 if (fRec.fFrameWidth > 0) {
682 rec.setStrokeStyle(fRec.fFrameWidth,
683 SkToBool(fRec.fFlags & kFrameAndFill_Flag));
684 // glyphs are always closed contours, so cap type is ignored,
685 // so we just pass something.
686 rec.setStrokeParams(SkPaint::kButt_Cap,
687 (SkPaint::Join)fRec.fStrokeJoin,
688 fRec.fMiterLimit);
689 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000690
reed@google.com7db9fe62011-04-11 11:57:54 +0000691 if (fPathEffect) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000692 SkPath effectPath;
reed@google.com4bbdeac2013-01-24 21:03:11 +0000693 if (fPathEffect->filterPath(&effectPath, localPath, &rec, NULL)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000694 localPath.swap(effectPath);
reed@google.com7db9fe62011-04-11 11:57:54 +0000695 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000696 }
697
reed@google.comfd4be262012-05-25 01:04:12 +0000698 if (rec.needToApply()) {
699 SkPath strokePath;
700 if (rec.applyToPath(&strokePath, localPath)) {
701 localPath.swap(strokePath);
702 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000703 }
reed@google.com82065d62011-02-07 15:30:46 +0000704
reed@android.com8a1c16f2008-12-17 15:59:43 +0000705 // now return stuff to the caller
reed@google.com7db9fe62011-04-11 11:57:54 +0000706 if (fillToDevMatrix) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000707 *fillToDevMatrix = matrix;
reed@google.com7db9fe62011-04-11 11:57:54 +0000708 }
709 if (devPath) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000710 localPath.transform(matrix, devPath);
reed@google.com7db9fe62011-04-11 11:57:54 +0000711 }
712 if (fillPath) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000713 fillPath->swap(localPath);
reed@google.com7db9fe62011-04-11 11:57:54 +0000714 }
715 } else { // nothing tricky to do
716 if (fillToDevMatrix) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000717 fillToDevMatrix->reset();
reed@google.com7db9fe62011-04-11 11:57:54 +0000718 }
719 if (devPath) {
720 if (fillPath == NULL) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000721 devPath->swap(path);
reed@google.com7db9fe62011-04-11 11:57:54 +0000722 } else {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000723 *devPath = path;
reed@google.com7db9fe62011-04-11 11:57:54 +0000724 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000725 }
reed@google.com82065d62011-02-07 15:30:46 +0000726
reed@google.com7db9fe62011-04-11 11:57:54 +0000727 if (fillPath) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000728 fillPath->swap(path);
reed@google.com7db9fe62011-04-11 11:57:54 +0000729 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000730 }
reed@google.com82065d62011-02-07 15:30:46 +0000731
reed@google.com7db9fe62011-04-11 11:57:54 +0000732 if (devPath) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000733 devPath->updateBoundsCache();
reed@google.com7db9fe62011-04-11 11:57:54 +0000734 }
735 if (fillPath) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000736 fillPath->updateBoundsCache();
reed@google.com7db9fe62011-04-11 11:57:54 +0000737 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000738}
739
740
reed@google.coma9d4e842012-08-14 19:13:55 +0000741void SkScalerContextRec::getMatrixFrom2x2(SkMatrix* dst) const {
bungeman@google.com50dd4102013-01-14 18:25:55 +0000742 dst->setAll(fPost2x2[0][0], fPost2x2[0][1], 0,
743 fPost2x2[1][0], fPost2x2[1][1], 0,
744 0, 0, SkScalarToPersp(SK_Scalar1));
reed@android.com8a1c16f2008-12-17 15:59:43 +0000745}
746
reed@google.coma9d4e842012-08-14 19:13:55 +0000747void SkScalerContextRec::getLocalMatrix(SkMatrix* m) const {
reed@google.comed43dff2013-06-04 16:56:27 +0000748 SkPaint::SetTextMatrix(m, fTextSize, fPreScaleX, fPreSkewX);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000749}
750
reed@google.coma9d4e842012-08-14 19:13:55 +0000751void SkScalerContextRec::getSingleMatrix(SkMatrix* m) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000752 this->getLocalMatrix(m);
753
754 // now concat the device matrix
reed@google.com7db9fe62011-04-11 11:57:54 +0000755 SkMatrix deviceMatrix;
756 this->getMatrixFrom2x2(&deviceMatrix);
757 m->postConcat(deviceMatrix);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000758}
759
reed@google.com2e684782011-08-24 15:38:46 +0000760SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix) {
761 SkASSERT(!matrix.hasPerspective());
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000762
reed@google.com2e684782011-08-24 15:38:46 +0000763 if (0 == matrix[SkMatrix::kMSkewY]) {
764 return kX_SkAxisAlignment;
765 }
766 if (0 == matrix[SkMatrix::kMScaleX]) {
767 return kY_SkAxisAlignment;
768 }
769 return kNone_SkAxisAlignment;
770}
771
reed@android.com62900b42009-02-11 15:07:19 +0000772///////////////////////////////////////////////////////////////////////////////
773
reed@android.com8a1c16f2008-12-17 15:59:43 +0000774#include "SkFontHost.h"
775
reed@android.com62900b42009-02-11 15:07:19 +0000776class SkScalerContext_Empty : public SkScalerContext {
777public:
reed@google.com0da48612013-03-19 16:06:52 +0000778 SkScalerContext_Empty(SkTypeface* face, const SkDescriptor* desc)
779 : SkScalerContext(face, desc) {}
reed@android.com62900b42009-02-11 15:07:19 +0000780
781protected:
bungeman@google.coma76de722012-10-26 19:35:54 +0000782 virtual unsigned generateGlyphCount() SK_OVERRIDE {
reed@android.com62900b42009-02-11 15:07:19 +0000783 return 0;
784 }
bungeman@google.coma76de722012-10-26 19:35:54 +0000785 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE {
reed@android.com62900b42009-02-11 15:07:19 +0000786 return 0;
787 }
bungeman@google.coma76de722012-10-26 19:35:54 +0000788 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE {
reed@android.com62900b42009-02-11 15:07:19 +0000789 glyph->zeroMetrics();
790 }
bungeman@google.coma76de722012-10-26 19:35:54 +0000791 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE {
reed@android.com62900b42009-02-11 15:07:19 +0000792 glyph->zeroMetrics();
793 }
bungeman@google.coma76de722012-10-26 19:35:54 +0000794 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE {}
795 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE {}
bungeman41078062014-07-07 08:16:37 -0700796 virtual void generateFontMetrics(SkPaint::FontMetrics* metrics) SK_OVERRIDE {
797 if (metrics) {
798 sk_bzero(metrics, sizeof(*metrics));
reed@android.com62900b42009-02-11 15:07:19 +0000799 }
800 }
801};
802
reed@android.comf2b98d62010-12-20 18:26:13 +0000803extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc);
804
reed@google.com84e22d82013-07-10 15:38:20 +0000805SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc,
806 bool allowFailure) const {
807 SkScalerContext* c = this->onCreateScalerContext(desc);
808
809 if (!c && !allowFailure) {
reed@google.com0da48612013-03-19 16:06:52 +0000810 c = SkNEW_ARGS(SkScalerContext_Empty,
811 (const_cast<SkTypeface*>(this), desc));
reed@android.com62900b42009-02-11 15:07:19 +0000812 }
813 return c;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000814}