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

Side by Side Diff: printing/pdf_metafile_cg_mac.h

Issue 2802093006: printing::Metafile: Simplify OS_MACOSX-specific code path (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PRINTING_PDF_METAFILE_CG_MAC_H_ 5 #ifndef PRINTING_PDF_METAFILE_CG_MAC_H_
6 #define PRINTING_PDF_METAFILE_CG_MAC_H_ 6 #define PRINTING_PDF_METAFILE_CG_MAC_H_
7 7
8 #include <ApplicationServices/ApplicationServices.h> 8 #include <stddef.h>
9 #include <CoreFoundation/CoreFoundation.h>
10 #include <stdint.h>
11 9
12 #include "base/mac/scoped_cftyperef.h" 10 #include "build/build_config.h"
Lei Zhang 2017/04/08 01:24:24 Not needed?
hal.canary 2017/04/11 19:07:27 I reverted most of this file. No longer applicab
13 #include "base/macros.h" 11 #include "printing/printing_export.h"
14 #include "printing/metafile.h"
15 12
16 namespace gfx { 13 struct CGRect;
17 class Rect; 14 typedef struct CGContext* CGContextRef;
Lei Zhang 2017/04/08 01:24:24 Can we use "using CGContextRef = struct CGContext*
hal.canary 2017/04/11 19:07:27 I reverted most of this file. No longer applicab
18 class Size;
19 }
20 15
21 namespace printing { 16 namespace printing {
22 17
23 // This class creates a graphics context that renders into a PDF data stream. 18 class PRINTING_EXPORT PdfMetafileCg {
24 class PRINTING_EXPORT PdfMetafileCg : public Metafile {
25 public: 19 public:
26 PdfMetafileCg(); 20 // |shrink_to_fit| specifies whether the output should be shrunk to fit a
27 ~PdfMetafileCg() override; 21 // destination page if the source PDF is bigger than the destination page in
28 22 // any dimension. If this is false, parts of the source PDF page that lie
29 // Metafile methods. 23 // outside the bounds will be clipped.
30 bool Init() override; 24 //
31 bool InitFromData(const void* src_buffer, size_t src_buffer_size) override; 25 // |stretch_to_fit| specifies whether the output should be stretched to fit
32 void StartPage(const gfx::Size& page_size, 26 // the destination page if the source page size is smaller in all dimensions.
33 const gfx::Rect& content_area, 27 //
34 const float& scale_factor) override; 28 // |center_horizontally| specifies whether the output (after any scaling is
35 bool FinishPage() override; 29 // done) should be centered horizontally within the destination page.
36 bool FinishDocument() override; 30 //
37 31 // |center_vertically| specifies whether the output (after any scaling is
38 uint32_t GetDataSize() const override; 32 // done) should be centered vertically within the destination page.
39 bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override; 33 // Note that all scaling preserves the original aspect ratio of the page.
40 34 //
41 gfx::Rect GetPageBounds(unsigned int page_number) const override; 35 // |autorotate| specifies whether the source PDF should be autorotated to fit
42 unsigned int GetPageCount() const override; 36 // on the destination page.
43 37 struct RenderPageParams {
44 // Note: The returned context *must not be retained* past Close(). If it is, 38 bool shrink_to_fit = false;
45 // the data returned from GetData will not be valid PDF data. 39 bool stretch_to_fit = false;
46 CGContextRef context() const override; 40 bool center_horizontally = false;
47 41 bool center_vertically = false;
48 bool RenderPage(unsigned int page_number, 42 bool autorotate = false;
49 skia::NativeDrawingContext context, 43 };
50 const CGRect rect, 44 // Renders the given page from src_buffer into |rect| in the given context.
Lei Zhang 2017/04/08 01:24:24 Refer to |src_buffer| consistently like other vari
hal.canary 2017/04/11 19:07:27 Done.
51 const MacRenderPageParams& params) const override; 45 // Pages use a 1-based index. The rendering uses the arguments in
52 46 // |params| to determine scaling, translation, and rotation.
53 private: 47 static bool RenderPage(const void* src_buffer,
Lei Zhang 2017/04/08 01:24:24 Change this to take: const std::vector& buffer, si
hal.canary 2017/04/11 19:07:27 Done.
54 // Returns a CGPDFDocumentRef version of |pdf_data_|. 48 size_t src_buffer_size,
55 CGPDFDocumentRef GetPDFDocument() const; 49 unsigned int page_number,
56 50 CGContextRef context,
57 // Context for rendering to the pdf. 51 const CGRect rect,
58 base::ScopedCFTypeRef<CGContextRef> context_; 52 const RenderPageParams& params);
59
60 // PDF backing store.
61 base::ScopedCFTypeRef<CFMutableDataRef> pdf_data_;
62
63 // Lazily-created CGPDFDocument representation of |pdf_data_|.
64 mutable base::ScopedCFTypeRef<CGPDFDocumentRef> pdf_doc_;
65
66 // Whether or not a page is currently open.
67 bool page_is_open_;
68
69 DISALLOW_COPY_AND_ASSIGN(PdfMetafileCg);
70 }; 53 };
71 54
72 } // namespace printing 55 } // namespace printing
73 56
74 #endif // PRINTING_PDF_METAFILE_CG_MAC_H_ 57 #endif // PRINTING_PDF_METAFILE_CG_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698