summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 21:30:39 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 21:30:39 +0000
commit4b63c934d571a5a1d773fd3129edeab4bd2c4504 (patch)
tree50f0df251c814e91a0a0510e9f76cb3b972e2fc7
parent8360c7edcb39a407723ce7c32a0fabeeae397f7a (diff)
downloadchromium_src-4b63c934d571a5a1d773fd3129edeab4bd2c4504.zip
chromium_src-4b63c934d571a5a1d773fd3129edeab4bd2c4504.tar.gz
chromium_src-4b63c934d571a5a1d773fd3129edeab4bd2c4504.tar.bz2
+ This CL pulls in all the PDF code (i.e. we are now compiling the PDF backend on Chrome).
+ Add a Metafile to contain Skia PDF content. + Add a VectorPlatformDevice for use with the Skia PDF backend. BUG=62889 TEST=NONE Review URL: http://codereview.chromium.org/6499024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80841 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--printing/pdf_metafile_skia.cc165
-rw-r--r--printing/pdf_metafile_skia.h74
-rw-r--r--printing/printing.gyp5
-rw-r--r--skia/config/SkUserConfig.h27
-rw-r--r--skia/ext/vector_platform_device_skia.cc254
-rw-r--r--skia/ext/vector_platform_device_skia.h106
-rw-r--r--skia/skia.gyp36
7 files changed, 667 insertions, 0 deletions
diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc
new file mode 100644
index 0000000..72d8908
--- /dev/null
+++ b/printing/pdf_metafile_skia.cc
@@ -0,0 +1,165 @@
+// 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_skia.h"
+
+#include "base/eintr_wrapper.h"
+#include "base/file_descriptor_posix.h"
+#include "base/file_util.h"
+#include "skia/ext/vector_platform_device_skia.h"
+#include "third_party/skia/include/core/SkRefCnt.h"
+#include "third_party/skia/include/core/SkStream.h"
+#include "third_party/skia/include/pdf/SkPDFDevice.h"
+#include "third_party/skia/include/pdf/SkPDFDocument.h"
+#include "third_party/skia/include/pdf/SkPDFPage.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/size.h"
+
+namespace printing {
+
+struct PdfMetafileSkiaData {
+ SkRefPtr<SkPDFDevice> current_page_;
+ SkPDFDocument pdf_doc_;
+ SkDynamicMemoryWStream pdf_stream_;
+};
+
+PdfMetafileSkia::~PdfMetafileSkia() {}
+
+bool PdfMetafileSkia::Init() {
+ return true;
+}
+bool PdfMetafileSkia::InitFromData(const void* src_buffer,
+ uint32 src_buffer_size) {
+ return data_->pdf_stream_.write(src_buffer, src_buffer_size);
+}
+
+skia::PlatformDevice* PdfMetafileSkia::StartPageForVectorCanvas(
+ const gfx::Size& page_size, const gfx::Point& content_origin,
+ const float& scale_factor) {
+ DCHECK(data_->current_page_.get() == NULL);
+
+ skia::VectorPlatformDeviceSkia* device =
+ new skia::VectorPlatformDeviceSkia(page_size.width(), page_size.height(),
+ SkPDFDevice::kFlip_OriginTransform);
+ device->setInitialTransform(content_origin.x(), content_origin.y(),
+ scale_factor);
+ data_->current_page_ = device->PdfDevice();
+ return device;
+}
+
+bool PdfMetafileSkia::StartPage(const gfx::Size& page_size,
+ const gfx::Point& content_origin,
+ const float& scale_factor) {
+ NOTREACHED();
+ return NULL;
+}
+
+bool PdfMetafileSkia::FinishPage() {
+ DCHECK(data_->current_page_.get());
+
+ data_->pdf_doc_.appendPage(data_->current_page_);
+ data_->current_page_ = NULL;
+ return true;
+}
+
+bool PdfMetafileSkia::FinishDocument() {
+ // Don't do anything if we've already set the data in InitFromData.
+ if (data_->pdf_stream_.getOffset())
+ return true;
+
+ if (data_->current_page_.get())
+ FinishPage();
+ return data_->pdf_doc_.emitPDF(&data_->pdf_stream_);
+}
+
+uint32 PdfMetafileSkia::GetDataSize() const {
+ return data_->pdf_stream_.getOffset();
+}
+
+bool PdfMetafileSkia::GetData(void* dst_buffer,
+ uint32 dst_buffer_size) const {
+ if (dst_buffer_size < GetDataSize())
+ return false;
+
+ memcpy(dst_buffer, data_->pdf_stream_.getStream(), dst_buffer_size);
+ return true;
+}
+
+bool PdfMetafileSkia::SaveTo(const FilePath& file_path) const {
+ DCHECK_GT(data_->pdf_stream_.getOffset(), 0U);
+ if (file_util::WriteFile(file_path, data_->pdf_stream_.getStream(),
+ GetDataSize()) != static_cast<int>(GetDataSize())) {
+ DLOG(ERROR) << "Failed to save file " << file_path.value().c_str();
+ return false;
+ }
+ return true;
+}
+
+gfx::Rect PdfMetafileSkia::GetPageBounds(unsigned int page_number) const {
+ // TODO(vandebo) add a method to get the page size for a given page to
+ // SkPDFDocument.
+ NOTIMPLEMENTED();
+ return gfx::Rect();
+}
+
+unsigned int PdfMetafileSkia::GetPageCount() const {
+ // TODO(vandebo) add a method to get the number of pages to SkPDFDocument.
+ NOTIMPLEMENTED();
+ return 0;
+}
+
+gfx::NativeDrawingContext PdfMetafileSkia::context() const {
+ NOTREACHED();
+ return NULL;
+}
+
+#if defined(OS_WIN)
+bool PdfMetafileSkia::Playback(gfx::NativeDrawingContext hdc,
+ const RECT* rect) const {
+ NOTREACHED();
+ return false;
+}
+
+bool PdfMetafileSkia::SafePlayback(gfx::NativeDrawingContext hdc) const {
+ NOTREACHED();
+ return false;
+}
+
+HENHMETAFILE PdfMetafileSkia::emf() const {
+ NOTREACHED();
+ return NULL;
+}
+#endif // if defined(OS_WIN)
+
+#if defined(OS_CHROMEOS)
+bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const {
+ DCHECK_GT(data_->pdf_stream_.getOffset(), 0U);
+
+ if (fd.fd < 0) {
+ DLOG(ERROR) << "Invalid file descriptor!";
+ return false;
+ }
+
+ bool result = true;
+ if (file_util::WriteFileDescriptor(fd.fd, data_->pdf_stream_.getStream(),
+ GetDataSize()) !=
+ static_cast<int>(GetDataSize())) {
+ DLOG(ERROR) << "Failed to save file with fd " << fd.fd;
+ result = false;
+ }
+
+ if (fd.auto_close) {
+ if (HANDLE_EINTR(close(fd.fd)) < 0) {
+ DPLOG(WARNING) << "close";
+ result = false;
+ }
+ }
+ return result;
+}
+#endif
+
+PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {}
+
+} // namespace printing
diff --git a/printing/pdf_metafile_skia.h b/printing/pdf_metafile_skia.h
new file mode 100644
index 0000000..4e8a003
--- /dev/null
+++ b/printing/pdf_metafile_skia.h
@@ -0,0 +1,74 @@
+// 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_SKIA_H_
+#define PRINTING_PDF_METAFILE_SKIA_H_
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/scoped_ptr.h"
+#include "build/build_config.h"
+#include "printing/native_metafile.h"
+
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
+
+namespace printing {
+
+struct PdfMetafileSkiaData;
+
+// This class uses Skia graphics library to generate a PDF document.
+class PdfMetafileSkia : public NativeMetafile {
+ public:
+ virtual ~PdfMetafileSkia();
+
+ // NativeMetafile interface
+ virtual bool Init();
+ virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);
+
+ virtual skia::PlatformDevice* StartPageForVectorCanvas(
+ const gfx::Size& page_size,
+ const gfx::Point& content_origin,
+ const float& scale_factor);
+ virtual bool StartPage(const gfx::Size& page_size,
+ const gfx::Point& content_origin,
+ 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 gfx::NativeDrawingContext context() const;
+
+#if defined(OS_WIN)
+ virtual bool Playback(gfx::NativeDrawingContext hdc, const RECT* rect) const;
+ virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const;
+ virtual HENHMETAFILE emf() const;
+#endif // if defined(OS_WIN)
+
+#if defined(OS_CHROMEOS)
+ virtual bool SaveToFD(const base::FileDescriptor& fd) const = 0;
+#endif // if defined(OS_CHROMEOS)
+
+ protected:
+ PdfMetafileSkia();
+
+ private:
+ friend class NativeMetafileFactory;
+
+ scoped_ptr<PdfMetafileSkiaData> data_;
+
+ DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
+};
+
+} // namespace printing
+
+#endif // PRINTING_PDF_METAFILE_MAC_H_
diff --git a/printing/printing.gyp b/printing/printing.gyp
index ae61a41..87b9485 100644
--- a/printing/printing.gyp
+++ b/printing/printing.gyp
@@ -51,6 +51,8 @@
'pdf_metafile_cairo_linux.h',
'pdf_metafile_cg_mac.cc',
'pdf_metafile_cg_mac.h',
+ 'pdf_metafile_skia.h',
+ 'pdf_metafile_skia.cc',
'printed_document_cairo.cc',
'printed_document.cc',
'printed_document.h',
@@ -107,6 +109,9 @@
'../build/linux/system.gyp:gtkprint',
],
}],
+ ['OS=="mac"',
+ {'sources/': [['exclude', 'pdf_metafile_skia\\.(cc|h)$']]}
+ ],
['OS=="win"', {
'defines': [
# PRINT_BACKEND_AVAILABLE disables the default dummy implementation
diff --git a/skia/config/SkUserConfig.h b/skia/config/SkUserConfig.h
index d9746b7..a7d830a 100644
--- a/skia/config/SkUserConfig.h
+++ b/skia/config/SkUserConfig.h
@@ -113,6 +113,33 @@
*/
//#define SK_USE_RUNTIME_GLOBALS
+/* If zlib is available and you want to support the flate compression
+ algorithm (used in PDF generation), define SK_ZLIB_INCLUDE to be the
+ include path.
+ */
+//#define SK_ZLIB_INCLUDE <zlib.h>
+#if defined(USE_SYSTEM_ZLIB)
+#define SK_ZLIB_INCLUDE <zlib.h>
+#else
+#define SK_ZLIB_INCLUDE "third_party/zlib/zlib.h"
+#define MOZ_Z_inflate inflate
+#define MOZ_Z_inflateInit_ inflateInit_
+#define MOZ_Z_inflateEnd inflateEnd
+#define MOZ_Z_deflate deflate
+#define MOZ_Z_deflateInit_ deflateInit_
+#define MOZ_Z_deflateEnd deflateEnd
+#endif
+
+/* Define this to allow PDF scalars above 32k. The PDF/A spec doesn't allow
+ them, but modern PDF interpreters should handle them just fine.
+ */
+//#define SK_ALLOW_LARGE_PDF_SCALARS
+
+/* Define this to remove dimension checks on bitmaps. Not all blits will be
+ correct yet, so this is mostly for debugging the implementation.
+ */
+//#define SK_ALLOW_OVER_32K_BITMAPS
+
/* To write debug messages to a console, skia will call SkDebugf(...) following
printf conventions (e.g. const char* format, ...). If you want to redirect
diff --git a/skia/ext/vector_platform_device_skia.cc b/skia/ext/vector_platform_device_skia.cc
new file mode 100644
index 0000000..8c064cb
--- /dev/null
+++ b/skia/ext/vector_platform_device_skia.cc
@@ -0,0 +1,254 @@
+// Copyright (c) 2009 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 "skia/ext/vector_platform_device_skia.h"
+
+#include "skia/ext/bitmap_platform_device.h"
+#include "third_party/skia/include/core/SkClipStack.h"
+#include "third_party/skia/include/core/SkDraw.h"
+#include "third_party/skia/include/core/SkRect.h"
+#include "third_party/skia/include/core/SkRegion.h"
+#include "third_party/skia/include/core/SkScalar.h"
+
+namespace skia {
+
+SkDevice* VectorPlatformDeviceSkiaFactory::newDevice(SkCanvas* noUsed,
+ SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque,
+ bool isForLayer) {
+ SkASSERT(config == SkBitmap::kARGB_8888_Config);
+ SkPDFDevice::OriginTransform flip = SkPDFDevice::kFlip_OriginTransform;
+ if (isForLayer)
+ flip = SkPDFDevice::kNoFlip_OriginTransform;
+ return new VectorPlatformDeviceSkia(width, height, flip);
+}
+
+static inline SkBitmap makeABitmap(int width, int height) {
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kNo_Config, width, height);
+ return bitmap;
+}
+
+VectorPlatformDeviceSkia::VectorPlatformDeviceSkia(
+ int width, int height, SkPDFDevice::OriginTransform flip)
+ : PlatformDevice(makeABitmap(width, height)),
+ pdf_device_(new SkPDFDevice(width, height, flip)) {
+ pdf_device_->unref(); // SkRefPtr and new both took a reference.
+ base_transform_.reset();
+}
+
+VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() {
+}
+
+bool VectorPlatformDeviceSkia::IsVectorial() {
+ return true;
+}
+
+bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() {
+ return false;
+}
+
+PlatformDevice::PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() {
+ // Even when drawing a vector representation of the page, we have to
+ // provide a raster surface for plugins to render into - they don't have
+ // a vector interface. Therefore we create a BitmapPlatformDevice here
+ // and return the context from it, then layer on the raster data as an
+ // image in EndPlatformPaint.
+ DCHECK(raster_surface_ == NULL);
+#if defined(OS_WIN)
+ raster_surface_ = BitmapPlatformDevice::create(pdf_device_->width(),
+ pdf_device_->height(),
+ false, /* not opaque */
+ NULL);
+#elif defined(OS_LINUX)
+ raster_surface_ = BitmapPlatformDevice::Create(pdf_device_->width(),
+ pdf_device_->height(),
+ false /* not opaque */);
+#endif
+ raster_surface_->unref(); // SkRefPtr and create both took a reference.
+
+ SkCanvas canvas(raster_surface_.get());
+ SkPaint black;
+ black.setColor(SK_ColorBLACK);
+ canvas.drawPaint(black);
+ return raster_surface_->BeginPlatformPaint();
+}
+
+void VectorPlatformDeviceSkia::EndPlatformPaint() {
+ DCHECK(raster_surface_ != NULL);
+ SkPaint paint;
+ pdf_device_->drawSprite(SkDraw(),
+ raster_surface_->accessBitmap(false),
+ base_transform_.getTranslateX(),
+ base_transform_.getTranslateY(),
+ paint);
+ raster_surface_ = NULL;
+}
+
+SkDeviceFactory* VectorPlatformDeviceSkia::getDeviceFactory() {
+ return SkNEW(VectorPlatformDeviceSkiaFactory);
+}
+
+uint32_t VectorPlatformDeviceSkia::getDeviceCapabilities() {
+ return kVector_Capability;
+}
+
+int VectorPlatformDeviceSkia::width() const {
+ return pdf_device_->width();
+}
+
+int VectorPlatformDeviceSkia::height() const {
+ return pdf_device_->height();
+}
+
+void VectorPlatformDeviceSkia::setMatrixClip(const SkMatrix& matrix,
+ const SkRegion& region,
+ const SkClipStack& stack) {
+ SkMatrix transform = base_transform_;
+ transform.preConcat(matrix);
+
+ DCHECK(SkMatrix::kTranslate_Mask == base_transform_.getType() ||
+ SkMatrix::kIdentity_Mask == base_transform_.getType());
+ SkRegion clip = region;
+ clip.translate(base_transform_.getTranslateX(),
+ base_transform_.getTranslateY());
+
+ pdf_device_->setMatrixClip(transform, clip, stack);
+}
+
+bool VectorPlatformDeviceSkia::readPixels(const SkIRect& srcRect,
+ SkBitmap* bitmap) {
+ return false;
+}
+
+void VectorPlatformDeviceSkia::drawPaint(const SkDraw& draw,
+ const SkPaint& paint) {
+ pdf_device_->drawPaint(draw, paint);
+}
+
+void VectorPlatformDeviceSkia::drawPoints(const SkDraw& draw,
+ SkCanvas::PointMode mode,
+ size_t count, const SkPoint pts[],
+ const SkPaint& paint) {
+ pdf_device_->drawPoints(draw, mode, count, pts, paint);
+}
+
+void VectorPlatformDeviceSkia::drawRect(const SkDraw& draw,
+ const SkRect& rect,
+ const SkPaint& paint) {
+ pdf_device_->drawRect(draw, rect, paint);
+}
+
+void VectorPlatformDeviceSkia::drawPath(const SkDraw& draw,
+ const SkPath& path,
+ const SkPaint& paint,
+ const SkMatrix* prePathMatrix,
+ bool pathIsMutable) {
+ pdf_device_->drawPath(draw, path, paint, prePathMatrix, pathIsMutable);
+}
+
+void VectorPlatformDeviceSkia::drawBitmap(const SkDraw& draw,
+ const SkBitmap& bitmap,
+ const SkIRect* srcRectOrNull,
+ const SkMatrix& matrix,
+ const SkPaint& paint) {
+ pdf_device_->drawBitmap(draw, bitmap, srcRectOrNull, matrix, paint);
+}
+
+void VectorPlatformDeviceSkia::drawSprite(const SkDraw& draw,
+ const SkBitmap& bitmap,
+ int x, int y,
+ const SkPaint& paint) {
+ pdf_device_->drawSprite(draw, bitmap, x, y, paint);
+}
+
+void VectorPlatformDeviceSkia::drawText(const SkDraw& draw,
+ const void* text,
+ size_t byteLength,
+ SkScalar x,
+ SkScalar y,
+ const SkPaint& paint) {
+ pdf_device_->drawText(draw, text, byteLength, x, y, paint);
+}
+
+void VectorPlatformDeviceSkia::drawPosText(const SkDraw& draw,
+ const void* text,
+ size_t len,
+ const SkScalar pos[],
+ SkScalar constY,
+ int scalarsPerPos,
+ const SkPaint& paint) {
+ pdf_device_->drawPosText(draw, text, len, pos, constY, scalarsPerPos, paint);
+}
+
+void VectorPlatformDeviceSkia::drawTextOnPath(const SkDraw& draw,
+ const void* text,
+ size_t len,
+ const SkPath& path,
+ const SkMatrix* matrix,
+ const SkPaint& paint) {
+ pdf_device_->drawTextOnPath(draw, text, len, path, matrix, paint);
+}
+
+void VectorPlatformDeviceSkia::drawVertices(const SkDraw& draw,
+ SkCanvas::VertexMode vmode,
+ int vertexCount,
+ const SkPoint vertices[],
+ const SkPoint texs[],
+ const SkColor colors[],
+ SkXfermode* xmode,
+ const uint16_t indices[],
+ int indexCount,
+ const SkPaint& paint) {
+ pdf_device_->drawVertices(draw, vmode, vertexCount, vertices, texs, colors,
+ xmode, indices, indexCount, paint);
+}
+
+void VectorPlatformDeviceSkia::drawDevice(const SkDraw& draw,
+ SkDevice* device,
+ int x,
+ int y,
+ const SkPaint& paint) {
+ SkDevice* real_device = device;
+ if ((device->getDeviceCapabilities() & kVector_Capability)) {
+ // Assume that a vectorial device means a VectorPlatformDeviceSkia, we need
+ // to unwrap the embedded SkPDFDevice.
+ VectorPlatformDeviceSkia* vector_device =
+ static_cast<VectorPlatformDeviceSkia*>(device);
+ real_device = vector_device->pdf_device_.get();
+ }
+ pdf_device_->drawDevice(draw, real_device, x, y, paint);
+}
+
+#if defined(OS_WIN)
+void VectorPlatformDeviceSkia::drawToHDC(HDC dc,
+ int x,
+ int y,
+ const RECT* src_rect) {
+ SkASSERT(false);
+}
+#endif
+
+void VectorPlatformDeviceSkia::setInitialTransform(int xOffset, int yOffset,
+ float scale_factor) {
+ // TODO(vandebo) Supporting a scale factor is some work because we have to
+ // transform both matrices and clips that come in, but Region only supports
+ // translation. Instead, we could change SkPDFDevice to include it in the
+ // initial transform. Delay that work until we would use it. Also checked
+ // in setMatrixClip.
+ DCHECK_EQ(1.0f, scale_factor);
+
+ base_transform_.setTranslate(xOffset, yOffset);
+ SkScalar scale = SkFloatToScalar(scale_factor);
+ base_transform_.postScale(scale, scale);
+
+ SkMatrix matrix;
+ matrix.reset();
+ SkRegion region;
+ SkClipStack stack;
+ setMatrixClip(matrix, region, stack);
+}
+
+} // namespace skia
diff --git a/skia/ext/vector_platform_device_skia.h b/skia/ext/vector_platform_device_skia.h
new file mode 100644
index 0000000..38cf0c5
--- /dev/null
+++ b/skia/ext/vector_platform_device_skia.h
@@ -0,0 +1,106 @@
+// 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 SKIA_EXT_VECTOR_PLATFORM_DEVICE_SKIA_H_
+#define SKIA_EXT_VECTOR_PLATFORM_DEVICE_SKIA_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "skia/ext/platform_device.h"
+#include "third_party/skia/include/core/SkMatrix.h"
+#include "third_party/skia/include/core/SkRefCnt.h"
+#include "third_party/skia/include/core/SkTScopedPtr.h"
+#include "third_party/skia/include/pdf/SkPDFDevice.h"
+
+class SkClipStack;
+struct SkIRect;
+struct SkRect;
+
+namespace skia {
+
+class BitmapPlatformDevice;
+
+class VectorPlatformDeviceSkiaFactory : public SkDeviceFactory {
+ public:
+ virtual SkDevice* newDevice(SkCanvas* notUsed, SkBitmap::Config config,
+ int width, int height, bool isOpaque,
+ bool isForLayer);
+};
+
+class VectorPlatformDeviceSkia : public PlatformDevice {
+ public:
+ VectorPlatformDeviceSkia(int width, int height,
+ SkPDFDevice::OriginTransform flip);
+
+ ~VectorPlatformDeviceSkia();
+
+ SkPDFDevice* PdfDevice() { return pdf_device_.get(); }
+
+ // PlatformDevice methods.
+ virtual bool IsVectorial();
+ virtual bool IsNativeFontRenderingAllowed();
+
+ virtual PlatformSurface BeginPlatformPaint();
+ virtual void EndPlatformPaint();
+
+ // SkDevice methods.
+ virtual SkDeviceFactory* getDeviceFactory();
+ virtual uint32_t getDeviceCapabilities();
+
+ virtual int width() const;
+ virtual int height() const;
+ virtual void setMatrixClip(const SkMatrix& matrix, const SkRegion& region,
+ const SkClipStack& stack);
+ virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
+
+ virtual void drawPaint(const SkDraw& draw, const SkPaint& paint);
+ virtual void drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
+ size_t count, const SkPoint[], const SkPaint& paint);
+ virtual void drawRect(const SkDraw& draw, const SkRect& rect,
+ const SkPaint& paint);
+ virtual void drawPath(const SkDraw& draw, const SkPath& path,
+ const SkPaint& paint, const SkMatrix* prePathMatrix,
+ bool pathIsMutable);
+ virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
+ const SkIRect* srcRectOrNull, const SkMatrix& matrix,
+ const SkPaint& paint);
+ virtual void drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
+ int x, int y, const SkPaint& paint);
+ virtual void drawText(const SkDraw& draw, const void* text, size_t len,
+ SkScalar x, SkScalar y, const SkPaint& paint);
+ virtual void drawPosText(const SkDraw& draw, const void* text, size_t len,
+ const SkScalar pos[], SkScalar constY,
+ int scalarsPerPos, const SkPaint& paint);
+ virtual void drawTextOnPath(const SkDraw& draw, const void* text, size_t len,
+ const SkPath& path, const SkMatrix* matrix,
+ const SkPaint& paint);
+ virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode,
+ int vertexCount, const SkPoint verts[],
+ const SkPoint texs[], const SkColor colors[],
+ SkXfermode* xmode, const uint16_t indices[],
+ int indexCount, const SkPaint& paint);
+ virtual void drawDevice(const SkDraw& draw, SkDevice*, int x, int y,
+ const SkPaint&);
+
+#if defined(OS_WIN)
+ virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect);
+#endif
+
+ // Our own methods.
+
+ // This needs to be called before anything is drawn.
+ void setInitialTransform(int xOffset, int yOffset, float scale_factor);
+
+ private:
+ SkRefPtr<SkPDFDevice> pdf_device_;
+ SkMatrix base_transform_;
+ SkRefPtr<BitmapPlatformDevice> raster_surface_;
+
+ DISALLOW_COPY_AND_ASSIGN(VectorPlatformDeviceSkia);
+};
+
+} // namespace skia
+
+#endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_SKIA_H_
diff --git a/skia/skia.gyp b/skia/skia.gyp
index 45d2a9a..c42d7ff 100644
--- a/skia/skia.gyp
+++ b/skia/skia.gyp
@@ -325,6 +325,7 @@
'../third_party/skia/src/core/SkFP.h',
'../third_party/skia/src/core/SkFilterProc.cpp',
'../third_party/skia/src/core/SkFilterProc.h',
+ '../third_party/skia/src/core/SkFlate.cpp',
'../third_party/skia/src/core/SkFlattenable.cpp',
'../third_party/skia/src/core/SkFloat.cpp',
'../third_party/skia/src/core/SkFloat.h',
@@ -462,6 +463,19 @@
'../third_party/skia/src/opts/opts_check_SSE2.cpp',
+ '../third_party/skia/src/pdf/SkPDFCatalog.cpp',
+ '../third_party/skia/src/pdf/SkPDFDevice.cpp',
+ '../third_party/skia/src/pdf/SkPDFDocument.cpp',
+ '../third_party/skia/src/pdf/SkPDFFont.cpp',
+ '../third_party/skia/src/pdf/SkPDFFormXObject.cpp',
+ '../third_party/skia/src/pdf/SkPDFGraphicState.cpp',
+ '../third_party/skia/src/pdf/SkPDFImage.cpp',
+ '../third_party/skia/src/pdf/SkPDFPage.cpp',
+ '../third_party/skia/src/pdf/SkPDFShader.cpp',
+ '../third_party/skia/src/pdf/SkPDFStream.cpp',
+ '../third_party/skia/src/pdf/SkPDFTypes.cpp',
+ '../third_party/skia/src/pdf/SkPDFUtils.cpp',
+
#'../third_party/skia/src/ports/SkFontHost_FONTPATH.cpp',
'../third_party/skia/src/ports/SkFontHost_FreeType.cpp',
#'../third_party/skia/src/ports/SkFontHost_android.cpp',
@@ -521,6 +535,7 @@
'../third_party/skia/include/core/SkEndian.h',
'../third_party/skia/include/core/SkFDot6.h',
'../third_party/skia/include/core/SkFixed.h',
+ '../third_party/skia/include/core/SkFlate.h',
'../third_party/skia/include/core/SkFlattenable.h',
'../third_party/skia/include/core/SkFloatBits.h',
'../third_party/skia/include/core/SkFloatingPoint.h',
@@ -605,6 +620,19 @@
'../third_party/skia/include/gpu/SkGr.h',
'../third_party/skia/include/gpu/SkGrTexturePixelRef.h',
+ '../third_party/skia/include/pdf/SkPDFCatalog.h',
+ '../third_party/skia/include/pdf/SkPDFDevice.h',
+ '../third_party/skia/include/pdf/SkPDFDocument.h',
+ '../third_party/skia/include/pdf/SkPDFFont.h',
+ '../third_party/skia/include/pdf/SkPDFFormXObject.h',
+ '../third_party/skia/include/pdf/SkPDFGraphicState.h',
+ '../third_party/skia/include/pdf/SkPDFImage.h',
+ '../third_party/skia/include/pdf/SkPDFPage.h',
+ '../third_party/skia/include/pdf/SkPDFShader.h',
+ '../third_party/skia/include/pdf/SkPDFStream.h',
+ '../third_party/skia/include/pdf/SkPDFTypes.h',
+ '../third_party/skia/include/pdf/SkPDFUtils.h',
+
'../third_party/skia/include/ports/SkStream_Win.h',
'../third_party/skia/include/ports/SkTypeface_win.h',
@@ -654,6 +682,8 @@
'ext/vector_platform_device_cairo_linux.h',
'ext/vector_platform_device_emf_win.cc',
'ext/vector_platform_device_emf_win.h',
+ 'ext/vector_platform_device_skia.cc',
+ 'ext/vector_platform_device_skia.h',
],
'include_dirs': [
'..',
@@ -663,6 +693,7 @@
'../third_party/skia/include/effects',
'../third_party/skia/include/gpu',
'../third_party/skia/include/images',
+ '../third_party/skia/include/pdf',
'../third_party/skia/include/ports',
'../third_party/skia/include/utils',
'../third_party/skia/gpu/include',
@@ -752,6 +783,10 @@
'defines': [
'SK_BUILD_FOR_MAC',
],
+ 'sources/': [
+ ['exclude', '/pdf/'],
+ ['exclude', 'ext/vector_platform_device_skia\\.(cc|h)'],
+ ],
'include_dirs': [
'../third_party/skia/include/utils/mac',
],
@@ -803,6 +838,7 @@
'../third_party/skia/include/config',
'../third_party/skia/include/core',
'../third_party/skia/include/effects',
+ '../third_party/skia/include/pdf',
'../third_party/skia/include/gpu',
'../third_party/skia/include/ports',
'../third_party/skia/gpu/include',