2012-10-10 15:20:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PdfRenderer_DEFINED
|
|
|
|
#define PdfRenderer_DEFINED
|
|
|
|
|
|
|
|
//
|
|
|
|
// PdfRender takes a SkPicture and writes it to a PDF file.
|
|
|
|
// An SkPicture can be built manually, or read from an SKP file.
|
|
|
|
//
|
|
|
|
|
2013-10-14 13:42:12 +00:00
|
|
|
#include "SkDocument.h"
|
2012-10-10 15:20:34 +00:00
|
|
|
#include "SkMath.h"
|
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "SkTypes.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
class SkBitmap;
|
|
|
|
class SkCanvas;
|
2013-10-14 13:42:12 +00:00
|
|
|
class SkWStream;
|
2012-10-10 15:20:34 +00:00
|
|
|
|
|
|
|
namespace sk_tools {
|
|
|
|
|
|
|
|
class PdfRenderer : public SkRefCnt {
|
|
|
|
public:
|
2013-10-14 13:42:12 +00:00
|
|
|
virtual void init(SkPicture* pict, SkWStream* stream);
|
2012-10-10 15:20:34 +00:00
|
|
|
virtual void setup() {}
|
2013-10-14 13:42:12 +00:00
|
|
|
virtual bool render() = 0;
|
2012-10-10 15:20:34 +00:00
|
|
|
virtual void end();
|
|
|
|
|
2013-10-03 19:29:21 +00:00
|
|
|
PdfRenderer(SkPicture::EncodeBitmap encoder)
|
2012-10-10 15:20:34 +00:00
|
|
|
: fPicture(NULL)
|
2013-04-24 13:01:01 +00:00
|
|
|
, fEncoder(encoder)
|
2013-10-14 13:42:12 +00:00
|
|
|
, fPdfDoc(NULL)
|
2012-10-10 15:20:34 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
protected:
|
2013-10-14 13:42:12 +00:00
|
|
|
SkCanvas* setupCanvas(SkWStream* stream, int width, int height);
|
2012-10-10 15:20:34 +00:00
|
|
|
|
|
|
|
SkAutoTUnref<SkCanvas> fCanvas;
|
|
|
|
SkPicture* fPicture;
|
2013-10-03 19:29:21 +00:00
|
|
|
SkPicture::EncodeBitmap fEncoder;
|
2013-10-14 13:42:12 +00:00
|
|
|
SkAutoTUnref<SkDocument> fPdfDoc;
|
2012-10-10 15:20:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SimplePdfRenderer : public PdfRenderer {
|
|
|
|
public:
|
2013-10-03 19:29:21 +00:00
|
|
|
SimplePdfRenderer(SkPicture::EncodeBitmap encoder)
|
2013-04-24 13:01:01 +00:00
|
|
|
: PdfRenderer(encoder) {}
|
2013-10-14 13:42:12 +00:00
|
|
|
virtual bool render() SK_OVERRIDE;
|
2012-10-10 15:20:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef PdfRenderer INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PdfRenderer_DEFINED
|