1 #include "SkTypeface.h" 2 #include "SkFontHost.h" 3 4 uint32_t SkTypeface::UniqueID(const SkTypeface* face) { 5 if (face) { 6 return face->uniqueID(); 7 } 8 9 // We cache the default fontID, assuming it will not change during a boot 10 // The initial value of 0 is fine, since a typeface's uniqueID should not 11 // be zero. 12 static uint32_t gDefaultFontID; 13 14 if (0 == gDefaultFontID) { 15 SkTypeface* defaultFace = SkFontHost::CreateTypeface(NULL, NULL, 16 SkTypeface::kNormal); 17 SkASSERT(defaultFace); 18 gDefaultFontID = defaultFace->uniqueID(); 19 defaultFace->unref(); 20 } 21 return gDefaultFontID; 22 } 23 24 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { 25 return SkTypeface::UniqueID(facea) == SkTypeface::UniqueID(faceb); 26 } 27 28 /////////////////////////////////////////////////////////////////////////////// 29 30 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { 31 return SkFontHost::CreateTypeface(NULL, name, style); 32 } 33 34 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { 35 return SkFontHost::CreateTypeface(family, NULL, s); 36 } 37 38 SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) { 39 return SkFontHost::CreateTypefaceFromStream(stream); 40 } 41 42 SkTypeface* SkTypeface::CreateFromFile(const char path[]) { 43 return SkFontHost::CreateTypefaceFromFile(path); 44 } 45 46 /////////////////////////////////////////////////////////////////////////////// 47 48 void SkTypeface::serialize(SkWStream* stream) const { 49 SkFontHost::Serialize(this, stream); 50 } 51 52 SkTypeface* SkTypeface::Deserialize(SkStream* stream) { 53 return SkFontHost::Deserialize(stream); 54 } 55 56 57