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.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "SkMath.h"
|
2013-04-24 13:01:01 +00:00
|
|
|
#include "SkPDFDevice.h"
|
2012-10-10 15:20:34 +00:00
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "SkTypes.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
class SkBitmap;
|
|
|
|
class SkCanvas;
|
|
|
|
|
|
|
|
namespace sk_tools {
|
|
|
|
|
|
|
|
class PdfRenderer : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
virtual void init(SkPicture* pict);
|
|
|
|
virtual void setup() {}
|
|
|
|
virtual void render() = 0;
|
|
|
|
virtual void end();
|
|
|
|
|
2013-04-24 13:01:01 +00:00
|
|
|
PdfRenderer(EncodeToDCTStream encoder)
|
2012-10-10 15:20:34 +00:00
|
|
|
: fPicture(NULL)
|
|
|
|
, fPDFDevice(NULL)
|
2013-04-24 13:01:01 +00:00
|
|
|
, fEncoder(encoder)
|
2012-10-10 15:20:34 +00:00
|
|
|
{}
|
|
|
|
|
2013-01-11 20:30:41 +00:00
|
|
|
void write(SkWStream* stream) const;
|
2012-10-10 15:20:34 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
SkCanvas* setupCanvas();
|
|
|
|
SkCanvas* setupCanvas(int width, int height);
|
|
|
|
|
|
|
|
SkAutoTUnref<SkCanvas> fCanvas;
|
|
|
|
SkPicture* fPicture;
|
|
|
|
SkPDFDevice* fPDFDevice;
|
2013-04-24 13:01:01 +00:00
|
|
|
EncodeToDCTStream fEncoder;
|
2012-10-10 15:20:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SimplePdfRenderer : public PdfRenderer {
|
|
|
|
public:
|
2013-04-24 13:01:01 +00:00
|
|
|
SimplePdfRenderer(EncodeToDCTStream encoder)
|
|
|
|
: PdfRenderer(encoder) {}
|
2012-10-10 15:20:34 +00:00
|
|
|
virtual void render() SK_OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef PdfRenderer INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PdfRenderer_DEFINED
|