djsollen@google.com | 9714516 | 2012-05-31 19:55:08 +0000 | [diff] [blame] | 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 | |
djsollen@google.com | 9714516 | 2012-05-31 19:55:08 +0000 | [diff] [blame] | 8 | #ifndef SkFontDescriptor_DEFINED |
| 9 | #define SkFontDescriptor_DEFINED |
| 10 | |
bungeman | d71b757 | 2014-09-18 10:55:32 -0700 | [diff] [blame] | 11 | #include "SkStream.h" |
djsollen@google.com | 9714516 | 2012-05-31 19:55:08 +0000 | [diff] [blame] | 12 | #include "SkString.h" |
| 13 | #include "SkTypeface.h" |
| 14 | |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 15 | class SkFontData { |
| 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 axisCount) |
| 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 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 35 | bool hasStream() const { return fStream.get() != nullptr; } |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 36 | SkStreamAsset* duplicateStream() const { return fStream->duplicate(); } |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame^] | 37 | SkStreamAsset* detachStream() { return fStream.release(); } |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 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 { |
djsollen@google.com | 9714516 | 2012-05-31 19:55:08 +0000 | [diff] [blame] | 51 | public: |
reed@google.com | 3b700f6 | 2012-05-31 21:16:48 +0000 | [diff] [blame] | 52 | SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal); |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 53 | // Does not affect ownership of SkStream. |
robertphillips | 3552ba1 | 2016-02-25 10:58:49 -0800 | [diff] [blame] | 54 | static bool Deserialize(SkStream*, SkFontDescriptor* result); |
djsollen@google.com | 9714516 | 2012-05-31 19:55:08 +0000 | [diff] [blame] | 55 | |
| 56 | void serialize(SkWStream*); |
| 57 | |
reed@google.com | 3b700f6 | 2012-05-31 21:16:48 +0000 | [diff] [blame] | 58 | SkTypeface::Style getStyle() { return fStyle; } |
| 59 | void setStyle(SkTypeface::Style style) { fStyle = style; } |
| 60 | |
bungeman | d71b757 | 2014-09-18 10:55:32 -0700 | [diff] [blame] | 61 | const char* getFamilyName() const { return fFamilyName.c_str(); } |
| 62 | const char* getFullName() const { return fFullName.c_str(); } |
| 63 | const char* getPostscriptName() const { return fPostscriptName.c_str(); } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 64 | bool hasFontData() const { return fFontData.get() != nullptr; } |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame^] | 65 | SkFontData* detachFontData() { return fFontData.release(); } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 66 | |
reed@google.com | 3b700f6 | 2012-05-31 21:16:48 +0000 | [diff] [blame] | 67 | void setFamilyName(const char* name) { fFamilyName.set(name); } |
| 68 | void setFullName(const char* name) { fFullName.set(name); } |
| 69 | void setPostscriptName(const char* name) { fPostscriptName.set(name); } |
bungeman | d71b757 | 2014-09-18 10:55:32 -0700 | [diff] [blame] | 70 | /** Set the font data only if it is necessary for serialization. |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 71 | * This method takes ownership of the font data. */ |
| 72 | void setFontData(SkFontData* data) { fFontData.reset(data); } |
djsollen@google.com | 9714516 | 2012-05-31 19:55:08 +0000 | [diff] [blame] | 73 | |
djsollen@google.com | 9714516 | 2012-05-31 19:55:08 +0000 | [diff] [blame] | 74 | private: |
reed@google.com | 3b700f6 | 2012-05-31 21:16:48 +0000 | [diff] [blame] | 75 | SkString fFamilyName; |
| 76 | SkString fFullName; |
| 77 | SkString fPostscriptName; |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 78 | SkAutoTDelete<SkFontData> fFontData; |
reed@google.com | 3b700f6 | 2012-05-31 21:16:48 +0000 | [diff] [blame] | 79 | |
| 80 | SkTypeface::Style fStyle; |
djsollen@google.com | 9714516 | 2012-05-31 19:55:08 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | #endif // SkFontDescriptor_DEFINED |