OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #ifndef SkPDFCanon_DEFINED | 7 #ifndef SkPDFCanon_DEFINED |
8 #define SkPDFCanon_DEFINED | 8 #define SkPDFCanon_DEFINED |
9 | 9 |
10 #include "SkPDFGraphicState.h" | 10 #include "SkPDFGraphicState.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 void reset(); | 41 void reset(); |
42 | 42 |
43 // Returns exact match if there is one. If not, it returns nullptr. | 43 // Returns exact match if there is one. If not, it returns nullptr. |
44 // If there is no exact match, but there is a related font, we | 44 // If there is no exact match, but there is a related font, we |
45 // still return nullptr, but also set *relatedFont. | 45 // still return nullptr, but also set *relatedFont. |
46 SkPDFFont* findFont(uint32_t fontID, | 46 SkPDFFont* findFont(uint32_t fontID, |
47 uint16_t glyphID, | 47 uint16_t glyphID, |
48 SkPDFFont** relatedFont) const; | 48 SkPDFFont** relatedFont) const; |
49 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); | 49 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); |
50 | 50 |
51 SkPDFFunctionShader* findFunctionShader(const SkPDFShader::State&) const; | 51 sk_sp<SkPDFObject> findFunctionShader(const SkPDFShader::State&) const; |
52 void addFunctionShader(SkPDFFunctionShader*); | 52 void addFunctionShader(sk_sp<SkPDFObject>, SkPDFShader::State); |
53 | 53 |
54 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const; | 54 sk_sp<SkPDFObject> findAlphaShader(const SkPDFShader::State&) const; |
55 void addAlphaShader(SkPDFAlphaFunctionShader*); | 55 void addAlphaShader(sk_sp<SkPDFObject>, SkPDFShader::State); |
56 | 56 |
57 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const; | 57 sk_sp<SkPDFObject> findImageShader(const SkPDFShader::State&) const; |
58 void addImageShader(SkPDFImageShader*); | 58 void addImageShader(sk_sp<SkPDFObject>, SkPDFShader::State); |
59 | 59 |
60 const SkPDFGraphicState* findGraphicState(const SkPDFGraphicState&) const; | 60 const SkPDFGraphicState* findGraphicState(const SkPDFGraphicState&) const; |
61 void addGraphicState(const SkPDFGraphicState*); | 61 void addGraphicState(const SkPDFGraphicState*); |
62 | 62 |
63 sk_sp<SkPDFObject> findPDFBitmap(SkBitmapKey key) const; | 63 sk_sp<SkPDFObject> findPDFBitmap(SkBitmapKey key) const; |
64 void addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject>); | 64 void addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject>); |
65 | 65 |
66 SkTHashMap<uint32_t, bool> fCanEmbedTypeface; | 66 SkTHashMap<uint32_t, bool> fCanEmbedTypeface; |
67 | 67 |
68 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get(
); } | 68 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get(
); } |
69 void setPixelSerializer(sk_sp<SkPixelSerializer> ps) { | 69 void setPixelSerializer(sk_sp<SkPixelSerializer> ps) { |
70 fPixelSerializer = std::move(ps); | 70 fPixelSerializer = std::move(ps); |
71 } | 71 } |
72 | 72 |
73 sk_sp<SkPDFStream> makeInvertFunction(); | 73 sk_sp<SkPDFStream> makeInvertFunction(); |
74 sk_sp<SkPDFDict> makeNoSmaskGraphicState(); | 74 sk_sp<SkPDFDict> makeNoSmaskGraphicState(); |
75 sk_sp<SkPDFArray> makeRangeObject(); | 75 sk_sp<SkPDFArray> makeRangeObject(); |
76 | 76 |
77 private: | 77 private: |
78 struct FontRec { | 78 struct FontRec { |
79 SkPDFFont* fFont; | 79 SkPDFFont* fFont; |
80 uint32_t fFontID; | 80 uint32_t fFontID; |
81 uint16_t fGlyphID; | 81 uint16_t fGlyphID; |
82 }; | 82 }; |
83 SkTDArray<FontRec> fFontRecords; | 83 SkTDArray<FontRec> fFontRecords; |
84 | 84 |
85 SkTDArray<SkPDFFunctionShader*> fFunctionShaderRecords; | 85 struct ShaderRec { |
86 | 86 SkPDFShader::State fShaderState; |
87 SkTDArray<SkPDFAlphaFunctionShader*> fAlphaShaderRecords; | 87 sk_sp<SkPDFObject> fShaderObject; |
88 | 88 ShaderRec(SkPDFShader::State s, sk_sp<SkPDFObject> o) |
89 SkTDArray<SkPDFImageShader*> fImageShaderRecords; | 89 : fShaderState(std::move(s)), fShaderObject(std::move(o)) {} |
| 90 }; |
| 91 SkTArray<ShaderRec> fFunctionShaderRecords; |
| 92 SkTArray<ShaderRec> fAlphaShaderRecords; |
| 93 SkTArray<ShaderRec> fImageShaderRecords; |
90 | 94 |
91 struct WrapGS { | 95 struct WrapGS { |
92 explicit WrapGS(const SkPDFGraphicState* ptr = nullptr) : fPtr(ptr) {} | 96 explicit WrapGS(const SkPDFGraphicState* ptr = nullptr) : fPtr(ptr) {} |
93 const SkPDFGraphicState* fPtr; | 97 const SkPDFGraphicState* fPtr; |
94 bool operator==(const WrapGS& rhs) const { | 98 bool operator==(const WrapGS& rhs) const { |
95 SkASSERT(fPtr); | 99 SkASSERT(fPtr); |
96 SkASSERT(rhs.fPtr); | 100 SkASSERT(rhs.fPtr); |
97 return *fPtr == *rhs.fPtr; | 101 return *fPtr == *rhs.fPtr; |
98 } | 102 } |
99 struct Hash { | 103 struct Hash { |
100 uint32_t operator()(const WrapGS& w) const { | 104 uint32_t operator()(const WrapGS& w) const { |
101 SkASSERT(w.fPtr); | 105 SkASSERT(w.fPtr); |
102 return w.fPtr->hash(); | 106 return w.fPtr->hash(); |
103 } | 107 } |
104 }; | 108 }; |
105 }; | 109 }; |
106 SkTHashSet<WrapGS, WrapGS::Hash> fGraphicStateRecords; | 110 SkTHashSet<WrapGS, WrapGS::Hash> fGraphicStateRecords; |
107 | 111 |
108 // TODO(halcanary): make SkTHashMap<K, sk_sp<V>> work correctly. | 112 // TODO(halcanary): make SkTHashMap<K, sk_sp<V>> work correctly. |
109 SkTHashMap<SkBitmapKey, SkPDFObject*> fPDFBitmapMap; | 113 SkTHashMap<SkBitmapKey, SkPDFObject*> fPDFBitmapMap; |
110 | 114 |
111 sk_sp<SkPixelSerializer> fPixelSerializer; | 115 sk_sp<SkPixelSerializer> fPixelSerializer; |
112 sk_sp<SkPDFStream> fInvertFunction; | 116 sk_sp<SkPDFStream> fInvertFunction; |
113 sk_sp<SkPDFDict> fNoSmaskGraphicState; | 117 sk_sp<SkPDFDict> fNoSmaskGraphicState; |
114 sk_sp<SkPDFArray> fRangeObject; | 118 sk_sp<SkPDFArray> fRangeObject; |
115 }; | 119 }; |
116 #endif // SkPDFCanon_DEFINED | 120 #endif // SkPDFCanon_DEFINED |
OLD | NEW |