Chromium Code Reviews| Index: printing/pdf_ps_metafile_cairo.cc |
| diff --git a/printing/pdf_ps_metafile_cairo.cc b/printing/pdf_ps_metafile_cairo.cc |
| index 8ab925833408d82d2f7bbceeb1bbe136dab6fd5a..3dc59ddaddab60c55ecb19a014cd069b4edbd195 100644 |
| --- a/printing/pdf_ps_metafile_cairo.cc |
| +++ b/printing/pdf_ps_metafile_cairo.cc |
| @@ -15,6 +15,8 @@ |
| #include "base/logging.h" |
| #include "printing/units.h" |
| #include "skia/ext/vector_platform_device_linux.h" |
| +#include "ui/gfx/rect.h" |
| +#include "ui/gfx/size.h" |
| namespace { |
| @@ -108,7 +110,6 @@ bool PdfPsMetafile::Init() { |
| } |
| cairo_set_user_data(context_, &kPdfMetafileKey, this, DestroyContextData); |
| - |
| return true; |
| } |
| @@ -123,7 +124,6 @@ bool PdfPsMetafile::Init(const void* src_buffer, uint32 src_buffer_size) { |
| data_ = std::string(reinterpret_cast<const char*>(src_buffer), |
| src_buffer_size); |
| - |
| return true; |
| } |
| @@ -144,8 +144,7 @@ bool PdfPsMetafile::SetRawData(const void* src_buffer, |
| return true; |
| } |
| -cairo_t* PdfPsMetafile::StartPage(double width_in_points, |
| - double height_in_points, |
| +cairo_t* PdfPsMetafile::StartPage(const gfx::Size& page_size, |
| double margin_top_in_points, |
| double margin_right_in_points, |
| double margin_bottom_in_points, |
| @@ -154,15 +153,15 @@ cairo_t* PdfPsMetafile::StartPage(double width_in_points, |
| DCHECK(IsContextValid(context_)); |
| // Passing this check implies page_surface_ is NULL, and current_page_ is |
| // empty. |
| - DCHECK_GT(width_in_points, 0.); |
| - DCHECK_GT(height_in_points, 0.); |
| + DCHECK_GT(page_size.width(), 0.); |
| + DCHECK_GT(page_size.height(), 0.); |
| // We build in extra room for the margins. The Cairo PDF backend will scale |
| // the output to fit a page. |
| double width = |
| - width_in_points + margin_left_in_points + margin_right_in_points; |
| + page_size.width() + margin_left_in_points + margin_right_in_points; |
|
vandebo (ex-Chrome)
2011/03/14 20:24:25
The argument obviously isn't page size, it's conte
dpapad
2011/03/14 22:15:12
Done. Also I removed unused args. The remaining ar
|
| double height = |
| - height_in_points + margin_top_in_points + margin_bottom_in_points; |
| + page_size.height() + margin_top_in_points + margin_bottom_in_points; |
| // Don't let WebKit draw over the margins. |
| cairo_surface_set_device_offset(surface_, |
| @@ -183,7 +182,7 @@ bool PdfPsMetafile::FinishPage() { |
| return true; |
| } |
| -void PdfPsMetafile::Close() { |
| +bool PdfPsMetafile::Close() { |
| DCHECK(IsSurfaceValid(surface_)); |
| DCHECK(IsContextValid(context_)); |
| @@ -198,6 +197,7 @@ void PdfPsMetafile::Close() { |
| CleanUpContext(&context_); |
| CleanUpSurface(&surface_); |
| + return true; |
| } |
| uint32 PdfPsMetafile::GetDataSize() const { |
| @@ -217,7 +217,27 @@ bool PdfPsMetafile::GetData(void* dst_buffer, uint32 dst_buffer_size) const { |
| return true; |
| } |
| -bool PdfPsMetafile::SaveTo(const base::FileDescriptor& fd) const { |
| +bool PdfPsMetafile::SaveTo(const FilePath& file_path) const { |
| + // We need to check at least these two members to ensure that either Init() |
| + // has been called to initialize |data_|, or metafile has been closed. |
| + DCHECK(!context_); |
| + DCHECK(!data_.empty()); |
| + |
| + bool success = true; |
| + if (file_util::WriteFile(file_path, data_.data(), GetDataSize()) < 0) { |
| + DLOG(ERROR) << "Failed to save file " << file_path.value().c_str(); |
| + success = false; |
| + } |
| + return success; |
| +} |
| + |
| +gfx::Rect PdfPsMetafile::GetPageBounds(unsigned int page_number) const { |
| + NOTIMPLEMENTED(); |
| + return gfx::Rect(); |
| +} |
| + |
| +#if defined(OS_CHROMEOS) |
| +bool PdfPsMetafile::SaveToFD(const base::FileDescriptor& fd) const { |
| // We need to check at least these two members to ensure that either Init() |
| // has been called to initialize |data_|, or metafile has been closed. |
| DCHECK(!context_); |
| @@ -244,6 +264,7 @@ bool PdfPsMetafile::SaveTo(const base::FileDescriptor& fd) const { |
| return success; |
| } |
| +#endif // if defined(OS_CHROMEOS) |
| PdfPsMetafile* PdfPsMetafile::FromCairoContext(cairo_t* context) { |
| return reinterpret_cast<PdfPsMetafile*>( |