| 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..9296bc9ab5aae234b95979ddafc4f7591df88aef 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 {
|
|
|
| @@ -127,50 +129,21 @@ bool PdfPsMetafile::Init(const void* src_buffer, uint32 src_buffer_size) {
|
| return true;
|
| }
|
|
|
| -bool PdfPsMetafile::SetRawData(const void* src_buffer,
|
| - uint32 src_buffer_size) {
|
| - if (!context_) {
|
| - // If Init has not already been called, just call Init()
|
| - return Init(src_buffer, src_buffer_size);
|
| - }
|
| - // If a context has already been created, remember this data in
|
| - // raw_override_data_
|
| - if (src_buffer == NULL || src_buffer_size == 0)
|
| - return false;
|
| -
|
| - raw_override_data_ = std::string(reinterpret_cast<const char*>(src_buffer),
|
| - src_buffer_size);
|
| +uint32 PdfPsMetafile::GetDataSize() 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());
|
|
|
| - return true;
|
| + return data_.size();
|
| }
|
|
|
| -cairo_t* PdfPsMetafile::StartPage(double width_in_points,
|
| - double height_in_points,
|
| - double margin_top_in_points,
|
| - double margin_right_in_points,
|
| - double margin_bottom_in_points,
|
| - double margin_left_in_points) {
|
| - DCHECK(IsSurfaceValid(surface_));
|
| - 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.);
|
| -
|
| - // 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;
|
| - double height =
|
| - height_in_points + margin_top_in_points + margin_bottom_in_points;
|
| -
|
| - // Don't let WebKit draw over the margins.
|
| - cairo_surface_set_device_offset(surface_,
|
| - margin_left_in_points,
|
| - margin_top_in_points);
|
| +bool PdfPsMetafile::GetData(void* dst_buffer, uint32 dst_buffer_size) const {
|
| + DCHECK(dst_buffer);
|
| + DCHECK_GT(dst_buffer_size, 0u);
|
| + memcpy(dst_buffer, data_.data(), dst_buffer_size);
|
|
|
| - cairo_pdf_surface_set_size(surface_, width, height);
|
| - return context_;
|
| + return true;
|
| }
|
|
|
| bool PdfPsMetafile::FinishPage() {
|
| @@ -200,49 +173,68 @@ void PdfPsMetafile::Close() {
|
| CleanUpSurface(&surface_);
|
| }
|
|
|
| -uint32 PdfPsMetafile::GetDataSize() 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());
|
|
|
| - return data_.size();
|
| + 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;
|
| }
|
|
|
| -bool PdfPsMetafile::GetData(void* dst_buffer, uint32 dst_buffer_size) const {
|
| - DCHECK(dst_buffer);
|
| - DCHECK_GT(dst_buffer_size, 0u);
|
| - memcpy(dst_buffer, data_.data(), dst_buffer_size);
|
| -
|
| - return true;
|
| +gfx::Rect PdfPsMetafile::GetPageBounds(unsigned int page_number) const {
|
| + NOTIMPLEMENTED();
|
| + return gfx::Rect();
|
| }
|
|
|
| -bool PdfPsMetafile::SaveTo(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_);
|
| - DCHECK(!data_.empty());
|
| +PlatformContext* PdfPsMetafile::StartPage(const gfx::Size& page_size,
|
| + double margin_top_in_points,
|
| + double margin_right_in_points,
|
| + double margin_bottom_in_points,
|
| + double margin_left_in_points) {
|
| + DCHECK(IsSurfaceValid(surface_));
|
| + DCHECK(IsContextValid(context_));
|
| + // Passing this check implies page_surface_ is NULL, and current_page_ is
|
| + // empty.
|
| + DCHECK_GT(page_size.width(), 0.);
|
| + DCHECK_GT(page_size.height(), 0.);
|
|
|
| - if (fd.fd < 0) {
|
| - DLOG(ERROR) << "Invalid file descriptor!";
|
| - return false;
|
| - }
|
| + // We build in extra room for the margins. The Cairo PDF backend will scale
|
| + // the output to fit a page.
|
| + double width =
|
| + page_size.width() + margin_left_in_points + margin_right_in_points;
|
| + double height =
|
| + page_size.height() + margin_top_in_points + margin_bottom_in_points;
|
|
|
| - bool success = true;
|
| - if (file_util::WriteFileDescriptor(fd.fd, data_.data(),
|
| - GetDataSize()) < 0) {
|
| - DLOG(ERROR) << "Failed to save file with fd " << fd.fd;
|
| - success = false;
|
| - }
|
| + // Don't let WebKit draw over the margins.
|
| + cairo_surface_set_device_offset(surface_,
|
| + margin_left_in_points,
|
| + margin_top_in_points);
|
| +
|
| + cairo_pdf_surface_set_size(surface_, width, height);
|
| + return context_;
|
| +}
|
|
|
| - if (fd.auto_close) {
|
| - if (HANDLE_EINTR(close(fd.fd)) < 0) {
|
| - DPLOG(WARNING) << "close";
|
| - success = false;
|
| - }
|
| +bool PdfPsMetafile::SetRawData(const void* src_buffer,
|
| + uint32 src_buffer_size) {
|
| + if (!context_) {
|
| + // If Init has not already been called, just call Init()
|
| + return Init(src_buffer, src_buffer_size);
|
| }
|
| + // If a context has already been created, remember this data in
|
| + // raw_override_data_
|
| + if (src_buffer == NULL || src_buffer_size == 0)
|
| + return false;
|
|
|
| - return success;
|
| + raw_override_data_ = std::string(reinterpret_cast<const char*>(src_buffer),
|
| + src_buffer_size);
|
| +
|
| + return true;
|
| }
|
|
|
| PdfPsMetafile* PdfPsMetafile::FromCairoContext(cairo_t* context) {
|
|
|