OLD | NEW |
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_EMF_WIN_H_ | 5 #ifndef PRINTING_EMF_WIN_H_ |
6 #define PRINTING_EMF_WIN_H_ | 6 #define PRINTING_EMF_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "printing/metafile.h" | 15 #include "printing/metafile.h" |
16 | 16 |
| 17 namespace base { |
17 class FilePath; | 18 class FilePath; |
| 19 } |
18 | 20 |
19 namespace gfx { | 21 namespace gfx { |
20 class Rect; | 22 class Rect; |
21 class Size; | 23 class Size; |
22 } | 24 } |
23 | 25 |
24 namespace printing { | 26 namespace printing { |
25 | 27 |
26 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx | 28 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx |
27 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350 | 29 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350 |
28 // MB, it can fail to print and not send an error message. | 30 // MB, it can fail to print and not send an error message. |
29 const size_t kMetafileMaxSize = 350*1024*1024; | 31 const size_t kMetafileMaxSize = 350*1024*1024; |
30 | 32 |
31 // Simple wrapper class that manage an EMF data stream and its virtual HDC. | 33 // Simple wrapper class that manage an EMF data stream and its virtual HDC. |
32 class PRINTING_EXPORT Emf : public Metafile { | 34 class PRINTING_EXPORT Emf : public Metafile { |
33 public: | 35 public: |
34 class Record; | 36 class Record; |
35 class Enumerator; | 37 class Enumerator; |
36 struct EnumerationContext; | 38 struct EnumerationContext; |
37 | 39 |
38 // Generates a virtual HDC that will record every GDI commands and compile | 40 // Generates a virtual HDC that will record every GDI commands and compile |
39 // it in a EMF data stream. | 41 // it in a EMF data stream. |
40 Emf(); | 42 Emf(); |
41 virtual ~Emf(); | 43 virtual ~Emf(); |
42 | 44 |
43 // Generates a new metafile that will record every GDI command, and will | 45 // Generates a new metafile that will record every GDI command, and will |
44 // be saved to |metafile_path|. | 46 // be saved to |metafile_path|. |
45 virtual bool InitToFile(const FilePath& metafile_path); | 47 virtual bool InitToFile(const base::FilePath& metafile_path); |
46 | 48 |
47 // Initializes the Emf with the data in |metafile_path|. | 49 // Initializes the Emf with the data in |metafile_path|. |
48 virtual bool InitFromFile(const FilePath& metafile_path); | 50 virtual bool InitFromFile(const base::FilePath& metafile_path); |
49 | 51 |
50 // Metafile methods. | 52 // Metafile methods. |
51 virtual bool Init() OVERRIDE; | 53 virtual bool Init() OVERRIDE; |
52 virtual bool InitFromData(const void* src_buffer, | 54 virtual bool InitFromData(const void* src_buffer, |
53 uint32 src_buffer_size) OVERRIDE; | 55 uint32 src_buffer_size) OVERRIDE; |
54 | 56 |
55 virtual SkDevice* StartPageForVectorCanvas( | 57 virtual SkDevice* StartPageForVectorCanvas( |
56 const gfx::Size& page_size, const gfx::Rect& content_area, | 58 const gfx::Size& page_size, const gfx::Rect& content_area, |
57 const float& scale_factor) OVERRIDE; | 59 const float& scale_factor) OVERRIDE; |
58 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls | 60 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls |
59 // (since StartPage and EndPage do not work in a metafile DC). Only valid | 61 // (since StartPage and EndPage do not work in a metafile DC). Only valid |
60 // when hdc_ is non-NULL. |page_size|, |content_area|, and |scale_factor| are | 62 // when hdc_ is non-NULL. |page_size|, |content_area|, and |scale_factor| are |
61 // ignored. | 63 // ignored. |
62 virtual bool StartPage(const gfx::Size& page_size, | 64 virtual bool StartPage(const gfx::Size& page_size, |
63 const gfx::Rect& content_area, | 65 const gfx::Rect& content_area, |
64 const float& scale_factor) OVERRIDE; | 66 const float& scale_factor) OVERRIDE; |
65 virtual bool FinishPage() OVERRIDE; | 67 virtual bool FinishPage() OVERRIDE; |
66 virtual bool FinishDocument() OVERRIDE; | 68 virtual bool FinishDocument() OVERRIDE; |
67 | 69 |
68 virtual uint32 GetDataSize() const OVERRIDE; | 70 virtual uint32 GetDataSize() const OVERRIDE; |
69 virtual bool GetData(void* buffer, uint32 size) const OVERRIDE; | 71 virtual bool GetData(void* buffer, uint32 size) const OVERRIDE; |
70 | 72 |
71 // Saves the EMF data to a file as-is. It is recommended to use the .emf file | 73 // Saves the EMF data to a file as-is. It is recommended to use the .emf file |
72 // extension but it is not enforced. This function synchronously writes to the | 74 // extension but it is not enforced. This function synchronously writes to the |
73 // file. For testing only. | 75 // file. For testing only. |
74 virtual bool SaveTo(const FilePath& file_path) const OVERRIDE; | 76 virtual bool SaveTo(const base::FilePath& file_path) const OVERRIDE; |
75 | 77 |
76 // Should be passed to Playback to keep the exact same size. | 78 // Should be passed to Playback to keep the exact same size. |
77 virtual gfx::Rect GetPageBounds(unsigned int page_number) const OVERRIDE; | 79 virtual gfx::Rect GetPageBounds(unsigned int page_number) const OVERRIDE; |
78 | 80 |
79 virtual unsigned int GetPageCount() const OVERRIDE { | 81 virtual unsigned int GetPageCount() const OVERRIDE { |
80 return page_count_; | 82 return page_count_; |
81 } | 83 } |
82 | 84 |
83 virtual HDC context() const OVERRIDE { | 85 virtual HDC context() const OVERRIDE { |
84 return hdc_; | 86 return hdc_; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 std::vector<Record> items_; | 198 std::vector<Record> items_; |
197 | 199 |
198 EnumerationContext context_; | 200 EnumerationContext context_; |
199 | 201 |
200 DISALLOW_COPY_AND_ASSIGN(Enumerator); | 202 DISALLOW_COPY_AND_ASSIGN(Enumerator); |
201 }; | 203 }; |
202 | 204 |
203 } // namespace printing | 205 } // namespace printing |
204 | 206 |
205 #endif // PRINTING_EMF_WIN_H_ | 207 #endif // PRINTING_EMF_WIN_H_ |
OLD | NEW |