OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 return doXObject_Image(pdfContext, canvas, (SkPdfImageDictionary*)ob
j); | 777 return doXObject_Image(pdfContext, canvas, (SkPdfImageDictionary*)ob
j); |
778 case kType1FormDictionary_SkPdfObjectType: | 778 case kType1FormDictionary_SkPdfObjectType: |
779 return doXObject_Form(pdfContext, canvas, (SkPdfType1FormDictionary*
)obj); | 779 return doXObject_Form(pdfContext, canvas, (SkPdfType1FormDictionary*
)obj); |
780 //case kObjectDictionaryXObjectPS_SkPdfObjectType: | 780 //case kObjectDictionaryXObjectPS_SkPdfObjectType: |
781 //return doXObject_PS(skxobj.asPS()); | 781 //return doXObject_PS(skxobj.asPS()); |
782 default: | 782 default: |
783 return kIgnoreError_PdfResult; | 783 return kIgnoreError_PdfResult; |
784 } | 784 } |
785 } | 785 } |
786 | 786 |
| 787 static PdfResult doPage(PdfContext* pdfContext, SkCanvas* canvas, SkPdfPageObjec
tDictionary* skobj) { |
| 788 if (!skobj) { |
| 789 return kIgnoreError_PdfResult; |
| 790 } |
| 791 |
| 792 if (!skobj->isContentsAStream(pdfContext->fPdfDoc)) { |
| 793 return kNYI_PdfResult; |
| 794 } |
| 795 |
| 796 SkPdfStream* stream = skobj->getContentsAsStream(pdfContext->fPdfDoc); |
| 797 |
| 798 if (!stream) { |
| 799 return kIgnoreError_PdfResult; |
| 800 } |
| 801 |
| 802 if (CheckRecursiveRendering::IsInRendering(skobj)) { |
| 803 // Oops, corrupt PDF! |
| 804 return kIgnoreError_PdfResult; |
| 805 } |
| 806 CheckRecursiveRendering checkRecursion(skobj); |
| 807 |
| 808 |
| 809 PdfOp_q(pdfContext, canvas, NULL); |
| 810 |
| 811 canvas->save(); |
| 812 |
| 813 if (skobj->Resources(pdfContext->fPdfDoc)) { |
| 814 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); |
| 815 } |
| 816 |
| 817 // TODO(edisonn): refactor common path with doXObject() |
| 818 // This is a group? |
| 819 if (skobj->has_Group()) { |
| 820 //TransparencyGroupDictionary* ... |
| 821 } |
| 822 |
| 823 SkPdfNativeTokenizer* tokenizer = |
| 824 pdfContext->fPdfDoc->tokenizerOfStream(stream, pdfContext->fTmpPageA
llocator); |
| 825 if (tokenizer != NULL) { |
| 826 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); |
| 827 looper.loop(); |
| 828 delete tokenizer; |
| 829 } |
| 830 |
| 831 // TODO(edisonn): should we restore the variable stack at the same state? |
| 832 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. |
| 833 canvas->restore(); |
| 834 PdfOp_Q(pdfContext, canvas, NULL); |
| 835 return kPartial_PdfResult; |
| 836 } |
| 837 |
787 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { | 838 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { |
788 pdfContext->fStateStack.push(pdfContext->fGraphicsState); | 839 pdfContext->fStateStack.push(pdfContext->fGraphicsState); |
789 canvas->save(); | 840 canvas->save(); |
790 return kOK_PdfResult; | 841 return kOK_PdfResult; |
791 } | 842 } |
792 | 843 |
793 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { | 844 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { |
794 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); | 845 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); |
795 pdfContext->fStateStack.pop(); | 846 pdfContext->fStateStack.pop(); |
796 canvas->restore(); | 847 canvas->restore(); |
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2178 if (!fPdfDoc) { | 2229 if (!fPdfDoc) { |
2179 return false; | 2230 return false; |
2180 } | 2231 } |
2181 | 2232 |
2182 if (page < 0 || page >= pages()) { | 2233 if (page < 0 || page >= pages()) { |
2183 return false; | 2234 return false; |
2184 } | 2235 } |
2185 | 2236 |
2186 PdfContext pdfContext(fPdfDoc); | 2237 PdfContext pdfContext(fPdfDoc); |
2187 | 2238 |
2188 SkPdfNativeTokenizer* tokenizer = fPdfDoc->tokenizerOfPage(page, pdfContext.
fTmpPageAllocator); | |
2189 if (!tokenizer) { | |
2190 // TODO(edisonn): report/warning/debug | |
2191 return false; | |
2192 } | |
2193 | |
2194 pdfContext.fOriginalMatrix = SkMatrix::I(); | 2239 pdfContext.fOriginalMatrix = SkMatrix::I(); |
2195 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page); | 2240 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page); |
2196 | 2241 |
2197 gPdfContext = &pdfContext; | 2242 gPdfContext = &pdfContext; |
2198 | 2243 |
2199 // TODO(edisonn): get matrix stuff right. | 2244 // TODO(edisonn): get matrix stuff right. |
2200 SkScalar z = SkIntToScalar(0); | 2245 SkScalar z = SkIntToScalar(0); |
2201 SkScalar w = dst.width(); | 2246 SkScalar w = dst.width(); |
2202 SkScalar h = dst.height(); | 2247 SkScalar h = dst.height(); |
2203 | 2248 |
(...skipping 29 matching lines...) Expand all Loading... |
2233 pdfContext.fGraphicsState.fCTM = pdfContext.fOriginalMatrix; | 2278 pdfContext.fGraphicsState.fCTM = pdfContext.fOriginalMatrix; |
2234 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState.fCTM; | 2279 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState.fCTM; |
2235 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState.fCTM; | 2280 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState.fCTM; |
2236 | 2281 |
2237 #ifndef PDF_DEBUG_NO_PAGE_CLIPING | 2282 #ifndef PDF_DEBUG_NO_PAGE_CLIPING |
2238 canvas->clipRect(dst, SkRegion::kIntersect_Op, true); | 2283 canvas->clipRect(dst, SkRegion::kIntersect_Op, true); |
2239 #endif | 2284 #endif |
2240 | 2285 |
2241 canvas->setMatrix(pdfContext.fOriginalMatrix); | 2286 canvas->setMatrix(pdfContext.fOriginalMatrix); |
2242 | 2287 |
2243 // erase with red before? | 2288 doPage(&pdfContext, canvas, fPdfDoc->page(page)); |
| 2289 |
| 2290 // TODO(edisonn:) erase with white before draw? |
2244 // SkPaint paint; | 2291 // SkPaint paint; |
2245 // paint.setColor(SK_ColorRED); | 2292 // paint.setColor(SK_ColorWHITE); |
2246 // canvas->drawRect(rect, paint); | 2293 // canvas->drawRect(rect, paint); |
2247 | 2294 |
2248 PdfMainLooper looper(NULL, tokenizer, &pdfContext, canvas); | |
2249 looper.loop(); | |
2250 | |
2251 delete tokenizer; | |
2252 | 2295 |
2253 canvas->flush(); | 2296 canvas->flush(); |
2254 return true; | 2297 return true; |
2255 } | 2298 } |
2256 | 2299 |
2257 bool SkPdfRenderer::load(const SkString inputFileName) { | 2300 bool SkPdfRenderer::load(const SkString inputFileName) { |
2258 unload(); | 2301 unload(); |
2259 | 2302 |
2260 // TODO(edisonn): create static function that could return NULL if there are
errors | 2303 // TODO(edisonn): create static function that could return NULL if there are
errors |
2261 fPdfDoc = new SkNativeParsedPDF(inputFileName.c_str()); | 2304 fPdfDoc = new SkNativeParsedPDF(inputFileName.c_str()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2318 | 2361 |
2319 rect = SkRect::MakeWH(width, height); | 2362 rect = SkRect::MakeWH(width, height); |
2320 | 2363 |
2321 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 2364 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
2322 | 2365 |
2323 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); | 2366 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); |
2324 SkCanvas canvas(device); | 2367 SkCanvas canvas(device); |
2325 | 2368 |
2326 return renderer.renderPage(page, &canvas, rect); | 2369 return renderer.renderPage(page, &canvas, rect); |
2327 } | 2370 } |
OLD | NEW |