edisonn@google.com | cf2cfa1 | 2013-08-21 16:31:37 +0000 | [diff] [blame^] | 1 | /* |
| 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.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 8 | #include "SkPdfGraphicsState.h" |
edisonn@google.com | 2ccc3af | 2013-07-23 17:43:18 +0000 | [diff] [blame] | 9 | #include "SkPdfNativeTokenizer.h" |
| 10 | |
edisonn@google.com | a0cefa1 | 2013-07-28 18:34:14 +0000 | [diff] [blame] | 11 | #include "SkDashPathEffect.h" |
| 12 | |
edisonn@google.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 13 | SkPdfContext::SkPdfContext(SkPdfNativeDoc* doc) |
edisonn@google.com | 2ccc3af | 2013-07-23 17:43:18 +0000 | [diff] [blame] | 14 | : fPdfDoc(doc) |
| 15 | , fTmpPageAllocator(new SkPdfAllocator()) { |
| 16 | } |
| 17 | |
edisonn@google.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 18 | SkPdfContext::~SkPdfContext() { |
edisonn@google.com | 2ccc3af | 2013-07-23 17:43:18 +0000 | [diff] [blame] | 19 | delete fTmpPageAllocator; |
| 20 | } |
edisonn@google.com | a0cefa1 | 2013-07-28 18:34:14 +0000 | [diff] [blame] | 21 | |
| 22 | void SkPdfGraphicsState::applyGraphicsState(SkPaint* paint, bool stroking) { |
| 23 | if (stroking) { |
| 24 | fStroking.applyGraphicsState(paint); |
| 25 | } else { |
| 26 | fNonStroking.applyGraphicsState(paint); |
| 27 | } |
| 28 | |
| 29 | // TODO(edisonn): get this from pdfContext->options, |
| 30 | // or pdfContext->addPaintOptions(&paint); |
| 31 | paint->setAntiAlias(true); |
| 32 | |
| 33 | // TODO(edisonn): miter, ... |
| 34 | if (stroking) { |
| 35 | paint->setStrokeWidth(SkDoubleToScalar(fLineWidth)); |
| 36 | // TODO(edisonn): perf, two sets of allocs, create SkDashPathEffect constr that takes ownership |
| 37 | // of the intervals |
edisonn@google.com | f111a4b | 2013-07-31 18:22:36 +0000 | [diff] [blame] | 38 | if (fDashArrayLength > 0) { |
edisonn@google.com | a0cefa1 | 2013-07-28 18:34:14 +0000 | [diff] [blame] | 39 | paint->setPathEffect(new SkDashPathEffect(fDashArray, fDashArrayLength, fDashPhase))->unref(); |
| 40 | } |
| 41 | } |
edisonn@google.com | f111a4b | 2013-07-31 18:22:36 +0000 | [diff] [blame] | 42 | |
| 43 | // TODO(edisonn): NYI multiple blend modes |
| 44 | if (fBlendModesLength == 1 && fBlendModes[0] != SkXfermode::kSrc_Mode) { |
| 45 | paint->setXfermodeMode(fBlendModes[0]); |
| 46 | } |
edisonn@google.com | 9a43c18 | 2013-08-01 20:06:42 +0000 | [diff] [blame] | 47 | |
| 48 | //paint->setStrokeMiter(SkDoubleToScalar(fMiterLimit)); |
| 49 | // TODO(edisonn): impl cap and join |
edisonn@google.com | a0cefa1 | 2013-07-28 18:34:14 +0000 | [diff] [blame] | 50 | } |