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:
parent
1f08698339
commit
0770044da6
17
Makefile
17
Makefile
@ -6,7 +6,7 @@ GPP := g++
|
|||||||
C_INCLUDES := -Iinclude/config -Iinclude/core -Iinclude/effects -Iinclude/images -Iinclude/utils
|
C_INCLUDES := -Iinclude/config -Iinclude/core -Iinclude/effects -Iinclude/images -Iinclude/utils
|
||||||
CFLAGS := -Wall -O2
|
CFLAGS := -Wall -O2
|
||||||
CFLAGS_SSE2 = $(CFLAGS) -msse2
|
CFLAGS_SSE2 = $(CFLAGS) -msse2
|
||||||
LINKER_OPTS := -lpthread
|
LINKER_OPTS := -lpthread -lz
|
||||||
DEFINES := -DSK_CAN_USE_FLOAT
|
DEFINES := -DSK_CAN_USE_FLOAT
|
||||||
HIDE = @
|
HIDE = @
|
||||||
|
|
||||||
@ -24,6 +24,10 @@ endif
|
|||||||
|
|
||||||
DEFINES += -DSK_SUPPORT_LCDTEXT
|
DEFINES += -DSK_SUPPORT_LCDTEXT
|
||||||
|
|
||||||
|
ifeq ($(SKIA_PDF_SUPPORT),true)
|
||||||
|
DEFINES += -DSK_SUPPORT_PDF
|
||||||
|
endif
|
||||||
|
|
||||||
# start with the core (required)
|
# start with the core (required)
|
||||||
include src/core/core_files.mk
|
include src/core/core_files.mk
|
||||||
SRC_LIST := $(addprefix src/core/, $(SOURCE))
|
SRC_LIST := $(addprefix src/core/, $(SOURCE))
|
||||||
@ -200,6 +204,17 @@ gm: $(GM_OBJS) out/libskia.a
|
|||||||
@echo "linking gm..."
|
@echo "linking gm..."
|
||||||
$(HIDE)$(GPP) $(GM_OBJS) out/libskia.a -o out/gm/gm $(LINKER_OPTS)
|
$(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
|
.PHONY: all
|
||||||
|
@ -3,6 +3,13 @@
|
|||||||
#include "SkGraphics.h"
|
#include "SkGraphics.h"
|
||||||
#include "SkImageDecoder.h"
|
#include "SkImageDecoder.h"
|
||||||
#include "SkImageEncoder.h"
|
#include "SkImageEncoder.h"
|
||||||
|
#include "SkStream.h"
|
||||||
|
#include "SkRefCnt.h"
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_PDF
|
||||||
|
#include "SkPDFDevice.h"
|
||||||
|
#include "SkPDFDocument.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace skiagm;
|
using namespace skiagm;
|
||||||
|
|
||||||
@ -44,12 +51,12 @@ static SkString make_name(const char shortName[], const char configName[]) {
|
|||||||
return name;
|
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);
|
SkString filename(path);
|
||||||
if (filename.size() && filename[filename.size() - 1] != '/') {
|
if (filename.size() && filename[filename.size() - 1] != '/') {
|
||||||
filename.append("/");
|
filename.append("/");
|
||||||
}
|
}
|
||||||
filename.appendf("%s.png", name.c_str());
|
filename.appendf("%s.%s", name.c_str(), suffix);
|
||||||
return filename;
|
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 {
|
static const struct {
|
||||||
SkBitmap::Config fConfig;
|
SkBitmap::Config fConfig;
|
||||||
bool fUsePicture;
|
bool fUsePicture;
|
||||||
@ -162,17 +192,18 @@ int main (int argc, char * const argv[]) {
|
|||||||
SkCanvas canvas(bitmap);
|
SkCanvas canvas(bitmap);
|
||||||
|
|
||||||
gm->draw(&canvas);
|
gm->draw(&canvas);
|
||||||
|
|
||||||
SkString name = make_name(gm->shortName(), gRec[i].fName);
|
SkString name = make_name(gm->shortName(), gRec[i].fName);
|
||||||
|
|
||||||
if (writePath) {
|
if (writePath) {
|
||||||
SkString path = make_filename(writePath, name);
|
SkString path = make_filename(writePath, name, "png");
|
||||||
bool success = write_bitmap(path, bitmap);
|
bool success = write_bitmap(path, bitmap);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
fprintf(stderr, "FAILED to write %s\n", path.c_str());
|
fprintf(stderr, "FAILED to write %s\n", path.c_str());
|
||||||
}
|
}
|
||||||
|
write_pdf(gm, writePath);
|
||||||
} else if (readPath) {
|
} else if (readPath) {
|
||||||
SkString path = make_filename(readPath, name);
|
SkString path = make_filename(readPath, name, "png");
|
||||||
SkBitmap orig;
|
SkBitmap orig;
|
||||||
bool success = SkImageDecoder::DecodeFile(path.c_str(), &orig,
|
bool success = SkImageDecoder::DecodeFile(path.c_str(), &orig,
|
||||||
SkBitmap::kARGB_8888_Config,
|
SkBitmap::kARGB_8888_Config,
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
algorithm (used in PDF generation), define SK_ZLIB_INCLUDE to be the
|
algorithm (used in PDF generation), define SK_ZLIB_INCLUDE to be the
|
||||||
include path.
|
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
|
/* 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,
|
which will run additional self-tests at startup. These can take a long time,
|
||||||
|
@ -131,10 +131,10 @@ static inline SkBitmap makeABitmap(int width, int height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkPDFDevice::SkPDFDevice(int width, int height)
|
SkPDFDevice::SkPDFDevice(int width, int height)
|
||||||
: fWidth(width),
|
: SkDevice(NULL, makeABitmap(width, height), false),
|
||||||
|
fWidth(width),
|
||||||
fHeight(height),
|
fHeight(height),
|
||||||
fGraphicStackIndex(0),
|
fGraphicStackIndex(0) {
|
||||||
SkDevice(NULL, makeABitmap(width, height), false) {
|
|
||||||
fGraphicStack[0].fColor = SK_ColorBLACK;
|
fGraphicStack[0].fColor = SK_ColorBLACK;
|
||||||
fGraphicStack[0].fTextSize = SK_ScalarNaN; // This has no default value.
|
fGraphicStack[0].fTextSize = SK_ScalarNaN; // This has no default value.
|
||||||
fGraphicStack[0].fTextScaleX = SK_Scalar1;
|
fGraphicStack[0].fTextScaleX = SK_Scalar1;
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
SkMemoryStream* extractImageData(const SkBitmap& bitmap) {
|
SkMemoryStream* extractImageData(const SkBitmap& bitmap) {
|
||||||
SkMemoryStream* result;
|
SkMemoryStream* result = NULL;
|
||||||
|
|
||||||
bitmap.lockPixels();
|
bitmap.lockPixels();
|
||||||
switch (bitmap.getConfig()) {
|
switch (bitmap.getConfig()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user