• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkFixed.h"
12 #include "SkStream.h"
13 #include "SkString.h"
14 #include "SkTypeface.h"
15 
16 class SkFontData {
17 public:
18     /** Makes a copy of the data in 'axis'. */
SkFontData(std::unique_ptr<SkStreamAsset> stream,int index,const SkFixed axis[],int axisCount)19     SkFontData(std::unique_ptr<SkStreamAsset> stream, int index, const SkFixed axis[],int axisCount)
20         : fStream(std::move(stream)), fIndex(index), fAxisCount(axisCount), fAxis(axisCount)
21     {
22         for (int i = 0; i < axisCount; ++i) {
23             fAxis[i] = axis[i];
24         }
25     }
SkFontData(const SkFontData & that)26     SkFontData(const SkFontData& that)
27         : fStream(that.fStream->duplicate())
28         , fIndex(that.fIndex)
29         , fAxisCount(that.fAxisCount)
30         , fAxis(fAxisCount)
31     {
32         for (int i = 0; i < fAxisCount; ++i) {
33             fAxis[i] = that.fAxis[i];
34         }
35     }
hasStream()36     bool hasStream() const { return fStream.get() != nullptr; }
detachStream()37     std::unique_ptr<SkStreamAsset> detachStream() { return std::move(fStream); }
getStream()38     SkStreamAsset* getStream() { return fStream.get(); }
getStream()39     SkStreamAsset const* getStream() const { return fStream.get(); }
getIndex()40     int getIndex() const { return fIndex; }
getAxisCount()41     int getAxisCount() const { return fAxisCount; }
getAxis()42     const SkFixed* getAxis() const { return fAxis.get(); }
43 
44 private:
45     std::unique_ptr<SkStreamAsset> fStream;
46     int fIndex;
47     int fAxisCount;
48     SkAutoSTMalloc<4, SkFixed> fAxis;
49 };
50 
51 class SkFontDescriptor : SkNoncopyable {
52 public:
53     SkFontDescriptor();
54     // Does not affect ownership of SkStream.
55     static bool Deserialize(SkStream*, SkFontDescriptor* result);
56 
57     void serialize(SkWStream*);
58 
getStyle()59     SkFontStyle getStyle() { return fStyle; }
setStyle(SkFontStyle style)60     void setStyle(SkFontStyle style) { fStyle = style; }
61 
getFamilyName()62     const char* getFamilyName() const { return fFamilyName.c_str(); }
getFullName()63     const char* getFullName() const { return fFullName.c_str(); }
getPostscriptName()64     const char* getPostscriptName() const { return fPostscriptName.c_str(); }
hasFontData()65     bool hasFontData() const { return fFontData.get() != nullptr; }
detachFontData()66     std::unique_ptr<SkFontData> detachFontData() { return std::move(fFontData); }
67 
setFamilyName(const char * name)68     void setFamilyName(const char* name) { fFamilyName.set(name); }
setFullName(const char * name)69     void setFullName(const char* name) { fFullName.set(name); }
setPostscriptName(const char * name)70     void setPostscriptName(const char* name) { fPostscriptName.set(name); }
71     /** Set the font data only if it is necessary for serialization. */
setFontData(std::unique_ptr<SkFontData> data)72     void setFontData(std::unique_ptr<SkFontData> data) { fFontData = std::move(data); }
73 
74 private:
75     SkString fFamilyName;
76     SkString fFullName;
77     SkString fPostscriptName;
78     std::unique_ptr<SkFontData> fFontData;
79 
80     SkFontStyle fStyle;
81 };
82 
83 #endif // SkFontDescriptor_DEFINED
84