1 /* 2 * Copyright 2012 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 SkFontDescriptor_DEFINED 9 #define SkFontDescriptor_DEFINED 10 11 #include "SkStream.h" 12 #include "SkString.h" 13 #include "SkTypeface.h" 14 15 class SkFontDescriptor { 16 public: 17 SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal); 18 // Does not affect ownership of SkStream. 19 SkFontDescriptor(SkStream*); 20 21 void serialize(SkWStream*); 22 getStyle()23 SkTypeface::Style getStyle() { return fStyle; } setStyle(SkTypeface::Style style)24 void setStyle(SkTypeface::Style style) { fStyle = style; } 25 getFamilyName()26 const char* getFamilyName() const { return fFamilyName.c_str(); } getFullName()27 const char* getFullName() const { return fFullName.c_str(); } getPostscriptName()28 const char* getPostscriptName() const { return fPostscriptName.c_str(); } hasFontData()29 bool hasFontData() const { return fFontData.get() != NULL; } 30 // Transfers ownership to the caller. transferFontData()31 SkStreamAsset* transferFontData() { return fFontData.detach(); } getFontIndex()32 int getFontIndex() const { return fFontIndex; } 33 setFamilyName(const char * name)34 void setFamilyName(const char* name) { fFamilyName.set(name); } setFullName(const char * name)35 void setFullName(const char* name) { fFullName.set(name); } setPostscriptName(const char * name)36 void setPostscriptName(const char* name) { fPostscriptName.set(name); } 37 /** Set the font data only if it is necessary for serialization. 38 * This method takes ownership of the stream (both reference and cursor). 39 */ setFontData(SkStreamAsset * stream)40 void setFontData(SkStreamAsset* stream) { fFontData.reset(stream); } setFontIndex(int index)41 void setFontIndex(int index) { fFontIndex = index; } 42 43 private: 44 SkString fFamilyName; 45 SkString fFullName; 46 SkString fPostscriptName; 47 SkAutoTDelete<SkStreamAsset> fFontData; 48 int fFontIndex; 49 50 SkTypeface::Style fStyle; 51 }; 52 53 #endif // SkFontDescriptor_DEFINED 54