• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 
9 #ifndef SkAutoKern_DEFINED
10 #define SkAutoKern_DEFINED
11 
12 #include "SkGlyph.h"
13 
14 #define SkAutoKern_Adjust(prev, next)    SkIntToScalar(((next) - (prev) + 32) >> 6)
15 
16 /* this is a helper class to perform auto-kerning
17  * the adjust() method returns a SkScalar corresponding
18  * to a +1/0/-1 pixel adjustment
19  */
20 
21 class SkAutoKern {
22 public:
SkAutoKern()23     SkAutoKern() : fPrevRsbDelta(0) {}
24 
adjust(const SkGlyph & glyph)25     SkScalar  adjust(const SkGlyph&  glyph)
26     {
27 //        if (SkAbs32(glyph.fLsbDelta) > 47 || SkAbs32(glyph.fRsbDelta) > 47)
28 //            printf("------- %d> L %d R %d\n", glyph.f_GlyphID, glyph.fLsbDelta, glyph.fRsbDelta);
29 
30 #if 0
31         int  distort = fPrevRsbDelta - glyph.fLsbDelta;
32 
33         fPrevRsbDelta = glyph.fRsbDelta;
34 
35         if (distort >= 32)
36             return -SK_Scalar1;
37         else if (distort < -32)
38             return +SK_Scalar1;
39         else
40             return 0;
41 #else
42         SkScalar adjust = SkAutoKern_Adjust(fPrevRsbDelta, glyph.fLsbDelta);
43         fPrevRsbDelta = glyph.fRsbDelta;
44         return adjust;
45 #endif
46     }
47 private:
48     int   fPrevRsbDelta;
49 };
50 
51 #endif
52