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
This commit is contained in:
reed@google.com 2010-12-20 19:46:07 +00:00
parent 1f08698339
commit 0770044da6
5 changed files with 57 additions and 11 deletions

View File

@ -6,7 +6,7 @@ GPP := g++
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 @@ endif
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 @@ gm: $(GM_OBJS) out/libskia.a
@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

View File

@ -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 @@ static SkString make_name(const char shortName[], const char configName[]) {
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 compare(const SkBitmap& target, const SkBitmap& base,
}
}
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;
@ -166,13 +196,14 @@ int main (int argc, char * const argv[]) {
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,

View File

@ -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,

View File

@ -131,10 +131,10 @@ static inline SkBitmap makeABitmap(int width, int height) {
}
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;

View File

@ -29,7 +29,7 @@
namespace {
SkMemoryStream* extractImageData(const SkBitmap& bitmap) {
SkMemoryStream* result;
SkMemoryStream* result = NULL;
bitmap.lockPixels();
switch (bitmap.getConfig()) {