pdfviewer: 1) debug code for drawText (show magenta background for text, to show text even when we fail to load/show it), 2) some cleanup: refactor and rename classes and files
Review URL: https://codereview.chromium.org/23020003 git-svn-id: http://skia.googlecode.com/svn/trunk@10716 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
c1bf2de835
commit
3aa355527a
@ -3,38 +3,10 @@
|
||||
|
||||
//#define PDF_TRACE
|
||||
//#define PDF_TRACE_READ_TOKEN
|
||||
//#define PDF_TRACE_DRAWTEXT
|
||||
//#define PDF_TRACE_DIFF_IN_PNG
|
||||
//#define PDF_DEBUG_NO_CLIPING
|
||||
//#define PDF_DEBUG_NO_PAGE_CLIPING
|
||||
//#define PDF_DEBUG_3X
|
||||
|
||||
// TODO(edisonn): move in trace util.
|
||||
#ifdef PDF_TRACE
|
||||
void SkTraceMatrix(const SkMatrix& matrix, const char* sz);
|
||||
void SkTraceRect(const SkRect& rect, const char* sz);
|
||||
#else
|
||||
#define SkTraceMatrix(a,b)
|
||||
#define SkTraceRect(a,b)
|
||||
#endif
|
||||
|
||||
struct NotOwnedString {
|
||||
const unsigned char* fBuffer;
|
||||
size_t fBytes;
|
||||
|
||||
static void init(NotOwnedString* str) {
|
||||
str->fBuffer = NULL;
|
||||
str->fBytes = 0;
|
||||
}
|
||||
|
||||
static void init(NotOwnedString* str, const char* sz) {
|
||||
str->fBuffer = (const unsigned char*)sz;
|
||||
str->fBytes = strlen(sz);
|
||||
}
|
||||
|
||||
bool equals(const char* sz) {
|
||||
return strncmp((const char*)fBuffer, sz, fBytes) == 0 && fBytes == strlen(sz);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __DEFINED__SkPdfConfig
|
||||
|
@ -148,7 +148,7 @@ SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool
|
||||
return typeface;
|
||||
}
|
||||
|
||||
SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkNativeParsedPDF* doc, SkPdfFontDescriptorDictionary* fd, bool loadFromName) {
|
||||
SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkPdfNativeDoc* doc, SkPdfFontDescriptorDictionary* fd, bool loadFromName) {
|
||||
// TODO(edisonn): partial implementation ... also const handling ...
|
||||
// Only one, at most be available
|
||||
SkPdfStream* pdfStream = NULL;
|
||||
@ -188,7 +188,7 @@ SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkNativeParsedPDF* doc, SkPdfFontDe
|
||||
return new SkPdfStandardFont(face);
|
||||
}
|
||||
|
||||
SkPdfFont* fontFromName(SkNativeParsedPDF* doc, SkPdfObject* obj, const char* fontName) {
|
||||
SkPdfFont* fontFromName(SkPdfNativeDoc* doc, SkPdfNativeObject* obj, const char* fontName) {
|
||||
SkTypeface* typeface = SkTypefaceFromPdfStandardFont(fontName, false, false);
|
||||
if (typeface != NULL) {
|
||||
return new SkPdfStandardFont(typeface);
|
||||
@ -196,7 +196,7 @@ SkPdfFont* fontFromName(SkNativeParsedPDF* doc, SkPdfObject* obj, const char* fo
|
||||
|
||||
// TODO(edisonn): perf - make a map
|
||||
for (unsigned int i = 0 ; i < doc->objects(); i++) {
|
||||
SkPdfObject* obj = doc->object(i);
|
||||
SkPdfNativeObject* obj = doc->object(i);
|
||||
if (!obj || !obj->isDictionary()) {
|
||||
continue;
|
||||
}
|
||||
@ -222,26 +222,26 @@ SkPdfFont* fontFromName(SkNativeParsedPDF* doc, SkPdfObject* obj, const char* fo
|
||||
return SkPdfFont::Default();
|
||||
}
|
||||
|
||||
SkPdfFont* SkPdfFont::fontFromPdfDictionaryOnce(SkNativeParsedPDF* doc, SkPdfFontDictionary* dict) {
|
||||
// TODO(edisonn): keep the type in a smart way in the SkPdfObject
|
||||
SkPdfFont* SkPdfFont::fontFromPdfDictionaryOnce(SkPdfNativeDoc* doc, SkPdfFontDictionary* dict) {
|
||||
// TODO(edisonn): keep the type in a smart way in the SkPdfNativeObject
|
||||
// 1) flag, isResolved (1bit): reset at reset, add/remove/update (array) and set(dict)
|
||||
// in a tree like structure, 3-4 bits for all the datatypes inheriting from obj (int, real, ...)
|
||||
// if is a dict, reserveve a few bytes to encode type of dict, and so on like in a tree
|
||||
// issue: type can be determined from context! atribute night be missing/wrong
|
||||
switch (doc->mapper()->mapFontDictionary(dict)) {
|
||||
case kType0FontDictionary_SkPdfObjectType:
|
||||
case kType0FontDictionary_SkPdfNativeObjectType:
|
||||
return fontFromType0FontDictionary(doc, dict->asType0FontDictionary());
|
||||
|
||||
case kTrueTypeFontDictionary_SkPdfObjectType:
|
||||
case kTrueTypeFontDictionary_SkPdfNativeObjectType:
|
||||
return fontFromTrueTypeFontDictionary(doc, dict->asTrueTypeFontDictionary());
|
||||
|
||||
case kType1FontDictionary_SkPdfObjectType:
|
||||
case kType1FontDictionary_SkPdfNativeObjectType:
|
||||
return fontFromType1FontDictionary(doc, dict->asType1FontDictionary());
|
||||
|
||||
case kMultiMasterFontDictionary_SkPdfObjectType:
|
||||
case kMultiMasterFontDictionary_SkPdfNativeObjectType:
|
||||
return fontFromMultiMasterFontDictionary(doc, dict->asMultiMasterFontDictionary());
|
||||
|
||||
case kType3FontDictionary_SkPdfObjectType:
|
||||
case kType3FontDictionary_SkPdfNativeObjectType:
|
||||
return fontFromType3FontDictionary(doc, dict->asType3FontDictionary());
|
||||
|
||||
default:
|
||||
@ -250,20 +250,20 @@ SkPdfFont* SkPdfFont::fontFromPdfDictionaryOnce(SkNativeParsedPDF* doc, SkPdfFon
|
||||
}
|
||||
}
|
||||
|
||||
SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkNativeParsedPDF* doc, SkPdfFontDictionary* dict) {
|
||||
SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkPdfNativeDoc* doc, SkPdfFontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // TODO(edisonn): report default one?
|
||||
}
|
||||
|
||||
if (!dict->hasData(SkPdfObject::kFont_Data)) {
|
||||
dict->setData(fontFromPdfDictionaryOnce(doc, dict), SkPdfObject::kFont_Data);
|
||||
if (!dict->hasData(SkPdfNativeObject::kFont_Data)) {
|
||||
dict->setData(fontFromPdfDictionaryOnce(doc, dict), SkPdfNativeObject::kFont_Data);
|
||||
}
|
||||
return (SkPdfFont*)dict->data(SkPdfObject::kFont_Data);
|
||||
return (SkPdfFont*)dict->data(SkPdfNativeObject::kFont_Data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkNativeParsedPDF* doc, SkPdfType0FontDictionary* dict) {
|
||||
SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -271,7 +271,7 @@ SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkNativeParsedPDF* doc, S
|
||||
return new SkPdfType0Font(doc, dict);
|
||||
}
|
||||
|
||||
SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkNativeParsedPDF* doc, SkPdfType1FontDictionary* dict) {
|
||||
SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkPdfNativeDoc* doc, SkPdfType1FontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -279,7 +279,7 @@ SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkNativeParsedPDF* doc,
|
||||
return new SkPdfType1Font(doc, dict);
|
||||
}
|
||||
|
||||
SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkNativeParsedPDF* doc, SkPdfType3FontDictionary* dict) {
|
||||
SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfNativeDoc* doc, SkPdfType3FontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -289,7 +289,7 @@ SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkNativeParsedPDF* doc, S
|
||||
return new SkPdfType3Font(doc, dict);
|
||||
}
|
||||
|
||||
SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkNativeParsedPDF* doc, SkPdfTrueTypeFontDictionary* dict) {
|
||||
SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfNativeDoc* doc, SkPdfTrueTypeFontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -297,7 +297,7 @@ SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkNativeParsedPDF*
|
||||
return new SkPdfTrueTypeFont(doc, dict);
|
||||
}
|
||||
|
||||
SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkNativeParsedPDF* doc, SkPdfMultiMasterFontDictionary* dict) {
|
||||
SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkPdfNativeDoc* doc, SkPdfMultiMasterFontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -305,7 +305,7 @@ SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkNativeParse
|
||||
return new SkPdfMultiMasterFont(doc, dict);
|
||||
}
|
||||
|
||||
static int skstoi(const SkPdfObject* str) {
|
||||
static int skstoi(const SkPdfNativeObject* str) {
|
||||
// TODO(edisonn): report err of it is not a (hex) string
|
||||
int ret = 0;
|
||||
for (unsigned int i = 0 ; i < str->lenstr(); i++) {
|
||||
@ -317,7 +317,7 @@ static int skstoi(const SkPdfObject* str) {
|
||||
|
||||
#define tokenIsKeyword(token,keyword) (token.fType == kKeyword_TokenType && token.fKeywordLength==sizeof(keyword)-1 && strncmp(token.fKeyword, keyword, sizeof(keyword)-1) == 0)
|
||||
|
||||
SkPdfToUnicode::SkPdfToUnicode(SkNativeParsedPDF* parsed, SkPdfStream* stream) : fParsed(parsed) {
|
||||
SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fParsed(parsed) {
|
||||
fCMapEncoding = NULL;
|
||||
fCMapEncodingFlag = NULL;
|
||||
|
||||
@ -413,7 +413,7 @@ SkPdfToUnicode::SkPdfToUnicode(SkNativeParsedPDF* parsed, SkPdfStream* stream) :
|
||||
}
|
||||
|
||||
|
||||
SkPdfType0Font::SkPdfType0Font(SkNativeParsedPDF* doc, SkPdfType0FontDictionary* dict) {
|
||||
SkPdfType0Font::SkPdfType0Font(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* dict) {
|
||||
fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str());
|
||||
fEncoding = NULL;
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include "SkTypeface.h"
|
||||
#include "SkUtils.h"
|
||||
#include "SkPdfBasics.h"
|
||||
#include "SkPdfGraphicsState.h"
|
||||
#include "SkPdfUtils.h"
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ struct SkPdfStandardFontEntry {
|
||||
|
||||
std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts();
|
||||
SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool italic);
|
||||
SkPdfFont* fontFromName(SkNativeParsedPDF* doc, SkPdfObject* obj, const char* fontName);
|
||||
SkPdfFont* fontFromName(SkPdfNativeDoc* doc, SkPdfNativeObject* obj, const char* fontName);
|
||||
|
||||
struct SkUnencodedText {
|
||||
void* text;
|
||||
@ -77,13 +77,13 @@ public:
|
||||
std::map<std::string, SkPdfEncoding*>& getStandardEncodings();
|
||||
|
||||
class SkPdfToUnicode {
|
||||
SkNativeParsedPDF* fParsed;
|
||||
SkPdfNativeDoc* fParsed;
|
||||
// TODO(edisonn): hide public members
|
||||
public:
|
||||
unsigned short* fCMapEncoding;
|
||||
unsigned char* fCMapEncodingFlag;
|
||||
|
||||
SkPdfToUnicode(SkNativeParsedPDF* parsed, SkPdfStream* stream);
|
||||
SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream);
|
||||
};
|
||||
|
||||
|
||||
@ -170,7 +170,7 @@ public:
|
||||
|
||||
const SkPdfEncoding* encoding() const {return fEncoding;}
|
||||
|
||||
void drawText(const SkDecodedText& text, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
||||
void drawText(const SkDecodedText& text, SkPaint* paint, SkPdfContext* pdfContext, SkCanvas* canvas) {
|
||||
for (int i = 0 ; i < text.size(); i++) {
|
||||
canvas->setMatrix(pdfContext->fGraphicsState.fMatrixTm);
|
||||
#ifdef PDF_TRACE
|
||||
@ -178,6 +178,16 @@ public:
|
||||
pdfContext->fGraphicsState.fMatrixTm.mapPoints(&point, 1);
|
||||
printf("DrawText at (%f, %f)\n", SkScalarToDouble(point.x()), SkScalarToDouble(point.y()));
|
||||
#endif // PDF_TRACE
|
||||
|
||||
#ifdef PDF_TRACE_DRAWTEXT
|
||||
SkPaint col;
|
||||
col.setColor(SK_ColorMAGENTA);
|
||||
SkRect rect = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0), SkDoubleToScalar(10.0), SkDoubleToScalar(10.0));
|
||||
canvas->save();
|
||||
canvas->setMatrix(pdfContext->fGraphicsState.fMatrixTm);
|
||||
canvas->drawRect(rect, col);
|
||||
canvas->restore();
|
||||
#endif
|
||||
double width = drawOneChar(text[i], paint, pdfContext, canvas);
|
||||
pdfContext->fGraphicsState.fMatrixTm.preTranslate(SkDoubleToScalar(width), SkDoubleToScalar(0.0));
|
||||
}
|
||||
@ -204,23 +214,23 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static SkPdfFont* fontFromPdfDictionary(SkNativeParsedPDF* doc, SkPdfFontDictionary* dict);
|
||||
static SkPdfFont* fontFromPdfDictionary(SkPdfNativeDoc* doc, SkPdfFontDictionary* dict);
|
||||
static SkPdfFont* Default() {return fontFromName(NULL, NULL, "TimesNewRoman");}
|
||||
|
||||
static SkPdfType0Font* fontFromType0FontDictionary(SkNativeParsedPDF* doc, SkPdfType0FontDictionary* dict);
|
||||
static SkPdfType1Font* fontFromType1FontDictionary(SkNativeParsedPDF* doc, SkPdfType1FontDictionary* dict);
|
||||
static SkPdfType3Font* fontFromType3FontDictionary(SkNativeParsedPDF* doc, SkPdfType3FontDictionary* dict);
|
||||
static SkPdfTrueTypeFont* fontFromTrueTypeFontDictionary(SkNativeParsedPDF* doc, SkPdfTrueTypeFontDictionary* dict);
|
||||
static SkPdfMultiMasterFont* fontFromMultiMasterFontDictionary(SkNativeParsedPDF* doc, SkPdfMultiMasterFontDictionary* dict);
|
||||
static SkPdfType0Font* fontFromType0FontDictionary(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* dict);
|
||||
static SkPdfType1Font* fontFromType1FontDictionary(SkPdfNativeDoc* doc, SkPdfType1FontDictionary* dict);
|
||||
static SkPdfType3Font* fontFromType3FontDictionary(SkPdfNativeDoc* doc, SkPdfType3FontDictionary* dict);
|
||||
static SkPdfTrueTypeFont* fontFromTrueTypeFontDictionary(SkPdfNativeDoc* doc, SkPdfTrueTypeFontDictionary* dict);
|
||||
static SkPdfMultiMasterFont* fontFromMultiMasterFontDictionary(SkPdfNativeDoc* doc, SkPdfMultiMasterFontDictionary* dict);
|
||||
|
||||
static SkPdfFont* fontFromFontDescriptor(SkNativeParsedPDF* doc, SkPdfFontDescriptorDictionary* fd, bool loadFromName = true);
|
||||
static SkPdfFont* fontFromFontDescriptor(SkPdfNativeDoc* doc, SkPdfFontDescriptorDictionary* fd, bool loadFromName = true);
|
||||
|
||||
public:
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) = 0;
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext, SkCanvas* canvas) = 0;
|
||||
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) = 0;
|
||||
|
||||
private:
|
||||
static SkPdfFont* fontFromPdfDictionaryOnce(SkNativeParsedPDF* doc, SkPdfFontDictionary* dict);
|
||||
static SkPdfFont* fontFromPdfDictionaryOnce(SkPdfNativeDoc* doc, SkPdfFontDictionary* dict);
|
||||
};
|
||||
|
||||
class SkPdfStandardFont : public SkPdfFont {
|
||||
@ -230,7 +240,7 @@ public:
|
||||
SkPdfStandardFont(SkTypeface* typeface) : fTypeface(typeface) {}
|
||||
|
||||
public:
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext, SkCanvas* canvas) {
|
||||
paint->setTypeface(fTypeface);
|
||||
paint->setTextEncoding(SkPaint::kUTF8_TextEncoding);
|
||||
|
||||
@ -249,11 +259,11 @@ public:
|
||||
|
||||
class SkPdfType0Font : public SkPdfFont {
|
||||
public:
|
||||
SkPdfType0Font(SkNativeParsedPDF* doc, SkPdfType0FontDictionary* dict);
|
||||
SkPdfType0Font(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* dict);
|
||||
|
||||
public:
|
||||
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext, SkCanvas* canvas) {
|
||||
return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
|
||||
}
|
||||
|
||||
@ -263,16 +273,23 @@ public:
|
||||
|
||||
class SkPdfType1Font : public SkPdfFont {
|
||||
public:
|
||||
SkPdfType1Font(SkNativeParsedPDF* doc, SkPdfType1FontDictionary* dict) {
|
||||
SkPdfType1Font(SkPdfNativeDoc* doc, SkPdfType1FontDictionary* dict) {
|
||||
if (dict->has_FontDescriptor()) {
|
||||
fBaseFont = SkPdfFont::fontFromFontDescriptor(doc, dict->FontDescriptor(doc));
|
||||
} else {
|
||||
fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str());
|
||||
}
|
||||
|
||||
if (dict->isEncodingAName(doc)) {
|
||||
fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName(doc).c_str());
|
||||
} else if (dict->isEncodingADictionary(doc)) {
|
||||
//SkPdfDictionary* dictEnc = dict->getEncodingAsDictionary(doc);
|
||||
}
|
||||
dict->FontDescriptor(doc);
|
||||
}
|
||||
|
||||
public:
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext, SkCanvas* canvas) {
|
||||
return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
|
||||
}
|
||||
|
||||
@ -283,13 +300,13 @@ public:
|
||||
|
||||
class SkPdfTrueTypeFont : public SkPdfType1Font {
|
||||
public:
|
||||
SkPdfTrueTypeFont(SkNativeParsedPDF* doc, SkPdfTrueTypeFontDictionary* dict) : SkPdfType1Font(doc, dict) {
|
||||
SkPdfTrueTypeFont(SkPdfNativeDoc* doc, SkPdfTrueTypeFontDictionary* dict) : SkPdfType1Font(doc, dict) {
|
||||
}
|
||||
};
|
||||
|
||||
class SkPdfMultiMasterFont : public SkPdfType1Font {
|
||||
public:
|
||||
SkPdfMultiMasterFont(SkNativeParsedPDF* doc, SkPdfMultiMasterFontDictionary* dict) : SkPdfType1Font(doc, dict) {
|
||||
SkPdfMultiMasterFont(SkPdfNativeDoc* doc, SkPdfMultiMasterFontDictionary* dict) : SkPdfType1Font(doc, dict) {
|
||||
}
|
||||
};
|
||||
/*
|
||||
@ -324,7 +341,7 @@ CIDToGIDMap* fCidToGid;
|
||||
|
||||
class SkPdfType3Font : public SkPdfFont {
|
||||
struct Type3FontChar {
|
||||
SkPdfObject* fObj;
|
||||
SkPdfNativeObject* fObj;
|
||||
double fWidth;
|
||||
};
|
||||
|
||||
@ -339,7 +356,7 @@ class SkPdfType3Font : public SkPdfFont {
|
||||
Type3FontChar* fChars;
|
||||
|
||||
public:
|
||||
SkPdfType3Font(SkNativeParsedPDF* parsed, SkPdfType3FontDictionary* dict) {
|
||||
SkPdfType3Font(SkPdfNativeDoc* parsed, SkPdfType3FontDictionary* dict) {
|
||||
fBaseFont = fontFromName(parsed, dict, dict->BaseFont(parsed).c_str());
|
||||
|
||||
if (dict->has_Encoding()) {
|
||||
@ -400,7 +417,7 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext, SkCanvas* canvas) {
|
||||
if (ch < fFirstChar || ch > fLastChar || !fChars[ch - fFirstChar].fObj) {
|
||||
return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
#include "SkPdfBasics.h"
|
||||
#include "SkPdfGraphicsState.h"
|
||||
#include "SkPdfNativeTokenizer.h"
|
||||
|
||||
#include "SkDashPathEffect.h"
|
||||
|
||||
PdfContext::PdfContext(SkNativeParsedPDF* doc)
|
||||
SkPdfContext::SkPdfContext(SkPdfNativeDoc* doc)
|
||||
: fPdfDoc(doc)
|
||||
, fTmpPageAllocator(new SkPdfAllocator()) {
|
||||
}
|
||||
|
||||
PdfContext::~PdfContext() {
|
||||
SkPdfContext::~SkPdfContext() {
|
||||
delete fTmpPageAllocator;
|
||||
}
|
||||
|
@ -4,19 +4,17 @@
|
||||
#include "SkCanvas.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPdfConfig.h"
|
||||
#include "SkPdfUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <stack>
|
||||
|
||||
class SkPdfFont;
|
||||
class SkPdfDoc;
|
||||
class SkPdfObject;
|
||||
class SkPdfNativeObject;
|
||||
class SkPdfResourceDictionary;
|
||||
class SkPdfSoftMaskDictionary;
|
||||
|
||||
class SkNativeParsedPDF;
|
||||
class SkPdfNativeDoc;
|
||||
class SkPdfAllocator;
|
||||
|
||||
// TODO(edisonn): better class design.
|
||||
@ -35,7 +33,7 @@ class SkPdfColorOperator {
|
||||
// TODO(edisonn): make color space an enum!
|
||||
public:
|
||||
NotOwnedString fColorSpace;
|
||||
SkPdfObject* fPattern;
|
||||
SkPdfNativeObject* fPattern;
|
||||
|
||||
/*
|
||||
color (various) The current color to be used during painting operations (see Section
|
||||
@ -67,7 +65,7 @@ public:
|
||||
fPattern = NULL;
|
||||
}
|
||||
|
||||
void setPatternColorSpace(SkPdfObject* pattern) {
|
||||
void setPatternColorSpace(SkPdfNativeObject* pattern) {
|
||||
fColorSpace.fBuffer = (const unsigned char*)"Pattern";
|
||||
fColorSpace.fBytes = 7; // strlen("Pattern")
|
||||
fPattern = pattern;
|
||||
@ -359,42 +357,19 @@ smoothness number (PDF 1.3) The precision with which col
|
||||
void applyGraphicsState(SkPaint* paint, bool stroking);
|
||||
};
|
||||
|
||||
// TODO(edisonn): better class design.
|
||||
// TODO(edisonn): could we remove it?
|
||||
// TODO(edisonn): rename to SkPdfInlineImage
|
||||
struct SkPdfInlineImage {
|
||||
std::map<std::string, std::string> fKeyValuePairs;
|
||||
std::string fImageData;
|
||||
};
|
||||
|
||||
// TODO(edisonn): better class design.
|
||||
// TODO(edisonn): rename to SkPdfContext
|
||||
struct PdfContext {
|
||||
std::stack<SkPdfObject*> fObjectStack;
|
||||
struct SkPdfContext {
|
||||
std::stack<SkPdfNativeObject*> fObjectStack;
|
||||
std::stack<SkPdfGraphicsState> fStateStack;
|
||||
SkPdfGraphicsState fGraphicsState;
|
||||
SkNativeParsedPDF* fPdfDoc;
|
||||
SkPdfNativeDoc* fPdfDoc;
|
||||
// TODO(edisonn): the allocator, could be freed after the page is done drawing.
|
||||
SkPdfAllocator* fTmpPageAllocator;
|
||||
SkMatrix fOriginalMatrix;
|
||||
|
||||
SkPdfInlineImage fInlineImage;
|
||||
|
||||
PdfContext(SkNativeParsedPDF* doc);
|
||||
~PdfContext();
|
||||
};
|
||||
|
||||
// TODO(edisonn): temporary code, to report how much of the PDF we actually think we rendered.
|
||||
// TODO(edisonn): rename to SkPdfResult
|
||||
enum PdfResult {
|
||||
kOK_PdfResult,
|
||||
kPartial_PdfResult,
|
||||
kNYI_PdfResult,
|
||||
kIgnoreError_PdfResult,
|
||||
kError_PdfResult,
|
||||
kUnsupported_PdfResult,
|
||||
|
||||
kCount_PdfResult
|
||||
SkPdfContext(SkPdfNativeDoc* doc);
|
||||
~SkPdfContext();
|
||||
};
|
||||
|
||||
#endif // __DEFINED__SkPdfBasics
|
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,7 @@
|
||||
|
||||
class SkBitmap;
|
||||
class SkCanvas;
|
||||
class SkNativeParsedPDF;
|
||||
class SkPdfNativeDoc;
|
||||
struct SkRect;
|
||||
class SkStream;
|
||||
|
||||
@ -22,7 +22,7 @@ enum SkPdfContent {
|
||||
|
||||
// TODO(edisonn): move in another file
|
||||
class SkPdfRenderer : public SkRefCnt {
|
||||
SkNativeParsedPDF* fPdfDoc;
|
||||
SkPdfNativeDoc* fPdfDoc;
|
||||
public:
|
||||
SkPdfRenderer() : fPdfDoc(NULL) {}
|
||||
virtual ~SkPdfRenderer() {unload();}
|
||||
|
@ -1,12 +1,60 @@
|
||||
#ifndef __DEFINED__SkPdfUtils
|
||||
#define __DEFINED__SkPdfUtils
|
||||
|
||||
#include "SkPdfBasics.h"
|
||||
#include "SkMatrix.h"
|
||||
#include "SkRect.h"
|
||||
|
||||
class SkPdfArray;
|
||||
class SkPdfContext;
|
||||
class SkCanvas;
|
||||
class SkPdfNativeObject;
|
||||
|
||||
// TODO(edisonn): temporary code, to report how much of the PDF we actually think we rendered.
|
||||
enum SkPdfResult {
|
||||
kOK_SkPdfResult,
|
||||
kPartial_SkPdfResult,
|
||||
kNYI_SkPdfResult,
|
||||
kIgnoreError_SkPdfResult,
|
||||
kError_SkPdfResult,
|
||||
kUnsupported_SkPdfResult,
|
||||
|
||||
kCount_SkPdfResult
|
||||
};
|
||||
|
||||
struct NotOwnedString {
|
||||
const unsigned char* fBuffer;
|
||||
size_t fBytes;
|
||||
|
||||
static void init(NotOwnedString* str) {
|
||||
str->fBuffer = NULL;
|
||||
str->fBytes = 0;
|
||||
}
|
||||
|
||||
static void init(NotOwnedString* str, const char* sz) {
|
||||
str->fBuffer = (const unsigned char*)sz;
|
||||
str->fBytes = strlen(sz);
|
||||
}
|
||||
|
||||
bool equals(const char* sz) {
|
||||
return strncmp((const char*)fBuffer, sz, fBytes) == 0 && fBytes == strlen(sz);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray);
|
||||
|
||||
PdfResult doType3Char(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObject* skobj, SkRect bBox, SkMatrix matrix, double textSize);
|
||||
SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfNativeObject* skobj, SkRect bBox, SkMatrix matrix, double textSize);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TRACE functions
|
||||
//
|
||||
#ifdef PDF_TRACE
|
||||
void SkTraceMatrix(const SkMatrix& matrix, const char* sz);
|
||||
void SkTraceRect(const SkRect& rect, const char* sz);
|
||||
#else
|
||||
#define SkTraceMatrix(a,b)
|
||||
#define SkTraceRect(a,b)
|
||||
#endif
|
||||
|
||||
#endif // __DEFINED__SkPdfUtils
|
||||
|
@ -9,10 +9,10 @@ from pdfspec_autogen import *
|
||||
# TODO(edisonn): date and some other types are in fact strings, with a custom format!!!
|
||||
# TODO(edisonn): refer to page 99 (PDF data types)
|
||||
knowTypes = {
|
||||
'(any)': ['SkPdfObject*', 'ret', datatypes.CppNull(), 'true', 'use a mapper'],
|
||||
'(any)': ['SkPdfNativeObject*', 'ret', datatypes.CppNull(), 'true', 'use a mapper'],
|
||||
# TODO(edisonn): return constant for undefined
|
||||
'(undefined)': ['SkPdfObject*', 'ret', datatypes.CppNull(), 'true', 'use a mapper'],
|
||||
'(various)': ['SkPdfObject*', 'ret', datatypes.CppNull(), 'true', 'use a mapper'],
|
||||
'(undefined)': ['SkPdfNativeObject*', 'ret', datatypes.CppNull(), 'true', 'use a mapper'],
|
||||
'(various)': ['SkPdfNativeObject*', 'ret', datatypes.CppNull(), 'true', 'use a mapper'],
|
||||
'array': ['SkPdfArray*', '(SkPdfArray*)ret', datatypes.CppNull(), 'ret->isArray()'],
|
||||
'boolean': ['bool', 'ret->boolValue()', datatypes.PdfBoolean('false'), 'ret->isBoolean()'],
|
||||
#date is a string, with special formating, add here the
|
||||
@ -254,8 +254,8 @@ class PdfClassManager:
|
||||
|
||||
for name in self.fClasses:
|
||||
cls = self.fClasses[name]
|
||||
cls.fEnum = 'k' + name + '_SkPdfObjectType'
|
||||
cls.fEnumEnd = 'k' + name + '__End_SkPdfObjectType'
|
||||
cls.fEnum = 'k' + name + '_SkPdfNativeObjectType'
|
||||
cls.fEnumEnd = 'k' + name + '__End_SkPdfNativeObjectType'
|
||||
|
||||
fileHeadersNative.write('#include "SkPdf' + cls.fName + '_autogen.h"\n')
|
||||
fileHeadersNativeCpp.write('#include "SkPdf' + cls.fName + '_autogen.cpp"\n')
|
||||
@ -280,8 +280,8 @@ class PdfClassManager:
|
||||
fileEnums.write('#define __DEFINED__SkPdfEnums\n')
|
||||
fileEnums.write('\n')
|
||||
|
||||
fileEnums.write('enum SkPdfObjectType {\n')
|
||||
fileEnums.write(' kNone_SkPdfObjectType = 0,\n')
|
||||
fileEnums.write('enum SkPdfNativeObjectType {\n')
|
||||
fileEnums.write(' kNone_SkPdfNativeObjectType = 0,\n')
|
||||
for enum in enumsRoot:
|
||||
self.writeEnum(fileEnums, enum, enumToCls)
|
||||
fileEnums.write('};\n')
|
||||
@ -315,13 +315,13 @@ class PdfClassManager:
|
||||
nativeFileClass.write('#include <string>\n')
|
||||
nativeFileClass.write('#include "SkPdfEnums_autogen.h"\n')
|
||||
nativeFileClass.write('#include "SkPdfNYI.h"\n')
|
||||
nativeFileClass.write('#include "SkPdfObject.h"\n')
|
||||
nativeFileClass.write('class SkNativeParsedPDF;\n')
|
||||
nativeFileClass.write('#include "SkPdfNativeObject.h"\n')
|
||||
nativeFileClass.write('class SkPdfNativeDoc;\n')
|
||||
|
||||
if cls.fBase != '':
|
||||
nativeFileClass.write('#include "SkPdf' + cls.fBase + '_autogen.h"\n')
|
||||
|
||||
nativeFileClassCpp.write('#include "SkNativeParsedPDF.h"\n')
|
||||
nativeFileClassCpp.write('#include "SkPdfNativeDoc.h"\n')
|
||||
|
||||
|
||||
nativeFileClass.write('\n')
|
||||
@ -330,7 +330,7 @@ class PdfClassManager:
|
||||
nativeFileClass.write('// ' + cls.fComment + '\n')
|
||||
|
||||
if cls.fBase == '':
|
||||
nativeFileClass.write('class SkPdf' + cls.fName + ' : public SkPdfObject {\n')
|
||||
nativeFileClass.write('class SkPdf' + cls.fName + ' : public SkPdfNativeObject {\n')
|
||||
else:
|
||||
nativeFileClass.write('class SkPdf' + cls.fName + ' : public SkPdf' + cls.fBase + ' {\n')
|
||||
|
||||
@ -375,9 +375,9 @@ class PdfClassManager:
|
||||
if len(prop.fTypes.split()) == 1:
|
||||
t = prop.fTypes.strip()
|
||||
|
||||
nativeFileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '(SkNativeParsedPDF* doc);\n')
|
||||
nativeFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + '::' + prop.fCppName + '(SkNativeParsedPDF* doc) {\n')
|
||||
nativeFileClassCpp.write(' SkPdfObject* ret = get(\"' + prop.fName + '\", \"' + prop.fAbr + '\");\n')
|
||||
nativeFileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '(SkPdfNativeDoc* doc);\n')
|
||||
nativeFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + '::' + prop.fCppName + '(SkPdfNativeDoc* doc) {\n')
|
||||
nativeFileClassCpp.write(' SkPdfNativeObject* ret = get(\"' + prop.fName + '\", \"' + prop.fAbr + '\");\n')
|
||||
nativeFileClassCpp.write(' if (doc) {ret = doc->resolveReference(ret);}\n')
|
||||
nativeFileClassCpp.write(' if ((ret != NULL && ' + knowTypes[t][3] + ') || (doc == NULL && ret != NULL && ret->isReference())) return ' + knowTypes[t][1] + ';\n')
|
||||
|
||||
@ -396,19 +396,19 @@ class PdfClassManager:
|
||||
for type in prop.fTypes.split():
|
||||
t = type.strip()
|
||||
|
||||
nativeFileClass.write(' bool is' + prop.fCppName + 'A' + t.title() + '(SkNativeParsedPDF* doc);\n')
|
||||
nativeFileClass.write(' bool is' + prop.fCppName + 'A' + t.title() + '(SkPdfNativeDoc* doc);\n')
|
||||
|
||||
nativeFileClassCpp.write('bool SkPdf' + cls.fName + '::is' + prop.fCppName + 'A' + t.title() + '(SkNativeParsedPDF* doc) {\n')
|
||||
nativeFileClassCpp.write(' SkPdfObject* ret = get(\"' + prop.fName + '\", \"' + prop.fAbr + '\");\n')
|
||||
nativeFileClassCpp.write('bool SkPdf' + cls.fName + '::is' + prop.fCppName + 'A' + t.title() + '(SkPdfNativeDoc* doc) {\n')
|
||||
nativeFileClassCpp.write(' SkPdfNativeObject* ret = get(\"' + prop.fName + '\", \"' + prop.fAbr + '\");\n')
|
||||
nativeFileClassCpp.write(' if (doc) {ret = doc->resolveReference(ret);}\n')
|
||||
nativeFileClassCpp.write(' return ret != NULL && ' + knowTypes[t][3] + ';\n')
|
||||
nativeFileClassCpp.write('}\n')
|
||||
nativeFileClassCpp.write('\n')
|
||||
|
||||
nativeFileClass.write(' ' + knowTypes[t][0] + ' get' + prop.fCppName + 'As' + t.title() + '(SkNativeParsedPDF* doc);\n')
|
||||
nativeFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + '::get' + prop.fCppName + 'As' + t.title() + '(SkNativeParsedPDF* doc) {\n')
|
||||
nativeFileClass.write(' ' + knowTypes[t][0] + ' get' + prop.fCppName + 'As' + t.title() + '(SkPdfNativeDoc* doc);\n')
|
||||
nativeFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + '::get' + prop.fCppName + 'As' + t.title() + '(SkPdfNativeDoc* doc) {\n')
|
||||
|
||||
nativeFileClassCpp.write(' SkPdfObject* ret = get(\"' + prop.fName + '\", \"' + prop.fAbr + '\");\n')
|
||||
nativeFileClassCpp.write(' SkPdfNativeObject* ret = get(\"' + prop.fName + '\", \"' + prop.fAbr + '\");\n')
|
||||
nativeFileClassCpp.write(' if (doc) {ret = doc->resolveReference(ret);}\n')
|
||||
nativeFileClassCpp.write(' if ((ret != NULL && ' + knowTypes[t][3] + ') || (doc == NULL && ret != NULL && ret->isReference())) return ' + knowTypes[t][1] + ';\n')
|
||||
|
||||
@ -458,51 +458,51 @@ class PdfClassManager:
|
||||
fileMapperNative.write('\n')
|
||||
|
||||
fileMapperNative.write('#include "SkPdfHeaders_autogen.h"\n')
|
||||
fileMapperNative.write('#include "SkNativeParsedPDF.h"\n')
|
||||
fileMapperNative.write('#include "SkPdfObject.h"\n')
|
||||
fileMapperNative.write('#include "SkPdfNativeDoc.h"\n')
|
||||
fileMapperNative.write('#include "SkPdfNativeObject.h"\n')
|
||||
|
||||
|
||||
fileMapperNativeCpp.write('#include "SkPdfMapper_autogen.h"\n')
|
||||
fileMapperNativeCpp.write('#include "SkPdfUtils.h"\n')
|
||||
fileMapperNativeCpp.write('#include "SkPdfObject.h"\n')
|
||||
fileMapperNativeCpp.write('#include "SkPdfNativeObject.h"\n')
|
||||
fileMapperNativeCpp.write('\n')
|
||||
|
||||
fileMapperNative.write('class SkPdfMapper {\n')
|
||||
|
||||
fileMapperNative.write(' SkNativeParsedPDF* fParsedDoc;\n')
|
||||
fileMapperNative.write(' SkPdfNativeDoc* fParsedDoc;\n')
|
||||
|
||||
fileMapperNative.write('public:\n')
|
||||
|
||||
fileMapperNative.write(' SkPdfMapper(SkNativeParsedPDF* doc) : fParsedDoc(doc) {}\n')
|
||||
fileMapperNative.write(' SkPdfMapper(SkPdfNativeDoc* doc) : fParsedDoc(doc) {}\n')
|
||||
fileMapperNative.write('\n')
|
||||
|
||||
for name in self.fClassesNamesInOrder:
|
||||
cls = self.fClasses[name]
|
||||
|
||||
fileMapperNative.write(' SkPdfObjectType map' + name + '(const SkPdfObject* in) const;\n')
|
||||
fileMapperNative.write(' SkPdfNativeObjectType map' + name + '(const SkPdfNativeObject* in) const;\n')
|
||||
|
||||
fileMapperNativeCpp.write('SkPdfObjectType SkPdfMapper::map' + name + '(const SkPdfObject* in) const {\n')
|
||||
fileMapperNativeCpp.write(' if (in == NULL || !is' + name + '(in)) return kNone_SkPdfObjectType;\n')
|
||||
fileMapperNativeCpp.write('SkPdfNativeObjectType SkPdfMapper::map' + name + '(const SkPdfNativeObject* in) const {\n')
|
||||
fileMapperNativeCpp.write(' if (in == NULL || !is' + name + '(in)) return kNone_SkPdfNativeObjectType;\n')
|
||||
fileMapperNativeCpp.write('\n')
|
||||
if len(cls.fEnumSubclasses) > 0:
|
||||
fileMapperNativeCpp.write(' SkPdfObjectType ret;\n')
|
||||
fileMapperNativeCpp.write(' SkPdfNativeObjectType ret;\n')
|
||||
|
||||
# stream must be last one
|
||||
hasStream = False
|
||||
for sub in cls.fEnumSubclasses:
|
||||
fileMapperNativeCpp.write(' if (kNone_SkPdfObjectType != (ret = map' + enumToCls[sub].fName + '(in))) return ret;\n')
|
||||
fileMapperNativeCpp.write(' if (kNone_SkPdfNativeObjectType != (ret = map' + enumToCls[sub].fName + '(in))) return ret;\n')
|
||||
|
||||
fileMapperNativeCpp.write('\n')
|
||||
|
||||
fileMapperNativeCpp.write(' return k' + name + '_SkPdfObjectType;\n')
|
||||
fileMapperNativeCpp.write(' return k' + name + '_SkPdfNativeObjectType;\n')
|
||||
fileMapperNativeCpp.write('}\n')
|
||||
fileMapperNativeCpp.write('\n')
|
||||
|
||||
for name in self.fClassesNamesInOrder:
|
||||
cls = self.fClasses[name]
|
||||
|
||||
fileMapperNative.write(' bool is' + name + '(const SkPdfObject* nativeObj) const ;\n')
|
||||
fileMapperNativeCpp.write('bool SkPdfMapper::is' + name + '(const SkPdfObject* nativeObj) const {\n')
|
||||
fileMapperNative.write(' bool is' + name + '(const SkPdfNativeObject* nativeObj) const ;\n')
|
||||
fileMapperNativeCpp.write('bool SkPdfMapper::is' + name + '(const SkPdfNativeObject* nativeObj) const {\n')
|
||||
|
||||
if cls.fCheck != '':
|
||||
fileMapperNativeCpp.write(' return ' + cls.fCheck + ';\n')
|
||||
@ -513,7 +513,7 @@ class PdfClassManager:
|
||||
prop = field.fProp
|
||||
if prop.fHasMust:
|
||||
if emitedRet == False:
|
||||
fileMapperNativeCpp.write(' const SkPdfObject* ret = NULL;\n')
|
||||
fileMapperNativeCpp.write(' const SkPdfNativeObject* ret = NULL;\n')
|
||||
emitedRet = True
|
||||
cntMust = cntMust + 1
|
||||
fileMapperNativeCpp.write(' if (!nativeObj->isDictionary()) return false;\n')
|
||||
@ -541,19 +541,19 @@ class PdfClassManager:
|
||||
fileMapperNativeCpp.write('\n')
|
||||
|
||||
# TODO(edisonn): dict should be a SkPdfDictionary ?
|
||||
fileMapperNative.write(' bool SkPdf' + name + 'FromDictionary(const SkPdfObject* dict, const char* key, SkPdf' + name + '** data) const ;\n')
|
||||
fileMapperNativeCpp.write('bool SkPdfMapper::SkPdf' + name + 'FromDictionary(const SkPdfObject* dict, const char* key, SkPdf' + name + '** data) const {\n')
|
||||
fileMapperNativeCpp.write(' const SkPdfObject* value = dict->get(key);\n')
|
||||
fileMapperNative.write(' bool SkPdf' + name + 'FromDictionary(const SkPdfNativeObject* dict, const char* key, SkPdf' + name + '** data) const ;\n')
|
||||
fileMapperNativeCpp.write('bool SkPdfMapper::SkPdf' + name + 'FromDictionary(const SkPdfNativeObject* dict, const char* key, SkPdf' + name + '** data) const {\n')
|
||||
fileMapperNativeCpp.write(' const SkPdfNativeObject* value = dict->get(key);\n')
|
||||
fileMapperNativeCpp.write(' if (value == NULL) { return false; }\n')
|
||||
fileMapperNativeCpp.write(' if (data == NULL) { return true; }\n')
|
||||
fileMapperNativeCpp.write(' if (kNone_SkPdfObjectType == map' + name + '(value)) return false;\n')
|
||||
fileMapperNativeCpp.write(' if (kNone_SkPdfNativeObjectType == map' + name + '(value)) return false;\n')
|
||||
fileMapperNativeCpp.write(' *data = (SkPdf' + name + '*)value;\n')
|
||||
fileMapperNativeCpp.write(' return true;\n');
|
||||
fileMapperNativeCpp.write('}\n')
|
||||
fileMapperNativeCpp.write('\n')
|
||||
|
||||
fileMapperNative.write(' bool SkPdf' + name + 'FromDictionary(const SkPdfObject* dict, const char* key, const char* abr, SkPdf' + name + '** data) const ;\n')
|
||||
fileMapperNativeCpp.write('bool SkPdfMapper::SkPdf' + name + 'FromDictionary(const SkPdfObject* dict, const char* key, const char* abr, SkPdf' + name + '** data) const {\n')
|
||||
fileMapperNative.write(' bool SkPdf' + name + 'FromDictionary(const SkPdfNativeObject* dict, const char* key, const char* abr, SkPdf' + name + '** data) const ;\n')
|
||||
fileMapperNativeCpp.write('bool SkPdfMapper::SkPdf' + name + 'FromDictionary(const SkPdfNativeObject* dict, const char* key, const char* abr, SkPdf' + name + '** data) const {\n')
|
||||
fileMapperNativeCpp.write(' if (SkPdf' + name + 'FromDictionary(dict, key, data)) return true;\n')
|
||||
fileMapperNativeCpp.write(' if (abr == NULL || *abr == \'\\0\') return false;\n')
|
||||
fileMapperNativeCpp.write(' return SkPdf' + name + 'FromDictionary(dict, abr, data);\n')
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "SkNativeParsedPDF.h"
|
||||
#include "SkPdfNativeDoc.h"
|
||||
#include "SkPdfNativeTokenizer.h"
|
||||
#include "SkPdfBasics.h"
|
||||
#include "SkPdfObject.h"
|
||||
#include "SkPdfNativeObject.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -59,7 +58,7 @@ static const unsigned char* ignoreLine(const unsigned char* current, const unsig
|
||||
return current;
|
||||
}
|
||||
|
||||
SkNativeParsedPDF* gDoc = NULL;
|
||||
SkPdfNativeDoc* gDoc = NULL;
|
||||
|
||||
// TODO(edisonn): NYI
|
||||
// TODO(edisonn): 3 constructuctors from URL, from stream, from file ...
|
||||
@ -69,7 +68,7 @@ SkNativeParsedPDF* gDoc = NULL;
|
||||
// 2) recoverable corupt file: remove endobj, endsteam, remove other keywords, use other white spaces, insert comments randomly, ...
|
||||
// 3) irrecoverable corrupt file
|
||||
|
||||
SkNativeParsedPDF::SkNativeParsedPDF(SkStream* stream)
|
||||
SkPdfNativeDoc::SkPdfNativeDoc(SkStream* stream)
|
||||
: fAllocator(new SkPdfAllocator())
|
||||
, fFileContent(NULL)
|
||||
, fContentLength(0)
|
||||
@ -82,7 +81,7 @@ SkNativeParsedPDF::SkNativeParsedPDF(SkStream* stream)
|
||||
init(ptr, size);
|
||||
}
|
||||
|
||||
SkNativeParsedPDF::SkNativeParsedPDF(const char* path)
|
||||
SkPdfNativeDoc::SkPdfNativeDoc(const char* path)
|
||||
: fAllocator(new SkPdfAllocator())
|
||||
, fFileContent(NULL)
|
||||
, fContentLength(0)
|
||||
@ -108,7 +107,7 @@ SkNativeParsedPDF::SkNativeParsedPDF(const char* path)
|
||||
}
|
||||
}
|
||||
|
||||
void SkNativeParsedPDF::init(const void* bytes, size_t length) {
|
||||
void SkPdfNativeDoc::init(const void* bytes, size_t length) {
|
||||
fFileContent = (const unsigned char*)bytes;
|
||||
fContentLength = length;
|
||||
const unsigned char* eofLine = lineHome(fFileContent, fFileContent + fContentLength - 1);
|
||||
@ -158,7 +157,7 @@ void SkNativeParsedPDF::init(const void* bytes, size_t length) {
|
||||
// and resolve references?... or not ...
|
||||
}
|
||||
|
||||
void SkNativeParsedPDF::loadWithoutXRef() {
|
||||
void SkPdfNativeDoc::loadWithoutXRef() {
|
||||
const unsigned char* current = fFileContent;
|
||||
const unsigned char* end = fFileContent + fContentLength;
|
||||
|
||||
@ -167,7 +166,7 @@ void SkNativeParsedPDF::loadWithoutXRef() {
|
||||
|
||||
current = skipPdfWhiteSpaces(0, current, end);
|
||||
while (current < end) {
|
||||
SkPdfObject token;
|
||||
SkPdfNativeObject token;
|
||||
current = nextObject(0, current, end, &token, NULL, NULL);
|
||||
if (token.isInteger()) {
|
||||
int id = (int)token.intValue();
|
||||
@ -189,7 +188,7 @@ void SkNativeParsedPDF::loadWithoutXRef() {
|
||||
|
||||
fObjects[id].fOffset = current - fFileContent;
|
||||
|
||||
SkPdfObject* obj = fAllocator->allocObject();
|
||||
SkPdfNativeObject* obj = fAllocator->allocObject();
|
||||
current = nextObject(0, current, end, obj, fAllocator, this);
|
||||
|
||||
fObjects[id].fResolvedReference = obj;
|
||||
@ -210,8 +209,8 @@ void SkNativeParsedPDF::loadWithoutXRef() {
|
||||
// TODO(edisonn): hack, detect root catalog - we need to implement liniarized support, and remove this hack.
|
||||
if (!fRootCatalogRef) {
|
||||
for (unsigned int i = 0 ; i < objects(); i++) {
|
||||
SkPdfObject* obj = object(i);
|
||||
SkPdfObject* root = (obj && obj->isDictionary()) ? obj->get("Root") : NULL;
|
||||
SkPdfNativeObject* obj = object(i);
|
||||
SkPdfNativeObject* root = (obj && obj->isDictionary()) ? obj->get("Root") : NULL;
|
||||
if (root && root->isReference()) {
|
||||
fRootCatalogRef = root;
|
||||
}
|
||||
@ -233,20 +232,20 @@ void SkNativeParsedPDF::loadWithoutXRef() {
|
||||
}
|
||||
|
||||
// TODO(edisonn): NYI
|
||||
SkNativeParsedPDF::~SkNativeParsedPDF() {
|
||||
SkPdfNativeDoc::~SkPdfNativeDoc() {
|
||||
sk_free((void*)fFileContent);
|
||||
delete fAllocator;
|
||||
}
|
||||
|
||||
const unsigned char* SkNativeParsedPDF::readCrossReferenceSection(const unsigned char* xrefStart, const unsigned char* trailerEnd) {
|
||||
SkPdfObject xref;
|
||||
const unsigned char* SkPdfNativeDoc::readCrossReferenceSection(const unsigned char* xrefStart, const unsigned char* trailerEnd) {
|
||||
SkPdfNativeObject xref;
|
||||
const unsigned char* current = nextObject(0, xrefStart, trailerEnd, &xref, NULL, NULL);
|
||||
|
||||
if (!xref.isKeyword("xref")) {
|
||||
return trailerEnd;
|
||||
}
|
||||
|
||||
SkPdfObject token;
|
||||
SkPdfNativeObject token;
|
||||
while (current < trailerEnd) {
|
||||
token.reset();
|
||||
const unsigned char* previous = current;
|
||||
@ -297,12 +296,12 @@ const unsigned char* SkNativeParsedPDF::readCrossReferenceSection(const unsigned
|
||||
return current;
|
||||
}
|
||||
|
||||
const unsigned char* SkNativeParsedPDF::readTrailer(const unsigned char* trailerStart, const unsigned char* trailerEnd, bool storeCatalog, long* prev, bool skipKeyword) {
|
||||
const unsigned char* SkPdfNativeDoc::readTrailer(const unsigned char* trailerStart, const unsigned char* trailerEnd, bool storeCatalog, long* prev, bool skipKeyword) {
|
||||
*prev = -1;
|
||||
|
||||
const unsigned char* current = trailerStart;
|
||||
if (!skipKeyword) {
|
||||
SkPdfObject trailerKeyword;
|
||||
SkPdfNativeObject trailerKeyword;
|
||||
// TODO(edisonn): use null allocator, and let it just fail if memory
|
||||
// needs allocated (but no crash)!
|
||||
current = nextObject(0, current, trailerEnd, &trailerKeyword, NULL, NULL);
|
||||
@ -314,7 +313,7 @@ const unsigned char* SkNativeParsedPDF::readTrailer(const unsigned char* trailer
|
||||
}
|
||||
}
|
||||
|
||||
SkPdfObject token;
|
||||
SkPdfNativeObject token;
|
||||
current = nextObject(0, current, trailerEnd, &token, fAllocator, NULL);
|
||||
if (!token.isDictionary()) {
|
||||
return current;
|
||||
@ -325,7 +324,7 @@ const unsigned char* SkNativeParsedPDF::readTrailer(const unsigned char* trailer
|
||||
}
|
||||
|
||||
if (storeCatalog) {
|
||||
SkPdfObject* ref = trailer->Root(NULL);
|
||||
SkPdfNativeObject* ref = trailer->Root(NULL);
|
||||
if (ref == NULL || !ref->isReference()) {
|
||||
// TODO(edisonn): oops, we have to fix the corrup pdf file
|
||||
return current;
|
||||
@ -340,7 +339,7 @@ const unsigned char* SkNativeParsedPDF::readTrailer(const unsigned char* trailer
|
||||
return current;
|
||||
}
|
||||
|
||||
void SkNativeParsedPDF::addCrossSectionInfo(int id, int generation, int offset, bool isFreed) {
|
||||
void SkPdfNativeDoc::addCrossSectionInfo(int id, int generation, int offset, bool isFreed) {
|
||||
// TODO(edisonn): security here
|
||||
while (fObjects.count() < id + 1) {
|
||||
reset(fObjects.append());
|
||||
@ -351,7 +350,7 @@ void SkNativeParsedPDF::addCrossSectionInfo(int id, int generation, int offset,
|
||||
fObjects[id].fResolvedReference = NULL;
|
||||
}
|
||||
|
||||
SkPdfObject* SkNativeParsedPDF::readObject(int id/*, int expectedGeneration*/) {
|
||||
SkPdfNativeObject* SkPdfNativeDoc::readObject(int id/*, int expectedGeneration*/) {
|
||||
long startOffset = fObjects[id].fOffset;
|
||||
//long endOffset = fObjects[id].fOffsetEnd;
|
||||
// TODO(edisonn): use hinted endOffset
|
||||
@ -364,10 +363,10 @@ SkPdfObject* SkNativeParsedPDF::readObject(int id/*, int expectedGeneration*/) {
|
||||
|
||||
SkPdfNativeTokenizer tokenizer(current, end - current, fMapper, fAllocator, this);
|
||||
|
||||
SkPdfObject idObj;
|
||||
SkPdfObject generationObj;
|
||||
SkPdfObject objKeyword;
|
||||
SkPdfObject* dict = fAllocator->allocObject();
|
||||
SkPdfNativeObject idObj;
|
||||
SkPdfNativeObject generationObj;
|
||||
SkPdfNativeObject objKeyword;
|
||||
SkPdfNativeObject* dict = fAllocator->allocObject();
|
||||
|
||||
current = nextObject(0, current, end, &idObj, NULL, NULL);
|
||||
if (current >= end) {
|
||||
@ -402,7 +401,7 @@ SkPdfObject* SkNativeParsedPDF::readObject(int id/*, int expectedGeneration*/) {
|
||||
return dict;
|
||||
}
|
||||
|
||||
void SkNativeParsedPDF::fillPages(SkPdfPageTreeNodeDictionary* tree) {
|
||||
void SkPdfNativeDoc::fillPages(SkPdfPageTreeNodeDictionary* tree) {
|
||||
SkPdfArray* kids = tree->Kids(this);
|
||||
if (kids == NULL) {
|
||||
*fPages.append() = (SkPdfPageObjectDictionary*)tree;
|
||||
@ -411,8 +410,8 @@ void SkNativeParsedPDF::fillPages(SkPdfPageTreeNodeDictionary* tree) {
|
||||
|
||||
int cnt = kids->size();
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
SkPdfObject* obj = resolveReference(kids->objAtAIndex(i));
|
||||
if (fMapper->mapPageObjectDictionary(obj) != kPageObjectDictionary_SkPdfObjectType) {
|
||||
SkPdfNativeObject* obj = resolveReference(kids->objAtAIndex(i));
|
||||
if (fMapper->mapPageObjectDictionary(obj) != kPageObjectDictionary_SkPdfNativeObjectType) {
|
||||
*fPages.append() = (SkPdfPageObjectDictionary*)obj;
|
||||
} else {
|
||||
// TODO(edisonn): verify that it is a page tree indeed
|
||||
@ -421,23 +420,23 @@ void SkNativeParsedPDF::fillPages(SkPdfPageTreeNodeDictionary* tree) {
|
||||
}
|
||||
}
|
||||
|
||||
int SkNativeParsedPDF::pages() const {
|
||||
int SkPdfNativeDoc::pages() const {
|
||||
return fPages.count();
|
||||
}
|
||||
|
||||
SkPdfPageObjectDictionary* SkNativeParsedPDF::page(int page) {
|
||||
SkPdfPageObjectDictionary* SkPdfNativeDoc::page(int page) {
|
||||
SkASSERT(page >= 0 && page < fPages.count());
|
||||
return fPages[page];
|
||||
}
|
||||
|
||||
|
||||
SkPdfResourceDictionary* SkNativeParsedPDF::pageResources(int page) {
|
||||
SkPdfResourceDictionary* SkPdfNativeDoc::pageResources(int page) {
|
||||
SkASSERT(page >= 0 && page < fPages.count());
|
||||
return fPages[page]->Resources(this);
|
||||
}
|
||||
|
||||
// TODO(edisonn): Partial implemented. Move the logics directly in the code generator for inheritable and default value?
|
||||
SkRect SkNativeParsedPDF::MediaBox(int page) {
|
||||
SkRect SkPdfNativeDoc::MediaBox(int page) {
|
||||
SkPdfPageObjectDictionary* current = fPages[page];
|
||||
while (!current->has_MediaBox() && current->has_Parent()) {
|
||||
current = (SkPdfPageObjectDictionary*)current->Parent(this);
|
||||
@ -449,7 +448,7 @@ SkRect SkNativeParsedPDF::MediaBox(int page) {
|
||||
}
|
||||
|
||||
// TODO(edisonn): stream or array ... ? for now only array
|
||||
SkPdfNativeTokenizer* SkNativeParsedPDF::tokenizerOfPage(int page,
|
||||
SkPdfNativeTokenizer* SkPdfNativeDoc::tokenizerOfPage(int page,
|
||||
SkPdfAllocator* allocator) {
|
||||
if (fPages[page]->isContentsAStream(this)) {
|
||||
return tokenizerOfStream(fPages[page]->getContentsAsStream(this), allocator);
|
||||
@ -460,7 +459,7 @@ SkPdfNativeTokenizer* SkNativeParsedPDF::tokenizerOfPage(int page,
|
||||
}
|
||||
}
|
||||
|
||||
SkPdfNativeTokenizer* SkNativeParsedPDF::tokenizerOfStream(SkPdfObject* stream,
|
||||
SkPdfNativeTokenizer* SkPdfNativeDoc::tokenizerOfStream(SkPdfNativeObject* stream,
|
||||
SkPdfAllocator* allocator) {
|
||||
if (stream == NULL) {
|
||||
return NULL;
|
||||
@ -470,18 +469,18 @@ SkPdfNativeTokenizer* SkNativeParsedPDF::tokenizerOfStream(SkPdfObject* stream,
|
||||
}
|
||||
|
||||
// TODO(edisonn): NYI
|
||||
SkPdfNativeTokenizer* SkNativeParsedPDF::tokenizerOfBuffer(const unsigned char* buffer, size_t len,
|
||||
SkPdfNativeTokenizer* SkPdfNativeDoc::tokenizerOfBuffer(const unsigned char* buffer, size_t len,
|
||||
SkPdfAllocator* allocator) {
|
||||
// warning does not track two calls in the same buffer! the buffer is updated!
|
||||
// make a clean copy if needed!
|
||||
return new SkPdfNativeTokenizer(buffer, len, fMapper, allocator, this);
|
||||
}
|
||||
|
||||
size_t SkNativeParsedPDF::objects() const {
|
||||
size_t SkPdfNativeDoc::objects() const {
|
||||
return fObjects.count();
|
||||
}
|
||||
|
||||
SkPdfObject* SkNativeParsedPDF::object(int i) {
|
||||
SkPdfNativeObject* SkPdfNativeDoc::object(int i) {
|
||||
SkASSERT(!(i < 0 || i > fObjects.count()));
|
||||
|
||||
if (i < 0 || i > fObjects.count()) {
|
||||
@ -497,35 +496,35 @@ SkPdfObject* SkNativeParsedPDF::object(int i) {
|
||||
return fObjects[i].fObj;
|
||||
}
|
||||
|
||||
const SkPdfMapper* SkNativeParsedPDF::mapper() const {
|
||||
const SkPdfMapper* SkPdfNativeDoc::mapper() const {
|
||||
return fMapper;
|
||||
}
|
||||
|
||||
SkPdfReal* SkNativeParsedPDF::createReal(double value) const {
|
||||
SkPdfObject* obj = fAllocator->allocObject();
|
||||
SkPdfObject::makeReal(value, obj);
|
||||
SkPdfReal* SkPdfNativeDoc::createReal(double value) const {
|
||||
SkPdfNativeObject* obj = fAllocator->allocObject();
|
||||
SkPdfNativeObject::makeReal(value, obj);
|
||||
return (SkPdfReal*)obj;
|
||||
}
|
||||
|
||||
SkPdfInteger* SkNativeParsedPDF::createInteger(int value) const {
|
||||
SkPdfObject* obj = fAllocator->allocObject();
|
||||
SkPdfObject::makeInteger(value, obj);
|
||||
SkPdfInteger* SkPdfNativeDoc::createInteger(int value) const {
|
||||
SkPdfNativeObject* obj = fAllocator->allocObject();
|
||||
SkPdfNativeObject::makeInteger(value, obj);
|
||||
return (SkPdfInteger*)obj;
|
||||
}
|
||||
|
||||
SkPdfString* SkNativeParsedPDF::createString(const unsigned char* sz, size_t len) const {
|
||||
SkPdfObject* obj = fAllocator->allocObject();
|
||||
SkPdfObject::makeString(sz, len, obj);
|
||||
SkPdfString* SkPdfNativeDoc::createString(const unsigned char* sz, size_t len) const {
|
||||
SkPdfNativeObject* obj = fAllocator->allocObject();
|
||||
SkPdfNativeObject::makeString(sz, len, obj);
|
||||
return (SkPdfString*)obj;
|
||||
}
|
||||
|
||||
SkPdfAllocator* SkNativeParsedPDF::allocator() const {
|
||||
SkPdfAllocator* SkPdfNativeDoc::allocator() const {
|
||||
return fAllocator;
|
||||
}
|
||||
|
||||
// TODO(edisonn): fix infinite loop if ref to itself!
|
||||
// TODO(edisonn): perf, fix refs at load, and resolve will simply return fResolvedReference?
|
||||
SkPdfObject* SkNativeParsedPDF::resolveReference(SkPdfObject* ref) {
|
||||
SkPdfNativeObject* SkPdfNativeDoc::resolveReference(SkPdfNativeObject* ref) {
|
||||
if (ref && ref->isReference()) {
|
||||
int id = ref->referenceId();
|
||||
// TODO(edisonn): generation/updates not supported now
|
||||
@ -564,13 +563,11 @@ SkPdfObject* SkNativeParsedPDF::resolveReference(SkPdfObject* ref) {
|
||||
return fObjects[id].fResolvedReference;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO(edisonn): fix the mess with const, probably we need to remove it pretty much everywhere
|
||||
return (SkPdfObject*)ref;
|
||||
return (SkPdfNativeObject*)ref;
|
||||
}
|
||||
|
||||
size_t SkNativeParsedPDF::bytesUsed() const {
|
||||
size_t SkPdfNativeDoc::bytesUsed() const {
|
||||
return fAllocator->bytesUsed() +
|
||||
fContentLength +
|
||||
fObjects.count() * sizeof(PublicObjectEntry) +
|
@ -8,7 +8,7 @@ class SkCanvas;
|
||||
|
||||
class SkPdfAllocator;
|
||||
class SkPdfMapper;
|
||||
class SkPdfObject;
|
||||
class SkPdfNativeObject;
|
||||
class SkPdfReal;
|
||||
class SkPdfInteger;
|
||||
class SkPdfString;
|
||||
@ -21,14 +21,14 @@ class SkPdfNativeTokenizer;
|
||||
|
||||
class SkStream;
|
||||
|
||||
class SkNativeParsedPDF {
|
||||
class SkPdfNativeDoc {
|
||||
private:
|
||||
struct PublicObjectEntry {
|
||||
long fOffset;
|
||||
// long endOffset; // TODO(edisonn): determine the end of the object, to be used when the doc is corrupted
|
||||
SkPdfObject* fObj;
|
||||
SkPdfNativeObject* fObj;
|
||||
// TODO(edisonn): perf ... probably it does not make sense to cache the ref. test it!
|
||||
SkPdfObject* fResolvedReference;
|
||||
SkPdfNativeObject* fResolvedReference;
|
||||
};
|
||||
|
||||
public:
|
||||
@ -38,22 +38,22 @@ public:
|
||||
// TODO(edisonn): allow corruptions of file (e.g. missing endobj, missing stream length, ...)
|
||||
// TODO(edisonn): encryption
|
||||
|
||||
SkNativeParsedPDF(const char* path);
|
||||
SkNativeParsedPDF(SkStream* stream);
|
||||
SkPdfNativeDoc(const char* path);
|
||||
SkPdfNativeDoc(SkStream* stream);
|
||||
|
||||
~SkNativeParsedPDF();
|
||||
~SkPdfNativeDoc();
|
||||
|
||||
int pages() const;
|
||||
SkPdfResourceDictionary* pageResources(int page);
|
||||
SkRect MediaBox(int page);
|
||||
SkPdfNativeTokenizer* tokenizerOfPage(int n, SkPdfAllocator* allocator);
|
||||
|
||||
SkPdfNativeTokenizer* tokenizerOfStream(SkPdfObject* stream, SkPdfAllocator* allocator);
|
||||
SkPdfNativeTokenizer* tokenizerOfStream(SkPdfNativeObject* stream, SkPdfAllocator* allocator);
|
||||
SkPdfNativeTokenizer* tokenizerOfBuffer(const unsigned char* buffer, size_t len,
|
||||
SkPdfAllocator* allocator);
|
||||
|
||||
size_t objects() const;
|
||||
SkPdfObject* object(int i);
|
||||
SkPdfNativeObject* object(int i);
|
||||
SkPdfPageObjectDictionary* page(int page);
|
||||
|
||||
const SkPdfMapper* mapper() const;
|
||||
@ -64,7 +64,7 @@ public:
|
||||
// the string does not own the char*
|
||||
SkPdfString* createString(const unsigned char* sz, size_t len) const;
|
||||
|
||||
SkPdfObject* resolveReference(SkPdfObject* ref);
|
||||
SkPdfNativeObject* resolveReference(SkPdfNativeObject* ref);
|
||||
|
||||
// Reports an approximation of all the memory usage.
|
||||
size_t bytesUsed() const;
|
||||
@ -86,7 +86,7 @@ private:
|
||||
obj->fOffset = -1;
|
||||
}
|
||||
|
||||
SkPdfObject* readObject(int id/*, int generation*/);
|
||||
SkPdfNativeObject* readObject(int id/*, int generation*/);
|
||||
|
||||
void fillPages(SkPdfPageTreeNodeDictionary* tree);
|
||||
|
||||
@ -95,7 +95,7 @@ private:
|
||||
SkPdfMapper* fMapper;
|
||||
const unsigned char* fFileContent;
|
||||
size_t fContentLength;
|
||||
SkPdfObject* fRootCatalogRef;
|
||||
SkPdfNativeObject* fRootCatalogRef;
|
||||
SkPdfCatalogDictionary* fRootCatalog;
|
||||
|
||||
mutable SkTDArray<PublicObjectEntry> fObjects;
|
@ -1,5 +1,5 @@
|
||||
|
||||
#include "SkPdfObject.h"
|
||||
#include "SkPdfNativeObject.h"
|
||||
#include "SkPdfStreamCommonDictionary_autogen.h"
|
||||
|
||||
#include "SkFlate.h"
|
||||
@ -9,9 +9,9 @@
|
||||
#include "SkBitmap.h"
|
||||
#include "SkPdfFont.h"
|
||||
|
||||
SkPdfObject SkPdfObject::kNull = SkPdfObject::makeNull();
|
||||
SkPdfNativeObject SkPdfNativeObject::kNull = SkPdfNativeObject::makeNull();
|
||||
|
||||
bool SkPdfObject::applyFlateDecodeFilter() {
|
||||
bool SkPdfNativeObject::applyFlateDecodeFilter() {
|
||||
if (!SkFlate::HaveFlate()) {
|
||||
// TODO(edisonn): warn, make callers handle it
|
||||
return false;
|
||||
@ -39,14 +39,14 @@ bool SkPdfObject::applyFlateDecodeFilter() {
|
||||
}
|
||||
}
|
||||
|
||||
bool SkPdfObject::applyDCTDecodeFilter() {
|
||||
bool SkPdfNativeObject::applyDCTDecodeFilter() {
|
||||
// this would fail, and it won't allow any more filters.
|
||||
// technically, it would be possible, but not a real world scenario
|
||||
// TODO(edisonn): or get the image here and store it for fast retrieval?
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkPdfObject::applyFilter(const char* name) {
|
||||
bool SkPdfNativeObject::applyFilter(const char* name) {
|
||||
if (strcmp(name, "FlateDecode") == 0) {
|
||||
return applyFlateDecodeFilter();
|
||||
} else if (strcmp(name, "DCTDecode") == 0) {
|
||||
@ -56,7 +56,7 @@ bool SkPdfObject::applyFilter(const char* name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkPdfObject::filterStream() {
|
||||
bool SkPdfNativeObject::filterStream() {
|
||||
if (!hasStream()) {
|
||||
return false;
|
||||
}
|
||||
@ -76,7 +76,7 @@ bool SkPdfObject::filterStream() {
|
||||
const SkPdfArray* filters = stream->getFilterAsArray(NULL);
|
||||
int cnt = filters->size();
|
||||
for (int i = cnt - 1; i >= 0; i--) {
|
||||
const SkPdfObject* filterName = filters->objAtAIndex(i);
|
||||
const SkPdfNativeObject* filterName = filters->objAtAIndex(i);
|
||||
if (filterName != NULL && filterName->isName()) {
|
||||
if (!applyFilter(filterName->nameValue())) {
|
||||
break;
|
||||
@ -90,7 +90,7 @@ bool SkPdfObject::filterStream() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkPdfObject::releaseData() {
|
||||
void SkPdfNativeObject::releaseData() {
|
||||
if (fData) {
|
||||
switch (fDataType) {
|
||||
case kFont_Data:
|
@ -12,6 +12,9 @@
|
||||
|
||||
#include "SkPdfNYI.h"
|
||||
#include "SkPdfConfig.h"
|
||||
#include "SkPdfUtils.h"
|
||||
|
||||
#include "SkPdfNativeTokenizer.h"
|
||||
|
||||
class SkPdfDictionary;
|
||||
class SkPdfStream;
|
||||
@ -25,7 +28,7 @@ SkMatrix SkMatrixFromPdfMatrix(double array[6]);
|
||||
#define kUnfilteredStreamBit 1
|
||||
#define kOwnedStreamBit 2
|
||||
|
||||
class SkPdfObject {
|
||||
class SkPdfNativeObject {
|
||||
public:
|
||||
enum ObjectType {
|
||||
kInvalid_PdfObjectType,
|
||||
@ -78,10 +81,10 @@ private:
|
||||
NotOwnedString fStr;
|
||||
|
||||
// TODO(edisonn): make sure the foorprint of fArray and fMap is small, otherwise, use pointers, or classes with up to 8 bytes in footprint
|
||||
SkTDArray<SkPdfObject*>* fArray;
|
||||
SkTDArray<SkPdfNativeObject*>* fArray;
|
||||
Reference fRef;
|
||||
};
|
||||
SkTDict<SkPdfObject*>* fMap;
|
||||
SkTDict<SkPdfNativeObject*>* fMap;
|
||||
|
||||
// TODO(edisonn): rename data with cache
|
||||
void* fData;
|
||||
@ -90,7 +93,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
SkPdfObject() : fObjectType(kInvalid_PdfObjectType), fMap(NULL), fData(NULL), fDataType(kEmpty_Data) {}
|
||||
SkPdfNativeObject() : fObjectType(kInvalid_PdfObjectType), fMap(NULL), fData(NULL), fDataType(kEmpty_Data) {}
|
||||
|
||||
|
||||
inline bool hasData(DataType type) {
|
||||
@ -109,7 +112,7 @@ public:
|
||||
|
||||
void releaseData();
|
||||
|
||||
// ~SkPdfObject() {
|
||||
// ~SkPdfNativeObject() {
|
||||
// //reset(); must be called manually!
|
||||
// }
|
||||
|
||||
@ -190,49 +193,49 @@ public:
|
||||
return nyi;
|
||||
}
|
||||
|
||||
static void makeBoolean(bool value, SkPdfObject* obj) {
|
||||
static void makeBoolean(bool value, SkPdfNativeObject* obj) {
|
||||
SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
|
||||
|
||||
obj->fObjectType = kBoolean_PdfObjectType;
|
||||
obj->fBooleanValue = value;
|
||||
}
|
||||
|
||||
static SkPdfObject makeBoolean(bool value) {
|
||||
SkPdfObject obj;
|
||||
static SkPdfNativeObject makeBoolean(bool value) {
|
||||
SkPdfNativeObject obj;
|
||||
obj.fObjectType = kBoolean_PdfObjectType;
|
||||
obj.fBooleanValue = value;
|
||||
return obj;
|
||||
}
|
||||
|
||||
static void makeInteger(int64_t value, SkPdfObject* obj) {
|
||||
static void makeInteger(int64_t value, SkPdfNativeObject* obj) {
|
||||
SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
|
||||
|
||||
obj->fObjectType = kInteger_PdfObjectType;
|
||||
obj->fIntegerValue = value;
|
||||
}
|
||||
|
||||
static void makeReal(double value, SkPdfObject* obj) {
|
||||
static void makeReal(double value, SkPdfNativeObject* obj) {
|
||||
SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
|
||||
|
||||
obj->fObjectType = kReal_PdfObjectType;
|
||||
obj->fRealValue = value;
|
||||
}
|
||||
|
||||
static void makeNull(SkPdfObject* obj) {
|
||||
static void makeNull(SkPdfNativeObject* obj) {
|
||||
SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
|
||||
|
||||
obj->fObjectType = kNull_PdfObjectType;
|
||||
}
|
||||
|
||||
static SkPdfObject makeNull() {
|
||||
SkPdfObject obj;
|
||||
static SkPdfNativeObject makeNull() {
|
||||
SkPdfNativeObject obj;
|
||||
obj.fObjectType = kNull_PdfObjectType;
|
||||
return obj;
|
||||
}
|
||||
|
||||
static SkPdfObject kNull;
|
||||
static SkPdfNativeObject kNull;
|
||||
|
||||
static void makeNumeric(const unsigned char* start, const unsigned char* end, SkPdfObject* obj) {
|
||||
static void makeNumeric(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj) {
|
||||
SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
|
||||
|
||||
// TODO(edisonn): NYI properly
|
||||
@ -252,7 +255,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static void makeReference(unsigned int id, unsigned int gen, SkPdfObject* obj) {
|
||||
static void makeReference(unsigned int id, unsigned int gen, SkPdfNativeObject* obj) {
|
||||
SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
|
||||
|
||||
obj->fObjectType = kReference_PdfObjectType;
|
||||
@ -261,69 +264,69 @@ public:
|
||||
}
|
||||
|
||||
|
||||
static void makeString(const unsigned char* start, SkPdfObject* obj) {
|
||||
static void makeString(const unsigned char* start, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, strlen((const char*)start), obj, kString_PdfObjectType);
|
||||
}
|
||||
|
||||
static void makeString(const unsigned char* start, const unsigned char* end, SkPdfObject* obj) {
|
||||
static void makeString(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, end - start, obj, kString_PdfObjectType);
|
||||
}
|
||||
|
||||
static void makeString(const unsigned char* start, size_t bytes, SkPdfObject* obj) {
|
||||
static void makeString(const unsigned char* start, size_t bytes, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, bytes, obj, kString_PdfObjectType);
|
||||
}
|
||||
|
||||
|
||||
static void makeHexString(const unsigned char* start, SkPdfObject* obj) {
|
||||
static void makeHexString(const unsigned char* start, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, strlen((const char*)start), obj, kHexString_PdfObjectType);
|
||||
}
|
||||
|
||||
static void makeHexString(const unsigned char* start, const unsigned char* end, SkPdfObject* obj) {
|
||||
static void makeHexString(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, end - start, obj, kHexString_PdfObjectType);
|
||||
}
|
||||
|
||||
static void makeHexString(const unsigned char* start, size_t bytes, SkPdfObject* obj) {
|
||||
static void makeHexString(const unsigned char* start, size_t bytes, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, bytes, obj, kHexString_PdfObjectType);
|
||||
}
|
||||
|
||||
|
||||
static void makeName(const unsigned char* start, SkPdfObject* obj) {
|
||||
static void makeName(const unsigned char* start, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, strlen((const char*)start), obj, kName_PdfObjectType);
|
||||
}
|
||||
|
||||
static void makeName(const unsigned char* start, const unsigned char* end, SkPdfObject* obj) {
|
||||
static void makeName(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, end - start, obj, kName_PdfObjectType);
|
||||
}
|
||||
|
||||
static void makeName(const unsigned char* start, size_t bytes, SkPdfObject* obj) {
|
||||
static void makeName(const unsigned char* start, size_t bytes, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, bytes, obj, kName_PdfObjectType);
|
||||
}
|
||||
|
||||
|
||||
static void makeKeyword(const unsigned char* start, SkPdfObject* obj) {
|
||||
static void makeKeyword(const unsigned char* start, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, strlen((const char*)start), obj, kKeyword_PdfObjectType);
|
||||
}
|
||||
|
||||
static void makeKeyword(const unsigned char* start, const unsigned char* end, SkPdfObject* obj) {
|
||||
static void makeKeyword(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, end - start, obj, kKeyword_PdfObjectType);
|
||||
}
|
||||
|
||||
static void makeKeyword(const unsigned char* start, size_t bytes, SkPdfObject* obj) {
|
||||
static void makeKeyword(const unsigned char* start, size_t bytes, SkPdfNativeObject* obj) {
|
||||
makeStringCore(start, bytes, obj, kKeyword_PdfObjectType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO(edisonn): make the functions to return SkPdfArray, move these functions in SkPdfArray
|
||||
static void makeEmptyArray(SkPdfObject* obj) {
|
||||
static void makeEmptyArray(SkPdfNativeObject* obj) {
|
||||
SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
|
||||
|
||||
obj->fObjectType = kArray_PdfObjectType;
|
||||
obj->fArray = new SkTDArray<SkPdfObject*>();
|
||||
obj->fArray = new SkTDArray<SkPdfNativeObject*>();
|
||||
// return (SkPdfArray*)obj;
|
||||
}
|
||||
|
||||
bool appendInArray(SkPdfObject* obj) {
|
||||
bool appendInArray(SkPdfNativeObject* obj) {
|
||||
SkASSERT(fObjectType == kArray_PdfObjectType);
|
||||
if (fObjectType != kArray_PdfObjectType) {
|
||||
// TODO(edisonn): report err
|
||||
@ -340,35 +343,35 @@ public:
|
||||
return fArray->count();
|
||||
}
|
||||
|
||||
SkPdfObject* objAtAIndex(int i) {
|
||||
SkPdfNativeObject* objAtAIndex(int i) {
|
||||
SkASSERT(fObjectType == kArray_PdfObjectType);
|
||||
|
||||
return (*fArray)[i];
|
||||
}
|
||||
|
||||
SkPdfObject* removeLastInArray() {
|
||||
SkPdfNativeObject* removeLastInArray() {
|
||||
SkASSERT(fObjectType == kArray_PdfObjectType);
|
||||
|
||||
SkPdfObject* ret = NULL;
|
||||
SkPdfNativeObject* ret = NULL;
|
||||
fArray->pop(&ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
const SkPdfObject* objAtAIndex(int i) const {
|
||||
const SkPdfNativeObject* objAtAIndex(int i) const {
|
||||
SkASSERT(fObjectType == kArray_PdfObjectType);
|
||||
|
||||
return (*fArray)[i];
|
||||
}
|
||||
|
||||
SkPdfObject* operator[](int i) {
|
||||
SkPdfNativeObject* operator[](int i) {
|
||||
SkASSERT(fObjectType == kArray_PdfObjectType);
|
||||
|
||||
return (*fArray)[i];
|
||||
}
|
||||
|
||||
const SkPdfObject* operator[](int i) const {
|
||||
const SkPdfNativeObject* operator[](int i) const {
|
||||
SkASSERT(fObjectType == kArray_PdfObjectType);
|
||||
|
||||
return (*fArray)[i];
|
||||
@ -376,11 +379,11 @@ public:
|
||||
|
||||
|
||||
// TODO(edisonn): make the functions to return SkPdfDictionary, move these functions in SkPdfDictionary
|
||||
static void makeEmptyDictionary(SkPdfObject* obj) {
|
||||
static void makeEmptyDictionary(SkPdfNativeObject* obj) {
|
||||
SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
|
||||
|
||||
obj->fObjectType = kDictionary_PdfObjectType;
|
||||
obj->fMap = new SkTDict<SkPdfObject*>(1);
|
||||
obj->fMap = new SkTDict<SkPdfNativeObject*>(1);
|
||||
obj->fStr.fBuffer = NULL;
|
||||
obj->fStr.fBytes = 0;
|
||||
}
|
||||
@ -392,7 +395,7 @@ public:
|
||||
// which will be used in code
|
||||
// add function SkPdfFastNameKey key(const char* key);
|
||||
// TODO(edisonn): setting the same key twike, will make the value undefined!
|
||||
bool set(const SkPdfObject* key, SkPdfObject* value) {
|
||||
bool set(const SkPdfNativeObject* key, SkPdfNativeObject* value) {
|
||||
SkASSERT(fObjectType == kDictionary_PdfObjectType);
|
||||
SkASSERT(key->fObjectType == kName_PdfObjectType);
|
||||
|
||||
@ -407,11 +410,11 @@ public:
|
||||
return set(key->fStr.fBuffer, key->fStr.fBytes, value);
|
||||
}
|
||||
|
||||
bool set(const char* key, SkPdfObject* value) {
|
||||
bool set(const char* key, SkPdfNativeObject* value) {
|
||||
return set((const unsigned char*)key, strlen(key), value);
|
||||
}
|
||||
|
||||
bool set(const unsigned char* key, size_t len, SkPdfObject* value) {
|
||||
bool set(const unsigned char* key, size_t len, SkPdfNativeObject* value) {
|
||||
SkASSERT(fObjectType == kDictionary_PdfObjectType);
|
||||
|
||||
if (fObjectType != kDictionary_PdfObjectType) {
|
||||
@ -422,7 +425,7 @@ public:
|
||||
return fMap->set((const char*)key, len, value);
|
||||
}
|
||||
|
||||
SkPdfObject* get(const SkPdfObject* key) {
|
||||
SkPdfNativeObject* get(const SkPdfNativeObject* key) {
|
||||
SkASSERT(fObjectType == kDictionary_PdfObjectType);
|
||||
SkASSERT(key->fObjectType == kName_PdfObjectType);
|
||||
|
||||
@ -436,18 +439,18 @@ public:
|
||||
return get(key->fStr.fBuffer, key->fStr.fBytes);
|
||||
}
|
||||
|
||||
SkPdfObject* get(const char* key) {
|
||||
SkPdfNativeObject* get(const char* key) {
|
||||
return get((const unsigned char*)key, strlen(key));
|
||||
}
|
||||
|
||||
SkPdfObject* get(const unsigned char* key, size_t len) {
|
||||
SkPdfNativeObject* get(const unsigned char* key, size_t len) {
|
||||
SkASSERT(fObjectType == kDictionary_PdfObjectType);
|
||||
SkASSERT(key);
|
||||
if (fObjectType != kDictionary_PdfObjectType) {
|
||||
// TODO(edisonn): report err
|
||||
return NULL;
|
||||
}
|
||||
SkPdfObject* ret = NULL;
|
||||
SkPdfNativeObject* ret = NULL;
|
||||
fMap->find((const char*)key, len, &ret);
|
||||
|
||||
#ifdef PDF_TRACE
|
||||
@ -459,7 +462,7 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
const SkPdfObject* get(const SkPdfObject* key) const {
|
||||
const SkPdfNativeObject* get(const SkPdfNativeObject* key) const {
|
||||
SkASSERT(fObjectType == kDictionary_PdfObjectType);
|
||||
SkASSERT(key->fObjectType == kName_PdfObjectType);
|
||||
|
||||
@ -473,18 +476,18 @@ public:
|
||||
return get(key->fStr.fBuffer, key->fStr.fBytes);
|
||||
}
|
||||
|
||||
const SkPdfObject* get(const char* key) const {
|
||||
const SkPdfNativeObject* get(const char* key) const {
|
||||
return get((const unsigned char*)key, strlen(key));
|
||||
}
|
||||
|
||||
const SkPdfObject* get(const unsigned char* key, size_t len) const {
|
||||
const SkPdfNativeObject* get(const unsigned char* key, size_t len) const {
|
||||
SkASSERT(fObjectType == kDictionary_PdfObjectType);
|
||||
SkASSERT(key);
|
||||
if (fObjectType != kDictionary_PdfObjectType) {
|
||||
// TODO(edisonn): report err
|
||||
return NULL;
|
||||
}
|
||||
SkPdfObject* ret = NULL;
|
||||
SkPdfNativeObject* ret = NULL;
|
||||
fMap->find((const char*)key, len, &ret);
|
||||
|
||||
#ifdef PDF_TRACE
|
||||
@ -496,8 +499,8 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
const SkPdfObject* get(const char* key, const char* abr) const {
|
||||
const SkPdfObject* ret = get(key);
|
||||
const SkPdfNativeObject* get(const char* key, const char* abr) const {
|
||||
const SkPdfNativeObject* ret = get(key);
|
||||
// TODO(edisonn): / is a valid name, and it might be an abreviation, so "" should not be like NULL
|
||||
// make this distiontion in generator, and remove "" from condition
|
||||
if (ret != NULL || abr == NULL || *abr == '\0') {
|
||||
@ -506,8 +509,8 @@ public:
|
||||
return get(abr);
|
||||
}
|
||||
|
||||
SkPdfObject* get(const char* key, const char* abr) {
|
||||
SkPdfObject* ret = get(key);
|
||||
SkPdfNativeObject* get(const char* key, const char* abr) {
|
||||
SkPdfNativeObject* ret = get(key);
|
||||
// TODO(edisonn): / is a valid name, and it might be an abreviation, so "" should not be like NULL
|
||||
// make this distiontion in generator, and remove "" from condition
|
||||
if (ret != NULL || abr == NULL || *abr == '\0') {
|
||||
@ -758,7 +761,7 @@ public:
|
||||
double array[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// TODO(edisonn): version where we could resolve references?
|
||||
const SkPdfObject* elem = objAtAIndex(i);
|
||||
const SkPdfNativeObject* elem = objAtAIndex(i);
|
||||
if (elem == NULL || !elem->isNumber()) {
|
||||
// TODO(edisonn): report error
|
||||
return SkRect::MakeEmpty();
|
||||
@ -781,7 +784,7 @@ public:
|
||||
double array[6];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
// TODO(edisonn): version where we could resolve references?
|
||||
const SkPdfObject* elem = objAtAIndex(i);
|
||||
const SkPdfNativeObject* elem = objAtAIndex(i);
|
||||
if (elem == NULL || !elem->isNumber()) {
|
||||
// TODO(edisonn): report error
|
||||
return SkMatrix::I();
|
||||
@ -862,6 +865,29 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static void append(SkString* str, const char* data, size_t len, const char* prefix = "\\x") {
|
||||
for (unsigned int i = 0 ; i < len; i++) {
|
||||
if (data[i] == kNUL_PdfWhiteSpace) {
|
||||
str->append(prefix);
|
||||
str->append("00");
|
||||
} else if (data[i] == kHT_PdfWhiteSpace) {
|
||||
str->append(prefix);
|
||||
str->append("09");
|
||||
} else if (data[i] == kLF_PdfWhiteSpace) {
|
||||
str->append(prefix);
|
||||
str->append("0A");
|
||||
} else if (data[i] == kFF_PdfWhiteSpace) {
|
||||
str->append(prefix);
|
||||
str->append("0C");
|
||||
} else if (data[i] == kCR_PdfWhiteSpace) {
|
||||
str->append(prefix);
|
||||
str->append("0D");
|
||||
} else {
|
||||
str->append(data + i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SkString toString(int firstRowLevel = 0, int level = 0) {
|
||||
SkString str;
|
||||
appendSpaces(&str, firstRowLevel);
|
||||
@ -884,7 +910,7 @@ public:
|
||||
|
||||
case kString_PdfObjectType:
|
||||
str.append("\"");
|
||||
str.append((const char*)fStr.fBuffer, fStr.fBytes);
|
||||
append(&str, (const char*)fStr.fBuffer, fStr.fBytes);
|
||||
str.append("\"");
|
||||
break;
|
||||
|
||||
@ -898,11 +924,11 @@ public:
|
||||
|
||||
case kName_PdfObjectType:
|
||||
str.append("/");
|
||||
str.append((const char*)fStr.fBuffer, fStr.fBytes);
|
||||
append(&str, (const char*)fStr.fBuffer, fStr.fBytes, "#");
|
||||
break;
|
||||
|
||||
case kKeyword_PdfObjectType:
|
||||
str.append((const char*)fStr.fBuffer, fStr.fBytes);
|
||||
append(&str, (const char*)fStr.fBuffer, fStr.fBytes);
|
||||
break;
|
||||
|
||||
case kArray_PdfObjectType:
|
||||
@ -919,8 +945,8 @@ public:
|
||||
break;
|
||||
|
||||
case kDictionary_PdfObjectType: {
|
||||
SkTDict<SkPdfObject*>::Iter iter(*fMap);
|
||||
SkPdfObject* obj = NULL;
|
||||
SkTDict<SkPdfNativeObject*>::Iter iter(*fMap);
|
||||
SkPdfNativeObject* obj = NULL;
|
||||
const char* key = NULL;
|
||||
str.append("<<\n");
|
||||
while ((key = iter.next(&obj)) != NULL) {
|
||||
@ -934,7 +960,7 @@ public:
|
||||
size_t length = 0;
|
||||
if (GetFilteredStreamRef(&stream, &length)) {
|
||||
str.append("stream\n");
|
||||
str.append((const char*)stream, length > 256 ? 256 : length);
|
||||
append(&str, (const char*)stream, length > 256 ? 256 : length);
|
||||
str.append("\nendstream");
|
||||
} else {
|
||||
str.append("stream STREAM_ERROR endstream");
|
||||
@ -964,15 +990,15 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static void makeStringCore(const unsigned char* start, SkPdfObject* obj, ObjectType type) {
|
||||
static void makeStringCore(const unsigned char* start, SkPdfNativeObject* obj, ObjectType type) {
|
||||
makeStringCore(start, strlen((const char*)start), obj, type);
|
||||
}
|
||||
|
||||
static void makeStringCore(const unsigned char* start, const unsigned char* end, SkPdfObject* obj, ObjectType type) {
|
||||
static void makeStringCore(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj, ObjectType type) {
|
||||
makeStringCore(start, end - start, obj, type);
|
||||
}
|
||||
|
||||
static void makeStringCore(const unsigned char* start, size_t bytes, SkPdfObject* obj, ObjectType type) {
|
||||
static void makeStringCore(const unsigned char* start, size_t bytes, SkPdfNativeObject* obj, ObjectType type) {
|
||||
SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
|
||||
|
||||
obj->fObjectType = type;
|
||||
@ -985,20 +1011,20 @@ private:
|
||||
bool applyDCTDecodeFilter();
|
||||
};
|
||||
|
||||
class SkPdfStream : public SkPdfObject {};
|
||||
class SkPdfArray : public SkPdfObject {};
|
||||
class SkPdfString : public SkPdfObject {};
|
||||
class SkPdfHexString : public SkPdfObject {};
|
||||
class SkPdfInteger : public SkPdfObject {};
|
||||
class SkPdfReal : public SkPdfObject {};
|
||||
class SkPdfNumber : public SkPdfObject {};
|
||||
class SkPdfStream : public SkPdfNativeObject {};
|
||||
class SkPdfArray : public SkPdfNativeObject {};
|
||||
class SkPdfString : public SkPdfNativeObject {};
|
||||
class SkPdfHexString : public SkPdfNativeObject {};
|
||||
class SkPdfInteger : public SkPdfNativeObject {};
|
||||
class SkPdfReal : public SkPdfNativeObject {};
|
||||
class SkPdfNumber : public SkPdfNativeObject {};
|
||||
|
||||
class SkPdfName : public SkPdfObject {
|
||||
SkPdfName() : SkPdfObject() {
|
||||
SkPdfObject::makeName((const unsigned char*)"", this);
|
||||
class SkPdfName : public SkPdfNativeObject {
|
||||
SkPdfName() : SkPdfNativeObject() {
|
||||
SkPdfNativeObject::makeName((const unsigned char*)"", this);
|
||||
}
|
||||
public:
|
||||
SkPdfName(char* name) : SkPdfObject() {
|
||||
SkPdfName(char* name) : SkPdfNativeObject() {
|
||||
this->makeName((const unsigned char*)name, this);
|
||||
}
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
|
||||
#include "SkPdfNativeTokenizer.h"
|
||||
#include "SkPdfObject.h"
|
||||
#include "SkPdfNativeObject.h"
|
||||
#include "SkPdfConfig.h"
|
||||
|
||||
#include "SkPdfStreamCommonDictionary_autogen.h"
|
||||
@ -126,7 +126,7 @@ const unsigned char* endOfPdfToken(int level, const unsigned char* start, const
|
||||
}
|
||||
|
||||
// last elem has to be ]
|
||||
static const unsigned char* readArray(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* array, SkPdfAllocator* allocator, SkNativeParsedPDF* doc) {
|
||||
static const unsigned char* readArray(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* array, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) {
|
||||
if (allocator == NULL) {
|
||||
// TODO(edisonn): report/warning error
|
||||
return end;
|
||||
@ -148,15 +148,15 @@ static const unsigned char* readArray(int level, const unsigned char* start, con
|
||||
return endOfToken;
|
||||
}
|
||||
|
||||
SkPdfObject* newObj = allocator->allocObject();
|
||||
SkPdfNativeObject* newObj = allocator->allocObject();
|
||||
start = nextObject(level + 1, start, end, newObj, allocator, doc);
|
||||
// TODO(edisonn): perf/memory: put the variables on the stack, and flush them on the array only when
|
||||
// we are sure they are not references!
|
||||
if (newObj->isKeywordReference() && array->size() >= 2 && array->objAtAIndex(array->size() - 1)->isInteger() && array->objAtAIndex(array->size() - 2)->isInteger()) {
|
||||
SkPdfObject* gen = array->removeLastInArray();
|
||||
SkPdfObject* id = array->removeLastInArray();
|
||||
SkPdfNativeObject* gen = array->removeLastInArray();
|
||||
SkPdfNativeObject* id = array->removeLastInArray();
|
||||
newObj->reset();
|
||||
SkPdfObject::makeReference((unsigned int)id->intValue(), (unsigned int)gen->intValue(), newObj);
|
||||
SkPdfNativeObject::makeReference((unsigned int)id->intValue(), (unsigned int)gen->intValue(), newObj);
|
||||
}
|
||||
array->appendInArray(newObj);
|
||||
}
|
||||
@ -296,7 +296,7 @@ static int readStringLength(int level, const unsigned char* start, const unsigne
|
||||
return readString(level, start, end, NULL) - start;
|
||||
}
|
||||
|
||||
static const unsigned char* readString(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) {
|
||||
static const unsigned char* readString(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* str, SkPdfAllocator* allocator) {
|
||||
if (!allocator) {
|
||||
return end;
|
||||
}
|
||||
@ -304,7 +304,7 @@ static const unsigned char* readString(int level, const unsigned char* start, co
|
||||
// TODO(edisonn): optimize the allocation, don't allocate new string, but put it in a preallocated buffer
|
||||
unsigned char* out = (unsigned char*)allocator->alloc(outLength);
|
||||
start = readString(level, start, end, out);
|
||||
SkPdfObject::makeString(out, out + outLength, str);
|
||||
SkPdfNativeObject::makeString(out, out + outLength, str);
|
||||
TRACE_STRING(out, out + outLength);
|
||||
return start; // consumed already ) at the end of the string
|
||||
}
|
||||
@ -443,7 +443,7 @@ static int readHexStringLength(int level, const unsigned char* start, const unsi
|
||||
return readHexString(level, start, end, NULL) - start;
|
||||
}
|
||||
|
||||
static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* str, SkPdfAllocator* allocator) {
|
||||
static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* str, SkPdfAllocator* allocator) {
|
||||
if (!allocator) {
|
||||
return end;
|
||||
}
|
||||
@ -451,7 +451,7 @@ static const unsigned char* readHexString(int level, const unsigned char* start,
|
||||
// TODO(edisonn): optimize the allocation, don't allocate new string, but put it in a preallocated buffer
|
||||
unsigned char* out = (unsigned char*)allocator->alloc(outLength);
|
||||
start = readHexString(level, start, end, out);
|
||||
SkPdfObject::makeHexString(out, out + outLength, str);
|
||||
SkPdfNativeObject::makeHexString(out, out + outLength, str);
|
||||
TRACE_HEXSTRING(out, out + outLength);
|
||||
return start; // consumed already > at the end of the string
|
||||
}
|
||||
@ -568,7 +568,7 @@ static int readNameLength(int level, const unsigned char* start, const unsigned
|
||||
return readName(level, start, end, NULL) - start;
|
||||
}
|
||||
|
||||
static const unsigned char* readName(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* name, SkPdfAllocator* allocator) {
|
||||
static const unsigned char* readName(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* name, SkPdfAllocator* allocator) {
|
||||
if (!allocator) {
|
||||
return end;
|
||||
}
|
||||
@ -576,7 +576,7 @@ static const unsigned char* readName(int level, const unsigned char* start, cons
|
||||
// TODO(edisonn): optimize the allocation, don't allocate new string, but put it in a preallocated buffer
|
||||
unsigned char* out = (unsigned char*)allocator->alloc(outLength);
|
||||
start = readName(level, start, end, out);
|
||||
SkPdfObject::makeName(out, out + outLength, name);
|
||||
SkPdfNativeObject::makeName(out, out + outLength, name);
|
||||
TRACE_NAME(out, out + outLength);
|
||||
return start;
|
||||
}
|
||||
@ -605,7 +605,7 @@ and it could get worse, with multiple object like this
|
||||
// right now implement the silly algorithm that assumes endstream is finishing the stream
|
||||
|
||||
|
||||
static const unsigned char* readStream(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* dict, SkNativeParsedPDF* doc) {
|
||||
static const unsigned char* readStream(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* dict, SkPdfNativeDoc* doc) {
|
||||
TRACE_INDENT(level, "Stream");
|
||||
start = skipPdfWhiteSpaces(level, start, end);
|
||||
if (!(start[0] == 's' && start[1] == 't' && start[2] == 'r' && start[3] == 'e' && start[4] == 'a' && start[5] == 'm')) {
|
||||
@ -682,7 +682,7 @@ static const unsigned char* readStream(int level, const unsigned char* start, co
|
||||
return start;
|
||||
}
|
||||
|
||||
static const unsigned char* readInlineImageStream(int level, const unsigned char* start, const unsigned char* end, SkPdfImageDictionary* inlineImage, SkNativeParsedPDF* doc) {
|
||||
static const unsigned char* readInlineImageStream(int level, const unsigned char* start, const unsigned char* end, SkPdfImageDictionary* inlineImage, SkPdfNativeDoc* doc) {
|
||||
TRACE_INDENT(level, "Inline Image");
|
||||
// We already processed ID keyword, and we should be positioned immediately after it
|
||||
|
||||
@ -714,26 +714,26 @@ static const unsigned char* readInlineImageStream(int level, const unsigned char
|
||||
return endEI;
|
||||
}
|
||||
|
||||
static const unsigned char* readDictionary(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* dict, SkPdfAllocator* allocator, SkNativeParsedPDF* doc) {
|
||||
static const unsigned char* readDictionary(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* dict, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) {
|
||||
if (allocator == NULL) {
|
||||
// TODO(edisonn): report/warning error
|
||||
return end;
|
||||
}
|
||||
TRACE_INDENT(level, "Dictionary");
|
||||
SkPdfObject::makeEmptyDictionary(dict);
|
||||
SkPdfNativeObject::makeEmptyDictionary(dict);
|
||||
|
||||
start = skipPdfWhiteSpaces(level, start, end);
|
||||
SkPdfAllocator tmpStorage; // keys will be stored in dict, we can free them immediately after set.
|
||||
|
||||
while (start < end && *start == kNamed_PdfDelimiter) {
|
||||
SkPdfObject key;
|
||||
SkPdfNativeObject key;
|
||||
//*start = '\0';
|
||||
start++;
|
||||
start = readName(level + 1, start, end, &key, &tmpStorage);
|
||||
start = skipPdfWhiteSpaces(level + 1, start, end);
|
||||
|
||||
if (start < end) {
|
||||
SkPdfObject* value = allocator->allocObject();
|
||||
SkPdfNativeObject* value = allocator->allocObject();
|
||||
start = nextObject(level + 1, start, end, value, allocator, doc);
|
||||
|
||||
start = skipPdfWhiteSpaces(level + 1, start, end);
|
||||
@ -741,16 +741,16 @@ static const unsigned char* readDictionary(int level, const unsigned char* start
|
||||
if (start < end) {
|
||||
// seems we have an indirect reference
|
||||
if (isPdfDigit(*start)) {
|
||||
SkPdfObject generation;
|
||||
SkPdfNativeObject generation;
|
||||
start = nextObject(level + 1, start, end, &generation, allocator, doc);
|
||||
|
||||
SkPdfObject keywordR;
|
||||
SkPdfNativeObject keywordR;
|
||||
start = nextObject(level + 1, start, end, &keywordR, allocator, doc);
|
||||
|
||||
if (value->isInteger() && generation.isInteger() && keywordR.isKeywordReference()) {
|
||||
int64_t id = value->intValue();
|
||||
value->reset();
|
||||
SkPdfObject::makeReference((unsigned int)id, (unsigned int)generation.intValue(), value);
|
||||
SkPdfNativeObject::makeReference((unsigned int)id, (unsigned int)generation.intValue(), value);
|
||||
dict->set(&key, value);
|
||||
} else {
|
||||
// error, ignore
|
||||
@ -767,7 +767,7 @@ static const unsigned char* readDictionary(int level, const unsigned char* start
|
||||
}
|
||||
start = skipPdfWhiteSpaces(level + 1, start, end);
|
||||
} else {
|
||||
dict->set(&key, &SkPdfObject::kNull);
|
||||
dict->set(&key, &SkPdfNativeObject::kNull);
|
||||
return end;
|
||||
}
|
||||
}
|
||||
@ -792,7 +792,7 @@ static const unsigned char* readDictionary(int level, const unsigned char* start
|
||||
return start;
|
||||
}
|
||||
|
||||
const unsigned char* nextObject(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* token, SkPdfAllocator* allocator, SkNativeParsedPDF* doc) {
|
||||
const unsigned char* nextObject(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* token, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) {
|
||||
const unsigned char* current;
|
||||
|
||||
// skip white spaces
|
||||
@ -812,7 +812,7 @@ const unsigned char* nextObject(int level, const unsigned char* start, const uns
|
||||
switch (*start) {
|
||||
case kOpenedSquareBracket_PdfDelimiter:
|
||||
//*start = '\0';
|
||||
SkPdfObject::makeEmptyArray(token);
|
||||
SkPdfNativeObject::makeEmptyArray(token);
|
||||
return readArray(level + 1, current, end, token, allocator, doc);
|
||||
|
||||
case kOpenedRoundBracket_PdfDelimiter:
|
||||
@ -847,31 +847,31 @@ const unsigned char* nextObject(int level, const unsigned char* start, const uns
|
||||
}
|
||||
|
||||
if (tokenLen == 4 && start[0] == 'n' && start[1] == 'u' && start[2] == 'l' && start[3] == 'l') {
|
||||
SkPdfObject::makeNull(token);
|
||||
SkPdfNativeObject::makeNull(token);
|
||||
return current;
|
||||
}
|
||||
|
||||
if (tokenLen == 4 && start[0] == 't' && start[1] == 'r' && start[2] == 'u' && start[3] == 'e') {
|
||||
SkPdfObject::makeBoolean(true, token);
|
||||
SkPdfNativeObject::makeBoolean(true, token);
|
||||
return current;
|
||||
}
|
||||
|
||||
if (tokenLen == 5 && start[0] == 'f' && start[1] == 'a' && start[2] == 'l' && start[3] == 's' && start[4] == 'e') {
|
||||
SkPdfObject::makeBoolean(false, token);
|
||||
SkPdfNativeObject::makeBoolean(false, token);
|
||||
return current;
|
||||
}
|
||||
|
||||
if (isPdfNumeric(*start)) {
|
||||
SkPdfObject::makeNumeric(start, current, token);
|
||||
SkPdfNativeObject::makeNumeric(start, current, token);
|
||||
} else {
|
||||
SkPdfObject::makeKeyword(start, current, token);
|
||||
SkPdfNativeObject::makeKeyword(start, current, token);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
SkPdfObject* SkPdfAllocator::allocBlock() {
|
||||
fSizeInBytes += BUFFER_SIZE * sizeof(SkPdfObject);
|
||||
return new SkPdfObject[BUFFER_SIZE];
|
||||
SkPdfNativeObject* SkPdfAllocator::allocBlock() {
|
||||
fSizeInBytes += BUFFER_SIZE * sizeof(SkPdfNativeObject);
|
||||
return new SkPdfNativeObject[BUFFER_SIZE];
|
||||
}
|
||||
|
||||
SkPdfAllocator::~SkPdfAllocator() {
|
||||
@ -890,19 +890,19 @@ SkPdfAllocator::~SkPdfAllocator() {
|
||||
delete[] fCurrent;
|
||||
}
|
||||
|
||||
SkPdfObject* SkPdfAllocator::allocObject() {
|
||||
SkPdfNativeObject* SkPdfAllocator::allocObject() {
|
||||
if (fCurrentUsed >= BUFFER_SIZE) {
|
||||
fHistory.push(fCurrent);
|
||||
fCurrent = allocBlock();
|
||||
fCurrentUsed = 0;
|
||||
fSizeInBytes += sizeof(SkPdfObject*);
|
||||
fSizeInBytes += sizeof(SkPdfNativeObject*);
|
||||
}
|
||||
fCurrentUsed++;
|
||||
return &fCurrent[fCurrentUsed - 1];
|
||||
}
|
||||
|
||||
// TODO(edisonn): perf: do no copy the buffers, but use them, and mark cache the result, so there is no need of a second pass
|
||||
SkPdfNativeTokenizer::SkPdfNativeTokenizer(SkPdfObject* objWithStream, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc) : fDoc(doc), fMapper(mapper), fAllocator(allocator), fUncompressedStream(NULL), fUncompressedStreamEnd(NULL), fEmpty(false), fHasPutBack(false) {
|
||||
SkPdfNativeTokenizer::SkPdfNativeTokenizer(SkPdfNativeObject* objWithStream, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) : fDoc(doc), fMapper(mapper), fAllocator(allocator), fUncompressedStream(NULL), fUncompressedStreamEnd(NULL), fEmpty(false), fHasPutBack(false) {
|
||||
const unsigned char* buffer = NULL;
|
||||
size_t len = 0;
|
||||
objWithStream->GetFilteredStreamRef(&buffer, &len);
|
||||
@ -915,7 +915,7 @@ SkPdfNativeTokenizer::SkPdfNativeTokenizer(SkPdfObject* objWithStream, const SkP
|
||||
fUncompressedStreamEnd = fUncompressedStream + len;
|
||||
}
|
||||
|
||||
SkPdfNativeTokenizer::SkPdfNativeTokenizer(const unsigned char* buffer, int len, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc) : fDoc(doc), fMapper(mapper), fAllocator(allocator), fEmpty(false), fHasPutBack(false) {
|
||||
SkPdfNativeTokenizer::SkPdfNativeTokenizer(const unsigned char* buffer, int len, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) : fDoc(doc), fMapper(mapper), fAllocator(allocator), fEmpty(false), fHasPutBack(false) {
|
||||
// TODO(edisonn): hack, find end of object
|
||||
char* endobj = strrstrk((char*)buffer, (char*)buffer + len, "endobj");
|
||||
if (endobj) {
|
||||
@ -929,7 +929,7 @@ SkPdfNativeTokenizer::~SkPdfNativeTokenizer() {
|
||||
}
|
||||
|
||||
bool SkPdfNativeTokenizer::readTokenCore(PdfToken* token) {
|
||||
SkPdfObject obj;
|
||||
SkPdfNativeObject obj;
|
||||
#ifdef PDF_TRACE_READ_TOKEN
|
||||
static int read_op = 0;
|
||||
#endif
|
||||
@ -944,12 +944,12 @@ bool SkPdfNativeTokenizer::readTokenCore(PdfToken* token) {
|
||||
fUncompressedStream = nextObject(0, fUncompressedStream, fUncompressedStreamEnd, &obj, fAllocator, fDoc);
|
||||
|
||||
// If it is a keyword, we will only get the pointer of the string
|
||||
if (obj.type() == SkPdfObject::kKeyword_PdfObjectType) {
|
||||
if (obj.type() == SkPdfNativeObject::kKeyword_PdfObjectType) {
|
||||
token->fKeyword = obj.c_str();
|
||||
token->fKeywordLength = obj.lenstr();
|
||||
token->fType = kKeyword_TokenType;
|
||||
} else {
|
||||
SkPdfObject* pobj = fAllocator->allocObject();
|
||||
SkPdfNativeObject* pobj = fAllocator->allocObject();
|
||||
*pobj = obj;
|
||||
token->fObject = pobj;
|
||||
token->fType = kObject_TokenType;
|
||||
@ -1027,7 +1027,7 @@ DECLARE_PDF_NAME(DCTDecode);
|
||||
#define HANDLE_NAME_ABBR(obj,longName,shortName) if (obj->isName(#shortName)) return &longName;
|
||||
|
||||
|
||||
static SkPdfObject* inlineImageKeyAbbreviationExpand(SkPdfObject* key) {
|
||||
static SkPdfNativeObject* inlineImageKeyAbbreviationExpand(SkPdfNativeObject* key) {
|
||||
if (!key || !key->isName()) {
|
||||
return key;
|
||||
}
|
||||
@ -1047,7 +1047,7 @@ static SkPdfObject* inlineImageKeyAbbreviationExpand(SkPdfObject* key) {
|
||||
return key;
|
||||
}
|
||||
|
||||
static SkPdfObject* inlineImageValueAbbreviationExpand(SkPdfObject* value) {
|
||||
static SkPdfNativeObject* inlineImageValueAbbreviationExpand(SkPdfNativeObject* value) {
|
||||
if (!value || !value->isName()) {
|
||||
return value;
|
||||
}
|
||||
@ -1076,17 +1076,17 @@ SkPdfImageDictionary* SkPdfNativeTokenizer::readInlineImage() {
|
||||
}
|
||||
|
||||
SkPdfImageDictionary* inlineImage = (SkPdfImageDictionary*)fAllocator->allocObject();
|
||||
SkPdfObject::makeEmptyDictionary(inlineImage);
|
||||
SkPdfNativeObject::makeEmptyDictionary(inlineImage);
|
||||
|
||||
while (fUncompressedStream < fUncompressedStreamEnd) {
|
||||
SkPdfObject* key = fAllocator->allocObject();
|
||||
SkPdfNativeObject* key = fAllocator->allocObject();
|
||||
fUncompressedStream = nextObject(0, fUncompressedStream, fUncompressedStreamEnd, key, fAllocator, fDoc);
|
||||
|
||||
if (key->isKeyword() && key->lenstr() == 2 && key->c_str()[0] == 'I' && key->c_str()[1] == 'D') { // ID
|
||||
fUncompressedStream = readInlineImageStream(0, fUncompressedStream, fUncompressedStreamEnd, inlineImage, fDoc);
|
||||
return inlineImage;
|
||||
} else {
|
||||
SkPdfObject* obj = fAllocator->allocObject();
|
||||
SkPdfNativeObject* obj = fAllocator->allocObject();
|
||||
fUncompressedStream = nextObject(0, fUncompressedStream, fUncompressedStreamEnd, obj, fAllocator, fDoc);
|
||||
// TODO(edisonn): perf maybe we should not expand abreviation like this
|
||||
inlineImage->set(inlineImageKeyAbbreviationExpand(key),
|
||||
|
@ -73,16 +73,16 @@ const unsigned char* endOfPdfToken(int level, const unsigned char* start, const
|
||||
// this would allow us not to do any garbage collection while we parse or draw a pdf, and defere it
|
||||
// while the user is looking at the image
|
||||
|
||||
class SkPdfObject;
|
||||
class SkPdfNativeObject;
|
||||
|
||||
class SkPdfAllocator {
|
||||
#define BUFFER_SIZE 1024
|
||||
SkTDArray<SkPdfObject*> fHistory;
|
||||
SkTDArray<SkPdfNativeObject*> fHistory;
|
||||
SkTDArray<void*> fHandles;
|
||||
SkPdfObject* fCurrent;
|
||||
SkPdfNativeObject* fCurrent;
|
||||
int fCurrentUsed;
|
||||
|
||||
SkPdfObject* allocBlock();
|
||||
SkPdfNativeObject* allocBlock();
|
||||
size_t fSizeInBytes;
|
||||
|
||||
public:
|
||||
@ -94,7 +94,7 @@ public:
|
||||
|
||||
~SkPdfAllocator();
|
||||
|
||||
SkPdfObject* allocObject();
|
||||
SkPdfNativeObject* allocObject();
|
||||
|
||||
// TODO(edisonn): free this memory in destructor, track the usage?
|
||||
void* alloc(size_t bytes) {
|
||||
@ -109,8 +109,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SkNativeParsedPDF;
|
||||
const unsigned char* nextObject(int level, const unsigned char* start, const unsigned char* end, SkPdfObject* token, SkPdfAllocator* allocator, SkNativeParsedPDF* doc);
|
||||
class SkPdfNativeDoc;
|
||||
const unsigned char* nextObject(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* token, SkPdfAllocator* allocator, SkPdfNativeDoc* doc);
|
||||
|
||||
enum SkPdfTokenType {
|
||||
kKeyword_TokenType,
|
||||
@ -120,7 +120,7 @@ enum SkPdfTokenType {
|
||||
struct PdfToken {
|
||||
const char* fKeyword;
|
||||
size_t fKeywordLength;
|
||||
SkPdfObject* fObject;
|
||||
SkPdfNativeObject* fObject;
|
||||
SkPdfTokenType fType;
|
||||
|
||||
PdfToken() : fKeyword(NULL), fKeywordLength(0), fObject(NULL) {}
|
||||
@ -128,8 +128,8 @@ struct PdfToken {
|
||||
|
||||
class SkPdfNativeTokenizer {
|
||||
public:
|
||||
SkPdfNativeTokenizer(SkPdfObject* objWithStream, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc);
|
||||
SkPdfNativeTokenizer(const unsigned char* buffer, int len, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc);
|
||||
SkPdfNativeTokenizer(SkPdfNativeObject* objWithStream, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc);
|
||||
SkPdfNativeTokenizer(const unsigned char* buffer, int len, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc);
|
||||
|
||||
virtual ~SkPdfNativeTokenizer();
|
||||
|
||||
@ -139,7 +139,7 @@ public:
|
||||
SkPdfImageDictionary* readInlineImage();
|
||||
|
||||
private:
|
||||
SkNativeParsedPDF* fDoc;
|
||||
SkPdfNativeDoc* fDoc;
|
||||
const SkPdfMapper* fMapper;
|
||||
SkPdfAllocator* fAllocator;
|
||||
|
||||
|
@ -12,16 +12,16 @@
|
||||
'target_name': 'libpdfviewer',
|
||||
'type': 'static_library',
|
||||
'sources': [
|
||||
'../experimental/PdfViewer/SkPdfBasics.cpp',
|
||||
'../experimental/PdfViewer/SkPdfGraphicsState.cpp',
|
||||
'../experimental/PdfViewer/SkPdfFont.cpp',
|
||||
'../experimental/PdfViewer/SkPdfRenderer.cpp',
|
||||
'../experimental/PdfViewer/SkPdfUtils.cpp',
|
||||
#'../experimental/PdfViewer/SkPdfNYI.cpp',
|
||||
'../experimental/PdfViewer/SkTrackDevice.cpp',
|
||||
'../experimental/PdfViewer/SkTracker.cpp',
|
||||
'../experimental/PdfViewer/pdfparser/native/SkPdfObject.cpp',
|
||||
'../experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp',
|
||||
'../experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp',
|
||||
'../experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp',
|
||||
'../experimental/PdfViewer/pdfparser/native/SkPdfNativeDoc.cpp',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/native/autogen/SkPdfMapper_autogen.cpp',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/native/autogen/SkPdfHeaders_autogen.cpp',
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user