michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkAutoKern_DEFINED michael@0: #define SkAutoKern_DEFINED michael@0: michael@0: #include "SkGlyph.h" michael@0: michael@0: #define SkAutoKern_AdjustF(prev, next) (((next) - (prev) + 32) >> 6 << 16) michael@0: #define SkAutoKern_AdjustS(prev, next) SkIntToScalar(((next) - (prev) + 32) >> 6) michael@0: michael@0: /* this is a helper class to perform auto-kerning michael@0: * the adjust() method returns a SkFixed corresponding michael@0: * to a +1/0/-1 pixel adjustment michael@0: */ michael@0: michael@0: class SkAutoKern { michael@0: public: michael@0: SkAutoKern() : fPrevRsbDelta(0) {} michael@0: michael@0: SkFixed adjust(const SkGlyph& glyph) michael@0: { michael@0: // if (SkAbs32(glyph.fLsbDelta) > 47 || SkAbs32(glyph.fRsbDelta) > 47) michael@0: // printf("------- %d> L %d R %d\n", glyph.f_GlyphID, glyph.fLsbDelta, glyph.fRsbDelta); michael@0: michael@0: #if 0 michael@0: int distort = fPrevRsbDelta - glyph.fLsbDelta; michael@0: michael@0: fPrevRsbDelta = glyph.fRsbDelta; michael@0: michael@0: if (distort >= 32) michael@0: return -SK_Fixed1; michael@0: else if (distort < -32) michael@0: return +SK_Fixed1; michael@0: else michael@0: return 0; michael@0: #else michael@0: SkFixed adjust = SkAutoKern_AdjustF(fPrevRsbDelta, glyph.fLsbDelta); michael@0: fPrevRsbDelta = glyph.fRsbDelta; michael@0: return adjust; michael@0: #endif michael@0: } michael@0: private: michael@0: int fPrevRsbDelta; michael@0: }; michael@0: michael@0: #endif