static void drawKernText(SkCanvas* canvas, const void* text, size_t len, SkScalar x, SkScalar y, const SkPaint& paint) { SkTypeface* face = paint.getTypeface(); if (!face) { canvas->drawText(text, len, x, y, paint); return; } SkAutoSTMalloc<128, uint16_t> glyphStorage(len); uint16_t* glyphs = glyphStorage.get(); int glyphCount = paint.textToGlyphs(text, len, glyphs); if (glyphCount < 1) { return; } SkAutoSTMalloc<128, int32_t> adjustmentStorage(glyphCount - 1); int32_t* adjustments = adjustmentStorage.get(); if (!face->getKerningPairAdjustments(glyphs, glyphCount, adjustments)) { canvas->drawText(text, len, x, y, paint); return; } SkPaint glyphPaint(paint); glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); SkAutoSTMalloc<128, SkPoint> posStorage(glyphCount); SkPoint* pos = posStorage.get(); getGlyphPositions(glyphPaint, glyphs, glyphCount, x, y, pos); applyKerning(pos, adjustments, glyphCount, glyphPaint); canvas->drawPosText(glyphs, glyphCount * sizeof(uint16_t), pos, glyphPaint); }
void gradCheck(skiatest::Reporter* reporter, SkShader* shader, SkShader::GradientInfo* info, SkShader::GradientType gt) const { SkAutoTMalloc<SkColor> colorStorage(fColorCount); SkAutoTMalloc<SkScalar> posStorage(fColorCount); info->fColorCount = fColorCount; info->fColors = colorStorage; info->fColorOffsets = posStorage.get(); REPORTER_ASSERT(reporter, shader->asAGradient(info) == gt); REPORTER_ASSERT(reporter, info->fColorCount == fColorCount); REPORTER_ASSERT(reporter, !memcmp(info->fColors, fColors, fColorCount * sizeof(SkColor))); REPORTER_ASSERT(reporter, !memcmp(info->fColorOffsets, fPos, fColorCount * sizeof(SkScalar))); REPORTER_ASSERT(reporter, fTileMode == info->fTileMode); }