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