2013-06-25 20:45:40 +00:00
|
|
|
#ifndef __DEFINED__SkPdfBasics
|
|
|
|
#define __DEFINED__SkPdfBasics
|
|
|
|
|
2013-06-26 17:48:12 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
2013-07-02 22:42:53 +00:00
|
|
|
#include "SkPdfConfig.h"
|
2013-06-26 17:48:12 +00:00
|
|
|
|
2013-06-25 20:45:40 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <cstdio>
|
2013-07-02 22:42:53 +00:00
|
|
|
#include <map>
|
2013-06-25 20:45:40 +00:00
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
class SkPdfFont;
|
|
|
|
class SkPdfDoc;
|
2013-06-26 17:48:12 +00:00
|
|
|
class SkPdfObject;
|
|
|
|
class SkPdfResourceDictionary;
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
class SkNativeParsedPDF;
|
2013-07-02 22:42:53 +00:00
|
|
|
|
2013-06-25 20:45:40 +00:00
|
|
|
// TODO(edisonn): better class design.
|
2013-07-02 22:42:53 +00:00
|
|
|
struct SkPdfColorOperator {
|
2013-07-10 17:09:50 +00:00
|
|
|
// does not own the char*
|
|
|
|
const char* fColorSpace; // TODO(edisonn): use SkString, or even char*
|
2013-06-25 20:45:40 +00:00
|
|
|
SkColor fColor;
|
|
|
|
double fOpacity; // ca or CA
|
|
|
|
// TODO(edisonn): add here other color space options.
|
|
|
|
|
|
|
|
void setRGBColor(SkColor color) {
|
|
|
|
// TODO(edisonn): ASSERT DeviceRGB is the color space.
|
|
|
|
fColor = color;
|
|
|
|
}
|
|
|
|
// TODO(edisonn): double check the default values for all fields.
|
2013-07-10 17:09:50 +00:00
|
|
|
SkPdfColorOperator() : fColorSpace(NULL), fColor(SK_ColorBLACK), fOpacity(1) {}
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
void applyGraphicsState(SkPaint* paint) {
|
|
|
|
paint->setColor(SkColorSetA(fColor, fOpacity * 255));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO(edisonn): better class design.
|
2013-07-02 22:42:53 +00:00
|
|
|
struct SkPdfGraphicsState {
|
2013-06-25 20:45:40 +00:00
|
|
|
SkMatrix fMatrix;
|
|
|
|
SkMatrix fMatrixTm;
|
|
|
|
SkMatrix fMatrixTlm;
|
|
|
|
|
|
|
|
double fCurPosX;
|
|
|
|
double fCurPosY;
|
|
|
|
|
|
|
|
double fCurFontSize;
|
|
|
|
bool fTextBlock;
|
|
|
|
SkPdfFont* fSkFont;
|
|
|
|
SkPath fPath;
|
|
|
|
bool fPathClosed;
|
|
|
|
|
|
|
|
// Clip that is applied after the drawing is done!!!
|
|
|
|
bool fHasClipPathToApply;
|
|
|
|
SkPath fClipPath;
|
|
|
|
|
2013-07-02 22:42:53 +00:00
|
|
|
SkPdfColorOperator fStroking;
|
|
|
|
SkPdfColorOperator fNonStroking;
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
double fLineWidth;
|
|
|
|
double fTextLeading;
|
|
|
|
double fWordSpace;
|
|
|
|
double fCharSpace;
|
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
SkPdfResourceDictionary* fResources;
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
SkBitmap fSMask;
|
|
|
|
|
2013-07-02 22:42:53 +00:00
|
|
|
SkPdfGraphicsState() {
|
2013-06-25 20:45:40 +00:00
|
|
|
fCurPosX = 0.0;
|
|
|
|
fCurPosY = 0.0;
|
|
|
|
fCurFontSize = 0.0;
|
|
|
|
fTextBlock = false;
|
|
|
|
fMatrix = SkMatrix::I();
|
|
|
|
fMatrixTm = SkMatrix::I();
|
|
|
|
fMatrixTlm = SkMatrix::I();
|
|
|
|
fPathClosed = true;
|
|
|
|
fLineWidth = 0;
|
|
|
|
fTextLeading = 0;
|
|
|
|
fWordSpace = 0;
|
|
|
|
fCharSpace = 0;
|
|
|
|
fHasClipPathToApply = false;
|
|
|
|
fResources = NULL;
|
|
|
|
fSkFont = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyGraphicsState(SkPaint* paint, bool stroking) {
|
|
|
|
if (stroking) {
|
|
|
|
fStroking.applyGraphicsState(paint);
|
|
|
|
} else {
|
|
|
|
fNonStroking.applyGraphicsState(paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(edisonn): get this from pdfContext->options,
|
|
|
|
// or pdfContext->addPaintOptions(&paint);
|
|
|
|
paint->setAntiAlias(true);
|
|
|
|
|
|
|
|
// TODO(edisonn): dashing, miter, ...
|
|
|
|
paint->setStrokeWidth(SkDoubleToScalar(fLineWidth));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO(edisonn): better class design.
|
2013-07-02 22:42:53 +00:00
|
|
|
// TODO(edisonn): could we remove it?
|
|
|
|
// TODO(edisonn): rename to SkPdfInlineImage
|
|
|
|
struct SkPdfInlineImage {
|
2013-06-25 20:45:40 +00:00
|
|
|
std::map<std::string, std::string> fKeyValuePairs;
|
|
|
|
std::string fImageData;
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO(edisonn): better class design.
|
2013-07-02 22:42:53 +00:00
|
|
|
// TODO(edisonn): rename to SkPdfContext
|
2013-06-25 20:45:40 +00:00
|
|
|
struct PdfContext {
|
|
|
|
std::stack<SkPdfObject*> fObjectStack;
|
2013-07-02 22:42:53 +00:00
|
|
|
std::stack<SkPdfGraphicsState> fStateStack;
|
|
|
|
SkPdfGraphicsState fGraphicsState;
|
2013-07-10 17:09:50 +00:00
|
|
|
SkNativeParsedPDF* fPdfDoc;
|
2013-06-25 20:45:40 +00:00
|
|
|
SkMatrix fOriginalMatrix;
|
|
|
|
|
2013-07-02 22:42:53 +00:00
|
|
|
SkPdfInlineImage fInlineImage;
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
PdfContext(SkNativeParsedPDF* doc) : fPdfDoc(doc) {}
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-07-02 22:42:53 +00:00
|
|
|
// TODO(edisonn): temporary code, to report how much of the PDF we actually think we rendered.
|
|
|
|
// TODO(edisonn): rename to SkPdfResult
|
2013-06-25 20:45:40 +00:00
|
|
|
enum PdfResult {
|
|
|
|
kOK_PdfResult,
|
|
|
|
kPartial_PdfResult,
|
|
|
|
kNYI_PdfResult,
|
|
|
|
kIgnoreError_PdfResult,
|
|
|
|
kError_PdfResult,
|
|
|
|
kUnsupported_PdfResult,
|
|
|
|
|
|
|
|
kCount_PdfResult
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __DEFINED__SkPdfBasics
|