1/* libs/graphics/sgl/SkAutoKern.h 2** 3** Copyright 2006, The Android Open Source Project 4** 5** Licensed under the Apache License, Version 2.0 (the "License"); 6** you may not use this file except in compliance with the License. 7** You may obtain a copy of the License at 8** 9** http://www.apache.org/licenses/LICENSE-2.0 10** 11** Unless required by applicable law or agreed to in writing, software 12** distributed under the License is distributed on an "AS IS" BASIS, 13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14** See the License for the specific language governing permissions and 15** limitations under the License. 16*/ 17 18#ifndef SkAutoKern_DEFINED 19#define SkAutoKern_DEFINED 20 21#include "SkScalerContext.h" 22 23#define SkAutoKern_AdjustF(prev, next) (((next) - (prev) + 32) >> 6 << 16) 24#define SkAutoKern_AdjustS(prev, next) SkIntToScalar(((next) - (prev) + 32) >> 6) 25 26/* this is a helper class to perform auto-kerning 27 * the adjust() method returns a SkFixed corresponding 28 * to a +1/0/-1 pixel adjustment 29 */ 30 31class SkAutoKern { 32public: 33 SkAutoKern() : fPrevRsbDelta(0) {} 34 35 SkFixed adjust(const SkGlyph& glyph) 36 { 37// if (SkAbs32(glyph.fLsbDelta) > 47 || SkAbs32(glyph.fRsbDelta) > 47) 38// printf("------- %d> L %d R %d\n", glyph.f_GlyphID, glyph.fLsbDelta, glyph.fRsbDelta); 39 40#if 0 41 int distort = fPrevRsbDelta - glyph.fLsbDelta; 42 43 fPrevRsbDelta = glyph.fRsbDelta; 44 45 if (distort >= 32) 46 return -SK_Fixed1; 47 else if (distort < -32) 48 return +SK_Fixed1; 49 else 50 return 0; 51#else 52 SkFixed adjust = SkAutoKern_AdjustF(fPrevRsbDelta, glyph.fLsbDelta); 53 fPrevRsbDelta = glyph.fRsbDelta; 54 return adjust; 55#endif 56 } 57private: 58 int fPrevRsbDelta; 59}; 60 61#endif 62 63