mode code cleanup (100c / l, comments)
Review URL: https://codereview.chromium.org/26912005 git-svn-id: http://skia.googlecode.com/svn/trunk@11716 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
d048a3c359
commit
e50d9a1fcd
@ -62,7 +62,9 @@ class SkPdfNativeObject;
|
||||
|
||||
#ifdef PDF_TRACK_STREAM_OFFSETS
|
||||
#define TRACK_OBJECT_SRC(a)
|
||||
#define STORE_TRACK_PARAMETERS(obj) (obj)->fStreamId = streamId; (obj)->fOffsetStart = offsetStart; (obj)->fOffsetEnd = offsetEnd;
|
||||
#define STORE_TRACK_PARAMETERS(obj) (obj)->fStreamId = streamId;\
|
||||
(obj)->fOffsetStart = offsetStart;\
|
||||
(obj)->fOffsetEnd = offsetEnd;
|
||||
#define STORE_TRACK_PARAMETER_OFFSET_END(obj,offsetEnd) (obj)->fOffsetEnd = (offsetEnd)-streamStart;
|
||||
#else
|
||||
#define TRACK_OBJECT_SRC(a)
|
||||
|
@ -7,9 +7,9 @@
|
||||
|
||||
#include "SkPdfFont.h"
|
||||
|
||||
#include "SkPdfNativeTokenizer.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkTypeface.h"
|
||||
#include "SkPdfNativeTokenizer.h"
|
||||
|
||||
SkTDict<SkPdfStandardFontEntry>& getStandardFonts() {
|
||||
static SkTDict<SkPdfStandardFontEntry> gPdfStandardFonts(100);
|
||||
@ -95,7 +95,8 @@ SkTDict<SkPdfStandardFontEntry>& getStandardFonts() {
|
||||
gPdfStandardFonts.set("Verdana-Bold", SkPdfStandardFontEntry("Verdana", true, false));
|
||||
gPdfStandardFonts.set("WenQuanYiMicroHei", SkPdfStandardFontEntry("WenQuanYi Micro Hei", false, false));
|
||||
|
||||
// TODO(edisonn): list all phonts available, builf post script name as in pdf spec
|
||||
// TODO(edisonn): list all fonts available, buil post script name as in pdf spec
|
||||
// TODO(edisonn): Does it work in all OSs ?
|
||||
/*
|
||||
* The PostScript name for the value of BaseFontis determined in one of two ways:
|
||||
• Use the PostScript name that is an optional entry in the “name” table of the
|
||||
@ -118,10 +119,6 @@ by underscores in the value of BaseFont. For instance, as illustrated in Example
|
||||
5.7, the name “MinionMM 366 465 11 ” (which ends with a space character)
|
||||
becomes /MinionMM_366_465_11_.
|
||||
*/
|
||||
|
||||
// might not work on all oses ?
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
return gPdfStandardFonts;
|
||||
@ -155,8 +152,9 @@ SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool
|
||||
return typeface;
|
||||
}
|
||||
|
||||
SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkPdfNativeDoc* doc, SkPdfFontDescriptorDictionary* fd, bool loadFromName) {
|
||||
// TODO(edisonn): partial implementation ... also const handling ...
|
||||
SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkPdfNativeDoc* doc, SkPdfFontDescriptorDictionary* fd,
|
||||
bool loadFromName) {
|
||||
// TODO(edisonn): partial implementation.
|
||||
// Only one, at most be available
|
||||
SkPdfStream* pdfStream = NULL;
|
||||
if (fd->has_FontFile()) {
|
||||
@ -233,7 +231,7 @@ SkPdfFont* SkPdfFont::fontFromPdfDictionaryOnce(SkPdfNativeDoc* doc, SkPdfFontDi
|
||||
// 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
|
||||
// if is a dict, reserve 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_SkPdfNativeObjectType:
|
||||
@ -270,7 +268,8 @@ SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkPdfNativeDoc* doc, SkPdfFontDictio
|
||||
|
||||
|
||||
|
||||
SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* dict) {
|
||||
SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfNativeDoc* doc,
|
||||
SkPdfType0FontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -278,7 +277,8 @@ SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfNativeDoc* doc, SkPd
|
||||
return new SkPdfType0Font(doc, dict);
|
||||
}
|
||||
|
||||
SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkPdfNativeDoc* doc, SkPdfType1FontDictionary* dict) {
|
||||
SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkPdfNativeDoc* doc,
|
||||
SkPdfType1FontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -286,7 +286,8 @@ SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkPdfNativeDoc* doc, SkP
|
||||
return new SkPdfType1Font(doc, dict);
|
||||
}
|
||||
|
||||
SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfNativeDoc* doc, SkPdfType3FontDictionary* dict) {
|
||||
SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfNativeDoc* doc,
|
||||
SkPdfType3FontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -296,7 +297,8 @@ SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfNativeDoc* doc, SkPd
|
||||
return new SkPdfType3Font(doc, dict);
|
||||
}
|
||||
|
||||
SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfNativeDoc* doc, SkPdfTrueTypeFontDictionary* dict) {
|
||||
SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfNativeDoc* doc,
|
||||
SkPdfTrueTypeFontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -304,7 +306,8 @@ SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfNativeDoc* doc
|
||||
return new SkPdfTrueTypeFont(doc, dict);
|
||||
}
|
||||
|
||||
SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkPdfNativeDoc* doc, SkPdfMultiMasterFontDictionary* dict) {
|
||||
SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(
|
||||
SkPdfNativeDoc* doc, SkPdfMultiMasterFontDictionary* dict) {
|
||||
if (dict == NULL) {
|
||||
return NULL; // default one?
|
||||
}
|
||||
@ -322,7 +325,9 @@ static int skstoi(const SkPdfNativeObject* str) {
|
||||
return ret & 0x0000ffff;
|
||||
}
|
||||
|
||||
#define tokenIsKeyword(token,keyword) (token.fType == kKeyword_TokenType && token.fKeywordLength==sizeof(keyword)-1 && strncmp(token.fKeyword, keyword, sizeof(keyword)-1) == 0)
|
||||
#define tokenIsKeyword(token,keyword) (token.fType == kKeyword_TokenType && \
|
||||
token.fKeywordLength==sizeof(keyword)-1 && \
|
||||
strncmp(token.fKeyword, keyword, sizeof(keyword)-1) == 0)
|
||||
|
||||
SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fParsed(parsed) {
|
||||
fCMapEncoding = NULL;
|
||||
@ -342,16 +347,16 @@ SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fP
|
||||
}
|
||||
|
||||
// TODO(edisonn): deal with multibyte character, or longer strings.
|
||||
// Ritght now we deal with up 2 characters, e.g. <0020> but not longer like <00660066006C>
|
||||
// Right now we deal with up 2 characters, e.g. <0020> but not longer like <00660066006C>
|
||||
//2 beginbfrange
|
||||
//<0000> <005E> <0020>
|
||||
//<005F> <0061> [<00660066> <00660069> <00660066006C>]
|
||||
|
||||
while (tokenizer->readToken(&token)) {
|
||||
|
||||
// TODO(edisonn): perf, macro that would make equal first for token.fKeywordLength with sizeof(keyword), instead od strlen, make sure it is keyword, not a char*
|
||||
if (tokenIsKeyword(token, "begincodespacerange")) {
|
||||
while (tokenizer->readToken(&token) && !tokenIsKeyword(token, "endcodespacerange")) {
|
||||
while (tokenizer->readToken(&token) &&
|
||||
!tokenIsKeyword(token, "endcodespacerange")) {
|
||||
// tokenizer->PutBack(token);
|
||||
// tokenizer->readToken(&token);
|
||||
// TODO(edisonn): check token type! ignore/report errors.
|
||||
@ -387,6 +392,7 @@ SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fP
|
||||
|
||||
|
||||
tokenizer->readToken(&token); // [ or just an array directly?
|
||||
// do not putback, we will reuse the read. See next commented read.
|
||||
// tokenizer->PutBack(token);
|
||||
|
||||
// TODO(edisonn): read spec: any string or only hex string?
|
||||
@ -404,22 +410,20 @@ SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fP
|
||||
// read one string
|
||||
} else if (token.fType == kObject_TokenType && token.fObject->isArray()) {
|
||||
// tokenizer->readToken(&token);
|
||||
// read array
|
||||
for (unsigned int i = 0; i < token.fObject->size(); i++) {
|
||||
fCMapEncodingFlag[start + i] |= 2;
|
||||
fCMapEncoding[start + i] = skstoi((*token.fObject)[i]);
|
||||
}
|
||||
// read array
|
||||
} else {
|
||||
tokenizer->PutBack(token);
|
||||
}
|
||||
|
||||
//fCMapEncodingFlag[from] = 1;
|
||||
//fCMapEncoding[from] = to;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SkPdfType0Font::SkPdfType0Font(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* dict) {
|
||||
fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str());
|
||||
fEncoding = NULL;
|
||||
@ -428,6 +432,7 @@ SkPdfType0Font::SkPdfType0Font(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* di
|
||||
if (dict->isEncodingAName(doc)) {
|
||||
fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName(doc).c_str());
|
||||
} else if (dict->isEncodingAStream(doc)) {
|
||||
// TODO(edisonn): NYI
|
||||
//fEncoding = loadEncodingFromStream(dict->getEncodingAsStream());
|
||||
} else {
|
||||
// TODO(edisonn): error ... warning .. assert?
|
||||
@ -451,8 +456,6 @@ SkTDict<SkPdfEncoding*>& getStandardEncodings() {
|
||||
SkPdfEncoding* SkPdfEncoding::fromName(const char* name) {
|
||||
SkPdfEncoding* encoding = NULL;
|
||||
if (!getStandardEncodings().find(name, &encoding)) {
|
||||
// TODO(edisonn): if the function return false, and we a guaranteed that the value is not
|
||||
// changed, delete this set to null
|
||||
encoding = NULL;
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,13 @@
|
||||
#ifndef SkPdfFont_DEFINED
|
||||
#define SkPdfFont_DEFINED
|
||||
|
||||
#include "SkPdfGraphicsState.h"
|
||||
#include "SkPdfHeaders_autogen.h"
|
||||
#include "SkPdfMapper_autogen.h"
|
||||
|
||||
#include "SkTypeface.h"
|
||||
#include "SkUtils.h"
|
||||
#include "SkPdfGraphicsState.h"
|
||||
#include "SkPdfUtils.h"
|
||||
#include "SkTypeface.h"
|
||||
#include "SkTDict.h"
|
||||
#include "SkUtils.h"
|
||||
|
||||
class SkPdfType0Font;
|
||||
class SkPdfType1Font;
|
||||
@ -174,26 +173,32 @@ public:
|
||||
|
||||
const SkPdfEncoding* encoding() const {return fEncoding;}
|
||||
|
||||
void drawText(const SkDecodedText& text, SkPaint* paint, SkPdfContext* 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
|
||||
SkPoint point = SkPoint::Make(SkDoubleToScalar(0), SkDoubleToScalar(0));
|
||||
pdfContext->fGraphicsState.fMatrixTm.mapPoints(&point, 1);
|
||||
printf("DrawText at (%f, %f)\n", SkScalarToDouble(point.x()), SkScalarToDouble(point.y()));
|
||||
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));
|
||||
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));
|
||||
pdfContext->fGraphicsState.fMatrixTm.preTranslate(SkDoubleToScalar(width),
|
||||
SkDoubleToScalar(0.0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,16 +226,24 @@ public:
|
||||
static SkPdfFont* fontFromPdfDictionary(SkPdfNativeDoc* doc, SkPdfFontDictionary* dict);
|
||||
static SkPdfFont* Default() {return fontFromName(NULL, NULL, "TimesNewRoman");}
|
||||
|
||||
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 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(SkPdfNativeDoc* 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, SkPdfContext* 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:
|
||||
@ -244,7 +257,8 @@ public:
|
||||
SkPdfStandardFont(SkTypeface* typeface) : fTypeface(typeface) {}
|
||||
|
||||
public:
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext, SkCanvas* canvas) {
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext,
|
||||
SkCanvas* canvas) {
|
||||
paint->setTypeface(fTypeface);
|
||||
paint->setTextEncoding(SkPaint::kUTF8_TextEncoding);
|
||||
|
||||
@ -267,7 +281,8 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext, SkCanvas* canvas) {
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext,
|
||||
SkCanvas* canvas) {
|
||||
return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
|
||||
}
|
||||
|
||||
@ -293,7 +308,8 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext, SkCanvas* canvas) {
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* pdfContext,
|
||||
SkCanvas* canvas) {
|
||||
return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
|
||||
}
|
||||
|
||||
@ -304,14 +320,14 @@ public:
|
||||
|
||||
class SkPdfTrueTypeFont : public SkPdfType1Font {
|
||||
public:
|
||||
SkPdfTrueTypeFont(SkPdfNativeDoc* doc, SkPdfTrueTypeFontDictionary* dict) : SkPdfType1Font(doc, dict) {
|
||||
}
|
||||
SkPdfTrueTypeFont(SkPdfNativeDoc* doc, SkPdfTrueTypeFontDictionary* dict)
|
||||
: SkPdfType1Font(doc, dict) {}
|
||||
};
|
||||
|
||||
class SkPdfMultiMasterFont : public SkPdfType1Font {
|
||||
public:
|
||||
SkPdfMultiMasterFont(SkPdfNativeDoc* doc, SkPdfMultiMasterFontDictionary* dict) : SkPdfType1Font(doc, dict) {
|
||||
}
|
||||
SkPdfMultiMasterFont(SkPdfNativeDoc* doc, SkPdfMultiMasterFontDictionary* dict)
|
||||
: SkPdfType1Font(doc, dict) {}
|
||||
};
|
||||
/*
|
||||
class CIDToGIDMap {
|
||||
@ -421,7 +437,8 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
virtual double drawOneChar(unsigned int ch, SkPaint* paint, SkPdfContext* 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);
|
||||
}
|
||||
@ -434,17 +451,22 @@ public:
|
||||
#endif
|
||||
|
||||
// TODO(edisonn): is it better to resolve the reference at load time, or now?
|
||||
doType3Char(pdfContext, canvas, pdfContext->fPdfDoc->resolveReference(fChars[ch - fFirstChar].fObj), fFontBBox, fFonMatrix, pdfContext->fGraphicsState.fCurFontSize);
|
||||
doType3Char(pdfContext,
|
||||
canvas,
|
||||
pdfContext->fPdfDoc->resolveReference(fChars[ch - fFirstChar].fObj),
|
||||
fFontBBox,
|
||||
fFonMatrix,
|
||||
pdfContext->fGraphicsState.fCurFontSize);
|
||||
|
||||
// TODO(edisonn): verify/test translate code, not tested yet
|
||||
pdfContext->fGraphicsState.fMatrixTm.preTranslate(SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSize * fChars[ch - fFirstChar].fWidth),
|
||||
SkDoubleToScalar(0.0));
|
||||
pdfContext->fGraphicsState.fMatrixTm.preTranslate(
|
||||
SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSize *
|
||||
fChars[ch - fFirstChar].fWidth),
|
||||
SkDoubleToScalar(0.0));
|
||||
return fChars[ch - fFirstChar].fWidth;
|
||||
}
|
||||
|
||||
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {
|
||||
|
||||
}
|
||||
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {}
|
||||
};
|
||||
|
||||
#endif // SkPdfFont_DEFINED
|
||||
|
@ -6,9 +6,9 @@
|
||||
*/
|
||||
|
||||
#include "SkPdfGraphicsState.h"
|
||||
#include "SkPdfNativeTokenizer.h"
|
||||
|
||||
#include "SkDashPathEffect.h"
|
||||
#include "SkPdfNativeTokenizer.h"
|
||||
|
||||
SkPdfContext::SkPdfContext(SkPdfNativeDoc* doc)
|
||||
: fPdfDoc(doc)
|
||||
@ -26,17 +26,19 @@ void SkPdfGraphicsState::applyGraphicsState(SkPaint* paint, bool stroking) {
|
||||
fNonStroking.applyGraphicsState(paint);
|
||||
}
|
||||
|
||||
// TODO(edisonn): get this from pdfContext->options,
|
||||
// TODO(edisonn): Perf, we should load this option from pdfContext->options,
|
||||
// or pdfContext->addPaintOptions(&paint);
|
||||
paint->setAntiAlias(true);
|
||||
|
||||
// TODO(edisonn): miter, ...
|
||||
if (stroking) {
|
||||
paint->setStrokeWidth(SkDoubleToScalar(fLineWidth));
|
||||
// TODO(edisonn): perf, two sets of allocs, create SkDashPathEffect constr that takes ownership
|
||||
// TODO(edisonn): perf, avoid allocs allocs
|
||||
// of the intervals
|
||||
if (fDashArrayLength > 0) {
|
||||
paint->setPathEffect(new SkDashPathEffect(fDashArray, fDashArrayLength, fDashPhase))->unref();
|
||||
paint->setPathEffect(new SkDashPathEffect(fDashArray,
|
||||
fDashArrayLength,
|
||||
fDashPhase))->unref();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,6 @@
|
||||
#include "SkPdfConfig.h"
|
||||
#include "SkPdfUtils.h"
|
||||
|
||||
//#include "SkTDStack.h"
|
||||
|
||||
class SkPdfFont;
|
||||
class SkPdfDoc;
|
||||
class SkPdfNativeObject;
|
||||
@ -461,9 +459,7 @@ smoothness number (PDF 1.3) The precision with which col
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO(edisonn): some defaults are contextual, they could on colorspace, pdf version, ...
|
||||
|
||||
SkPdfGraphicsState() {
|
||||
fCurPosX = 0.0;
|
||||
@ -493,19 +489,18 @@ smoothness number (PDF 1.3) The precision with which col
|
||||
fSMask = NULL;
|
||||
}
|
||||
|
||||
// TODO(edisonn): make two functons instead, stroking and non stoking, avoid branching
|
||||
// TODO(edisonn): make two functions instead, stroking and non stoking, avoid branching
|
||||
void applyGraphicsState(SkPaint* paint, bool stroking);
|
||||
};
|
||||
|
||||
// TODO(edisonn): better class design.
|
||||
// TODO(edisonn): rename to SkPdfContext
|
||||
class SkPdfContext {
|
||||
public:
|
||||
SkTDStackNew<SkPdfNativeObject*> fObjectStack;
|
||||
SkTDStackNew<SkPdfGraphicsState> fStateStack;
|
||||
SkPdfGraphicsState fGraphicsState;
|
||||
SkPdfNativeDoc* fPdfDoc;
|
||||
// TODO(edisonn): the allocator, could be freed after the page is done drawing.
|
||||
// TODO(edisonn): the allocator, could be freed after the page is done drawing, so we have the
|
||||
// pixels on the screen asap.
|
||||
SkPdfAllocator* fTmpPageAllocator;
|
||||
SkMatrix fOriginalMatrix;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -9,9 +9,7 @@
|
||||
#ifndef SkPdfRenderer_DEFINED
|
||||
#define SkPdfRenderer_DEFINED
|
||||
|
||||
// TODO(edisonn): how to remove this dependency? Should I remove the ref counting?
|
||||
#include "SkRefCnt.h"
|
||||
// TODO(edisonn): remove this dependency
|
||||
// TODO(edisonn): remove this dependency, and load only from a stream!
|
||||
#include "SkString.h"
|
||||
|
||||
class SkBitmap;
|
||||
@ -26,22 +24,36 @@ enum SkPdfContent {
|
||||
kAll_SkPdfContent,
|
||||
};
|
||||
|
||||
// TODO(edisonn): move in another file
|
||||
class SkPdfRenderer : public SkRefCnt {
|
||||
// TODO(edisonn): add options to render forms, checkboxes, ...
|
||||
// TODO(edisonn): Add API for Forms viewing and editing
|
||||
// e.g. SkBitmap getPage(int page);
|
||||
// int formsCount();
|
||||
// SkForm getForm(int formID); // SkForm(SkRect, .. other data)
|
||||
// TODO (edisonn): Add intend when loading pdf, for example: for viewing, for parsing content, ...
|
||||
|
||||
class SkPdfRenderer {
|
||||
SkPdfNativeDoc* fPdfDoc;
|
||||
public:
|
||||
SkPdfRenderer() : fPdfDoc(NULL) {}
|
||||
virtual ~SkPdfRenderer() {unload();}
|
||||
|
||||
// TODO(edisonn): add options to render forms, or not
|
||||
bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const;
|
||||
|
||||
// TODO(edisonn): deprecated, should be removed!
|
||||
bool load(const SkString inputFileName);
|
||||
|
||||
bool load(SkStream* stream);
|
||||
bool loaded() const {return fPdfDoc != NULL;}
|
||||
int pages() const;
|
||||
|
||||
void unload();
|
||||
|
||||
bool loaded() const {return fPdfDoc != NULL;}
|
||||
|
||||
int pages() const;
|
||||
|
||||
SkRect MediaBox(int page) const;
|
||||
|
||||
// TODO(edisonn): for testing only, probably it should be removed, unless some client wants to
|
||||
// let users know how much memory the PDF needs.
|
||||
size_t bytesUsed() const;
|
||||
};
|
||||
|
||||
|
@ -30,22 +30,33 @@ const char* getSeverityName(SkPdfIssueSeverity sev) {
|
||||
// TODO(edisonn): add a flag to set the minimum warning level
|
||||
|
||||
#ifdef PDF_REPORT
|
||||
void SkPdfReport( SkPdfIssueSeverity sev, SkPdfIssue issue, const char* context, const SkPdfNativeObject* obj, SkPdfContext* pdfContext) {
|
||||
void SkPdfReport(SkPdfIssueSeverity sev, SkPdfIssue issue,
|
||||
const char* context,
|
||||
const SkPdfNativeObject* obj,
|
||||
SkPdfContext* pdfContext) {
|
||||
if (sev >= kIgnoreError_SkPdfIssueSeverity) {
|
||||
printf("%s: %s\n", getSeverityName(sev), context);
|
||||
}
|
||||
}
|
||||
|
||||
void SkPdfReportUnexpectedType(SkPdfIssueSeverity sev, const char* context, const SkPdfNativeObject* obj, int anyOfTypes, SkPdfContext* pdfContext) {
|
||||
if (sev >= kIgnoreError_SkPdfIssueSeverity) {
|
||||
printf("%s: %s\n", getSeverityName(sev), context);
|
||||
}
|
||||
}
|
||||
|
||||
void SkPdfReportIf(bool report, SkPdfIssueSeverity sev, SkPdfIssue issue, const char* context, const SkPdfNativeObject* obj, SkPdfContext* pdfContext) {
|
||||
void SkPdfReportIf(bool report,
|
||||
SkPdfIssueSeverity sev, SkPdfIssue issue,
|
||||
const char* context,
|
||||
const SkPdfNativeObject* obj,
|
||||
SkPdfContext* pdfContext) {
|
||||
if (!report) {
|
||||
return;
|
||||
}
|
||||
SkPdfReport(sev, issue, context, obj, pdfContext);
|
||||
}
|
||||
|
||||
void SkPdfReportUnexpectedType(SkPdfIssueSeverity sev,
|
||||
const char* context,
|
||||
const SkPdfNativeObject* obj,
|
||||
int anyOfTypes, SkPdfContext* pdfContext) {
|
||||
if (sev >= kIgnoreError_SkPdfIssueSeverity) {
|
||||
printf("%s: %s\n", getSeverityName(sev), context);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // PDF_REPORT
|
||||
|
@ -14,9 +14,11 @@
|
||||
class SkPdfNativeObject;
|
||||
class SkPdfContext;
|
||||
|
||||
// TODO(edisonn): ability to turn on asserts for known good files
|
||||
|
||||
enum SkPdfIssueSeverity {
|
||||
kInfo_SkPdfIssueSeverity,
|
||||
kCodeWarning_SkPdfIssueSeverity, // e.g. like NYI, which has nothing to do with an error in the file
|
||||
kCodeWarning_SkPdfIssueSeverity, // e.g. like NYI, PDF file is Ok.
|
||||
kWarning_SkPdfIssueSeverity,
|
||||
kIgnoreError_SkPdfIssueSeverity,
|
||||
kError_SkPdfIssueSeverity,
|
||||
@ -51,15 +53,24 @@ enum SkPdfIssue {
|
||||
kNoFlateLibrary_SkPdfIssue,
|
||||
kBadStream_SkPdfIssue,
|
||||
|
||||
|
||||
_kCount__SkPdfIssue
|
||||
};
|
||||
|
||||
#ifdef PDF_REPORT
|
||||
|
||||
void SkPdfReportIf(bool report, SkPdfIssueSeverity sev, SkPdfIssue issue, const char* context, const SkPdfNativeObject* obj, SkPdfContext* pdfContext);
|
||||
void SkPdfReport( SkPdfIssueSeverity sev, SkPdfIssue issue, const char* context, const SkPdfNativeObject* obj, SkPdfContext* pdfContext);
|
||||
void SkPdfReportUnexpectedType( SkPdfIssueSeverity sev, const char* context, const SkPdfNativeObject* obj, int anyOfTypes, SkPdfContext* pdfContext);
|
||||
void SkPdfReportIf(bool report,
|
||||
SkPdfIssueSeverity sev, SkPdfIssue issue,
|
||||
const char* context,
|
||||
const SkPdfNativeObject* obj,
|
||||
SkPdfContext* pdfContext);
|
||||
void SkPdfReport(SkPdfIssueSeverity sev, SkPdfIssue issue,
|
||||
const char* context,
|
||||
const SkPdfNativeObject* obj,
|
||||
SkPdfContext* pdfContext);
|
||||
void SkPdfReportUnexpectedType(SkPdfIssueSeverity sev,
|
||||
const char* context,
|
||||
const SkPdfNativeObject* obj, int anyOfTypes,
|
||||
SkPdfContext* pdfContext);
|
||||
#define SkPdfREPORTCODE(code) code
|
||||
|
||||
#else // !PDF_REPORT
|
||||
|
@ -59,7 +59,8 @@ bool operator !=(const SkString& first, const char* second);
|
||||
|
||||
SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray);
|
||||
|
||||
SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfNativeObject* skobj, SkRect bBox, SkMatrix matrix, double textSize);
|
||||
SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfNativeObject* skobj,
|
||||
SkRect bBox, SkMatrix matrix, double textSize);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
@ -150,7 +150,8 @@ protected:
|
||||
const uint16_t indices[], int indexCount,
|
||||
const SkPaint& paint) {
|
||||
before();
|
||||
INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices, indexCount, paint);
|
||||
INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
|
||||
indexCount, paint);
|
||||
after();
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,10 @@
|
||||
#include "SkBitmap.h"
|
||||
#include "SkPoint.h"
|
||||
|
||||
// TODO(edisonn): draw plan from point! - list of draw ops of a point, like a tree!
|
||||
// TODO(edisonn): Minimal PDF to draw some points - remove everything that it is not needed,
|
||||
// save pdf uncompressed
|
||||
|
||||
#define MAX_TRACKING_POINTS 100
|
||||
|
||||
class SkTracker {
|
||||
@ -105,7 +109,8 @@ public:
|
||||
fBeforeTouched[i] = pickColor(bitmap, fExpectedTouched[i].x(), fExpectedTouched[i].y());
|
||||
}
|
||||
for (int i = 0 ; i < fCntExpectedUntouched; i++) {
|
||||
fBeforeUntouched[i] = pickColor(bitmap, fExpectedUntouched[i].x(), fExpectedUntouched[i].y());
|
||||
fBeforeUntouched[i] = pickColor(bitmap, fExpectedUntouched[i].x(),
|
||||
fExpectedUntouched[i].y());
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,17 +124,20 @@ public:
|
||||
if (fBreakOnAny) {
|
||||
doBreak = false;
|
||||
for (int i = 0 ; i < fCntExpectedTouched; i++) {
|
||||
doBreak = doBreak || fBeforeTouched[i] != pickColor(bitmap, fExpectedTouched[i].x(), fExpectedTouched[i].y());
|
||||
doBreak = doBreak || fBeforeTouched[i] != pickColor(bitmap, fExpectedTouched[i].x(),
|
||||
fExpectedTouched[i].y());
|
||||
}
|
||||
} else {
|
||||
doBreak = true;
|
||||
for (int i = 0 ; i < fCntExpectedTouched; i++) {
|
||||
doBreak = doBreak && fBeforeTouched[i] != pickColor(bitmap, fExpectedTouched[i].x(), fExpectedTouched[i].y());
|
||||
doBreak = doBreak && fBeforeTouched[i] != pickColor(bitmap, fExpectedTouched[i].x(),
|
||||
fExpectedTouched[i].y());
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0 ; i < fCntExpectedUntouched; i++) {
|
||||
doBreak = doBreak && fBeforeUntouched[i] == pickColor(bitmap, fExpectedUntouched[i].x(), fExpectedUntouched[i].y());
|
||||
doBreak = doBreak && fBeforeUntouched[i] == pickColor(bitmap, fExpectedUntouched[i].x(),
|
||||
fExpectedUntouched[i].y());
|
||||
}
|
||||
|
||||
if (doBreak) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "SkImageDecoder.h"
|
||||
#include "SkImageEncoder.h"
|
||||
#include "SkOSFile.h"
|
||||
#include "SkPdfRenderer.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkTypeface.h"
|
||||
@ -24,8 +25,6 @@
|
||||
#include "SkGpuDevice.h"
|
||||
#endif
|
||||
|
||||
#include "SkPdfRenderer.h"
|
||||
|
||||
DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to process.");
|
||||
DEFINE_string2(writePath, w, "", "Directory to write the rendered pages.");
|
||||
DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page.");
|
||||
@ -43,7 +42,6 @@ DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any ren
|
||||
DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disabled)");
|
||||
DEFINE_string2(config, c, "8888", "Canvas to render:\n"
|
||||
"\t8888 - argb\n"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
"\tgpu: use the gpu\n"
|
||||
#endif
|
||||
@ -51,9 +49,6 @@ DEFINE_string2(config, c, "8888", "Canvas to render:\n"
|
||||
);
|
||||
DEFINE_bool2(transparentBackground, t, false, "Make background transparent instead of white.");
|
||||
|
||||
|
||||
// TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not to render at all
|
||||
|
||||
/**
|
||||
* Given list of directories and files to use as input, expects to find .pdf
|
||||
* files and it will convert them to .png files writing them in the same directory
|
||||
@ -203,9 +198,11 @@ static bool render_page(const SkString& outputDir,
|
||||
SkColor background = FLAGS_transparentBackground ? SK_ColorTRANSPARENT : SK_ColorWHITE;
|
||||
|
||||
#ifdef PDF_DEBUG_3X
|
||||
setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScalarToDouble(height), background);
|
||||
setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScalarToDouble(height),
|
||||
background);
|
||||
#else
|
||||
setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height), background);
|
||||
setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height),
|
||||
background);
|
||||
#endif
|
||||
SkAutoTUnref<SkBaseDevice> device;
|
||||
if (strcmp(FLAGS_config[0], "8888") == 0) {
|
||||
@ -251,7 +248,8 @@ static bool render_page(const SkString& outputDir,
|
||||
SkImageEncoder::EncodeFile(outputPath.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
|
||||
|
||||
if (FLAGS_showMemoryUsage) {
|
||||
SkDebugf("Memory usage after page %i rendered: %u\n", page < 0 ? 0 : page, (unsigned int)renderer.bytesUsed());
|
||||
SkDebugf("Memory usage after page %i rendered: %u\n",
|
||||
page < 0 ? 0 : page, (unsigned int)renderer.bytesUsed());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -281,7 +279,8 @@ static bool process_pdf(const SkString& inputPath, const SkString& outputDir,
|
||||
for (int i = 0 ; i < FLAGS_benchLoad; i++) {
|
||||
success = renderer.load(inputPath) && success;
|
||||
if (FLAGS_showMemoryUsage) {
|
||||
SkDebugf("Memory usage after load %i number : %u\n", i, (unsigned int)renderer.bytesUsed());
|
||||
SkDebugf("Memory usage after load %i number : %u\n", i,
|
||||
(unsigned int)renderer.bytesUsed());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -296,19 +295,43 @@ static bool process_pdf(const SkString& inputPath, const SkString& outputDir,
|
||||
// TODO(edisonn) if (i == 1) start timer
|
||||
if (strcmp(FLAGS_pages[0], "all") == 0) {
|
||||
for (int pn = 0; pn < renderer.pages(); ++pn) {
|
||||
success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success;
|
||||
success = render_page(
|
||||
outputDir,
|
||||
inputFilename,
|
||||
renderer,
|
||||
FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 :
|
||||
pn) &&
|
||||
success;
|
||||
}
|
||||
} else if (strcmp(FLAGS_pages[0], "reverse") == 0) {
|
||||
for (int pn = renderer.pages() - 1; pn >= 0; --pn) {
|
||||
success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success;
|
||||
success = render_page(
|
||||
outputDir,
|
||||
inputFilename,
|
||||
renderer,
|
||||
FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 :
|
||||
pn) &&
|
||||
success;
|
||||
}
|
||||
} else if (strcmp(FLAGS_pages[0], "first") == 0) {
|
||||
success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : 0) && success;
|
||||
success = render_page(
|
||||
outputDir,
|
||||
inputFilename,
|
||||
renderer,
|
||||
FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : 0) &&
|
||||
success;
|
||||
} else if (strcmp(FLAGS_pages[0], "last") == 0) {
|
||||
success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) && success;
|
||||
success = render_page(
|
||||
outputDir,
|
||||
inputFilename,
|
||||
renderer,
|
||||
FLAGS_noExtensionForOnePagePdf &&
|
||||
renderer.pages() == 1 ? -1 : renderer.pages() - 1) && success;
|
||||
} else {
|
||||
int pn = atoi(FLAGS_pages[0]);
|
||||
success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success;
|
||||
success = render_page(outputDir, inputFilename, renderer,
|
||||
FLAGS_noExtensionForOnePagePdf &&
|
||||
renderer.pages() == 1 ? -1 : pn) && success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user