blob: 0a08432a73047abc0e20066f68eeb8d22e8696aa [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
10#ifndef SkAutoKern_DEFINED
11#define SkAutoKern_DEFINED
12
bungeman@google.combbe50132012-07-24 20:33:21 +000013#include "SkGlyph.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014
15#define SkAutoKern_AdjustF(prev, next) (((next) - (prev) + 32) >> 6 << 16)
16#define SkAutoKern_AdjustS(prev, next) SkIntToScalar(((next) - (prev) + 32) >> 6)
17
18/* this is a helper class to perform auto-kerning
19 * the adjust() method returns a SkFixed corresponding
20 * to a +1/0/-1 pixel adjustment
21 */
22
23class SkAutoKern {
24public:
25 SkAutoKern() : fPrevRsbDelta(0) {}
26
rmistry@google.comfbfcd562012-08-23 18:09:54 +000027 SkFixed adjust(const SkGlyph& glyph)
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 {
29// if (SkAbs32(glyph.fLsbDelta) > 47 || SkAbs32(glyph.fRsbDelta) > 47)
30// printf("------- %d> L %d R %d\n", glyph.f_GlyphID, glyph.fLsbDelta, glyph.fRsbDelta);
31
32#if 0
33 int distort = fPrevRsbDelta - glyph.fLsbDelta;
34
35 fPrevRsbDelta = glyph.fRsbDelta;
36
37 if (distort >= 32)
38 return -SK_Fixed1;
39 else if (distort < -32)
40 return +SK_Fixed1;
41 else
42 return 0;
43#else
44 SkFixed adjust = SkAutoKern_AdjustF(fPrevRsbDelta, glyph.fLsbDelta);
45 fPrevRsbDelta = glyph.fRsbDelta;
46 return adjust;
47#endif
48 }
49private:
50 int fPrevRsbDelta;
51};
52
53#endif
54