epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #ifndef SkAutoKern_DEFINED |
| 11 | #define SkAutoKern_DEFINED |
| 12 | |
bungeman@google.com | bbe5013 | 2012-07-24 20:33:21 +0000 | [diff] [blame] | 13 | #include "SkGlyph.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | |
| 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 | |
| 23 | class SkAutoKern { |
| 24 | public: |
| 25 | SkAutoKern() : fPrevRsbDelta(0) {} |
| 26 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 27 | SkFixed adjust(const SkGlyph& glyph) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | { |
| 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 | } |
| 49 | private: |
| 50 | int fPrevRsbDelta; |
| 51 | }; |
| 52 | |
| 53 | #endif |
| 54 | |