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 16 class SkPath; 17 18 /* 19 * Wrapper class to turn a font cache descriptor into a key 20 * for GrFontScaler-related lookups 21 */ 22 class GrFontDescKey : public SkRefCnt { 23 public: 24 SK_DECLARE_INST_COUNT(GrFontDescKey) 25 26 typedef uint32_t Hash; 27 28 explicit GrFontDescKey(const SkDescriptor& desc); 29 virtual ~GrFontDescKey(); 30 getHash()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 40 private: 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 */ 61 class GrFontScaler : public SkRefCnt { 62 public: 63 SK_DECLARE_INST_COUNT(GrFontScaler) 64 65 explicit GrFontScaler(SkGlyphCache* strike); 66 virtual ~GrFontScaler(); 67 68 const GrFontDescKey* getKey(); 69 GrMaskFormat getMaskFormat() const; 70 GrMaskFormat getPackedGlyphMaskFormat(GrGlyph::PackedID) const; 71 bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds); 72 bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, 73 int rowBytes, void* image); 74 bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds); 75 bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height, 76 void* image); 77 bool getGlyphPath(uint16_t glyphID, SkPath*); 78 79 private: 80 SkGlyphCache* fStrike; 81 GrFontDescKey* fKey; 82 83 typedef SkRefCnt INHERITED; 84 }; 85 86 #endif 87