documentation: SkDocument::MakePDF()
also, update some tools. DOCS_PREVIEW= https://skia.org/user/sample/pdf?cl=1936283003 DOCS_PREVIEW= https://skia.org/user/api/canvas?cl=1936283003 Review-Url: https://codereview.chromium.org/1936283003
This commit is contained in:
parent
68f7460fd1
commit
676ab68b04
@ -1379,7 +1379,7 @@ SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
|
||||
#ifdef SK_BUILD_FOR_ANDROID
|
||||
name.prepend("/sdcard/");
|
||||
#endif
|
||||
fPDFDocument.reset(SkDocument::CreatePDF(name.c_str()));
|
||||
fPDFDocument = SkDocument::MakePDF(name.c_str());
|
||||
canvas = fPDFDocument->beginPage(this->width(), this->height());
|
||||
} else if (fSaveToSKP) {
|
||||
canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0);
|
||||
|
@ -181,7 +181,7 @@ private:
|
||||
|
||||
bool fSaveToPdf;
|
||||
bool fSaveToSKP;
|
||||
SkAutoTUnref<SkDocument> fPDFDocument;
|
||||
sk_sp<SkDocument> fPDFDocument;
|
||||
|
||||
bool fUseClip;
|
||||
bool fUsePicture;
|
||||
|
@ -37,13 +37,13 @@ the memory into which the canvas commands are drawn.
|
||||
void raster(int width, int height,
|
||||
void(*draw)(SkCanvas*),
|
||||
const char* path) {
|
||||
SkAutoTUnref<SkSurface> rasterSurface(
|
||||
SkSurface::NewRasterN32Premul(width, height));
|
||||
sk_sp<SkSurface> rasterSurface(
|
||||
SkSurface::MakeRasterN32Premul(width, height));
|
||||
SkCanvas* rasterCanvas = rasterSurface->getCanvas();
|
||||
draw(rasterCanvas);
|
||||
SkAutoTUnref<SkImage> img(s->newImageSnapshot());
|
||||
sk_sp<SkImage> img(s->newImageSnapshot());
|
||||
if (!img) { return; }
|
||||
SkAutoTUnref<SkData> png(img->encode());
|
||||
sk_sp<SkData> png(img->encode());
|
||||
if (!png) { return; }
|
||||
SkFILEWStream out(path);
|
||||
(void)out.write(png->data(), png->size());
|
||||
@ -60,8 +60,8 @@ explicitly, instead of asking Skia to manage it.
|
||||
size_t rowBytes = info.minRowBytes();
|
||||
size_t size = info.getSafeSize(rowBytes);
|
||||
std::vector<char> pixelMemory(size); // allocate memory
|
||||
SkAutoTUnref<SkSurface> surface(
|
||||
SkSurface::NewRasterDirect(
|
||||
sk_sp<SkSurface> surface(
|
||||
SkSurface::MakeRasterDirect(
|
||||
info, &pixelMemory[0], rowBytes));
|
||||
SkCanvas* canvas = surface.getCanvas();
|
||||
draw(canvas);
|
||||
@ -89,17 +89,17 @@ example, we use a `GrContextFactory` to create a context.
|
||||
GrContextFactory grFactory;
|
||||
GrContext* context = grFactory.get(GrContextFactory::kNative_GLContextType);
|
||||
SkImageInfo info = SkImageInfo:: MakeN32Premul(width, height);
|
||||
SkAutoTUnref<SkSurface> gpuSurface(
|
||||
SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info));
|
||||
sk_sp<SkSurface> gpuSurface(
|
||||
SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
|
||||
if (!gpuSurface) {
|
||||
SkDebugf("SkSurface::NewRenderTarget returned null\n");
|
||||
SkDebugf("SkSurface::MakeRenderTarget returned null\n");
|
||||
return;
|
||||
}
|
||||
SkCanvas* gpuCanvas = gpuSurface->getCanvas();
|
||||
draw(gpuCanvas);
|
||||
SkAutoTUnref<SkImage> img(s->newImageSnapshot());
|
||||
sk_sp<SkImage> img(s->newImageSnapshot());
|
||||
if (!img) { return; }
|
||||
SkAutoTUnref<SkData> png(img->encode());
|
||||
sk_sp<SkData> png(img->encode());
|
||||
if (!png) { return; }
|
||||
SkFILEWStream out(path);
|
||||
(void)out.write(png->data(), png->size());
|
||||
@ -120,7 +120,7 @@ a document must include multiple pages.
|
||||
void(*draw)(SkCanvas*),
|
||||
const char* path) {
|
||||
SkFILEWStream pdfStream(path);
|
||||
SkAutoTUnref<SkDocument> pdfDoc(SkDocument::CreatePDF(&pdfStream));
|
||||
sk_sp<SkDocument> pdfDoc(SkDocument::MakePDF(&pdfStream));
|
||||
SkCanvas* pdfCanvas = pdfDoc->beginPage(SkIntToScalar(width),
|
||||
SkIntToScalar(height));
|
||||
draw(pdfCanvas);
|
||||
@ -145,7 +145,7 @@ The SkPicture backend uses SkPictureRecorder instead of SkSurface.
|
||||
SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width),
|
||||
SkIntToScalar(height));
|
||||
draw(recordingCanvas);
|
||||
SkAutoTUnref<SkPicture> picture(recorder.endRecordingAsPicture());
|
||||
sk_sp<SkPicture> picture(recorder.endRecordingAsPicture());
|
||||
SkFILEWStream skpStream(path);
|
||||
// Open SKP files with `SampleApp --picture SKP_FILE`
|
||||
picture->serialize(&skpStream);
|
||||
@ -162,7 +162,7 @@ nothing.
|
||||
|
||||
#include "SkNullCanvas.h"
|
||||
void picture(int, int, void(*draw)(SkCanvas*), const char*) {
|
||||
SkAutoTDelete<SkCanvas> nullCanvas(SkCreateNullCanvas());
|
||||
sk_sp<SkCanvas> nullCanvas(SkCreateNullCanvas());
|
||||
draw(nullCanvas); // NoOp
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ The (*still experimental*) SkXPS canvas writes into an XPS document.
|
||||
void(*draw)(SkCanvas*),
|
||||
const char* path) {
|
||||
SkFILEWStream xpsStream(path);
|
||||
SkAutoTUnref<SkDocument> xpsDoc(SkDocument::CreateXPS(&pdfStream));
|
||||
sk_sp<SkDocument> xpsDoc(SkDocument::MakeXPS(&pdfStream));
|
||||
SkCanvas* xpsCanvas = xpsDoc->beginPage(SkIntToScalar(width),
|
||||
SkIntToScalar(height));
|
||||
draw(xpsCanvas);
|
||||
@ -202,8 +202,9 @@ The (*still experimental*) SkSVG canvas writes into an SVG document.
|
||||
void(*draw)(SkCanvas*),
|
||||
const char* path) {
|
||||
SkFILEWStream svgStream(path);
|
||||
SkAutoTDelete<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(&svgStream));
|
||||
SkAutoTUnref<SkCanvas> svgCanvas(SkSVGCanvas::Create(
|
||||
std::unique_ptr<SkXMLWriter> xmlWriter(
|
||||
new SkXMLStreamWriter(&svgStream));
|
||||
sk_sp<SkCanvas> svgCanvas(SkSVGCanvas::Create(
|
||||
SkRect::MakeWH(SkIntToScalar(src.size().width()),
|
||||
SkIntToScalar(src.size().height())),
|
||||
xmlWriter));
|
||||
|
@ -9,19 +9,22 @@ via the SkDocument and SkCanvas APIs.
|
||||
#include "SkDocument.h"
|
||||
|
||||
bool WritePDF(SkWStream* outputStream) {
|
||||
sk_sp<SkDocument> pdfDocument(SkDocument::CreatePDF(outputStream));
|
||||
typedef SkDocument::Attribute Attr;
|
||||
Attr info[] = {
|
||||
Attr(SkString("Title"), SkString("....")),
|
||||
Attr(SkString("Author"), SkString("....")),
|
||||
Attr(SkString("Subject"), SkString("....")),
|
||||
Attr(SkString("Keywords"), SkString("....")),
|
||||
Attr(SkString("Creator"), SkString("....")),
|
||||
};
|
||||
int infoCount = sizeof(info) / sizeof(info[0]);
|
||||
SkTime::DateTime now;
|
||||
SkTime::GetDateTime(&now);
|
||||
pdfDocument->setMetadata(info, infoCount, &now, &now);
|
||||
SkDocument::PDFMetadata metadata;
|
||||
metadata.fCreator = "creator....";
|
||||
metadata.fTitle = "title...";
|
||||
metadata.fAuthor = "author...";
|
||||
metadata.fSubject = "subject...";
|
||||
metadata.fKeywords = "keywords...";
|
||||
metadata.fCreator = "creator...";
|
||||
SkTime::DateTime now = get_current_date_and_time();
|
||||
metadata.fCreation.fEnabled = true;
|
||||
metadata.fCreation.fDateTime = now;
|
||||
metadata.fModified.fEnabled = true;
|
||||
metadata.fModified.fDateTime = now;
|
||||
sk_sp<SkDocument> pdfDocument(SkDocument::MakePDF(
|
||||
outputStream, SK_ScalarDefaultRasterDPI, metadata,
|
||||
nullptr, true);
|
||||
assert(pdfDocument);
|
||||
|
||||
int numberOfPages = ....;
|
||||
for (int page = 0; page < numberOfPages; ++page) {
|
||||
|
@ -1950,12 +1950,12 @@ static int lsk_newDocumentPDF(lua_State* L) {
|
||||
file = lua_tolstring(L, 1, nullptr);
|
||||
}
|
||||
|
||||
SkDocument* doc = SkDocument::CreatePDF(file);
|
||||
sk_sp<SkDocument> doc = SkDocument::MakePDF(file);
|
||||
if (nullptr == doc) {
|
||||
// do I need to push a nil on the stack and return 1?
|
||||
return 0;
|
||||
} else {
|
||||
push_ref(L, doc)->unref();
|
||||
push_ref(L, std::move(doc));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ int main() {
|
||||
}
|
||||
if (options.pdf) {
|
||||
SkDynamicMemoryWStream pdfStream;
|
||||
sk_sp<SkDocument> document(SkDocument::CreatePDF(&pdfStream));
|
||||
sk_sp<SkDocument> document(SkDocument::MakePDF(&pdfStream));
|
||||
draw(document->beginPage(options.size.width(), options.size.height()));
|
||||
document->close();
|
||||
pdfData.reset(pdfStream.copyToData());
|
||||
|
@ -48,7 +48,7 @@ static bool do_surface(int w, int h, const char path[], const char text[],
|
||||
|
||||
static bool do_document(int w, int h, const char path[], const char text[],
|
||||
const SkPaint& paint) {
|
||||
SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path));
|
||||
sk_sp<SkDocument> doc(SkDocument::MakePDF(path));
|
||||
if (doc.get()) {
|
||||
SkScalar width = SkIntToScalar(w);
|
||||
SkScalar height = SkIntToScalar(h);
|
||||
|
Loading…
Reference in New Issue
Block a user