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