5e00989a28
prepare to deprecate SkPDFDevice constructor, and route gm and render_pdfs to use SkDocument::Create pdf interface instead. - controlled by a flag add comments where we are supposed to flatten other features (paint, shaders, ... ) R=reed@google.com, bungeman@google.com, scroggo@google.com, vandebo@chromium.org, bsalomon@google.com Author: edisonn@google.com Review URL: https://codereview.chromium.org/24811002 git-svn-id: http://skia.googlecode.com/svn/trunk@11751 2bbb7eff-a529-9590-31e7-b0007b416f81
61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
/*
|
|
* Copyright 2012 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "PdfRenderer.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkDevice.h"
|
|
#include "SkPDFDevice.h"
|
|
#include "SkPDFDocument.h"
|
|
|
|
namespace sk_tools {
|
|
|
|
void PdfRenderer::init(SkPicture* pict, SkWStream* stream) {
|
|
SkASSERT(NULL == fPicture);
|
|
SkASSERT(NULL == fCanvas.get());
|
|
if (fPicture != NULL || NULL != fCanvas.get()) {
|
|
return;
|
|
}
|
|
|
|
SkASSERT(pict != NULL);
|
|
if (NULL == pict) {
|
|
return;
|
|
}
|
|
|
|
fPicture = pict;
|
|
fCanvas.reset(this->setupCanvas(stream, pict->width(), pict->height()));
|
|
}
|
|
|
|
SkCanvas* PdfRenderer::setupCanvas(SkWStream* stream, int width, int height) {
|
|
fPdfDoc.reset(SkDocument::CreatePDF(stream, NULL, fEncoder));
|
|
|
|
SkCanvas* canvas = fPdfDoc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
|
|
canvas->ref();
|
|
|
|
return canvas;
|
|
}
|
|
|
|
void PdfRenderer::end() {
|
|
fPicture = NULL;
|
|
fCanvas.reset(NULL);
|
|
fPdfDoc.reset(NULL);
|
|
}
|
|
|
|
bool SimplePdfRenderer::render() {
|
|
SkASSERT(fCanvas.get() != NULL);
|
|
SkASSERT(fPicture != NULL);
|
|
if (NULL == fCanvas.get() || NULL == fPicture) {
|
|
return false;
|
|
}
|
|
|
|
fCanvas->drawPicture(*fPicture);
|
|
fCanvas->flush();
|
|
|
|
return fPdfDoc->close();
|
|
}
|
|
|
|
}
|