RIP podofo
Review URL: https://codereview.chromium.org/18518005 git-svn-id: http://skia.googlecode.com/svn/trunk@9964 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
2854e24f53
commit
dfa1ebcf0c
@ -1,102 +0,0 @@
|
||||
#include "SkPdfPodofoTokenizer.h"
|
||||
|
||||
#include "SkTypes.h"
|
||||
#include "SkPdfStream_autogen.h"
|
||||
#include "SkPdfMapper_autogen.h"
|
||||
|
||||
#include "podofo.h"
|
||||
|
||||
// maps to a null doc, if the code asks for it, we should err/crash.
|
||||
SkPdfMapper gNullMapper(NULL);
|
||||
|
||||
SkPdfPodofoTokenizer::SkPdfPodofoTokenizer(const SkPodofoParsedPDF* parser, PoDoFo::PdfContentsTokenizer* tokenizer)
|
||||
: fMapper(parser->mapper()), fDoc(parser->podofo()), fTokenizer(tokenizer), fUncompressedStream(NULL), fUncompressedStreamLength(0), fEmpty(false), fHasPutBack(false) {}
|
||||
|
||||
SkPdfPodofoTokenizer::SkPdfPodofoTokenizer(const SkPdfObject* objWithStream) : fMapper(&gNullMapper), fDoc(NULL), fTokenizer(NULL), fUncompressedStream(NULL), fUncompressedStreamLength(0), fEmpty(false), fHasPutBack(false) {
|
||||
fUncompressedStream = NULL;
|
||||
fUncompressedStreamLength = 0;
|
||||
|
||||
fDoc = NULL;
|
||||
|
||||
SkPdfStream* stream = NULL;
|
||||
if (objWithStream &&
|
||||
objWithStream->doc()->mapper()->mapStream(objWithStream, &stream) &&
|
||||
stream->GetFilteredCopy(&fUncompressedStream, &fUncompressedStreamLength) &&
|
||||
fUncompressedStream != NULL &&
|
||||
fUncompressedStreamLength != 0) {
|
||||
fTokenizer = new PoDoFo::PdfContentsTokenizer(fUncompressedStream, fUncompressedStreamLength);
|
||||
fDoc = objWithStream->doc()->podofo();
|
||||
} else {
|
||||
fEmpty = true;
|
||||
}
|
||||
}
|
||||
|
||||
SkPdfPodofoTokenizer::SkPdfPodofoTokenizer(const char* buffer, int len) : fMapper(&gNullMapper), fDoc(NULL), fTokenizer(NULL), fUncompressedStream(NULL), fUncompressedStreamLength(0), fEmpty(false), fHasPutBack(false) {
|
||||
try {
|
||||
fTokenizer = new PoDoFo::PdfContentsTokenizer(buffer, len);
|
||||
} catch (PoDoFo::PdfError& e) {
|
||||
fEmpty = true;
|
||||
}
|
||||
}
|
||||
|
||||
SkPdfPodofoTokenizer::~SkPdfPodofoTokenizer() {
|
||||
free(fUncompressedStream);
|
||||
}
|
||||
|
||||
bool SkPdfPodofoTokenizer::readTokenCore(PdfToken* token) {
|
||||
PoDoFo::PdfVariant var;
|
||||
PoDoFo::EPdfContentsType type;
|
||||
|
||||
token->fKeyword = NULL;
|
||||
token->fObject = NULL;
|
||||
|
||||
bool ret = fTokenizer->ReadNext(type, token->fKeyword, var);
|
||||
|
||||
if (!ret) return ret;
|
||||
|
||||
switch (type) {
|
||||
case PoDoFo::ePdfContentsType_Keyword:
|
||||
token->fType = kKeyword_TokenType;
|
||||
break;
|
||||
|
||||
case PoDoFo::ePdfContentsType_Variant: {
|
||||
token->fType = kObject_TokenType;
|
||||
PoDoFo::PdfObject* obj = new PoDoFo::PdfObject(var);
|
||||
fMapper->mapObject(obj, &token->fObject);
|
||||
}
|
||||
break;
|
||||
|
||||
case PoDoFo::ePdfContentsType_ImageData:
|
||||
token->fType = kImageData_TokenType;
|
||||
// TODO(edisonn): inline images seem to work without it
|
||||
break;
|
||||
}
|
||||
#ifdef PDF_TRACE
|
||||
std::string str;
|
||||
if (token->fObject) {
|
||||
token->fObject->podofo()->ToString(str);
|
||||
}
|
||||
printf("%s %s\n", token->fType == kKeyword_TokenType ? "Keyword" : token->fType == kObject_TokenType ? "Object" : "ImageData", token->fKeyword ? token->fKeyword : str.c_str());
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SkPdfPodofoTokenizer::PutBack(PdfToken token) {
|
||||
SkASSERT(!fHasPutBack);
|
||||
fHasPutBack = true;
|
||||
fPutBack = token;
|
||||
}
|
||||
|
||||
bool SkPdfPodofoTokenizer::readToken(PdfToken* token) {
|
||||
if (fHasPutBack) {
|
||||
*token = fPutBack;
|
||||
fHasPutBack = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fEmpty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return readTokenCore(token);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
#ifndef EXPERIMENTAL_PDFVIEWER_PDFPARSER_PODOFO_SKPDFPODOFOTOKENIZER_H_
|
||||
#define EXPERIMENTAL_PDFVIEWER_PDFPARSER_PODOFO_SKPDFPODOFOTOKENIZER_H_
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
class SkPdfObject;
|
||||
class SkPdfMapper;
|
||||
class SkPodofoParsedPDF;
|
||||
|
||||
namespace PoDoFo {
|
||||
class PdfMemDocument;
|
||||
class PdfContentsTokenizer;
|
||||
}
|
||||
|
||||
enum SkPdfTokenType {
|
||||
kKeyword_TokenType,
|
||||
kObject_TokenType,
|
||||
kImageData_TokenType, // TODO(edisonn): inline images seem to work without it
|
||||
};
|
||||
|
||||
struct PdfToken {
|
||||
const char* fKeyword;
|
||||
SkPdfObject* fObject;
|
||||
SkPdfTokenType fType;
|
||||
|
||||
PdfToken() : fKeyword(NULL), fObject(NULL) {}
|
||||
};
|
||||
|
||||
class SkPdfPodofoTokenizer {
|
||||
public:
|
||||
SkPdfPodofoTokenizer(const SkPodofoParsedPDF* parser, PoDoFo::PdfContentsTokenizer* tokenizer);
|
||||
SkPdfPodofoTokenizer(const SkPdfObject* objWithStream);
|
||||
SkPdfPodofoTokenizer(const char* buffer, int len);
|
||||
|
||||
virtual ~SkPdfPodofoTokenizer();
|
||||
|
||||
bool readToken(PdfToken* token);
|
||||
bool readTokenCore(PdfToken* token);
|
||||
void PutBack(PdfToken token);
|
||||
|
||||
private:
|
||||
const SkPdfMapper* fMapper;
|
||||
const PoDoFo::PdfMemDocument* fDoc;
|
||||
PoDoFo::PdfContentsTokenizer* fTokenizer;
|
||||
|
||||
char* fUncompressedStream;
|
||||
long fUncompressedStreamLength;
|
||||
|
||||
bool fEmpty;
|
||||
bool fHasPutBack;
|
||||
PdfToken fPutBack;
|
||||
};
|
||||
|
||||
#endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_PODOFO_SKPDFPODOFOTOKENIZER_H_
|
@ -1,193 +0,0 @@
|
||||
#include "SkPodofoParsedPDF.h"
|
||||
|
||||
#include "SkPdfPodofoTokenizer.h"
|
||||
#include "SkPdfHeaders_autogen.h"
|
||||
#include "SkPdfMapper_autogen.h"
|
||||
#include "SkPdfBasics.h"
|
||||
#include "SkPdfParser.h"
|
||||
|
||||
#include "podofo.h"
|
||||
|
||||
SkPodofoParsedPDF::SkPodofoParsedPDF(const char* path) : fDoc(new PoDoFo::PdfMemDocument(path))
|
||||
, fMapper(new SkPdfMapper(this)) {}
|
||||
|
||||
SkPodofoParsedPDF::~SkPodofoParsedPDF() {
|
||||
delete fDoc;
|
||||
delete fMapper;
|
||||
}
|
||||
|
||||
int SkPodofoParsedPDF::pages() const {
|
||||
return fDoc->GetPageCount();
|
||||
}
|
||||
|
||||
double SkPodofoParsedPDF::width(int page) const {
|
||||
PoDoFo::PdfRect rect = fDoc->GetPage(page)->GetMediaBox();
|
||||
return rect.GetWidth() + rect.GetLeft();
|
||||
}
|
||||
|
||||
double SkPodofoParsedPDF::height(int page) const {
|
||||
PoDoFo::PdfRect rect = fDoc->GetPage(page)->GetMediaBox();
|
||||
return rect.GetHeight() + rect.GetBottom();
|
||||
}
|
||||
|
||||
const SkPdfResourceDictionary* SkPodofoParsedPDF::pageResources(int page) const {
|
||||
SkPdfPageObjectDictionary* pg = NULL;
|
||||
SkPdfObject* obj = make(fDoc->GetPage(page)->GetObject());
|
||||
fMapper->mapPageObjectDictionary(obj, &pg);
|
||||
return pg ? pg->Resources() : NULL;
|
||||
}
|
||||
|
||||
SkRect SkPodofoParsedPDF::MediaBox(int page) const {
|
||||
PoDoFo::PdfRect rect = fDoc->GetPage(page)->GetMediaBox();
|
||||
SkRect skrect = SkRect::MakeLTRB(SkDoubleToScalar(rect.GetLeft()),
|
||||
SkDoubleToScalar(rect.GetBottom()),
|
||||
SkDoubleToScalar(rect.GetLeft() + rect.GetWidth()),
|
||||
SkDoubleToScalar(rect.GetBottom() + rect.GetHeight()));
|
||||
return skrect;
|
||||
}
|
||||
|
||||
|
||||
SkPdfPodofoTokenizer* SkPodofoParsedPDF::tokenizerOfPage(int page) const {
|
||||
PoDoFo::PdfContentsTokenizer* t = new PoDoFo::PdfContentsTokenizer(fDoc->GetPage(page));
|
||||
return new SkPdfPodofoTokenizer(this, t);
|
||||
}
|
||||
|
||||
SkPdfPodofoTokenizer* SkPodofoParsedPDF::tokenizerOfStream(const SkPdfStream* stream) const {
|
||||
if (stream == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* buffer = NULL;
|
||||
long len = 0;
|
||||
stream->GetFilteredCopy(&buffer, &len);
|
||||
return tokenizerOfBuffer(buffer, len);
|
||||
}
|
||||
|
||||
SkPdfPodofoTokenizer* SkPodofoParsedPDF::tokenizerOfBuffer(char* buffer, size_t len) const {
|
||||
PoDoFo::PdfContentsTokenizer* t = new PoDoFo::PdfContentsTokenizer(buffer, len);
|
||||
return new SkPdfPodofoTokenizer(this, t);
|
||||
}
|
||||
|
||||
size_t SkPodofoParsedPDF::objects() const {
|
||||
return fDoc->GetObjects().GetSize();
|
||||
}
|
||||
|
||||
const SkPdfObject* SkPodofoParsedPDF::object(int i) const {
|
||||
PoDoFo::PdfVecObjects& objects = (PoDoFo::PdfVecObjects&)fDoc->GetObjects();
|
||||
return make(objects[i]);
|
||||
}
|
||||
|
||||
SkPdfObject* SkPodofoParsedPDF::make(PoDoFo::PdfObject* obj) const {
|
||||
return new SkPdfObject(this, obj);
|
||||
}
|
||||
|
||||
const SkPdfObject* SkPodofoParsedPDF::make(const PoDoFo::PdfObject* obj) const {
|
||||
return new SkPdfObject(this, obj);
|
||||
}
|
||||
|
||||
const SkPdfMapper* SkPodofoParsedPDF::mapper() const {
|
||||
return fMapper;
|
||||
}
|
||||
|
||||
SkPdfNumber* SkPodofoParsedPDF::createNumber(double number) const {
|
||||
return new SkPdfNumber(this, new PoDoFo::PdfObject(PoDoFo::PdfVariant(number)));
|
||||
}
|
||||
|
||||
SkPdfInteger* SkPodofoParsedPDF::createInteger(int value) const {
|
||||
return new SkPdfInteger(this, new PoDoFo::PdfObject(PoDoFo::PdfVariant((PoDoFo::pdf_int64)value)));
|
||||
}
|
||||
|
||||
SkPdfString* SkPodofoParsedPDF::createString(char* sz, size_t len) const {
|
||||
// TODO(edisonn): NYI
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PdfContext* gPdfContext = NULL;
|
||||
|
||||
void SkPodofoParsedPDF::drawPage(int page, SkCanvas* canvas) const {
|
||||
SkPdfPodofoTokenizer* tokenizer = tokenizerOfPage(page);
|
||||
|
||||
PdfContext pdfContext(this);
|
||||
pdfContext.fOriginalMatrix = SkMatrix::I();
|
||||
pdfContext.fGraphicsState.fResources = pageResources(page);
|
||||
|
||||
gPdfContext = &pdfContext;
|
||||
|
||||
// TODO(edisonn): get matrix stuff right.
|
||||
// TODO(edisonn): add DPI/scale/zoom.
|
||||
SkScalar z = SkIntToScalar(0);
|
||||
SkRect rect = MediaBox(page);
|
||||
SkScalar w = rect.width();
|
||||
SkScalar h = rect.height();
|
||||
|
||||
SkPoint pdfSpace[4] = {SkPoint::Make(z, z), SkPoint::Make(w, z), SkPoint::Make(w, h), SkPoint::Make(z, h)};
|
||||
// SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w, h), SkPoint::Make(w, z), SkPoint::Make(z, z)};
|
||||
|
||||
// TODO(edisonn): add flag for this app to create sourunding buffer zone
|
||||
// TODO(edisonn): add flagg for no clipping.
|
||||
// Use larger image to make sure we do not draw anything outside of page
|
||||
// could be used in tests.
|
||||
|
||||
#ifdef PDF_DEBUG_3X
|
||||
SkPoint skiaSpace[4] = {SkPoint::Make(w+z, h+h), SkPoint::Make(w+w, h+h), SkPoint::Make(w+w, h+z), SkPoint::Make(w+z, h+z)};
|
||||
#else
|
||||
SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w, h), SkPoint::Make(w, z), SkPoint::Make(z, z)};
|
||||
#endif
|
||||
//SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(w, h)};
|
||||
//SkPoint skiaSpace[2] = {SkPoint::Make(w, z), SkPoint::Make(z, h)};
|
||||
|
||||
//SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(z, h)};
|
||||
//SkPoint skiaSpace[2] = {SkPoint::Make(z, h), SkPoint::Make(z, z)};
|
||||
|
||||
//SkPoint pdfSpace[3] = {SkPoint::Make(z, z), SkPoint::Make(z, h), SkPoint::Make(w, h)};
|
||||
//SkPoint skiaSpace[3] = {SkPoint::Make(z, h), SkPoint::Make(z, z), SkPoint::Make(w, 0)};
|
||||
|
||||
SkAssertResult(pdfContext.fOriginalMatrix.setPolyToPoly(pdfSpace, skiaSpace, 4));
|
||||
SkTraceMatrix(pdfContext.fOriginalMatrix, "Original matrix");
|
||||
|
||||
|
||||
pdfContext.fGraphicsState.fMatrix = pdfContext.fOriginalMatrix;
|
||||
pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState.fMatrix;
|
||||
pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState.fMatrix;
|
||||
|
||||
canvas->setMatrix(pdfContext.fOriginalMatrix);
|
||||
|
||||
#ifndef PDF_DEBUG_NO_PAGE_CLIPING
|
||||
canvas->clipRect(SkRect::MakeXYWH(z, z, w, h), SkRegion::kIntersect_Op, true);
|
||||
#endif
|
||||
|
||||
// erase with red before?
|
||||
// SkPaint paint;
|
||||
// paint.setColor(SK_ColorRED);
|
||||
// canvas->drawRect(rect, paint);
|
||||
|
||||
PdfMainLooper looper(NULL, tokenizer, &pdfContext, canvas);
|
||||
looper.loop();
|
||||
|
||||
delete tokenizer;
|
||||
|
||||
canvas->flush();
|
||||
}
|
||||
|
||||
// TODO(edisonn): move in trace util.
|
||||
#include "SkMatrix.h"
|
||||
#include "SkRect.h"
|
||||
|
||||
#ifdef PDF_TRACE
|
||||
void SkTraceMatrix(const SkMatrix& matrix, const char* sz) {
|
||||
printf("SkMatrix %s ", sz);
|
||||
for (int i = 0 ; i < 9 ; i++) {
|
||||
printf("%f ", SkScalarToDouble(matrix.get(i)));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void SkTraceRect(const SkRect& rect, const char* sz) {
|
||||
printf("SkRect %s ", sz);
|
||||
printf("x = %f ", SkScalarToDouble(rect.x()));
|
||||
printf("y = %f ", SkScalarToDouble(rect.y()));
|
||||
printf("w = %f ", SkScalarToDouble(rect.width()));
|
||||
printf("h = %f ", SkScalarToDouble(rect.height()));
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
@ -1,59 +0,0 @@
|
||||
#ifndef EXPERIMENTAL_PDFVIEWER_PDFPARSER_PODOFO_SKPODOFOPARSEDPDF_H_
|
||||
#define EXPERIMENTAL_PDFVIEWER_PDFPARSER_PODOFO_SKPODOFOPARSEDPDF_H_
|
||||
|
||||
#include "SkRect.h"
|
||||
|
||||
class SkCanvas;
|
||||
|
||||
class SkPdfInteger;
|
||||
class SkPdfMapper;
|
||||
class SkPdfNumber;
|
||||
class SkPdfObject;
|
||||
class SkPdfResourceDictionary;
|
||||
class SkPdfStream;
|
||||
class SkPdfString;
|
||||
|
||||
class SkPdfPodofoTokenizer;
|
||||
|
||||
namespace PoDoFo {
|
||||
class PdfMemDocument;
|
||||
class PdfObject;
|
||||
}
|
||||
|
||||
class SkPodofoParsedPDF {
|
||||
public:
|
||||
SkPodofoParsedPDF(const char* path);
|
||||
virtual ~SkPodofoParsedPDF();
|
||||
|
||||
virtual int pages() const;
|
||||
virtual double width(int page) const;
|
||||
virtual double height(int page) const;
|
||||
const SkPdfResourceDictionary* pageResources(int page) const;
|
||||
virtual SkRect MediaBox(int n) const;
|
||||
virtual SkPdfPodofoTokenizer* tokenizerOfPage(int n) const;
|
||||
|
||||
virtual SkPdfPodofoTokenizer* tokenizerOfStream(const SkPdfStream* stream) const;
|
||||
virtual SkPdfPodofoTokenizer* tokenizerOfBuffer(char* buffer, size_t len) const;
|
||||
|
||||
virtual size_t objects() const;
|
||||
virtual const SkPdfObject* object(int i) const;
|
||||
|
||||
PoDoFo::PdfMemDocument* podofo() const {return fDoc;}
|
||||
|
||||
const SkPdfMapper* mapper() const;
|
||||
|
||||
SkPdfNumber* createNumber(double number) const;
|
||||
SkPdfInteger* createInteger(int value) const;
|
||||
SkPdfString* createString(char* sz, size_t len) const;
|
||||
|
||||
void drawPage(int page, SkCanvas* canvas) const;
|
||||
|
||||
private:
|
||||
SkPdfObject* make(PoDoFo::PdfObject* obj) const;
|
||||
const SkPdfObject* make(const PoDoFo::PdfObject* obj) const;
|
||||
|
||||
PoDoFo::PdfMemDocument* fDoc;
|
||||
SkPdfMapper* fMapper;
|
||||
};
|
||||
|
||||
#endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_PODOFO_SKPODOFOPARSEDPDF_H_
|
@ -1,414 +0,0 @@
|
||||
|
||||
#include "SkPodofoUtils.h"
|
||||
#include "SkMatrix.h"
|
||||
#include "SkPdfHeaders_autogen.h"
|
||||
#include "SkPdfMapper_autogen.h"
|
||||
|
||||
#include "podofo.h"
|
||||
|
||||
const PoDoFo::PdfObject* resolveReferenceObject(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfObject* obj,
|
||||
bool resolveOneElementArrays) {
|
||||
while (obj && (obj->IsReference() || (resolveOneElementArrays &&
|
||||
obj->IsArray() &&
|
||||
obj->GetArray().GetSize() == 1))) {
|
||||
if (obj->IsReference()) {
|
||||
// We need to force the non const, the only update we will do is for recurssion checks.
|
||||
PoDoFo::PdfReference& ref = (PoDoFo::PdfReference&)obj->GetReference();
|
||||
obj = pdfDoc->podofo()->GetObjects().GetObject(ref);
|
||||
} else {
|
||||
obj = &obj->GetArray()[0];
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
// TODO(edisonn): deal with synonyms (/BPC == /BitsPerComponent), here or in GetKey?
|
||||
// Always pass long form in key, and have a map of long -> short key
|
||||
bool LongFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
long* data) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)));
|
||||
|
||||
if (value == NULL || !value->IsNumber()) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
*data = value->GetNumber();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LongFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
long* data) {
|
||||
if (LongFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return LongFromDictionary(pdfDoc, dict, abr, data);
|
||||
}
|
||||
|
||||
bool DoubleFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
double* data) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)));
|
||||
|
||||
if (value == NULL || (!value->IsReal() && !value->IsNumber())) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
*data = value->GetReal();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DoubleFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
double* data) {
|
||||
if (DoubleFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return DoubleFromDictionary(pdfDoc, dict, abr, data);
|
||||
}
|
||||
|
||||
|
||||
bool BoolFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
bool* data) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)));
|
||||
|
||||
if (value == NULL || !value->IsBool()) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
*data = value->GetBool();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BoolFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
bool* data) {
|
||||
if (BoolFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return BoolFromDictionary(pdfDoc, dict, abr, data);
|
||||
}
|
||||
|
||||
bool NameFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
std::string* data) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)),
|
||||
true);
|
||||
if (value == NULL || !value->IsName()) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
*data = value->GetName().GetName();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NameFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
std::string* data) {
|
||||
if (NameFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return NameFromDictionary(pdfDoc, dict, abr, data);
|
||||
}
|
||||
|
||||
bool StringFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
std::string* data) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)),
|
||||
true);
|
||||
if (value == NULL || (!value->IsString() && !value->IsHexString())) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
*data = value->GetString().GetString();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StringFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
std::string* data) {
|
||||
if (StringFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return StringFromDictionary(pdfDoc, dict, abr, data);
|
||||
}
|
||||
|
||||
|
||||
bool SkMatrixFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
SkMatrix** matrix) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)));
|
||||
|
||||
if (value == NULL || !value->IsArray()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value->GetArray().GetSize() != 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double array[6];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
const PoDoFo::PdfObject* elem = resolveReferenceObject(pdfDoc, &value->GetArray()[i]);
|
||||
if (elem == NULL || (!elem->IsReal() && !elem->IsNumber())) {
|
||||
return false;
|
||||
}
|
||||
array[i] = elem->GetReal();
|
||||
}
|
||||
|
||||
*matrix = new SkMatrix();
|
||||
**matrix = SkMatrixFromPdfMatrix(array);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkMatrixFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkMatrix** data) {
|
||||
if (SkMatrixFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return SkMatrixFromDictionary(pdfDoc, dict, abr, data);
|
||||
|
||||
}
|
||||
|
||||
bool SkRectFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
SkRect** rect) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)));
|
||||
|
||||
if (value == NULL || !value->IsArray()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value->GetArray().GetSize() != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double array[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const PoDoFo::PdfObject* elem = resolveReferenceObject(pdfDoc, &value->GetArray()[i]);
|
||||
if (elem == NULL || (!elem->IsReal() && !elem->IsNumber())) {
|
||||
return false;
|
||||
}
|
||||
array[i] = elem->GetReal();
|
||||
}
|
||||
|
||||
*rect = new SkRect();
|
||||
**rect = SkRect::MakeLTRB(SkDoubleToScalar(array[0]),
|
||||
SkDoubleToScalar(array[1]),
|
||||
SkDoubleToScalar(array[2]),
|
||||
SkDoubleToScalar(array[3]));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkRectFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkRect** data) {
|
||||
if (SkRectFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return SkRectFromDictionary(pdfDoc, dict, abr, data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
SkPdfObject* get(const SkPdfObject* obj, const char* key, const char* abr = "") {
|
||||
PoDoFo::PdfObject* podofoObj = NULL;
|
||||
if (obj == NULL) return NULL;
|
||||
const SkPdfDictionary* dict = obj->asDictionary();
|
||||
if (dict == NULL) return NULL;
|
||||
if (!dict->podofo()->IsDictionary()) return NULL;
|
||||
ObjectFromDictionary(dict->doc(), dict->podofo()->GetDictionary(), key, abr, &podofoObj);
|
||||
SkPdfObject* ret = NULL;
|
||||
obj->doc()->mapper()->mapObject(podofoObj, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ArrayFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfArray* data) {return false;}
|
||||
|
||||
bool FileSpecFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfFileSpec* data) {return false;}
|
||||
|
||||
bool StreamFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfStream** data);
|
||||
|
||||
bool TreeFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfTree** data) {return false;}
|
||||
|
||||
bool DateFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfDate* data) {return false;}
|
||||
|
||||
bool FunctionFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfFunction* data) {return false;}
|
||||
|
||||
|
||||
|
||||
|
||||
bool ArrayFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
SkPdfArray** data) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)),
|
||||
true);
|
||||
if (value == NULL || !value->IsArray()) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return pdfDoc->mapper()->mapArray(value, data);
|
||||
}
|
||||
|
||||
|
||||
bool ArrayFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfArray** data) {
|
||||
if (ArrayFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return ArrayFromDictionary(pdfDoc, dict, abr, data);
|
||||
}
|
||||
|
||||
/*
|
||||
bool DictionaryFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
SkPoDoFo::PdfDictionary** data) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)),
|
||||
true);
|
||||
if (value == NULL || !value->IsDictionary()) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return pdfDoc->mapper()->mapDictionary(value, data);
|
||||
}
|
||||
|
||||
bool DictionaryFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPoDoFo::PdfDictionary** data) {
|
||||
if (DictionaryFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return DictionaryFromDictionary(pdfDoc, dict, abr, data);
|
||||
}
|
||||
*/
|
||||
|
||||
bool ObjectFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
PoDoFo::PdfObject** data) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)),
|
||||
true);
|
||||
if (value == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return true;
|
||||
}
|
||||
*data = (PoDoFo::PdfObject*)value;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ObjectFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
PoDoFo::PdfObject** data) {
|
||||
if (ObjectFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return ObjectFromDictionary(pdfDoc, dict, abr, data);
|
||||
}
|
||||
|
||||
bool StreamFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
SkPdfStream** data) {
|
||||
const PoDoFo::PdfObject* value = resolveReferenceObject(pdfDoc,
|
||||
dict.GetKey(PoDoFo::PdfName(key)),
|
||||
true);
|
||||
if (value == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return true;
|
||||
}
|
||||
return pdfDoc->mapper()->mapStream(value, data);
|
||||
}
|
||||
|
||||
bool StreamFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfStream** data) {
|
||||
if (StreamFromDictionary(pdfDoc, dict, key, data)) return true;
|
||||
if (abr == NULL || *abr == '\0') return false;
|
||||
return StreamFromDictionary(pdfDoc, dict, abr, data);
|
||||
}
|
@ -1,122 +0,0 @@
|
||||
#ifndef EXPERIMENTAL_PDFVIEWER_PDFPARSER_PODOFO_SKPODOFOUTILS_H_
|
||||
#define EXPERIMENTAL_PDFVIEWER_PDFPARSER_PODOFO_SKPODOFOUTILS_H_
|
||||
|
||||
#include <string>
|
||||
#include "SkPdfNYI.h"
|
||||
|
||||
class SkMatrix;
|
||||
class SkRect;
|
||||
|
||||
namespace PoDoFo {
|
||||
class PdfDictionary;
|
||||
class PdfObject;
|
||||
}
|
||||
|
||||
class SkPodofoParsedPDF;
|
||||
|
||||
const PoDoFo::PdfObject* resolveReferenceObject(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfObject* obj,
|
||||
bool resolveOneElementArrays = false);
|
||||
|
||||
bool LongFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
long* data);
|
||||
|
||||
bool DoubleFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
double* data);
|
||||
|
||||
bool BoolFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
bool* data);
|
||||
|
||||
bool NameFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
std::string* data);
|
||||
|
||||
bool StringFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
std::string* data);
|
||||
/*
|
||||
class SkPoDoFo::PdfDictionary;
|
||||
bool DictionaryFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPoDoFo::PdfDictionary** data);
|
||||
*/
|
||||
|
||||
bool skpdfmap(const SkPodofoParsedPDF& podofoDoc, const PoDoFo::PdfObject& podofoObj, PoDoFo::PdfObject** out);
|
||||
|
||||
bool ObjectFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
PoDoFo::PdfObject** data);
|
||||
|
||||
|
||||
class SkPdfArray;
|
||||
class SkPdfStream;
|
||||
|
||||
bool ArrayFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfArray** data);
|
||||
|
||||
bool SkMatrixFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkMatrix** data);
|
||||
|
||||
bool FileSpecFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfFileSpec* data);
|
||||
|
||||
|
||||
bool StreamFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfStream** data);
|
||||
|
||||
bool TreeFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfTree** data);
|
||||
|
||||
bool DateFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfDate* data);
|
||||
|
||||
bool SkRectFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkRect** data);
|
||||
|
||||
bool FunctionFromDictionary(const SkPodofoParsedPDF* pdfDoc,
|
||||
const PoDoFo::PdfDictionary& dict,
|
||||
const char* key,
|
||||
const char* abr,
|
||||
SkPdfFunction* data);
|
||||
|
||||
SkMatrix SkMatrixFromPdfMatrix(double array[6]);
|
||||
|
||||
#endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_PODOFO_SKPODOFOUTILS_H_
|
Loading…
Reference in New Issue
Block a user