blob: 9f3917b6ce9817ef6a4b95cc04ceb7ef5f1a506b [file] [log] [blame]
edisonn@google.comcf2cfa12013-08-21 16:31:37 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
edisonn@google.com3aa35552013-08-14 18:26:20 +00008#include "SkPdfGraphicsState.h"
edisonn@google.com2ccc3af2013-07-23 17:43:18 +00009
edisonn@google.coma0cefa12013-07-28 18:34:14 +000010#include "SkDashPathEffect.h"
edisonn@google.come50d9a12013-10-10 20:58:22 +000011#include "SkPdfNativeTokenizer.h"
edisonn@google.coma0cefa12013-07-28 18:34:14 +000012
edisonn@google.com3aa35552013-08-14 18:26:20 +000013SkPdfContext::SkPdfContext(SkPdfNativeDoc* doc)
edisonn@google.com2ccc3af2013-07-23 17:43:18 +000014 : fPdfDoc(doc)
15 , fTmpPageAllocator(new SkPdfAllocator()) {
16}
17
edisonn@google.com3aa35552013-08-14 18:26:20 +000018SkPdfContext::~SkPdfContext() {
edisonn@google.com2ccc3af2013-07-23 17:43:18 +000019 delete fTmpPageAllocator;
20}
edisonn@google.coma0cefa12013-07-28 18:34:14 +000021
22void SkPdfGraphicsState::applyGraphicsState(SkPaint* paint, bool stroking) {
23 if (stroking) {
24 fStroking.applyGraphicsState(paint);
25 } else {
26 fNonStroking.applyGraphicsState(paint);
27 }
28
edisonn@google.come50d9a12013-10-10 20:58:22 +000029 // TODO(edisonn): Perf, we should load this option from pdfContext->options,
edisonn@google.coma0cefa12013-07-28 18:34:14 +000030 // or pdfContext->addPaintOptions(&paint);
31 paint->setAntiAlias(true);
32
33 // TODO(edisonn): miter, ...
34 if (stroking) {
35 paint->setStrokeWidth(SkDoubleToScalar(fLineWidth));
edisonn@google.come50d9a12013-10-10 20:58:22 +000036 // TODO(edisonn): perf, avoid allocs allocs
edisonn@google.coma0cefa12013-07-28 18:34:14 +000037 // of the intervals
edisonn@google.comf111a4b2013-07-31 18:22:36 +000038 if (fDashArrayLength > 0) {
edisonn@google.come50d9a12013-10-10 20:58:22 +000039 paint->setPathEffect(new SkDashPathEffect(fDashArray,
40 fDashArrayLength,
41 fDashPhase))->unref();
edisonn@google.coma0cefa12013-07-28 18:34:14 +000042 }
43 }
edisonn@google.comf111a4b2013-07-31 18:22:36 +000044
45 // TODO(edisonn): NYI multiple blend modes
46 if (fBlendModesLength == 1 && fBlendModes[0] != SkXfermode::kSrc_Mode) {
47 paint->setXfermodeMode(fBlendModes[0]);
48 }
edisonn@google.com9a43c182013-08-01 20:06:42 +000049
50 //paint->setStrokeMiter(SkDoubleToScalar(fMiterLimit));
51 // TODO(edisonn): impl cap and join
edisonn@google.coma0cefa12013-07-28 18:34:14 +000052}