gfx/skia/trunk/src/gpu/GrTextContext.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/GrTextContext.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +/*
     1.5 + * Copyright 2010 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#include "GrTextContext.h"
    1.12 +#include "GrContext.h"
    1.13 +
    1.14 +#include "SkAutoKern.h"
    1.15 +#include "SkGlyphCache.h"
    1.16 +#include "SkGr.h"
    1.17 +
    1.18 +GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& properties) :
    1.19 +                            fContext(context), fDeviceProperties(properties), fDrawTarget(NULL) {
    1.20 +}
    1.21 +
    1.22 +void GrTextContext::init(const GrPaint& grPaint, const SkPaint& skPaint) {
    1.23 +    const GrClipData* clipData = fContext->getClip();
    1.24 +
    1.25 +    SkRect devConservativeBound;
    1.26 +    clipData->fClipStack->getConservativeBounds(
    1.27 +                                     -clipData->fOrigin.fX,
    1.28 +                                     -clipData->fOrigin.fY,
    1.29 +                                     fContext->getRenderTarget()->width(),
    1.30 +                                     fContext->getRenderTarget()->height(),
    1.31 +                                     &devConservativeBound);
    1.32 +
    1.33 +    devConservativeBound.roundOut(&fClipRect);
    1.34 +
    1.35 +    fDrawTarget = fContext->getTextTarget();
    1.36 +
    1.37 +    fPaint = grPaint;
    1.38 +    fSkPaint = skPaint;
    1.39 +}
    1.40 +
    1.41 +//*** change to output positions?
    1.42 +void GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
    1.43 +                                const char text[], size_t byteLength, SkVector* stopVector) {
    1.44 +    SkFixed     x = 0, y = 0;
    1.45 +    const char* stop = text + byteLength;
    1.46 +
    1.47 +    SkAutoKern  autokern;
    1.48 +
    1.49 +    while (text < stop) {
    1.50 +        // don't need x, y here, since all subpixel variants will have the
    1.51 +        // same advance
    1.52 +        const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
    1.53 +
    1.54 +        x += autokern.adjust(glyph) + glyph.fAdvanceX;
    1.55 +        y += glyph.fAdvanceY;
    1.56 +    }
    1.57 +    stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y));
    1.58 +
    1.59 +    SkASSERT(text == stop);
    1.60 +}
    1.61 +
    1.62 +static void GlyphCacheAuxProc(void* data) {
    1.63 +    GrFontScaler* scaler = (GrFontScaler*)data;
    1.64 +    SkSafeUnref(scaler);
    1.65 +}
    1.66 +
    1.67 +GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) {
    1.68 +    void* auxData;
    1.69 +    GrFontScaler* scaler = NULL;
    1.70 +
    1.71 +    if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) {
    1.72 +        scaler = (GrFontScaler*)auxData;
    1.73 +    }
    1.74 +    if (NULL == scaler) {
    1.75 +        scaler = SkNEW_ARGS(SkGrFontScaler, (cache));
    1.76 +        cache->setAuxProc(GlyphCacheAuxProc, scaler);
    1.77 +    }
    1.78 +
    1.79 +    return scaler;
    1.80 +}

mercurial