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" |
11 #include "SkPDFShader.h" | 11 #include "SkPDFShader.h" |
12 #include "SkPixelSerializer.h" | 12 #include "SkPixelSerializer.h" |
13 #include "SkTDArray.h" | 13 #include "SkTDArray.h" |
14 #include "SkTHash.h" | 14 #include "SkTHash.h" |
15 #include "SkBitmapKey.h" | 15 #include "SkBitmapKey.h" |
16 | 16 |
| 17 class SkAdvancedTypefaceMetrics; |
17 class SkPDFFont; | 18 class SkPDFFont; |
18 | 19 |
19 /** | 20 /** |
20 * The SkPDFCanon canonicalizes objects across PDF pages | 21 * The SkPDFCanon canonicalizes objects across PDF pages |
21 * (SkPDFDevices) and across draw calls. | 22 * (SkPDFDevices) and across draw calls. |
22 * | 23 * |
23 * The PDF backend works correctly if: | 24 * The PDF backend works correctly if: |
24 * - There is no more than one SkPDFCanon for each thread. | 25 * - There is no more than one SkPDFCanon for each thread. |
25 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation. | 26 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation. |
26 * - All SkPDFDevices in a document share the same SkPDFCanon. | 27 * - All SkPDFDevices in a document share the same SkPDFCanon. |
27 * The SkPDFDocument class makes this happen by owning a single | 28 * The SkPDFDocument class makes this happen by owning a single |
28 * SkPDFCanon. | 29 * SkPDFCanon. |
29 * | 30 * |
30 * The addFoo() methods will ref the Foo; the canon's destructor will | 31 * The addFoo() methods will ref the Foo; the canon's destructor will |
31 * call foo->unref() on all of these objects. | 32 * call foo->unref() on all of these objects. |
32 * | 33 * |
33 * The findFoo() methods do not change the ref count of the Foo | 34 * The findFoo() methods do not change the ref count of the Foo |
34 * objects. | 35 * objects. |
35 */ | 36 */ |
36 class SkPDFCanon : SkNoncopyable { | 37 class SkPDFCanon : SkNoncopyable { |
37 public: | 38 public: |
38 ~SkPDFCanon() { this->reset(); } | 39 ~SkPDFCanon(); |
39 | 40 |
40 // reset to original setting, unrefs all objects. | 41 // reset to original setting, unrefs all objects. |
41 void reset(); | 42 void reset(); |
42 | 43 |
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 | |
45 // still return nullptr, but also set *relatedFont. | |
46 SkPDFFont* findFont(uint32_t fontID, | |
47 uint16_t glyphID, | |
48 SkPDFFont** relatedFont) const; | |
49 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); | |
50 | |
51 sk_sp<SkPDFObject> findFunctionShader(const SkPDFShader::State&) const; | 44 sk_sp<SkPDFObject> findFunctionShader(const SkPDFShader::State&) const; |
52 void addFunctionShader(sk_sp<SkPDFObject>, SkPDFShader::State); | 45 void addFunctionShader(sk_sp<SkPDFObject>, SkPDFShader::State); |
53 | 46 |
54 sk_sp<SkPDFObject> findAlphaShader(const SkPDFShader::State&) const; | 47 sk_sp<SkPDFObject> findAlphaShader(const SkPDFShader::State&) const; |
55 void addAlphaShader(sk_sp<SkPDFObject>, SkPDFShader::State); | 48 void addAlphaShader(sk_sp<SkPDFObject>, SkPDFShader::State); |
56 | 49 |
57 sk_sp<SkPDFObject> findImageShader(const SkPDFShader::State&) const; | 50 sk_sp<SkPDFObject> findImageShader(const SkPDFShader::State&) const; |
58 void addImageShader(sk_sp<SkPDFObject>, SkPDFShader::State); | 51 void addImageShader(sk_sp<SkPDFObject>, SkPDFShader::State); |
59 | 52 |
60 const SkPDFGraphicState* findGraphicState(const SkPDFGraphicState&) const; | 53 const SkPDFGraphicState* findGraphicState(const SkPDFGraphicState&) const; |
61 void addGraphicState(const SkPDFGraphicState*); | 54 void addGraphicState(const SkPDFGraphicState*); |
62 | 55 |
63 sk_sp<SkPDFObject> findPDFBitmap(SkBitmapKey key) const; | 56 sk_sp<SkPDFObject> findPDFBitmap(SkBitmapKey key) const; |
64 void addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject>); | 57 void addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject>); |
65 | 58 |
66 SkTHashMap<uint32_t, bool> fCanEmbedTypeface; | 59 SkTHashMap<uint32_t, SkAdvancedTypefaceMetrics*> fTypefaceMetrics; |
| 60 SkTHashMap<uint32_t, SkPDFDict*> fFontDescriptors; |
| 61 SkTHashMap<uint64_t, SkPDFFont*> fFontMap; |
67 | 62 |
68 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get(
); } | 63 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get(
); } |
69 void setPixelSerializer(sk_sp<SkPixelSerializer> ps) { | 64 void setPixelSerializer(sk_sp<SkPixelSerializer> ps) { |
70 fPixelSerializer = std::move(ps); | 65 fPixelSerializer = std::move(ps); |
71 } | 66 } |
72 | 67 |
73 sk_sp<SkPDFStream> makeInvertFunction(); | 68 sk_sp<SkPDFStream> makeInvertFunction(); |
74 sk_sp<SkPDFDict> makeNoSmaskGraphicState(); | 69 sk_sp<SkPDFDict> makeNoSmaskGraphicState(); |
75 sk_sp<SkPDFArray> makeRangeObject(); | 70 sk_sp<SkPDFArray> makeRangeObject(); |
76 | 71 |
77 private: | 72 private: |
78 struct FontRec { | |
79 SkPDFFont* fFont; | |
80 uint32_t fFontID; | |
81 uint16_t fGlyphID; | |
82 }; | |
83 SkTDArray<FontRec> fFontRecords; | |
84 | |
85 struct ShaderRec { | 73 struct ShaderRec { |
86 SkPDFShader::State fShaderState; | 74 SkPDFShader::State fShaderState; |
87 sk_sp<SkPDFObject> fShaderObject; | 75 sk_sp<SkPDFObject> fShaderObject; |
88 ShaderRec(SkPDFShader::State s, sk_sp<SkPDFObject> o) | 76 ShaderRec(SkPDFShader::State s, sk_sp<SkPDFObject> o) |
89 : fShaderState(std::move(s)), fShaderObject(std::move(o)) {} | 77 : fShaderState(std::move(s)), fShaderObject(std::move(o)) {} |
90 }; | 78 }; |
91 SkTArray<ShaderRec> fFunctionShaderRecords; | 79 SkTArray<ShaderRec> fFunctionShaderRecords; |
92 SkTArray<ShaderRec> fAlphaShaderRecords; | 80 SkTArray<ShaderRec> fAlphaShaderRecords; |
93 SkTArray<ShaderRec> fImageShaderRecords; | 81 SkTArray<ShaderRec> fImageShaderRecords; |
94 | 82 |
(...skipping 16 matching lines...) Expand all Loading... |
111 | 99 |
112 // TODO(halcanary): make SkTHashMap<K, sk_sp<V>> work correctly. | 100 // TODO(halcanary): make SkTHashMap<K, sk_sp<V>> work correctly. |
113 SkTHashMap<SkBitmapKey, SkPDFObject*> fPDFBitmapMap; | 101 SkTHashMap<SkBitmapKey, SkPDFObject*> fPDFBitmapMap; |
114 | 102 |
115 sk_sp<SkPixelSerializer> fPixelSerializer; | 103 sk_sp<SkPixelSerializer> fPixelSerializer; |
116 sk_sp<SkPDFStream> fInvertFunction; | 104 sk_sp<SkPDFStream> fInvertFunction; |
117 sk_sp<SkPDFDict> fNoSmaskGraphicState; | 105 sk_sp<SkPDFDict> fNoSmaskGraphicState; |
118 sk_sp<SkPDFArray> fRangeObject; | 106 sk_sp<SkPDFArray> fRangeObject; |
119 }; | 107 }; |
120 #endif // SkPDFCanon_DEFINED | 108 #endif // SkPDFCanon_DEFINED |
OLD | NEW |