Remove unused parameters to SkDocument::CreatePDF
All image compression currently uses (losseless) Deflate, not Jpeg. All clients simply use SkDocument::CreatePDF(stream). SampleApp and SkLua still use SkDocument::CreatePDF(path). Review URL: https://codereview.chromium.org/935843007
This commit is contained in:
parent
8e65712486
commit
8c92dc1dc2
@ -35,50 +35,33 @@ public:
|
||||
SK_DECLARE_INST_COUNT(SkDocument)
|
||||
|
||||
/**
|
||||
* Create a PDF-backed document, writing the results into a file.
|
||||
* If there is an error trying to create the doc, returns NULL.
|
||||
* encoder sets the DCTEncoder for images, to encode a bitmap
|
||||
* as JPEG (DCT).
|
||||
* rasterDpi - the DPI 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.
|
||||
* 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 SkWStream* 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 dpi 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.
|
||||
* @returns NULL if there is an error, otherwise a newly created
|
||||
* PDF-backed SkDocument.
|
||||
*/
|
||||
static SkDocument* CreatePDF(
|
||||
const char filename[],
|
||||
SkPicture::EncodeBitmap encoder = NULL,
|
||||
SkScalar rasterDpi = SK_ScalarDefaultRasterDPI);
|
||||
static SkDocument* CreatePDF(SkWStream*,
|
||||
SkScalar dpi = SK_ScalarDefaultRasterDPI);
|
||||
|
||||
/**
|
||||
* Create a PDF-backed document, writing the results into a stream.
|
||||
* If there is an error trying to create the doc, returns NULL.
|
||||
*
|
||||
* The document may write to the stream at anytime during its lifetime,
|
||||
* until either close() is called or the document is deleted. Once close()
|
||||
* has been called, and all of the data has been written to the stream,
|
||||
* if there is a Done proc provided, it will be called with the stream.
|
||||
* The proc can delete the stream, or whatever it needs to do.
|
||||
* encoder sets the DCTEncoder for images, to encode a bitmap
|
||||
* as JPEG (DCT).
|
||||
* Done - clean up method intended to allow deletion of the stream.
|
||||
* Its aborted parameter is true if the cleanup is due to an abort
|
||||
* call. It is false otherwise.
|
||||
* rasterDpi - the DPI 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. */
|
||||
static SkDocument* CreatePDF(
|
||||
SkWStream*, void (*Done)(SkWStream*,bool aborted) = NULL,
|
||||
SkPicture::EncodeBitmap encoder = NULL,
|
||||
SkScalar rasterDpi = SK_ScalarDefaultRasterDPI);
|
||||
* Create a PDF-backed document, writing the results into a file.
|
||||
*/
|
||||
static SkDocument* CreatePDF(const char outputFilePath[],
|
||||
SkScalar dpi = SK_ScalarDefaultRasterDPI);
|
||||
|
||||
/**
|
||||
* Begin a new page for the document, returning the canvas that will draw
|
||||
@ -112,6 +95,7 @@ public:
|
||||
|
||||
protected:
|
||||
SkDocument(SkWStream*, void (*)(SkWStream*, bool aborted));
|
||||
|
||||
// note: subclasses must call close() in their destructor, as the base class
|
||||
// cannot do this for them.
|
||||
virtual ~SkDocument();
|
||||
|
@ -138,20 +138,6 @@ public:
|
||||
*/
|
||||
uint32_t uniqueID() const { return fUniqueID; }
|
||||
|
||||
/**
|
||||
* Function to encode an SkBitmap to an SkData. A function with this
|
||||
* signature can be passed to serialize() and SkWriteBuffer.
|
||||
* Returning NULL will tell the SkWriteBuffer to use
|
||||
* SkBitmap::flatten() to store the bitmap.
|
||||
*
|
||||
* @param pixelRefOffset DEPRECATED -- caller assumes it will return 0.
|
||||
* @return SkData If non-NULL, holds encoded data representing the passed
|
||||
* in bitmap. The caller is responsible for calling unref().
|
||||
*
|
||||
* TODO: No longer used by SkPicture. Still used by PDF though. Move into PDF.
|
||||
*/
|
||||
typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm);
|
||||
|
||||
/**
|
||||
* Serialize to a stream. If non NULL, serializer will be used to serialize
|
||||
* any bitmaps in the picture.
|
||||
|
@ -11,16 +11,14 @@
|
||||
|
||||
class SkDocument_PDF : public SkDocument {
|
||||
public:
|
||||
SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*,bool),
|
||||
SkPicture::EncodeBitmap encoder,
|
||||
SkDocument_PDF(SkWStream* stream,
|
||||
void (*doneProc)(SkWStream*,bool),
|
||||
SkScalar rasterDpi)
|
||||
: SkDocument(stream, doneProc)
|
||||
, fEncoder(encoder)
|
||||
, fRasterDpi(rasterDpi) {
|
||||
fDoc = SkNEW(SkPDFDocument);
|
||||
fCanvas = NULL;
|
||||
fDevice = NULL;
|
||||
}
|
||||
: SkDocument(stream, doneProc)
|
||||
, fDoc(SkNEW(SkPDFDocument))
|
||||
, fDevice(NULL)
|
||||
, fCanvas(NULL)
|
||||
, fRasterDpi(rasterDpi) {}
|
||||
|
||||
virtual ~SkDocument_PDF() {
|
||||
// subclasses must call close() in their destructors
|
||||
@ -37,9 +35,6 @@ protected:
|
||||
mediaBoxSize.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height));
|
||||
|
||||
fDevice = SkNEW_ARGS(SkPDFDevice, (mediaBoxSize, mediaBoxSize, SkMatrix::I()));
|
||||
if (fEncoder) {
|
||||
fDevice->setDCTEncoder(fEncoder);
|
||||
}
|
||||
if (fRasterDpi != 0) {
|
||||
fDevice->setRasterDpi(fRasterDpi);
|
||||
}
|
||||
@ -82,29 +77,24 @@ private:
|
||||
SkPDFDocument* fDoc;
|
||||
SkPDFDevice* fDevice;
|
||||
SkCanvas* fCanvas;
|
||||
SkPicture::EncodeBitmap fEncoder;
|
||||
SkScalar fRasterDpi;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*,bool),
|
||||
SkPicture::EncodeBitmap enc,
|
||||
SkScalar dpi) {
|
||||
return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc, dpi)) : NULL;
|
||||
SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) {
|
||||
return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, NULL, dpi)) : NULL;
|
||||
}
|
||||
|
||||
static void delete_wstream(SkWStream* stream, bool aborted) {
|
||||
SkDELETE(stream);
|
||||
}
|
||||
|
||||
SkDocument* SkDocument::CreatePDF(const char path[],
|
||||
SkPicture::EncodeBitmap enc,
|
||||
SkScalar dpi) {
|
||||
SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) {
|
||||
SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path));
|
||||
if (!stream->isValid()) {
|
||||
SkDELETE(stream);
|
||||
return NULL;
|
||||
}
|
||||
return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi));
|
||||
return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi));
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ public:
|
||||
* encoding and decoding might not be worth the space savings,
|
||||
* if any at all.
|
||||
*/
|
||||
void setDCTEncoder(SkPicture::EncodeBitmap encoder) {
|
||||
void setDCTEncoder(SkData* (*encoder)(size_t*, const SkBitmap&)) {
|
||||
fEncoder = encoder;
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ private:
|
||||
// Glyph ids used for each font on this device.
|
||||
SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage;
|
||||
|
||||
SkPicture::EncodeBitmap fEncoder;
|
||||
SkData* (*fEncoder)(size_t*, const SkBitmap&);
|
||||
SkScalar fRasterDpi;
|
||||
|
||||
SkBitmap fLegacyBitmap;
|
||||
|
@ -458,7 +458,7 @@ static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap,
|
||||
// static
|
||||
SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
|
||||
const SkIRect& srcRect,
|
||||
SkPicture::EncodeBitmap encoder) {
|
||||
SkData* (*encoder)(size_t*, const SkBitmap&)) {
|
||||
if (bitmap.colorType() == kUnknown_SkColorType) {
|
||||
return NULL;
|
||||
}
|
||||
@ -511,7 +511,7 @@ SkPDFImage::SkPDFImage(SkStream* stream,
|
||||
const SkBitmap& bitmap,
|
||||
bool isAlpha,
|
||||
const SkIRect& srcRect,
|
||||
SkPicture::EncodeBitmap encoder)
|
||||
SkData* (*encoder)(size_t*, const SkBitmap&))
|
||||
: fIsAlpha(isAlpha),
|
||||
fSrcRect(srcRect),
|
||||
fEncoder(encoder) {
|
||||
@ -720,7 +720,7 @@ static bool is_jfif_jpeg(SkData* data) {
|
||||
SkPDFObject* SkPDFCreateImageObject(
|
||||
const SkBitmap& bitmap,
|
||||
const SkIRect& subset,
|
||||
SkPicture::EncodeBitmap encoder) {
|
||||
SkData* (*encoder)(size_t*, const SkBitmap&)) {
|
||||
if (SkPDFObject* pdfBitmap = SkPDFBitmap::Create(bitmap, subset)) {
|
||||
return pdfBitmap;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ struct SkIRect;
|
||||
* back on SkPDFImage::CreateImage.
|
||||
*/
|
||||
SkPDFObject* SkPDFCreateImageObject(
|
||||
const SkBitmap&, const SkIRect& subset, SkPicture::EncodeBitmap);
|
||||
const SkBitmap&, const SkIRect& subset, SkData* (*)(size_t*, const SkBitmap&));
|
||||
|
||||
/** \class SkPDFImage
|
||||
|
||||
@ -50,7 +50,7 @@ public:
|
||||
*/
|
||||
static SkPDFImage* CreateImage(const SkBitmap& bitmap,
|
||||
const SkIRect& srcRect,
|
||||
SkPicture::EncodeBitmap encoder);
|
||||
SkData* (*encoder)(size_t*, const SkBitmap&));
|
||||
|
||||
virtual ~SkPDFImage();
|
||||
|
||||
@ -62,7 +62,7 @@ private:
|
||||
SkBitmap fBitmap;
|
||||
bool fIsAlpha;
|
||||
SkIRect fSrcRect;
|
||||
SkPicture::EncodeBitmap fEncoder;
|
||||
SkData* (*fEncoder)(size_t*, const SkBitmap&);
|
||||
bool fStreamValid;
|
||||
|
||||
/** Create a PDF image XObject. Entries for the image properties are
|
||||
@ -81,7 +81,7 @@ private:
|
||||
* May be NULL.
|
||||
*/
|
||||
SkPDFImage(SkStream* stream, const SkBitmap& bitmap, bool isAlpha,
|
||||
const SkIRect& srcRect, SkPicture::EncodeBitmap encoder);
|
||||
const SkIRect& srcRect, SkData* (*encoder)(size_t*, const SkBitmap&));
|
||||
|
||||
/** Copy constructor, used to generate substitutes.
|
||||
* @param image The SkPDFImage to copy.
|
||||
|
@ -56,11 +56,6 @@ DEFINE_string2(match, m, "",
|
||||
"If a file does not match any list entry,\n"
|
||||
"it is skipped unless some list entry starts with ~");
|
||||
|
||||
DEFINE_int32(jpegQuality, 100,
|
||||
"Encodes images in JPEG at quality level N, which can be in "
|
||||
"range 0-100). N = -1 will disable JPEG compression. "
|
||||
"Default is N = 100, maximum quality.");
|
||||
|
||||
/** Replaces the extension of a file.
|
||||
* @param path File name whose extension will be changed.
|
||||
* @param old_extension The old extension.
|
||||
@ -83,25 +78,6 @@ static bool replace_filename_extension(SkString* path,
|
||||
return false;
|
||||
}
|
||||
|
||||
// the size_t* parameter is deprecated, so we ignore it
|
||||
static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) {
|
||||
if (FLAGS_jpegQuality == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkBitmap bm = bitmap;
|
||||
#if defined(SK_BUILD_FOR_MAC)
|
||||
// Workaround bug #1043 where bitmaps with referenced pixels cause
|
||||
// CGImageDestinationFinalize to crash
|
||||
SkBitmap copy;
|
||||
bitmap.deepCopyTo(©);
|
||||
bm = copy;
|
||||
#endif
|
||||
|
||||
return SkImageEncoder::EncodeData(
|
||||
bm, SkImageEncoder::kJPEG_Type, FLAGS_jpegQuality);
|
||||
}
|
||||
|
||||
/** Builds the output filename. path = dir/name, and it replaces expected
|
||||
* .skp extension with .pdf extention.
|
||||
* @param path Output filename.
|
||||
@ -162,10 +138,9 @@ static SkWStream* open_stream(const SkString& outputDir,
|
||||
* output, using the provided encoder.
|
||||
*/
|
||||
static bool pdf_to_stream(SkPicture* picture,
|
||||
SkWStream* output,
|
||||
SkPicture::EncodeBitmap encoder) {
|
||||
SkWStream* output) {
|
||||
SkAutoTUnref<SkDocument> pdfDocument(
|
||||
SkDocument::CreatePDF(output, NULL, encoder));
|
||||
SkDocument::CreatePDF(output));
|
||||
SkCanvas* canvas = pdfDocument->beginPage(picture->cullRect().width(),
|
||||
picture->cullRect().height());
|
||||
canvas->drawPicture(picture);
|
||||
@ -264,7 +239,7 @@ int tool_main_core(int argc, char** argv) {
|
||||
++failures;
|
||||
continue;
|
||||
}
|
||||
if (!pdf_to_stream(picture, stream.get(), encode_to_dct_data)) {
|
||||
if (!pdf_to_stream(picture, stream.get())) {
|
||||
SkDebugf("Error in PDF Serialization.");
|
||||
++failures;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user