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

Side by Side Diff: printing/pdf_metafile_skia.cc

Issue 10702144: roll skia to 4552 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « DEPS ('k') | skia/skia.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "printing/pdf_metafile_skia.h" 5 #include "printing/pdf_metafile_skia.h"
6 6
7 #include "base/eintr_wrapper.h" 7 #include "base/eintr_wrapper.h"
8 #include "base/file_descriptor_posix.h" 8 #include "base/file_descriptor_posix.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 uint32 PdfMetafileSkia::GetDataSize() const { 112 uint32 PdfMetafileSkia::GetDataSize() const {
113 return data_->pdf_stream_.getOffset(); 113 return data_->pdf_stream_.getOffset();
114 } 114 }
115 115
116 bool PdfMetafileSkia::GetData(void* dst_buffer, 116 bool PdfMetafileSkia::GetData(void* dst_buffer,
117 uint32 dst_buffer_size) const { 117 uint32 dst_buffer_size) const {
118 if (dst_buffer_size < GetDataSize()) 118 if (dst_buffer_size < GetDataSize())
119 return false; 119 return false;
120 120
121 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); 121 SkAutoDataUnref data(data_->pdf_stream_.copyToData());
122 memcpy(dst_buffer, data.bytes(), dst_buffer_size); 122 memcpy(dst_buffer, data->bytes(), dst_buffer_size);
123 return true; 123 return true;
124 } 124 }
125 125
126 bool PdfMetafileSkia::SaveTo(const FilePath& file_path) const { 126 bool PdfMetafileSkia::SaveTo(const FilePath& file_path) const {
127 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U); 127 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U);
128 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); 128 SkAutoDataUnref data(data_->pdf_stream_.copyToData());
129 if (file_util::WriteFile(file_path, 129 if (file_util::WriteFile(file_path,
130 reinterpret_cast<const char*>(data.data()), 130 reinterpret_cast<const char*>(data->data()),
131 GetDataSize()) != static_cast<int>(GetDataSize())) { 131 GetDataSize()) != static_cast<int>(GetDataSize())) {
132 DLOG(ERROR) << "Failed to save file " << file_path.value().c_str(); 132 DLOG(ERROR) << "Failed to save file " << file_path.value().c_str();
133 return false; 133 return false;
134 } 134 }
135 return true; 135 return true;
136 } 136 }
137 137
138 gfx::Rect PdfMetafileSkia::GetPageBounds(unsigned int page_number) const { 138 gfx::Rect PdfMetafileSkia::GetPageBounds(unsigned int page_number) const {
139 // TODO(vandebo) add a method to get the page size for a given page to 139 // TODO(vandebo) add a method to get the page size for a given page to
140 // SkPDFDocument. 140 // SkPDFDocument.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 should do something like the following CL in PluginInstance::PrintPDFOutput: 177 should do something like the following CL in PluginInstance::PrintPDFOutput:
178 http://codereview.chromium.org/7200040/diff/1/webkit/plugins/ppapi/ppapi_plugin_ instance.cc 178 http://codereview.chromium.org/7200040/diff/1/webkit/plugins/ppapi/ppapi_plugin_ instance.cc
179 */ 179 */
180 bool PdfMetafileSkia::RenderPage(unsigned int page_number, 180 bool PdfMetafileSkia::RenderPage(unsigned int page_number,
181 CGContextRef context, 181 CGContextRef context,
182 const CGRect rect, 182 const CGRect rect,
183 const MacRenderPageParams& params) const { 183 const MacRenderPageParams& params) const {
184 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U); 184 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U);
185 if (data_->pdf_cg_.GetDataSize() == 0) { 185 if (data_->pdf_cg_.GetDataSize() == 0) {
186 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); 186 SkAutoDataUnref data(data_->pdf_stream_.copyToData());
187 data_->pdf_cg_.InitFromData(data.bytes(), data.size()); 187 data_->pdf_cg_.InitFromData(data->bytes(), data->size());
188 } 188 }
189 return data_->pdf_cg_.RenderPage(page_number, context, rect, params); 189 return data_->pdf_cg_.RenderPage(page_number, context, rect, params);
190 } 190 }
191 #endif 191 #endif
192 192
193 #if defined(OS_CHROMEOS) 193 #if defined(OS_CHROMEOS)
194 bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const { 194 bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const {
195 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U); 195 DCHECK_GT(data_->pdf_stream_.getOffset(), 0U);
196 196
197 if (fd.fd < 0) { 197 if (fd.fd < 0) {
198 DLOG(ERROR) << "Invalid file descriptor!"; 198 DLOG(ERROR) << "Invalid file descriptor!";
199 return false; 199 return false;
200 } 200 }
201 201
202 bool result = true; 202 bool result = true;
203 SkAutoDataUnref data(data_->pdf_stream_.copyToData()); 203 SkAutoDataUnref data(data_->pdf_stream_.copyToData());
204 if (file_util::WriteFileDescriptor(fd.fd, 204 if (file_util::WriteFileDescriptor(fd.fd,
205 reinterpret_cast<const char*>(data.data()), 205 reinterpret_cast<const char*>(data->data()) ,
206 GetDataSize()) != 206 GetDataSize()) !=
207 static_cast<int>(GetDataSize())) { 207 static_cast<int>(GetDataSize())) {
208 DLOG(ERROR) << "Failed to save file with fd " << fd.fd; 208 DLOG(ERROR) << "Failed to save file with fd " << fd.fd;
209 result = false; 209 result = false;
210 } 210 }
211 211
212 if (fd.auto_close) { 212 if (fd.auto_close) {
213 if (HANDLE_EINTR(close(fd.fd)) < 0) { 213 if (HANDLE_EINTR(close(fd.fd)) < 0) {
214 DPLOG(WARNING) << "close"; 214 DPLOG(WARNING) << "close";
215 result = false; 215 result = false;
(...skipping 11 matching lines...) Expand all
227 PdfMetafileSkia* PdfMetafileSkia::GetMetafileForCurrentPage() { 227 PdfMetafileSkia* PdfMetafileSkia::GetMetafileForCurrentPage() {
228 SkPDFDocument pdf_doc(SkPDFDocument::kDraftMode_Flags); 228 SkPDFDocument pdf_doc(SkPDFDocument::kDraftMode_Flags);
229 SkDynamicMemoryWStream pdf_stream; 229 SkDynamicMemoryWStream pdf_stream;
230 if (!pdf_doc.appendPage(data_->current_page_.get())) 230 if (!pdf_doc.appendPage(data_->current_page_.get()))
231 return NULL; 231 return NULL;
232 232
233 if (!pdf_doc.emitPDF(&pdf_stream)) 233 if (!pdf_doc.emitPDF(&pdf_stream))
234 return NULL; 234 return NULL;
235 235
236 SkAutoDataUnref data(pdf_stream.copyToData()); 236 SkAutoDataUnref data(pdf_stream.copyToData());
237 if (data.size() == 0) 237 if (data->size() == 0)
238 return NULL; 238 return NULL;
239 239
240 PdfMetafileSkia* metafile = new PdfMetafileSkia; 240 PdfMetafileSkia* metafile = new PdfMetafileSkia;
241 metafile->InitFromData(data.bytes(), data.size()); 241 metafile->InitFromData(data->bytes(), data->size());
242 return metafile; 242 return metafile;
243 } 243 }
244 244
245 } // namespace printing 245 } // namespace printing
OLDNEW
« no previous file with comments | « DEPS ('k') | skia/skia.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698