| 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'. */ | 
|---|
| 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 | } | 
|---|
| 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 | } | 
|---|
| 37 | bool hasStream() const { return fStream.get() != nullptr; } | 
|---|
| 38 | std::unique_ptr<SkStreamAsset> detachStream() { return std::move(fStream); } | 
|---|
| 39 | SkStreamAsset* getStream() { return fStream.get(); } | 
|---|
| 40 | SkStreamAsset const* getStream() const { return fStream.get(); } | 
|---|
| 41 | int getIndex() const { return fIndex; } | 
|---|
| 42 | int getAxisCount() const { return fAxisCount; } | 
|---|
| 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 |  | 
|---|
| 60 | SkFontStyle getStyle() const { return fStyle; } | 
|---|
| 61 | void setStyle(SkFontStyle style) { fStyle = style; } | 
|---|
| 62 |  | 
|---|
| 63 | const char* getFamilyName() const { return fFamilyName.c_str(); } | 
|---|
| 64 | const char* getFullName() const { return fFullName.c_str(); } | 
|---|
| 65 | const char* getPostscriptName() const { return fPostscriptName.c_str(); } | 
|---|
| 66 | bool hasFontData() const { return fFontData.get() != nullptr; } | 
|---|
| 67 | std::unique_ptr<SkFontData> detachFontData() { return std::move(fFontData); } | 
|---|
| 68 |  | 
|---|
| 69 | void setFamilyName(const char* name) { fFamilyName.set(name); } | 
|---|
| 70 | void setFullName(const char* name) { fFullName.set(name); } | 
|---|
| 71 | void setPostscriptName(const char* name) { fPostscriptName.set(name); } | 
|---|
| 72 | /** Set the font data only if it is necessary for serialization. */ | 
|---|
| 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 |  | 
|---|