OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkFontDescriptor_DEFINED | 8 #ifndef SkFontDescriptor_DEFINED |
9 #define SkFontDescriptor_DEFINED | 9 #define SkFontDescriptor_DEFINED |
10 | 10 |
11 #include "SkFixed.h" | 11 #include "SkFixed.h" |
12 #include "SkStream.h" | 12 #include "SkStream.h" |
13 #include "SkString.h" | 13 #include "SkString.h" |
14 #include "SkTypeface.h" | 14 #include "SkTypeface.h" |
15 | 15 |
16 class SkFontData { | 16 class SkFontData { |
17 public: | 17 public: |
18 /** Makes a copy of the data in 'axis'. */ | 18 /** This takes ownership of 'stream'. Makes a copy of the data in 'axis'. */ |
19 SkFontData(std::unique_ptr<SkStreamAsset> stream, int index, const SkFixed a
xis[],int axisCount) | 19 SkFontData(SkStreamAsset* stream, int index, const SkFixed axis[], int axisC
ount) |
20 : fStream(std::move(stream)), fIndex(index), fAxisCount(axisCount), fAxi
s(axisCount) | 20 : fStream(stream), fIndex(index), fAxisCount(axisCount), fAxis(axisCount
) |
21 { | 21 { |
22 for (int i = 0; i < axisCount; ++i) { | 22 for (int i = 0; i < axisCount; ++i) { |
23 fAxis[i] = axis[i]; | 23 fAxis[i] = axis[i]; |
24 } | 24 } |
25 } | 25 } |
26 SkFontData(const SkFontData& that) | 26 SkFontData(const SkFontData& that) |
27 : fStream(that.fStream->duplicate()) | 27 : fStream(that.fStream->duplicate()) |
28 , fIndex(that.fIndex) | 28 , fIndex(that.fIndex) |
29 , fAxisCount(that.fAxisCount) | 29 , fAxisCount(that.fAxisCount) |
30 , fAxis(fAxisCount) | 30 , fAxis(fAxisCount) |
31 { | 31 { |
32 for (int i = 0; i < fAxisCount; ++i) { | 32 for (int i = 0; i < fAxisCount; ++i) { |
33 fAxis[i] = that.fAxis[i]; | 33 fAxis[i] = that.fAxis[i]; |
34 } | 34 } |
35 } | 35 } |
36 bool hasStream() const { return fStream.get() != nullptr; } | 36 bool hasStream() const { return fStream.get() != nullptr; } |
37 std::unique_ptr<SkStreamAsset> detachStream() { return std::move(fStream); } | 37 SkStreamAsset* duplicateStream() const { return fStream->duplicate(); } |
| 38 SkStreamAsset* detachStream() { return fStream.release(); } |
38 SkStreamAsset* getStream() { return fStream.get(); } | 39 SkStreamAsset* getStream() { return fStream.get(); } |
39 SkStreamAsset const* getStream() const { return fStream.get(); } | |
40 int getIndex() const { return fIndex; } | 40 int getIndex() const { return fIndex; } |
41 int getAxisCount() const { return fAxisCount; } | 41 int getAxisCount() const { return fAxisCount; } |
42 const SkFixed* getAxis() const { return fAxis.get(); } | 42 const SkFixed* getAxis() const { return fAxis.get(); } |
43 | 43 |
44 private: | 44 private: |
45 std::unique_ptr<SkStreamAsset> fStream; | 45 SkAutoTDelete<SkStreamAsset> fStream; |
46 int fIndex; | 46 int fIndex; |
47 int fAxisCount; | 47 int fAxisCount; |
48 SkAutoSTMalloc<4, SkFixed> fAxis; | 48 SkAutoSTMalloc<4, SkFixed> fAxis; |
49 }; | 49 }; |
50 | 50 |
51 class SkFontDescriptor : SkNoncopyable { | 51 class SkFontDescriptor : SkNoncopyable { |
52 public: | 52 public: |
53 SkFontDescriptor(); | 53 SkFontDescriptor(); |
54 // Does not affect ownership of SkStream. | 54 // Does not affect ownership of SkStream. |
55 static bool Deserialize(SkStream*, SkFontDescriptor* result); | 55 static bool Deserialize(SkStream*, SkFontDescriptor* result); |
56 | 56 |
57 void serialize(SkWStream*); | 57 void serialize(SkWStream*); |
58 | 58 |
59 SkFontStyle getStyle() { return fStyle; } | 59 SkFontStyle getStyle() { return fStyle; } |
60 void setStyle(SkFontStyle style) { fStyle = style; } | 60 void setStyle(SkFontStyle style) { fStyle = style; } |
61 | 61 |
62 const char* getFamilyName() const { return fFamilyName.c_str(); } | 62 const char* getFamilyName() const { return fFamilyName.c_str(); } |
63 const char* getFullName() const { return fFullName.c_str(); } | 63 const char* getFullName() const { return fFullName.c_str(); } |
64 const char* getPostscriptName() const { return fPostscriptName.c_str(); } | 64 const char* getPostscriptName() const { return fPostscriptName.c_str(); } |
65 bool hasFontData() const { return fFontData.get() != nullptr; } | 65 bool hasFontData() const { return fFontData.get() != nullptr; } |
66 std::unique_ptr<SkFontData> detachFontData() { return std::move(fFontData);
} | 66 SkFontData* detachFontData() { return fFontData.release(); } |
67 | 67 |
68 void setFamilyName(const char* name) { fFamilyName.set(name); } | 68 void setFamilyName(const char* name) { fFamilyName.set(name); } |
69 void setFullName(const char* name) { fFullName.set(name); } | 69 void setFullName(const char* name) { fFullName.set(name); } |
70 void setPostscriptName(const char* name) { fPostscriptName.set(name); } | 70 void setPostscriptName(const char* name) { fPostscriptName.set(name); } |
71 /** Set the font data only if it is necessary for serialization. */ | 71 /** Set the font data only if it is necessary for serialization. |
72 void setFontData(std::unique_ptr<SkFontData> data) { fFontData = std::move(d
ata); } | 72 * This method takes ownership of the font data. */ |
| 73 void setFontData(SkFontData* data) { fFontData.reset(data); } |
73 | 74 |
74 private: | 75 private: |
75 SkString fFamilyName; | 76 SkString fFamilyName; |
76 SkString fFullName; | 77 SkString fFullName; |
77 SkString fPostscriptName; | 78 SkString fPostscriptName; |
78 std::unique_ptr<SkFontData> fFontData; | 79 SkAutoTDelete<SkFontData> fFontData; |
79 | 80 |
80 SkFontStyle fStyle; | 81 SkFontStyle fStyle; |
81 }; | 82 }; |
82 | 83 |
83 #endif // SkFontDescriptor_DEFINED | 84 #endif // SkFontDescriptor_DEFINED |
OLD | NEW |