• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 #ifndef SkPDFCanon_DEFINED
8 #define SkPDFCanon_DEFINED
9 
10 #include "SkBitmapKey.h"
11 #include "SkPDFGradientShader.h"
12 #include "SkPDFGraphicState.h"
13 #include "SkPDFShader.h"
14 #include "SkPixelSerializer.h"
15 #include "SkTDArray.h"
16 #include "SkTHash.h"
17 #include "SkTypeface.h"
18 
19 class SkPDFFont;
20 struct SkAdvancedTypefaceMetrics;
21 
22 /**
23  *  The SkPDFCanon canonicalizes objects across PDF pages
24  *  (SkPDFDevices) and across draw calls.
25  */
26 class SkPDFCanon {
27 public:
28     ~SkPDFCanon();
29     SkPDFCanon();
30     SkPDFCanon(const SkPDFCanon&) = delete;
31     SkPDFCanon& operator=(const SkPDFCanon&) = delete;
32 
33     SkTHashMap<SkPDFImageShaderKey, sk_sp<SkPDFObject>> fImageShaderMap;
34 
35     SkPDFGradientShader::HashMap fGradientPatternMap;
36 
37     SkTHashMap<SkBitmapKey, sk_sp<SkPDFObject>> fPDFBitmapMap;
38 
39     SkTHashMap<uint32_t, std::unique_ptr<SkAdvancedTypefaceMetrics>> fTypefaceMetrics;
40     SkTHashMap<uint32_t, sk_sp<SkPDFDict>> fFontDescriptors;
41     SkTHashMap<uint64_t, sk_sp<SkPDFFont>> fFontMap;
42 
43     SkTHashMap<SkPDFStrokeGraphicState, sk_sp<SkPDFDict>> fStrokeGSMap;
44     SkTHashMap<SkPDFFillGraphicState, sk_sp<SkPDFDict>> fFillGSMap;
45 
46     sk_sp<SkPixelSerializer> fPixelSerializer;
47     sk_sp<SkPDFStream> fInvertFunction;
48     sk_sp<SkPDFDict> fNoSmaskGraphicState;
49     sk_sp<SkPDFArray> fRangeObject;
50 
51     SK_BEGIN_REQUIRE_DENSE
52     struct BitmapGlyphKey {
53         SkFontID fFontID;      // uint32_t
54         SkScalar fTextSize;    // float32
55         SkScalar fTextScaleX;  // float32
56         SkScalar fTextSkewX;   // float32
57         SkGlyphID fGlyphID;    // uint16_t
58         uint16_t fPadding;
59     };
60     SK_END_REQUIRE_DENSE
61     struct BitmapGlyph {
62         sk_sp<SkImage> fImage;
63         SkIPoint fOffset;
64     };
65     SkTHashMap<BitmapGlyphKey, BitmapGlyph> fBitmapGlyphImages;
66 };
67 
68 inline bool operator==(const SkPDFCanon::BitmapGlyphKey& u, const SkPDFCanon::BitmapGlyphKey& v) {
69     return memcmp(&u, &u, sizeof(SkPDFCanon::BitmapGlyphKey)) == 0;
70 }
71 #endif  // SkPDFCanon_DEFINED
72