add option to write PDFs from gm
fix some compile warnings (reorder initializers, init local ptr)
git-svn-id: http://skia.googlecode.com/svn/trunk@642 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/Makefile b/Makefile
index dc6fd30..38f2891 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
C_INCLUDES := -Iinclude/config -Iinclude/core -Iinclude/effects -Iinclude/images -Iinclude/utils
CFLAGS := -Wall -O2
CFLAGS_SSE2 = $(CFLAGS) -msse2
-LINKER_OPTS := -lpthread
+LINKER_OPTS := -lpthread -lz
DEFINES := -DSK_CAN_USE_FLOAT
HIDE = @
@@ -24,6 +24,10 @@
DEFINES += -DSK_SUPPORT_LCDTEXT
+ifeq ($(SKIA_PDF_SUPPORT),true)
+ DEFINES += -DSK_SUPPORT_PDF
+endif
+
# start with the core (required)
include src/core/core_files.mk
SRC_LIST := $(addprefix src/core/, $(SOURCE))
@@ -200,6 +204,17 @@
@echo "linking gm..."
$(HIDE)$(GPP) $(GM_OBJS) out/libskia.a -o out/gm/gm $(LINKER_OPTS)
+SAMPLEPDF_SRCS := samplepdf.cpp
+
+SAMPLEPDF_SRCS := $(addprefix tools/, $(SAMPLEPDF_SRCS))
+
+SAMPLEPDF_OBJS := $(SAMPLEPDF_SRCS:.cpp=.o)
+SAMPLEPDF_OBJS := $(addprefix out/, $(SAMPLEPDF_OBJS))
+
+samplepdf: $(SAMPLEPDF_OBJS) out/libskia.a
+ @echo "linking samplepdf..."
+ $(HIDE)$(GPP) $(SAMPLEPDF_OBJS) out/libskia.a -o out/tools/samplepdf $(LINKER_OPTS)
+
##############################################################################
.PHONY: all
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 0be08e0..3bcf437 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -3,6 +3,13 @@
#include "SkGraphics.h"
#include "SkImageDecoder.h"
#include "SkImageEncoder.h"
+#include "SkStream.h"
+#include "SkRefCnt.h"
+
+#ifdef SK_SUPPORT_PDF
+ #include "SkPDFDevice.h"
+ #include "SkPDFDocument.h"
+#endif
using namespace skiagm;
@@ -44,12 +51,12 @@
return name;
}
-static SkString make_filename(const char path[], const SkString& name) {
+static SkString make_filename(const char path[], const SkString& name, const char suffix[]) {
SkString filename(path);
if (filename.size() && filename[filename.size() - 1] != '/') {
filename.append("/");
}
- filename.appendf("%s.png", name.c_str());
+ filename.appendf("%s.%s", name.c_str(), suffix);
return filename;
}
@@ -109,6 +116,29 @@
}
}
+static void write_pdf(GM* gm, const char writePath[]) {
+#ifdef SK_SUPPORT_PDF
+ SkISize size = gm->getISize();
+ SkPDFDevice* dev = new SkPDFDevice(size.width(), size.height());
+ SkAutoUnref aur(dev);
+
+ {
+ SkCanvas c(dev);
+ gm->draw(&c);
+ }
+
+ SkDynamicMemoryWStream output;
+ SkPDFDocument doc;
+ doc.appendPage(dev);
+ doc.emitPDF(&output);
+
+ SkString shortName(gm->shortName());
+ SkString path = make_filename(writePath, shortName, "pdf");
+ SkFILEWStream stream(path.c_str());
+ stream.write(output.getStream(), output.getOffset());
+#endif
+}
+
static const struct {
SkBitmap::Config fConfig;
bool fUsePicture;
@@ -162,17 +192,18 @@
SkCanvas canvas(bitmap);
gm->draw(&canvas);
-
+
SkString name = make_name(gm->shortName(), gRec[i].fName);
if (writePath) {
- SkString path = make_filename(writePath, name);
+ SkString path = make_filename(writePath, name, "png");
bool success = write_bitmap(path, bitmap);
if (!success) {
fprintf(stderr, "FAILED to write %s\n", path.c_str());
}
+ write_pdf(gm, writePath);
} else if (readPath) {
- SkString path = make_filename(readPath, name);
+ SkString path = make_filename(readPath, name, "png");
SkBitmap orig;
bool success = SkImageDecoder::DecodeFile(path.c_str(), &orig,
SkBitmap::kARGB_8888_Config,
diff --git a/include/config/SkUserConfig.h b/include/config/SkUserConfig.h
index a2df745..721f5f7 100644
--- a/include/config/SkUserConfig.h
+++ b/include/config/SkUserConfig.h
@@ -121,7 +121,7 @@
algorithm (used in PDF generation), define SK_ZLIB_INCLUDE to be the
include path.
*/
-//#define SK_ZLIB_INCLUDE <zlib.h>
+#define SK_ZLIB_INCLUDE <zlib.h>
/* If SK_DEBUG is defined, then you can optionally define SK_SUPPORT_UNITTEST
which will run additional self-tests at startup. These can take a long time,
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 9aefd0a..fec9a4f 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -131,10 +131,10 @@
}
SkPDFDevice::SkPDFDevice(int width, int height)
- : fWidth(width),
+ : SkDevice(NULL, makeABitmap(width, height), false),
+ fWidth(width),
fHeight(height),
- fGraphicStackIndex(0),
- SkDevice(NULL, makeABitmap(width, height), false) {
+ fGraphicStackIndex(0) {
fGraphicStack[0].fColor = SK_ColorBLACK;
fGraphicStack[0].fTextSize = SK_ScalarNaN; // This has no default value.
fGraphicStack[0].fTextScaleX = SK_Scalar1;
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index 65b9b24..2162eae 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -29,7 +29,7 @@
namespace {
SkMemoryStream* extractImageData(const SkBitmap& bitmap) {
- SkMemoryStream* result;
+ SkMemoryStream* result = NULL;
bitmap.lockPixels();
switch (bitmap.getConfig()) {