2 * Copyright 2010 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "GrTextContext.h"
11 #include "SkAutoKern.h"
12 #include "SkGlyphCache.h"
15 GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& properties) :
16 fContext(context), fDeviceProperties(properties), fDrawTarget(NULL) {
19 void GrTextContext::init(const GrPaint& grPaint, const SkPaint& skPaint) {
20 const GrClipData* clipData = fContext->getClip();
22 SkRect devConservativeBound;
23 clipData->fClipStack->getConservativeBounds(
24 -clipData->fOrigin.fX,
25 -clipData->fOrigin.fY,
26 fContext->getRenderTarget()->width(),
27 fContext->getRenderTarget()->height(),
28 &devConservativeBound);
30 devConservativeBound.roundOut(&fClipRect);
32 fDrawTarget = fContext->getTextTarget();
38 //*** change to output positions?
39 void GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
40 const char text[], size_t byteLength, SkVector* stopVector) {
42 const char* stop = text + byteLength;
47 // don't need x, y here, since all subpixel variants will have the
49 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
51 x += autokern.adjust(glyph) + glyph.fAdvanceX;
54 stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y));
56 SkASSERT(text == stop);
59 static void GlyphCacheAuxProc(void* data) {
60 GrFontScaler* scaler = (GrFontScaler*)data;
64 GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) {
66 GrFontScaler* scaler = NULL;
68 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) {
69 scaler = (GrFontScaler*)auxData;
72 scaler = SkNEW_ARGS(SkGrFontScaler, (cache));
73 cache->setAuxProc(GlyphCacheAuxProc, scaler);