blob: 3e7f7a8d4e05669acaea1e82ec9e07bb3534c39d [file] [log] [blame]
edisonn@google.com3aa35552013-08-14 18:26:20 +00001#include "SkPdfGraphicsState.h"
edisonn@google.com2ccc3af2013-07-23 17:43:18 +00002#include "SkPdfNativeTokenizer.h"
3
edisonn@google.coma0cefa12013-07-28 18:34:14 +00004#include "SkDashPathEffect.h"
5
edisonn@google.com3aa35552013-08-14 18:26:20 +00006SkPdfContext::SkPdfContext(SkPdfNativeDoc* doc)
edisonn@google.com2ccc3af2013-07-23 17:43:18 +00007 : fPdfDoc(doc)
8 , fTmpPageAllocator(new SkPdfAllocator()) {
9}
10
edisonn@google.com3aa35552013-08-14 18:26:20 +000011SkPdfContext::~SkPdfContext() {
edisonn@google.com2ccc3af2013-07-23 17:43:18 +000012 delete fTmpPageAllocator;
13}
edisonn@google.coma0cefa12013-07-28 18:34:14 +000014
15void SkPdfGraphicsState::applyGraphicsState(SkPaint* paint, bool stroking) {
16 if (stroking) {
17 fStroking.applyGraphicsState(paint);
18 } else {
19 fNonStroking.applyGraphicsState(paint);
20 }
21
22 // TODO(edisonn): get this from pdfContext->options,
23 // or pdfContext->addPaintOptions(&paint);
24 paint->setAntiAlias(true);
25
26 // TODO(edisonn): miter, ...
27 if (stroking) {
28 paint->setStrokeWidth(SkDoubleToScalar(fLineWidth));
29 // TODO(edisonn): perf, two sets of allocs, create SkDashPathEffect constr that takes ownership
30 // of the intervals
edisonn@google.comf111a4b2013-07-31 18:22:36 +000031 if (fDashArrayLength > 0) {
edisonn@google.coma0cefa12013-07-28 18:34:14 +000032 paint->setPathEffect(new SkDashPathEffect(fDashArray, fDashArrayLength, fDashPhase))->unref();
33 }
34 }
edisonn@google.comf111a4b2013-07-31 18:22:36 +000035
36 // TODO(edisonn): NYI multiple blend modes
37 if (fBlendModesLength == 1 && fBlendModes[0] != SkXfermode::kSrc_Mode) {
38 paint->setXfermodeMode(fBlendModes[0]);
39 }
edisonn@google.com9a43c182013-08-01 20:06:42 +000040
41 //paint->setStrokeMiter(SkDoubleToScalar(fMiterLimit));
42 // TODO(edisonn): impl cap and join
edisonn@google.coma0cefa12013-07-28 18:34:14 +000043}