summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorabodenha@chromium.org <abodenha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-08 22:31:30 +0000
committerabodenha@chromium.org <abodenha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-08 22:31:30 +0000
commitd9b54277b1c2239aa1c67317dacb6874529612e6 (patch)
tree4b6e6742f879fef3594de2fedfcca17b5b32cbad /printing
parent148447da707a8de139f9fa9b11edf27e2edccd7d (diff)
downloadchromium_src-d9b54277b1c2239aa1c67317dacb6874529612e6.zip
chromium_src-d9b54277b1c2239aa1c67317dacb6874529612e6.tar.gz
chromium_src-d9b54277b1c2239aa1c67317dacb6874529612e6.tar.bz2
Remove dead cairo code.
BUG= TEST=No visible changes. Review URL: http://codereview.chromium.org/7847002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/metafile_impl.h2
-rw-r--r--printing/pdf_metafile_cairo_linux.cc259
-rw-r--r--printing/pdf_metafile_cairo_linux.h88
-rw-r--r--printing/pdf_metafile_cairo_linux_unittest.cc85
-rw-r--r--printing/printing.gyp3
5 files changed, 0 insertions, 437 deletions
diff --git a/printing/metafile_impl.h b/printing/metafile_impl.h
index dd09e09..38c68a3 100644
--- a/printing/metafile_impl.h
+++ b/printing/metafile_impl.h
@@ -9,8 +9,6 @@
#include "printing/emf_win.h"
#elif defined(OS_MACOSX)
#include "printing/pdf_metafile_cg_mac.h"
-#elif defined(OS_POSIX)
-#include "printing/pdf_metafile_cairo_linux.h"
#endif
#if !defined(OS_MACOSX) || defined(USE_SKIA)
diff --git a/printing/pdf_metafile_cairo_linux.cc b/printing/pdf_metafile_cairo_linux.cc
deleted file mode 100644
index af2aa5c..0000000
--- a/printing/pdf_metafile_cairo_linux.cc
+++ /dev/null
@@ -1,259 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "printing/pdf_metafile_cairo_linux.h"
-
-#include <stdio.h>
-
-#include <cairo.h>
-#include <cairo-pdf.h>
-
-#include "base/eintr_wrapper.h"
-#include "base/file_descriptor_posix.h"
-#include "base/file_util.h"
-#include "base/logging.h"
-#include "printing/units.h"
-#include "skia/ext/vector_platform_device_cairo_linux.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/size.h"
-
-namespace {
-
-// Tests if |surface| is valid.
-bool IsSurfaceValid(cairo_surface_t* surface) {
- return cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS;
-}
-
-// Tests if |context| is valid.
-bool IsContextValid(cairo_t* context) {
- return cairo_status(context) == CAIRO_STATUS_SUCCESS;
-}
-
-// Destroys and resets |surface|.
-void CleanUpSurface(cairo_surface_t** surface) {
- if (*surface) {
- cairo_surface_destroy(*surface);
- *surface = NULL;
- }
-}
-
-// Destroys and resets |context|.
-void CleanUpContext(cairo_t** context) {
- if (*context) {
- cairo_destroy(*context);
- *context = NULL;
- }
-}
-
-// Callback function for Cairo to write PDF stream.
-// |dst_buffer| is actually a pointer of type `std::string*`.
-cairo_status_t WriteCairoStream(void* dst_buffer,
- const unsigned char* src_data,
- unsigned int src_data_length) {
- DCHECK(dst_buffer);
- DCHECK(src_data);
- DCHECK_GT(src_data_length, 0u);
-
- std::string* buffer = reinterpret_cast<std::string*>(dst_buffer);
- buffer->append(reinterpret_cast<const char*>(src_data), src_data_length);
-
- return CAIRO_STATUS_SUCCESS;
-}
-
-} // namespace
-
-namespace printing {
-
-PdfMetafileCairo::PdfMetafileCairo()
- : surface_(NULL),
- context_(NULL),
- current_data_(NULL) {
-}
-
-PdfMetafileCairo::~PdfMetafileCairo() {
- // Releases all resources if we forgot to do so.
- CleanUpAll();
-}
-
-bool PdfMetafileCairo::Init() {
- // We need to check |current_data_| to ensure Init/InitFromData has not been
- // called before.
- DCHECK(!current_data_);
-
- current_data_ = &cairo_data_;
- // Creates an 1 by 1 Cairo surface for the entire PDF file.
- // The size for each page will be overwritten later in StartPage().
- surface_ = cairo_pdf_surface_create_for_stream(WriteCairoStream,
- current_data_, 1, 1);
-
- // Cairo always returns a valid pointer.
- // Hence, we have to check if it points to a "nil" object.
- if (!IsSurfaceValid(surface_)) {
- DLOG(ERROR) << "Cannot create Cairo surface for PdfMetafileCairo!";
- CleanUpSurface(&surface_);
- return false;
- }
-
- // Creates a context.
- context_ = cairo_create(surface_);
- if (!IsContextValid(context_)) {
- DLOG(ERROR) << "Cannot create Cairo context for PdfMetafileCairo!";
- CleanUpContext(&context_);
- CleanUpSurface(&surface_);
- return false;
- }
-
- return true;
-}
-
-bool PdfMetafileCairo::InitFromData(const void* src_buffer,
- uint32 src_buffer_size) {
- if (src_buffer == NULL || src_buffer_size == 0)
- return false;
-
- raw_data_ = std::string(reinterpret_cast<const char*>(src_buffer),
- src_buffer_size);
- current_data_ = &raw_data_;
- return true;
-}
-
-SkDevice* PdfMetafileCairo::StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Rect& content_area,
- const float& scale_factor) {
- if (!StartPage(page_size, content_area, scale_factor))
- return NULL;
-
- return skia::VectorPlatformDeviceCairo::CreateDevice(
- context_, page_size.width(), page_size.height(), true);
-}
-
-bool PdfMetafileCairo::StartPage(const gfx::Size& page_size,
- const gfx::Rect& content_area,
- const float& scale_factor) {
- 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);
- // |scale_factor| is not supported yet.
- DCHECK_EQ(scale_factor, 1);
-
- // Don't let WebKit draw over the margins.
- cairo_surface_set_device_offset(surface_,
- content_area.x(),
- content_area.y());
-
- cairo_pdf_surface_set_size(surface_, page_size.width(), page_size.height());
- return context_ != NULL;
-}
-
-bool PdfMetafileCairo::FinishPage() {
- DCHECK(IsSurfaceValid(surface_));
- DCHECK(IsContextValid(context_));
-
- // Flushes all rendering for current page.
- cairo_surface_flush(surface_);
- cairo_show_page(context_);
- return true;
-}
-
-bool PdfMetafileCairo::FinishDocument() {
- DCHECK(IsSurfaceValid(surface_));
- DCHECK(IsContextValid(context_));
-
- cairo_surface_finish(surface_);
-
- DCHECK(!cairo_data_.empty()); // Make sure we did get something.
-
- CleanUpContext(&context_);
- CleanUpSurface(&surface_);
- return true;
-}
-
-uint32 PdfMetafileCairo::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(!current_data_->empty());
-
- return current_data_->size();
-}
-
-bool PdfMetafileCairo::GetData(void* dst_buffer, uint32 dst_buffer_size) const {
- DCHECK(dst_buffer);
- DCHECK_GT(dst_buffer_size, 0u);
- memcpy(dst_buffer, current_data_->data(), dst_buffer_size);
-
- return true;
-}
-
-cairo_t* PdfMetafileCairo::context() const {
- return context_;
-}
-
-bool PdfMetafileCairo::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(!current_data_->empty());
-
- bool success = true;
- if (file_util::WriteFile(file_path, current_data_->data(), GetDataSize())
- != static_cast<int>(GetDataSize())) {
- DLOG(ERROR) << "Failed to save file " << file_path.value().c_str();
- success = false;
- }
- return success;
-}
-
-gfx::Rect PdfMetafileCairo::GetPageBounds(unsigned int page_number) const {
- NOTIMPLEMENTED();
- return gfx::Rect();
-}
-
-unsigned int PdfMetafileCairo::GetPageCount() const {
- NOTIMPLEMENTED();
- return 1;
-}
-
-#if defined(OS_CHROMEOS)
-bool PdfMetafileCairo::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_);
- DCHECK(!current_data_->empty());
-
- if (fd.fd < 0) {
- DLOG(ERROR) << "Invalid file descriptor!";
- return false;
- }
-
- bool success = true;
- if (file_util::WriteFileDescriptor(fd.fd, current_data_->data(),
- GetDataSize()) < 0) {
- DLOG(ERROR) << "Failed to save file with fd " << fd.fd;
- success = false;
- }
-
- if (fd.auto_close) {
- if (HANDLE_EINTR(close(fd.fd)) < 0) {
- DPLOG(WARNING) << "close";
- success = false;
- }
- }
-
- return success;
-}
-#endif // if defined(OS_CHROMEOS)
-
-void PdfMetafileCairo::CleanUpAll() {
- CleanUpContext(&context_);
- CleanUpSurface(&surface_);
- cairo_data_.clear();
- raw_data_.clear();
- skia::VectorPlatformDeviceCairo::ClearFontCache();
-}
-
-} // namespace printing
diff --git a/printing/pdf_metafile_cairo_linux.h b/printing/pdf_metafile_cairo_linux.h
deleted file mode 100644
index 28c0698..0000000
--- a/printing/pdf_metafile_cairo_linux.h
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef PRINTING_PDF_METAFILE_CAIRO_LINUX_H_
-#define PRINTING_PDF_METAFILE_CAIRO_LINUX_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/gtest_prod_util.h"
-#include "printing/metafile.h"
-
-namespace gfx {
-class Point;
-class Rect;
-class Size;
-}
-
-typedef struct _cairo_surface cairo_surface_t;
-
-namespace printing {
-
-// This class uses Cairo graphics library to generate PDF stream and stores
-// rendering results in a string buffer.
-class PRINTING_EXPORT PdfMetafileCairo : public Metafile {
- public:
- PdfMetafileCairo();
- virtual ~PdfMetafileCairo();
-
- // Metafile methods.
- virtual bool Init();
-
- // Calling InitFromData() sets the data for this metafile and masks data
- // induced by previous calls to Init() or InitFromData(), even if drawing
- // continues on the surface returned by a previous call to Init().
- virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);
-
- virtual SkDevice* StartPageForVectorCanvas(
- const gfx::Size& page_size, const gfx::Rect& content_area,
- const float& scale_factor);
-
- virtual bool StartPage(const gfx::Size& page_size,
- const gfx::Rect& content_area,
- const float& scale_factor);
- virtual bool FinishPage();
- virtual bool FinishDocument();
-
- virtual uint32 GetDataSize() const;
- virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const;
-
- virtual bool SaveTo(const FilePath& file_path) const;
-
- virtual gfx::Rect GetPageBounds(unsigned int page_number) const;
- virtual unsigned int GetPageCount() const;
-
- virtual cairo_t* context() const;
-
-#if defined(OS_CHROMEOS)
- virtual bool SaveToFD(const base::FileDescriptor& fd) const;
-#endif // if defined(OS_CHROMEOS)
-
- private:
- // Cleans up all resources.
- void CleanUpAll();
-
- // Cairo surface and context for entire PDF file.
- cairo_surface_t* surface_;
- cairo_t* context_;
-
- // Buffer stores PDF contents for entire PDF file.
- std::string cairo_data_;
- // Buffer stores PDF contents. It can only be populated from InitFromData().
- // Any calls to StartPage(), FinishPage(), FinishDocument() do not affect
- // this buffer.
- // Note: Such calls will result in DCHECK errors if Init() has not been called
- // first.
- std::string raw_data_;
- // Points to the appropriate buffer depending on the way the object was
- // initialized (Init() vs InitFromData()).
- std::string* current_data_;
-
- DISALLOW_COPY_AND_ASSIGN(PdfMetafileCairo);
-};
-
-} // namespace printing
-
-#endif // PRINTING_PDF_METAFILE_CAIRO_LINUX_H_
diff --git a/printing/pdf_metafile_cairo_linux_unittest.cc b/printing/pdf_metafile_cairo_linux_unittest.cc
deleted file mode 100644
index 0ea08f81..0000000
--- a/printing/pdf_metafile_cairo_linux_unittest.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "printing/pdf_metafile_cairo_linux.h"
-
-#include <fcntl.h>
-#include <string>
-#include <vector>
-
-#include "base/file_descriptor_posix.h"
-#include "base/file_path.h"
-#include "base/file_util.h"
-#include "base/string_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/size.h"
-
-typedef struct _cairo cairo_t;
-
-namespace {
-
-class PdfMetafileCairoTest : public testing::Test {};
-
-} // namespace
-
-namespace printing {
-
-TEST_F(PdfMetafileCairoTest, Pdf) {
- // Tests in-renderer constructor.
- printing::PdfMetafileCairo pdf;
- EXPECT_TRUE(pdf.Init());
-
- // Renders page 1.
- EXPECT_TRUE(pdf.StartPage(gfx::Size(72, 73), gfx::Rect(4, 5, 64, 63), 1));
- // In theory, we should use Cairo to draw something on |context|.
- EXPECT_TRUE(pdf.FinishPage());
-
- // Renders page 2.
- EXPECT_TRUE(pdf.StartPage(gfx::Size(72, 73), gfx::Rect(4, 5, 64, 63), 1));
- // In theory, we should use Cairo to draw something on |context|.
- EXPECT_TRUE(pdf.FinishPage());
-
- // Closes the file.
- pdf.FinishDocument();
-
- // Checks data size.
- uint32 size = pdf.GetDataSize();
- EXPECT_GT(size, 0u);
-
- // Gets resulting data.
- std::vector<char> buffer(size, 0x00);
- pdf.GetData(&buffer.front(), size);
-
- // Tests another constructor.
- printing::PdfMetafileCairo pdf2;
- EXPECT_TRUE(pdf2.InitFromData(&buffer.front(), size));
-
- // Tries to get the first 4 characters from pdf2.
- std::vector<char> buffer2(4, 0x00);
- pdf2.GetData(&buffer2.front(), 4);
-
- // Tests if the header begins with "%PDF".
- std::string header(&buffer2.front(), 4);
- EXPECT_EQ(header.find("%PDF", 0), 0u);
-
- // Tests if we can save data.
- EXPECT_TRUE(pdf.SaveTo(FilePath("/dev/null")));
-
- // Test overriding the metafile with raw data.
- printing::PdfMetafileCairo pdf3;
- EXPECT_TRUE(pdf3.Init());
- EXPECT_TRUE(pdf3.StartPage(gfx::Size(72, 73), gfx::Rect(4, 5, 64, 63), 1));
- std::string test_raw_data = "Dummy PDF";
- EXPECT_TRUE(pdf3.InitFromData(test_raw_data.c_str(), test_raw_data.size()));
- EXPECT_TRUE(pdf3.FinishPage());
- pdf3.FinishDocument();
- size = pdf3.GetDataSize();
- EXPECT_EQ(test_raw_data.size(), size);
- std::string output;
- pdf3.GetData(WriteInto(&output, size + 1), size);
- EXPECT_EQ(test_raw_data, output);
-}
-
-} // namespace printing
diff --git a/printing/printing.gyp b/printing/printing.gyp
index 256108e..4d7aa20 100644
--- a/printing/printing.gyp
+++ b/printing/printing.gyp
@@ -50,8 +50,6 @@
'page_setup.cc',
'page_setup.h',
'page_size_margins.h',
- 'pdf_metafile_cairo_linux.cc',
- 'pdf_metafile_cairo_linux.h',
'pdf_metafile_cg_mac.cc',
'pdf_metafile_cg_mac.h',
'pdf_metafile_skia.h',
@@ -177,7 +175,6 @@
'page_number_unittest.cc',
'page_range_unittest.cc',
'page_setup_unittest.cc',
- 'pdf_metafile_cairo_linux_unittest.cc',
'pdf_metafile_cg_mac_unittest.cc',
'printed_page_unittest.cc',
'printing_context_win_unittest.cc',