Home | History | Annotate | Download | only in core
      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 
     23     SkTypeface::Style getStyle() { return fStyle; }
     24     void setStyle(SkTypeface::Style style) { fStyle = style; }
     25 
     26     const char* getFamilyName() const { return fFamilyName.c_str(); }
     27     const char* getFullName() const { return fFullName.c_str(); }
     28     const char* getPostscriptName() const { return fPostscriptName.c_str(); }
     29     bool hasFontData() const { return fFontData.get() != NULL; }
     30     // Transfers ownership to the caller.
     31     SkStreamAsset* transferFontData() { return fFontData.detach(); }
     32     int getFontIndex() const { return fFontIndex; }
     33 
     34     void setFamilyName(const char* name) { fFamilyName.set(name); }
     35     void setFullName(const char* name) { fFullName.set(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      */
     40     void setFontData(SkStreamAsset* stream) { fFontData.reset(stream); }
     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