1/* 2 * Copyright 2010 Google Inc. 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#ifndef GrFontScaler_DEFINED 9#define GrFontScaler_DEFINED 10 11#include "GrGlyph.h" 12#include "GrTypes.h" 13 14#include "SkDescriptor.h" 15 16class SkPath; 17 18/* 19 * Wrapper class to turn a font cache descriptor into a key 20 * for GrFontScaler-related lookups 21 */ 22class GrFontDescKey : public SkRefCnt { 23public: 24 SK_DECLARE_INST_COUNT(GrFontDescKey) 25 26 typedef uint32_t Hash; 27 28 explicit GrFontDescKey(const SkDescriptor& desc); 29 virtual ~GrFontDescKey(); 30 31 Hash getHash() const { return fHash; } 32 33 bool operator<(const GrFontDescKey& rh) const { 34 return fHash < rh.fHash || (fHash == rh.fHash && this->lt(rh)); 35 } 36 bool operator==(const GrFontDescKey& rh) const { 37 return fHash == rh.fHash && this->eq(rh); 38 } 39 40private: 41 // helper functions for comparisons 42 bool lt(const GrFontDescKey& rh) const; 43 bool eq(const GrFontDescKey& rh) const; 44 45 SkDescriptor* fDesc; 46 enum { 47 kMaxStorageInts = 16 48 }; 49 uint32_t fStorage[kMaxStorageInts]; 50 const Hash fHash; 51 52 typedef SkRefCnt INHERITED; 53}; 54 55/* 56 * This is Gr's interface to the host platform's font scaler. 57 * 58 * The client is responsible for instantiating this. The instance is created 59 * for a specific font+size+matrix. 60 */ 61class GrFontScaler : public SkRefCnt { 62public: 63 SK_DECLARE_INST_COUNT(GrFontScaler) 64 65 explicit GrFontScaler(SkGlyphCache* strike); 66 virtual ~GrFontScaler(); 67 68 const GrFontDescKey* getKey(); 69 GrMaskFormat getMaskFormat(); 70 bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds); 71 bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, 72 int rowBytes, void* image); 73 bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds); 74 bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height, 75 void* image); 76 bool getGlyphPath(uint16_t glyphID, SkPath*); 77 78private: 79 SkGlyphCache* fStrike; 80 GrFontDescKey* fKey; 81 82 typedef SkRefCnt INHERITED; 83}; 84 85#endif 86