OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_ps_metafile_cairo.h" | 5 #include "printing/pdf_ps_metafile_cairo.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <cairo.h> | 9 #include <cairo.h> |
10 #include <cairo-pdf.h> | 10 #include <cairo-pdf.h> |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 } | 210 } |
211 | 211 |
212 bool PdfPsMetafile::GetData(void* dst_buffer, uint32 dst_buffer_size) const { | 212 bool PdfPsMetafile::GetData(void* dst_buffer, uint32 dst_buffer_size) const { |
213 DCHECK(dst_buffer); | 213 DCHECK(dst_buffer); |
214 DCHECK_GT(dst_buffer_size, 0u); | 214 DCHECK_GT(dst_buffer_size, 0u); |
215 memcpy(dst_buffer, data_.data(), dst_buffer_size); | 215 memcpy(dst_buffer, data_.data(), dst_buffer_size); |
216 | 216 |
217 return true; | 217 return true; |
218 } | 218 } |
219 | 219 |
220 bool PdfPsMetafile::SaveTo(const base::FileDescriptor& fd) const { | 220 bool PdfPsMetafile::SaveTo(const FilePath& file_path) const { |
221 // We need to check at least these two members to ensure that either Init() | 221 // We need to check at least these two members to ensure that either Init() |
222 // has been called to initialize |data_|, or metafile has been closed. | 222 // has been called to initialize |data_|, or metafile has been closed. |
223 DCHECK(!context_); | 223 DCHECK(!context_); |
224 DCHECK(!data_.empty()); | 224 DCHECK(!data_.empty()); |
225 | 225 |
226 if (fd.fd < 0) { | |
227 DLOG(ERROR) << "Invalid file descriptor!"; | |
228 return false; | |
229 } | |
230 | |
231 bool success = true; | 226 bool success = true; |
232 if (file_util::WriteFileDescriptor(fd.fd, data_.data(), | 227 if (file_util::WriteFile(file_path, |
vandebo (ex-Chrome)
2011/03/08 00:39:35
Fits on one line now.
dpapad
2011/03/08 19:39:22
Done.
| |
233 GetDataSize()) < 0) { | 228 data_.data(), |
234 DLOG(ERROR) << "Failed to save file with fd " << fd.fd; | 229 GetDataSize()) < 0) { |
230 DLOG(ERROR) << "Failed to save file " << file_path.value().c_str(); | |
235 success = false; | 231 success = false; |
236 } | 232 } |
237 | |
238 if (fd.auto_close) { | |
239 if (HANDLE_EINTR(close(fd.fd)) < 0) { | |
240 DPLOG(WARNING) << "close"; | |
241 success = false; | |
242 } | |
243 } | |
244 | |
245 return success; | 233 return success; |
246 } | 234 } |
247 | 235 |
248 PdfPsMetafile* PdfPsMetafile::FromCairoContext(cairo_t* context) { | 236 PdfPsMetafile* PdfPsMetafile::FromCairoContext(cairo_t* context) { |
249 return reinterpret_cast<PdfPsMetafile*>( | 237 return reinterpret_cast<PdfPsMetafile*>( |
250 cairo_get_user_data(context, &kPdfMetafileKey)); | 238 cairo_get_user_data(context, &kPdfMetafileKey)); |
251 } | 239 } |
252 | 240 |
253 void PdfPsMetafile::CleanUpAll() { | 241 void PdfPsMetafile::CleanUpAll() { |
254 CleanUpContext(&context_); | 242 CleanUpContext(&context_); |
255 CleanUpSurface(&surface_); | 243 CleanUpSurface(&surface_); |
256 data_.clear(); | 244 data_.clear(); |
257 skia::VectorPlatformDevice::ClearFontCache(); | 245 skia::VectorPlatformDevice::ClearFontCache(); |
258 } | 246 } |
259 | 247 |
260 const double PdfPsMetafile::kTopMarginInInch = 0.25; | 248 const double PdfPsMetafile::kTopMarginInInch = 0.25; |
261 const double PdfPsMetafile::kBottomMarginInInch = 0.56; | 249 const double PdfPsMetafile::kBottomMarginInInch = 0.56; |
262 const double PdfPsMetafile::kLeftMarginInInch = 0.25; | 250 const double PdfPsMetafile::kLeftMarginInInch = 0.25; |
263 const double PdfPsMetafile::kRightMarginInInch = 0.25; | 251 const double PdfPsMetafile::kRightMarginInInch = 0.25; |
264 | 252 |
265 } // namespace printing | 253 } // namespace printing |
OLD | NEW |