aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/PDFBench.cpp15
-rw-r--r--dm/DMSrcSink.cpp4
-rw-r--r--include/core/SkDocument.h70
-rw-r--r--public.bzl1
-rw-r--r--src/pdf/SkPDFBitmap.cpp29
-rw-r--r--src/pdf/SkPDFBitmap.h7
-rw-r--r--src/pdf/SkPDFCanon.h4
-rw-r--r--src/pdf/SkPDFDevice.cpp5
-rw-r--r--src/pdf/SkPDFDocument.cpp87
-rw-r--r--src/pdf/SkPDFDocument.h26
-rw-r--r--tests/PDFDocumentTest.cpp60
-rw-r--r--tests/PDFMetadataAttributeTest.cpp3
-rw-r--r--tools/shape/using_skia_and_harfbuzz.cpp5
13 files changed, 186 insertions, 130 deletions
diff --git a/bench/PDFBench.cpp b/bench/PDFBench.cpp
index 8593928d00..c2a8e60249 100644
--- a/bench/PDFBench.cpp
+++ b/bench/PDFBench.cpp
@@ -84,7 +84,11 @@ protected:
return;
}
while (loops-- > 0) {
- auto object = SkPDFCreateBitmapObject(fImage, nullptr);
+ auto object = SkPDFCreateBitmapObject(fImage,
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ nullptr,
+#endif
+ false);
SkASSERT(object);
if (!object) {
return;
@@ -121,7 +125,11 @@ protected:
return;
}
while (loops-- > 0) {
- auto object = SkPDFCreateBitmapObject(fImage, nullptr);
+ auto object = SkPDFCreateBitmapObject(fImage,
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ nullptr,
+#endif
+ false);
SkASSERT(object);
if (!object) {
return;
@@ -214,8 +222,7 @@ struct PDFShaderBench : public Benchmark {
SkASSERT(fShader);
while (loops-- > 0) {
SkNullWStream nullStream;
- SkPDFDocument doc(&nullStream, nullptr, 72,
- SkDocument::PDFMetadata(), nullptr, false);
+ SkPDFDocument doc(&nullStream, nullptr, SkDocument::PDFMetadata());
sk_sp<SkPDFObject> shader = SkPDFMakeShader(&doc, fShader.get(), SkMatrix::I(),
{0, 0, 400, 400}, SK_ColorBLACK);
}
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index a43f8d1906..d3566b6d92 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1645,7 +1645,9 @@ Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
metadata.fTitle = src.name();
metadata.fSubject = "rendering correctness test";
metadata.fCreator = "Skia/DM";
- sk_sp<SkDocument> doc = SkDocument::MakePDF(dst, fRasterDpi, metadata, nullptr, fPDFA);
+ metadata.fRasterDPI = fRasterDpi;
+ metadata.fPDFA = fPDFA;
+ sk_sp<SkDocument> doc = SkDocument::MakePDF(dst, metadata);
if (!doc) {
return "SkDocument::MakePDF() returned nullptr";
}
diff --git a/include/core/SkDocument.h b/include/core/SkDocument.h
index a868f1e699..df7cd73c3a 100644
--- a/include/core/SkDocument.h
+++ b/include/core/SkDocument.h
@@ -10,7 +10,9 @@
#include "SkBitmap.h"
#include "SkPicture.h"
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
#include "SkPixelSerializer.h"
+#endif
#include "SkRect.h"
#include "SkRefCnt.h"
#include "SkString.h"
@@ -86,8 +88,34 @@ public:
* The date and time the document was most recently modified.
*/
OptionalTimestamp fModified;
+
+ /** The DPI (pixels-per-inch) at which features without
+ * native PDF support will be rasterized (e.g. draw image
+ * with perspective, draw text with perspective, ...) A
+ * larger DPI would create a PDF that reflects the
+ * original intent with better fidelity, but it can make
+ * for larger PDF files too, which would use more memory
+ * while rendering, and it would be slower to be processed
+ * or sent online or to printer.
+ */
+ SkScalar fRasterDPI = SK_ScalarDefaultRasterDPI;
+
+ /** If true, include XMP metadata, a document UUID, and sRGB output intent information.
+ * This adds length to the document and makes it non-reproducable, but are necessary
+ * features for PDF/A-2b conformance
+ */
+ bool fPDFA = false;
+
+ /**
+ * Encoding quality controls the trade-off between size and quality. By default this is
+ * set to 101 percent, which corresponds to lossless encoding. If this value is set to
+ * a value <= 100, and the image is opaque, it will be encoded (using JPEG) with that
+ * quality setting.
+ */
+ int fEncodingQuality = 101;
};
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
/**
* Create a PDF-backed document, writing the results into a
* SkWStream.
@@ -109,16 +137,6 @@ public:
* or sent online or to printer.
* @param metadata a PDFmetadata object. Any fields may be left
* empty.
- * @param jpegEncoder For PDF documents, if a jpegEncoder is set,
- * use it to encode SkImages and SkBitmaps as [JFIF]JPEGs.
- * This feature is deprecated and is only supplied for
- * backwards compatability.
- * The prefered method to create PDFs with JPEG images is
- * to use SkImage::NewFromEncoded() and not jpegEncoder.
- * Chromium uses NewFromEncoded.
- * If the encoder is unset, or if jpegEncoder->onEncode()
- * returns NULL, fall back on encoding images losslessly
- * with Deflate.
* @param pdfa Iff true, include XMP metadata, a document UUID,
* and sRGB output intent information. This adds length
* to the document and makes it non-reproducable, but are
@@ -129,23 +147,32 @@ public:
*/
static sk_sp<SkDocument> MakePDF(SkWStream* stream,
SkScalar dpi,
- const SkDocument::PDFMetadata& metadata,
+ const PDFMetadata& metadata,
sk_sp<SkPixelSerializer> jpegEncoder,
bool pdfa);
-
- static sk_sp<SkDocument> MakePDF(SkWStream* stream,
- SkScalar dpi = SK_ScalarDefaultRasterDPI) {
- return SkDocument::MakePDF(stream, dpi, SkDocument::PDFMetadata(),
- nullptr, false);
- }
-
- static sk_sp<SkDocument> MakePDF(SkWStream* stream, const PDFMetadata& metadata);
-
/**
* Create a PDF-backed document, writing the results into a file.
*/
static sk_sp<SkDocument> MakePDF(const char outputFilePath[],
SkScalar dpi = SK_ScalarDefaultRasterDPI);
+ static sk_sp<SkDocument> MakePDF(SkWStream* stream, SkScalar dpi);
+#endif
+
+ /**
+ * Create a PDF-backed document, writing the results into a
+ * SkWStream.
+ *
+ * PDF pages are sized in point units. 1 pt == 1/72 inch == 127/360 mm.
+ *
+ * @param stream A PDF document will be written to this stream. The document may write
+ * to the stream at anytime during its lifetime, until either close() is
+ * called or the document is deleted.
+ * @param metadata a PDFmetadata object. Any fields may be left empty.
+ *
+ * @returns NULL if there is an error, otherwise a newly created PDF-backed SkDocument.
+ */
+ static sk_sp<SkDocument> MakePDF(SkWStream* stream, const PDFMetadata& metadata);
+ static sk_sp<SkDocument> MakePDF(SkWStream* stream);
#ifdef SK_BUILD_FOR_WIN
/**
@@ -179,8 +206,7 @@ public:
* into the page. The document owns this canvas, and it will go out of
* scope when endPage() or close() is called, or the document is deleted.
*/
- SkCanvas* beginPage(SkScalar width, SkScalar height,
- const SkRect* content = nullptr);
+ SkCanvas* beginPage(SkScalar width, SkScalar height, const SkRect* content = nullptr);
/**
* Call endPage() when the content for the current page has been drawn
diff --git a/public.bzl b/public.bzl
index c346d7436c..6281ce3fff 100644
--- a/public.bzl
+++ b/public.bzl
@@ -586,6 +586,7 @@ def base_defines(os_conditions):
"SK_JUMPER_DISABLE_8BIT",
# JPEG is in codec_limited
"SK_HAS_JPEG_LIBRARY",
+ "SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER",
] + skia_select(
os_conditions,
[
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp
index 8c312963da..f97eeff484 100644
--- a/src/pdf/SkPDFBitmap.cpp
+++ b/src/pdf/SkPDFBitmap.cpp
@@ -408,16 +408,15 @@ void PDFJpegBitmap::emitObject(SkWStream* stream,
////////////////////////////////////////////////////////////////////////////////
sk_sp<SkPDFObject> SkPDFCreateBitmapObject(sk_sp<SkImage> image,
- SkPixelSerializer* pixelSerializer) {
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ SkPixelSerializer* pixelSerializer,
+#endif
+ int encodingQuality) {
SkASSERT(image);
+ SkASSERT(encodingQuality >= 0);
sk_sp<SkData> data = image->refEncodedData();
SkJFIFInfo info;
- if (data && SkIsJFIF(data.get(), &info) &&
- (!pixelSerializer ||
- pixelSerializer->useEncodedData(data->data(), data->size()))) {
- // If there is a SkPixelSerializer, give it a chance to
- // re-encode the JPEG with more compression by returning false
- // from useEncodedData.
+ if (data && SkIsJFIF(data.get(), &info)) {
bool yuv = info.fType == SkJFIFInfo::kYCbCr;
if (info.fSize == image->dimensions()) { // Sanity check.
// hold on to data, not image.
@@ -428,6 +427,7 @@ sk_sp<SkPDFObject> SkPDFCreateBitmapObject(sk_sp<SkImage> image,
}
}
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
if (pixelSerializer) {
SkBitmap bm;
SkPixmap pmap;
@@ -441,9 +441,22 @@ sk_sp<SkPDFObject> SkPDFCreateBitmapObject(sk_sp<SkImage> image,
}
}
}
+#endif
+
+ const bool isOpaque = image_compute_is_opaque(image.get());
+
+ if (encodingQuality <= 100 && isOpaque) {
+ data = image->encodeToData(SkEncodedImageFormat::kJPEG, encodingQuality);
+ if (data && SkIsJFIF(data.get(), &info)) {
+ bool yuv = info.fType == SkJFIFInfo::kYCbCr;
+ if (info.fSize == image->dimensions()) { // Sanity check.
+ return sk_make_sp<PDFJpegBitmap>(info.fSize, data.get(), yuv);
+ }
+ }
+ }
sk_sp<SkPDFObject> smask;
- if (!image_compute_is_opaque(image.get())) {
+ if (!isOpaque) {
smask = sk_make_sp<PDFAlphaBitmap>(image);
}
#ifdef SK_PDF_IMAGE_STATS
diff --git a/src/pdf/SkPDFBitmap.h b/src/pdf/SkPDFBitmap.h
index 8de796c70b..a4e8ec5ccb 100644
--- a/src/pdf/SkPDFBitmap.h
+++ b/src/pdf/SkPDFBitmap.h
@@ -10,7 +10,9 @@
#include "SkRefCnt.h"
class SkImage;
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
class SkPixelSerializer;
+#endif
class SkPDFObject;
/**
@@ -19,6 +21,9 @@ class SkPDFObject;
* the image, and its emitObject() does not cache any data.
*/
sk_sp<SkPDFObject> SkPDFCreateBitmapObject(sk_sp<SkImage>,
- SkPixelSerializer*);
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ SkPixelSerializer*,
+#endif
+ int encodingQuality);
#endif // SkPDFBitmap_DEFINED
diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h
index 8edd06e391..d68e471289 100644
--- a/src/pdf/SkPDFCanon.h
+++ b/src/pdf/SkPDFCanon.h
@@ -11,7 +11,9 @@
#include "SkPDFGradientShader.h"
#include "SkPDFGraphicState.h"
#include "SkPDFShader.h"
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
#include "SkPixelSerializer.h"
+#endif
#include "SkTDArray.h"
#include "SkTHash.h"
#include "SkTypeface.h"
@@ -43,7 +45,9 @@ public:
SkTHashMap<SkPDFStrokeGraphicState, sk_sp<SkPDFDict>> fStrokeGSMap;
SkTHashMap<SkPDFFillGraphicState, sk_sp<SkPDFDict>> fFillGSMap;
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
sk_sp<SkPixelSerializer> fPixelSerializer;
+#endif
sk_sp<SkPDFStream> fInvertFunction;
sk_sp<SkPDFDict> fNoSmaskGraphicState;
sk_sp<SkPDFArray> fRangeObject;
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index aae792bb8b..582a44a963 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -2512,7 +2512,10 @@ void SkPDFDevice::internalDrawImageRect(SkKeyedImage imageSubset,
if (!pdfimage) {
SkASSERT(imageSubset);
pdfimage = SkPDFCreateBitmapObject(imageSubset.release(),
- fDocument->canon()->fPixelSerializer.get());
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ fDocument->canon()->fPixelSerializer.get(),
+#endif
+ fDocument->metadata().fEncodingQuality);
if (!pdfimage) {
return;
}
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index 9b23798a3f..f7c35ca2ac 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -12,6 +12,9 @@
#include "SkPDFCanon.h"
#include "SkPDFDevice.h"
#include "SkPDFUtils.h"
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+#include "SkPixelSerializer.h"
+#endif
#include "SkStream.h"
SkPDFObjectSerializer::SkPDFObjectSerializer() : fBaseOffset(0), fNextToBeSerialized(0) {}
@@ -173,15 +176,16 @@ static sk_sp<SkPDFDict> generate_page_tree(SkTArray<sk_sp<SkPDFDict>>* pages) {
SkPDFDocument::SkPDFDocument(SkWStream* stream,
void (*doneProc)(SkWStream*, bool),
- SkScalar rasterDpi,
- const SkDocument::PDFMetadata& metadata,
- sk_sp<SkPixelSerializer> jpegEncoder,
- bool pdfa)
+ const SkDocument::PDFMetadata& metadata
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ , sk_sp<SkPixelSerializer> jpegEncoder
+#endif
+ )
: SkDocument(stream, doneProc)
- , fRasterDpi(rasterDpi)
- , fMetadata(metadata)
- , fPDFA(pdfa) {
+ , fMetadata(metadata) {
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
fCanon.fPixelSerializer = std::move(jpegEncoder);
+#endif
}
SkPDFDocument::~SkPDFDocument() {
@@ -200,7 +204,7 @@ SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height) {
// if this is the first page if the document.
fObjectSerializer.serializeHeader(this->getStream(), fMetadata);
fDests = sk_make_sp<SkPDFDict>();
- if (fPDFA) {
+ if (fMetadata.fPDFA) {
SkPDFMetadata::UUID uuid = SkPDFMetadata::CreateUUID(fMetadata);
// We use the same UUID for Document ID and Instance ID since this
// is the first revision of this document (and Skia does not
@@ -404,7 +408,7 @@ void SkPDFDocument::onClose(SkWStream* stream) {
return;
}
auto docCatalog = sk_make_sp<SkPDFDict>("Catalog");
- if (fPDFA) {
+ if (fMetadata.fPDFA) {
SkASSERT(fXMP);
docCatalog->insertObjRef("Metadata", fXMP);
// Don't specify OutputIntents if we are not in PDF/A mode since
@@ -432,37 +436,58 @@ void SkPDFDocument::onClose(SkWStream* stream) {
sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream,
void (*proc)(SkWStream*, bool),
- SkScalar dpi,
- const SkDocument::PDFMetadata& metadata,
- sk_sp<SkPixelSerializer> jpeg,
- bool pdfa) {
- if (dpi <= 0) {
- dpi = 72.0f;
+ const SkDocument::PDFMetadata& metadata
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ , sk_sp<SkPixelSerializer> jpeg
+#endif
+ ) {
+ SkDocument::PDFMetadata meta = metadata;
+ if (meta.fRasterDPI <= 0) {
+ meta.fRasterDPI = 72.0f;
+ }
+ if (meta.fEncodingQuality < 0) {
+ meta.fEncodingQuality = 0;
}
- return stream ? sk_make_sp<SkPDFDocument>(stream, proc, dpi, metadata,
- std::move(jpeg), pdfa)
+ return stream ? sk_make_sp<SkPDFDocument>(stream, proc, meta
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ , std::move(jpeg)
+#endif
+ )
: nullptr;
}
-sk_sp<SkDocument> SkDocument::MakePDF(const char path[], SkScalar dpi) {
- auto delete_wstream = [](SkWStream* stream, bool) { delete stream; };
- auto stream = skstd::make_unique<SkFILEWStream>(path);
- return stream->isValid()
- ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi,
- SkDocument::PDFMetadata(), nullptr,
- false)
- : nullptr;
+sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream, const PDFMetadata& metadata) {
+ return SkPDFMakeDocument(stream, nullptr, metadata);
}
+sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream) {
+ return SkPDFMakeDocument(stream, nullptr, PDFMetadata());
+}
+
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream,
SkScalar dpi,
- const SkDocument::PDFMetadata& metadata,
+ const PDFMetadata& metadata,
sk_sp<SkPixelSerializer> jpegEncoder,
bool pdfa) {
- return SkPDFMakeDocument(stream, nullptr, dpi, metadata,
- std::move(jpegEncoder), pdfa);
+ PDFMetadata meta = metadata;
+ meta.fRasterDPI = dpi;
+ meta.fPDFA = pdfa;
+ return SkPDFMakeDocument(stream, nullptr, meta, jpegEncoder);
}
-
-sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream, const PDFMetadata& metadata) {
- return MakePDF(stream, SK_ScalarDefaultRasterDPI, metadata, nullptr, false);
+sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream, SkScalar dpi) {
+ PDFMetadata meta;
+ meta.fRasterDPI = dpi;
+ return SkPDFMakeDocument(stream, nullptr, meta, nullptr);
+}
+sk_sp<SkDocument> SkDocument::MakePDF(const char path[], SkScalar dpi) {
+ auto delete_wstream = [](SkWStream* stream, bool) { delete stream; };
+ auto stream = skstd::make_unique<SkFILEWStream>(path);
+ if (!stream->isValid()) {
+ return nullptr;
+ }
+ PDFMetadata meta;
+ meta.fRasterDPI = dpi;
+ return SkPDFMakeDocument(stream.release(), delete_wstream, meta, nullptr);
}
+#endif
diff --git a/src/pdf/SkPDFDocument.h b/src/pdf/SkPDFDocument.h
index 3e3a50ae83..7cfd0bd1c3 100644
--- a/src/pdf/SkPDFDocument.h
+++ b/src/pdf/SkPDFDocument.h
@@ -10,6 +10,9 @@
#include "SkDocument.h"
#include "SkPDFCanon.h"
#include "SkPDFMetadata.h"
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+#include "SkPixelSerializer.h"
+#endif
#include "SkPDFFont.h"
class SkPDFDevice;
@@ -26,10 +29,11 @@ class SkPDFDevice;
*/
sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream,
void (*doneProc)(SkWStream*, bool),
- SkScalar rasterDpi,
- const SkDocument::PDFMetadata&,
- sk_sp<SkPixelSerializer>,
- bool pdfa);
+ const SkDocument::PDFMetadata&
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ , sk_sp<SkPixelSerializer> = nullptr
+#endif
+ );
// Logically part of SkPDFDocument (like SkPDFCanon), but separate to
// keep similar functionality together.
@@ -56,10 +60,11 @@ class SkPDFDocument : public SkDocument {
public:
SkPDFDocument(SkWStream*,
void (*)(SkWStream*, bool),
- SkScalar,
- const SkDocument::PDFMetadata&,
- sk_sp<SkPixelSerializer>,
- bool);
+ const SkDocument::PDFMetadata&
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ , sk_sp<SkPixelSerializer> = nullptr
+#endif
+ );
~SkPDFDocument() override;
SkCanvas* onBeginPage(SkScalar, SkScalar) override;
void onEndPage() override;
@@ -77,8 +82,9 @@ public:
*/
void serialize(const sk_sp<SkPDFObject>&);
SkPDFCanon* canon() { return &fCanon; }
- SkScalar rasterDpi() const { return fRasterDpi; }
+ SkScalar rasterDpi() const { return fMetadata.fRasterDPI; }
void registerFont(SkPDFFont* f) { fFonts.add(f); }
+ const PDFMetadata& metadata() const { return fMetadata; }
private:
SkPDFObjectSerializer fObjectSerializer;
@@ -90,9 +96,7 @@ private:
std::unique_ptr<SkCanvas> fCanvas;
sk_sp<SkPDFObject> fID;
sk_sp<SkPDFObject> fXMP;
- SkScalar fRasterDpi;
SkDocument::PDFMetadata fMetadata;
- bool fPDFA;
void reset();
};
diff --git a/tests/PDFDocumentTest.cpp b/tests/PDFDocumentTest.cpp
index 82dafa3f15..d92929ea89 100644
--- a/tests/PDFDocumentTest.cpp
+++ b/tests/PDFDocumentTest.cpp
@@ -56,7 +56,8 @@ static void test_abortWithFile(skiatest::Reporter* reporter) {
// Make sure doc's destructor is called to flush.
{
- sk_sp<SkDocument> doc(SkDocument::MakePDF(path.c_str()));
+ SkFILEWStream stream(path.c_str());
+ sk_sp<SkDocument> doc = SkDocument::MakePDF(&stream);
SkCanvas* canvas = doc->beginPage(100, 100);
canvas->drawColor(SK_ColorRED);
@@ -85,13 +86,15 @@ static void test_file(skiatest::Reporter* reporter) {
return;
}
- sk_sp<SkDocument> doc(SkDocument::MakePDF(path.c_str()));
-
- SkCanvas* canvas = doc->beginPage(100, 100);
+ {
+ SkFILEWStream stream(path.c_str());
+ sk_sp<SkDocument> doc = SkDocument::MakePDF(&stream);
+ SkCanvas* canvas = doc->beginPage(100, 100);
- canvas->drawColor(SK_ColorRED);
- doc->endPage();
- doc->close();
+ canvas->drawColor(SK_ColorRED);
+ doc->endPage();
+ doc->close();
+ }
FILE* file = fopen(path.c_str(), "r");
REPORTER_ASSERT(reporter, file != nullptr);
@@ -123,41 +126,6 @@ DEF_TEST(SkPDF_document_tests, reporter) {
test_close(reporter);
}
-namespace {
-class JPEGSerializer final : public SkPixelSerializer {
- bool onUseEncodedData(const void*, size_t) override { return true; }
- SkData* onEncode(const SkPixmap& pixmap) override {
- return sk_tool_utils::EncodeImageToData(pixmap, SkEncodedImageFormat::kJPEG, 85).release();
- }
-};
-} // namespace
-
-size_t count_bytes(const SkBitmap& bm, bool useDCT) {
- SkDynamicMemoryWStream stream;
- sk_sp<SkDocument> doc;
- if (useDCT) {
- doc = SkDocument::MakePDF(&stream, SK_ScalarDefaultRasterDPI,
- SkDocument::PDFMetadata(),
- sk_make_sp<JPEGSerializer>(), false);
- } else {
- doc = SkDocument::MakePDF(&stream);
- }
- SkCanvas* canvas = doc->beginPage(64, 64);
- canvas->drawBitmap(bm, 0, 0);
- doc->endPage();
- doc->close();
- return stream.bytesWritten();
-}
-
-DEF_TEST(SkPDF_document_dct_encoder, r) {
- REQUIRE_PDF_DOCUMENT(SkPDF_document_dct_encoder, r);
- SkBitmap bm;
- if (GetResourceAsBitmap("images/mandrill_64.png", &bm)) {
- // Lossy encoding works better on photographs.
- REPORTER_ASSERT(r, count_bytes(bm, true) < count_bytes(bm, false));
- }
-}
-
DEF_TEST(SkPDF_document_skbug_4734, r) {
REQUIRE_PDF_DOCUMENT(SkPDF_document_skbug_4734, r);
SkDynamicMemoryWStream stream;
@@ -189,10 +157,10 @@ DEF_TEST(SkPDF_pdfa_document, r) {
pdfMetadata.fTitle = "test document";
pdfMetadata.fCreation.fEnabled = true;
pdfMetadata.fCreation.fDateTime = {0, 1999, 12, 5, 31, 23, 59, 59};
+ pdfMetadata.fPDFA = true;
SkDynamicMemoryWStream buffer;
- auto doc = SkDocument::MakePDF(&buffer, SK_ScalarDefaultRasterDPI,
- pdfMetadata, nullptr, /* pdfa = */ true);
+ auto doc = SkDocument::MakePDF(&buffer, pdfMetadata);
doc->beginPage(64, 64)->drawColor(SK_ColorRED);
doc->close();
sk_sp<SkData> data(buffer.detachAsData());
@@ -210,8 +178,8 @@ DEF_TEST(SkPDF_pdfa_document, r) {
}
}
pdfMetadata.fProducer = "phoney library";
- doc = SkDocument::MakePDF(&buffer, SK_ScalarDefaultRasterDPI,
- pdfMetadata, nullptr, /* pdfa = */ true);
+ pdfMetadata.fPDFA = true;
+ doc = SkDocument::MakePDF(&buffer, pdfMetadata);
doc->beginPage(64, 64)->drawColor(SK_ColorRED);
doc->close();
data = buffer.detachAsData();
diff --git a/tests/PDFMetadataAttributeTest.cpp b/tests/PDFMetadataAttributeTest.cpp
index 01351faec3..bdfd7d6190 100644
--- a/tests/PDFMetadataAttributeTest.cpp
+++ b/tests/PDFMetadataAttributeTest.cpp
@@ -25,8 +25,7 @@ DEF_TEST(SkPDF_Metadata, r) {
metadata.fModified.fDateTime = now;
SkDynamicMemoryWStream pdf;
- sk_sp<SkDocument> doc = SkDocument::MakePDF(&pdf, SK_ScalarDefaultRasterDPI,
- metadata, nullptr, false);
+ sk_sp<SkDocument> doc = SkDocument::MakePDF(&pdf, metadata);
doc->beginPage(612.0f, 792.0f);
doc->close();
sk_sp<SkData> data = pdf.detachAsData();
diff --git a/tools/shape/using_skia_and_harfbuzz.cpp b/tools/shape/using_skia_and_harfbuzz.cpp
index 248160cda4..533fd1e10d 100644
--- a/tools/shape/using_skia_and_harfbuzz.cpp
+++ b/tools/shape/using_skia_and_harfbuzz.cpp
@@ -171,8 +171,7 @@ private:
////////////////////////////////////////////////////////////////////////////////
-static sk_sp<SkDocument> MakePDFDocument(const Config &config,
- SkWStream *wStream) {
+static sk_sp<SkDocument> MakePDFDocument(const Config &config, SkWStream *wStream) {
SkDocument::PDFMetadata pdf_info;
pdf_info.fTitle = config.title.value.c_str();
pdf_info.fAuthor = config.author.value.c_str();
@@ -186,7 +185,7 @@ static sk_sp<SkDocument> MakePDFDocument(const Config &config,
pdf_info.fCreation.fDateTime = now;
pdf_info.fModified.fEnabled = true;
pdf_info.fModified.fDateTime = now;
- pdfa = true;
+ pdf_info.fPDFA = true;
#endif
return SkDocument::MakePDF(wStream, pdf_info);
}