Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: src/core/SkFontDescriptor.h

Issue 2339273002: SkFontData to use smart pointers. (Closed)
Patch Set: Add trivial bodies to the trivial implementations. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/animator/SkAnimator.cpp ('k') | src/core/SkFontDescriptor.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** This takes ownership of 'stream'. Makes a copy of the data in 'axis'. */ 18 /** Makes a copy of the data in 'axis'. */
19 SkFontData(SkStreamAsset* stream, int index, const SkFixed axis[], int axisC ount) 19 SkFontData(std::unique_ptr<SkStreamAsset> stream, int index, const SkFixed a xis[],int axisCount)
20 : fStream(stream), fIndex(index), fAxisCount(axisCount), fAxis(axisCount ) 20 : fStream(std::move(stream)), fIndex(index), fAxisCount(axisCount), fAxi s(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 SkStreamAsset* duplicateStream() const { return fStream->duplicate(); } 37 std::unique_ptr<SkStreamAsset> detachStream() { return std::move(fStream); }
38 SkStreamAsset* detachStream() { return fStream.release(); }
39 SkStreamAsset* getStream() { return fStream.get(); } 38 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 SkAutoTDelete<SkStreamAsset> fStream; 45 std::unique_ptr<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 SkFontData* detachFontData() { return fFontData.release(); } 66 std::unique_ptr<SkFontData> detachFontData() { return std::move(fFontData); }
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 * This method takes ownership of the font data. */ 72 void setFontData(std::unique_ptr<SkFontData> data) { fFontData = std::move(d ata); }
73 void setFontData(SkFontData* data) { fFontData.reset(data); }
74 73
75 private: 74 private:
76 SkString fFamilyName; 75 SkString fFamilyName;
77 SkString fFullName; 76 SkString fFullName;
78 SkString fPostscriptName; 77 SkString fPostscriptName;
79 SkAutoTDelete<SkFontData> fFontData; 78 std::unique_ptr<SkFontData> fFontData;
80 79
81 SkFontStyle fStyle; 80 SkFontStyle fStyle;
82 }; 81 };
83 82
84 #endif // SkFontDescriptor_DEFINED 83 #endif // SkFontDescriptor_DEFINED
OLDNEW
« no previous file with comments | « src/animator/SkAnimator.cpp ('k') | src/core/SkFontDescriptor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698