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 "SkStream.h" | 11 #include "SkStream.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "SkTypeface.h" | 13 #include "SkTypeface.h" |
14 | 14 |
15 class SkFontDescriptor { | 15 class SkFontData : SkNoncopyable { |
| 16 public: |
| 17 /** This takes ownership of 'stream'. Makes a copy of the data in 'axis'. */ |
| 18 SkFontData(SkStreamAsset* stream, int index, int axisCount, const SkFixed ax
is[]) |
| 19 : fStream(stream), fIndex(index), fAxisCount(axisCount), fAxis(axisCount
) |
| 20 { |
| 21 for (int i = 0; i < axisCount; ++i) { |
| 22 fAxis[i] = axis[i]; |
| 23 } |
| 24 } |
| 25 bool hasStream() const { return fStream.get() != NULL; } |
| 26 SkStreamAsset* detachStream() { return fStream.detach(); } |
| 27 int getIndex() const { return fIndex; } |
| 28 int getAxisCount() const { return fAxisCount; } |
| 29 const SkFixed* getAxis() const { return fAxis.get(); } |
| 30 |
| 31 private: |
| 32 SkAutoTDelete<SkStreamAsset> fStream; |
| 33 int fIndex; |
| 34 int fAxisCount; |
| 35 SkAutoSTMalloc<4, SkFixed> fAxis; |
| 36 }; |
| 37 |
| 38 class SkFontDescriptor : SkNoncopyable { |
16 public: | 39 public: |
17 SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal); | 40 SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal); |
18 // Does not affect ownership of SkStream. | 41 // Does not affect ownership of SkStream. |
19 SkFontDescriptor(SkStream*); | 42 SkFontDescriptor(SkStream*); |
20 | 43 |
21 void serialize(SkWStream*); | 44 void serialize(SkWStream*); |
22 | 45 |
23 SkTypeface::Style getStyle() { return fStyle; } | 46 SkTypeface::Style getStyle() { return fStyle; } |
24 void setStyle(SkTypeface::Style style) { fStyle = style; } | 47 void setStyle(SkTypeface::Style style) { fStyle = style; } |
25 | 48 |
26 const char* getFamilyName() const { return fFamilyName.c_str(); } | 49 const char* getFamilyName() const { return fFamilyName.c_str(); } |
27 const char* getFullName() const { return fFullName.c_str(); } | 50 const char* getFullName() const { return fFullName.c_str(); } |
28 const char* getPostscriptName() const { return fPostscriptName.c_str(); } | 51 const char* getPostscriptName() const { return fPostscriptName.c_str(); } |
29 bool hasFontData() const { return fFontData.get() != NULL; } | 52 bool hasFontData() const { return fFontData.get() != NULL; } |
30 // Transfers ownership to the caller. | 53 // Transfers ownership to the caller. |
31 SkStreamAsset* transferFontData() { return fFontData.detach(); } | 54 SkFontData* getFontData() { return fFontData.get(); } |
32 int getFontIndex() const { return fFontIndex; } | |
33 | 55 |
34 void setFamilyName(const char* name) { fFamilyName.set(name); } | 56 void setFamilyName(const char* name) { fFamilyName.set(name); } |
35 void setFullName(const char* name) { fFullName.set(name); } | 57 void setFullName(const char* name) { fFullName.set(name); } |
36 void setPostscriptName(const char* name) { fPostscriptName.set(name); } | 58 void setPostscriptName(const char* name) { fPostscriptName.set(name); } |
37 /** Set the font data only if it is necessary for serialization. | 59 /** Set the font data only if it is necessary for serialization. |
38 * This method takes ownership of the stream (both reference and cursor). | 60 * This method takes ownership of the font data. */ |
39 */ | 61 void setFontData(SkFontData* data) { fFontData.reset(data); } |
40 void setFontData(SkStreamAsset* stream) { fFontData.reset(stream); } | |
41 void setFontIndex(int index) { fFontIndex = index; } | |
42 | 62 |
43 private: | 63 private: |
44 SkString fFamilyName; | 64 SkString fFamilyName; |
45 SkString fFullName; | 65 SkString fFullName; |
46 SkString fPostscriptName; | 66 SkString fPostscriptName; |
47 SkAutoTDelete<SkStreamAsset> fFontData; | 67 SkAutoTDelete<SkFontData> fFontData; |
48 int fFontIndex; | |
49 | 68 |
50 SkTypeface::Style fStyle; | 69 SkTypeface::Style fStyle; |
51 }; | 70 }; |
52 | 71 |
53 #endif // SkFontDescriptor_DEFINED | 72 #endif // SkFontDescriptor_DEFINED |
OLD | NEW |