gfx/skia/trunk/src/core/SkAutoKern.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkAutoKern.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2006 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkAutoKern_DEFINED
    1.14 +#define SkAutoKern_DEFINED
    1.15 +
    1.16 +#include "SkGlyph.h"
    1.17 +
    1.18 +#define SkAutoKern_AdjustF(prev, next)    (((next) - (prev) + 32) >> 6 << 16)
    1.19 +#define SkAutoKern_AdjustS(prev, next)    SkIntToScalar(((next) - (prev) + 32) >> 6)
    1.20 +
    1.21 +/* this is a helper class to perform auto-kerning
    1.22 + * the adjust() method returns a SkFixed corresponding
    1.23 + * to a +1/0/-1 pixel adjustment
    1.24 + */
    1.25 +
    1.26 +class SkAutoKern {
    1.27 +public:
    1.28 +    SkAutoKern() : fPrevRsbDelta(0) {}
    1.29 +
    1.30 +    SkFixed  adjust(const SkGlyph&  glyph)
    1.31 +    {
    1.32 +//        if (SkAbs32(glyph.fLsbDelta) > 47 || SkAbs32(glyph.fRsbDelta) > 47)
    1.33 +//            printf("------- %d> L %d R %d\n", glyph.f_GlyphID, glyph.fLsbDelta, glyph.fRsbDelta);
    1.34 +
    1.35 +#if 0
    1.36 +        int  distort = fPrevRsbDelta - glyph.fLsbDelta;
    1.37 +
    1.38 +        fPrevRsbDelta = glyph.fRsbDelta;
    1.39 +
    1.40 +        if (distort >= 32)
    1.41 +            return -SK_Fixed1;
    1.42 +        else if (distort < -32)
    1.43 +            return +SK_Fixed1;
    1.44 +        else
    1.45 +            return 0;
    1.46 +#else
    1.47 +        SkFixed adjust = SkAutoKern_AdjustF(fPrevRsbDelta, glyph.fLsbDelta);
    1.48 +        fPrevRsbDelta = glyph.fRsbDelta;
    1.49 +        return adjust;
    1.50 +#endif
    1.51 +    }
    1.52 +private:
    1.53 +    int   fPrevRsbDelta;
    1.54 +};
    1.55 +
    1.56 +#endif

mercurial