Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: src/pdf/SkPDFDevice.h

Issue 1839633003: SkPDF: PDFDevice::ContentEntry now implemented with SinglyLinkedList (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-03-28 (Monday) 13:12:45 EDT Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/pdf.gypi ('k') | src/pdf/SkPDFDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 7
8 #ifndef SkPDFDevice_DEFINED 8 #ifndef SkPDFDevice_DEFINED
9 #define SkPDFDevice_DEFINED 9 #define SkPDFDevice_DEFINED
10 10
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
12 #include "SkBitmapKey.h" 12 #include "SkBitmapKey.h"
13 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkClipStack.h" 14 #include "SkClipStack.h"
15 #include "SkData.h" 15 #include "SkData.h"
16 #include "SkDevice.h" 16 #include "SkDevice.h"
17 #include "SkPaint.h" 17 #include "SkPaint.h"
18 #include "SkPath.h" 18 #include "SkPath.h"
19 #include "SkPicture.h" 19 #include "SkPicture.h"
20 #include "SkRect.h" 20 #include "SkRect.h"
21 #include "SkRefCnt.h" 21 #include "SkRefCnt.h"
22 #include "SkStream.h" 22 #include "SkStream.h"
23 #include "SkTDArray.h" 23 #include "SkTDArray.h"
24 #include "SkTemplates.h" 24 #include "SkTemplates.h"
25 25
26 #include "SkSinglyLinkedList.h"
27
26 class SkPDFArray; 28 class SkPDFArray;
27 class SkPDFCanon; 29 class SkPDFCanon;
28 class SkPDFDevice; 30 class SkPDFDevice;
29 class SkPDFDocument; 31 class SkPDFDocument;
30 class SkPDFDict; 32 class SkPDFDict;
31 class SkPDFFont; 33 class SkPDFFont;
32 class SkPDFFormXObject; 34 class SkPDFFormXObject;
33 class SkPDFGlyphSetMap; 35 class SkPDFGlyphSetMap;
34 class SkPDFGraphicState; 36 class SkPDFGraphicState;
35 class SkPDFObject; 37 class SkPDFObject;
36 class SkPDFShader; 38 class SkPDFShader;
37 class SkPDFStream; 39 class SkPDFStream;
38 class SkRRect; 40 class SkRRect;
39 41
40 // Private classes.
41 struct ContentEntry;
42 struct GraphicStateEntry;
43
44 /** \class SkPDFDevice 42 /** \class SkPDFDevice
45 43
46 The drawing context for the PDF backend. 44 The drawing context for the PDF backend.
47 */ 45 */
48 class SkPDFDevice final : public SkBaseDevice { 46 class SkPDFDevice final : public SkBaseDevice {
49 public: 47 public:
50 /** Create a PDF drawing context. SkPDFDevice applies a 48 /** Create a PDF drawing context. SkPDFDevice applies a
51 * scale-and-translate transform to move the origin from the 49 * scale-and-translate transform to move the origin from the
52 * bottom left (PDF default) to the top left (Skia default). 50 * bottom left (PDF default) to the top left (Skia default).
53 * @param pageSize Page size in point units. 51 * @param pageSize Page size in point units.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 166
169 /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font 167 /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font
170 * that shows on this device. 168 * that shows on this device.
171 */ 169 */
172 const SkPDFGlyphSetMap& getFontGlyphUsage() const { 170 const SkPDFGlyphSetMap& getFontGlyphUsage() const {
173 return *(fFontGlyphUsage.get()); 171 return *(fFontGlyphUsage.get());
174 } 172 }
175 173
176 SkPDFCanon* getCanon() const; 174 SkPDFCanon* getCanon() const;
177 175
176 // It is important to not confuse GraphicStateEntry with SkPDFGraphicState, the
177 // later being our representation of an object in the PDF file.
178 struct GraphicStateEntry {
179 GraphicStateEntry();
180
181 // Compare the fields we care about when setting up a new content entry.
182 bool compareInitialState(const GraphicStateEntry& b);
183
184 SkMatrix fMatrix;
185 // We can't do set operations on Paths, though PDF natively supports
186 // intersect. If the clip stack does anything other than intersect,
187 // we have to fall back to the region. Treat fClipStack as authoritativ e.
188 // See https://bugs.skia.org/221
189 SkClipStack fClipStack;
190 SkRegion fClipRegion;
191
192 // When emitting the content entry, we will ensure the graphic state
193 // is set to these values first.
194 SkColor fColor;
195 SkScalar fTextScaleX; // Zero means we don't care what the value is.
196 SkPaint::Style fTextFill; // Only if TextScaleX is non-zero.
197 int fShaderIndex;
198 int fGraphicStateIndex;
199
200 // We may change the font (i.e. for Type1 support) within a
201 // ContentEntry. This is the one currently in effect, or nullptr if non e.
202 SkPDFFont* fFont;
203 // In PDF, text size has no default value. It is only valid if fFont is
204 // not nullptr.
205 SkScalar fTextSize;
206 };
207
178 protected: 208 protected:
179 const SkBitmap& onAccessBitmap() override { 209 const SkBitmap& onAccessBitmap() override {
180 return fLegacyBitmap; 210 return fLegacyBitmap;
181 } 211 }
182 212
183 sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) over ride; 213 sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) over ride;
184 214
185 void drawAnnotation(const SkDraw&, const SkRect&, const char key[], SkData* value) override; 215 void drawAnnotation(const SkDraw&, const SkRect&, const char key[], SkData* value) override;
186 216
187 private: 217 private:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 255
226 SkTArray<RectWithData> fLinkToURLs; 256 SkTArray<RectWithData> fLinkToURLs;
227 SkTArray<RectWithData> fLinkToDestinations; 257 SkTArray<RectWithData> fLinkToDestinations;
228 SkTArray<NamedDestination> fNamedDestinations; 258 SkTArray<NamedDestination> fNamedDestinations;
229 259
230 SkTDArray<SkPDFObject*> fGraphicStateResources; 260 SkTDArray<SkPDFObject*> fGraphicStateResources;
231 SkTDArray<SkPDFObject*> fXObjectResources; 261 SkTDArray<SkPDFObject*> fXObjectResources;
232 SkTDArray<SkPDFFont*> fFontResources; 262 SkTDArray<SkPDFFont*> fFontResources;
233 SkTDArray<SkPDFObject*> fShaderResources; 263 SkTDArray<SkPDFObject*> fShaderResources;
234 264
235 std::unique_ptr<ContentEntry> fContentEntries; 265 struct ContentEntry {
236 ContentEntry* fLastContentEntry; 266 GraphicStateEntry fState;
267 SkDynamicMemoryWStream fContent;
268 };
269 SkSinglyLinkedList<ContentEntry> fContentEntries;
237 270
238 const SkClipStack* fClipStack; 271 const SkClipStack* fClipStack;
239 272
240 // Glyph ids used for each font on this device. 273 // Glyph ids used for each font on this device.
241 std::unique_ptr<SkPDFGlyphSetMap> fFontGlyphUsage; 274 std::unique_ptr<SkPDFGlyphSetMap> fFontGlyphUsage;
242 275
243 SkScalar fRasterDpi; 276 SkScalar fRasterDpi;
244 277
245 SkBitmap fLegacyBitmap; 278 SkBitmap fLegacyBitmap;
246 279
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 int getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID); 326 int getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID);
294 327
295 void internalDrawPaint(const SkPaint& paint, ContentEntry* contentEntry); 328 void internalDrawPaint(const SkPaint& paint, ContentEntry* contentEntry);
296 329
297 void internalDrawImage(const SkMatrix& origMatrix, 330 void internalDrawImage(const SkMatrix& origMatrix,
298 const SkClipStack* clipStack, 331 const SkClipStack* clipStack,
299 const SkRegion& origClipRegion, 332 const SkRegion& origClipRegion,
300 SkImageBitmap imageBitmap, 333 SkImageBitmap imageBitmap,
301 const SkPaint& paint); 334 const SkPaint& paint);
302 335
303 /** Helper method for copyContentToData. It is responsible for copying the
304 * list of content entries |entry| to |data|.
305 */
306 void copyContentEntriesToData(ContentEntry* entry, SkWStream* data) const;
307
308 bool handleInversePath(const SkDraw& d, const SkPath& origPath, 336 bool handleInversePath(const SkDraw& d, const SkPath& origPath,
309 const SkPaint& paint, bool pathIsMutable, 337 const SkPaint& paint, bool pathIsMutable,
310 const SkMatrix* prePathMatrix = nullptr); 338 const SkMatrix* prePathMatrix = nullptr);
311 void handlePointAnnotation(const SkPoint&, const SkMatrix&, const char key[] , SkData* value); 339 void handlePointAnnotation(const SkPoint&, const SkMatrix&, const char key[] , SkData* value);
312 void handlePathAnnotation(const SkPath&, const SkDraw& d, const char key[], SkData* value); 340 void handlePathAnnotation(const SkPath&, const SkDraw& d, const char key[], SkData* value);
313 341
314 typedef SkBaseDevice INHERITED; 342 typedef SkBaseDevice INHERITED;
315 343
316 // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to create 344 // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to create
317 // an SkPDFDevice 345 // an SkPDFDevice
318 //friend class SkDocument_PDF; 346 //friend class SkDocument_PDF;
319 //friend class SkPDFImageShader; 347 //friend class SkPDFImageShader;
320 }; 348 };
321 349
322 #endif 350 #endif
OLDNEW
« no previous file with comments | « gyp/pdf.gypi ('k') | src/pdf/SkPDFDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698