Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: experimental/PdfViewer/SkPdfRenderer.cpp

Issue 22678003: pdfviewer: remove save/restore used with q/Q operators (we already do there save and restore) (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 if (!skobj || !skobj->hasStream()) { 718 if (!skobj || !skobj->hasStream()) {
719 return kIgnoreError_PdfResult; 719 return kIgnoreError_PdfResult;
720 } 720 }
721 721
722 if (!skobj->has_BBox()) { 722 if (!skobj->has_BBox()) {
723 return kIgnoreError_PdfResult; 723 return kIgnoreError_PdfResult;
724 } 724 }
725 725
726 PdfOp_q(pdfContext, canvas, NULL); 726 PdfOp_q(pdfContext, canvas, NULL);
727 727
728 canvas->save();
729
730 728
731 if (skobj->Resources(pdfContext->fPdfDoc)) { 729 if (skobj->Resources(pdfContext->fPdfDoc)) {
732 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd fDoc); 730 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd fDoc);
733 } 731 }
734 732
735 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix"); 733 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix");
736 734
737 if (skobj->has_Matrix()) { 735 if (skobj->has_Matrix()) {
738 pdfContext->fGraphicsState.fCTM.preConcat(skobj->Matrix(pdfContext->fPdf Doc)); 736 pdfContext->fGraphicsState.fCTM.preConcat(skobj->Matrix(pdfContext->fPdf Doc));
739 SkMatrix matrix = pdfContext->fGraphicsState.fCTM; 737 SkMatrix matrix = pdfContext->fGraphicsState.fCTM;
(...skipping 30 matching lines...) Expand all
770 delete tokenizer; 768 delete tokenizer;
771 } 769 }
772 770
773 // TODO(edisonn): should we restore the variable stack at the same state? 771 // TODO(edisonn): should we restore the variable stack at the same state?
774 // There could be operands left, that could be consumed by a parent tokenize r when we pop. 772 // There could be operands left, that could be consumed by a parent tokenize r when we pop.
775 773
776 if (skobj->has_Group()) { 774 if (skobj->has_Group()) {
777 canvas->restore(); 775 canvas->restore();
778 } 776 }
779 777
780 canvas->restore();
781 PdfOp_Q(pdfContext, canvas, NULL); 778 PdfOp_Q(pdfContext, canvas, NULL);
782 return kPartial_PdfResult; 779 return kPartial_PdfResult;
783 } 780 }
784 781
785 782
786 // TODO(edisonn): Extract a class like ObjWithStream 783 // TODO(edisonn): Extract a class like ObjWithStream
787 static PdfResult doXObject_Pattern(PdfContext* pdfContext, SkCanvas* canvas, SkP dfType1PatternDictionary* skobj) { 784 static PdfResult doXObject_Pattern(PdfContext* pdfContext, SkCanvas* canvas, SkP dfType1PatternDictionary* skobj) {
788 if (!skobj || !skobj->hasStream()) { 785 if (!skobj || !skobj->hasStream()) {
789 return kIgnoreError_PdfResult; 786 return kIgnoreError_PdfResult;
790 } 787 }
791 788
792 if (!skobj->has_BBox()) { 789 if (!skobj->has_BBox()) {
793 return kIgnoreError_PdfResult; 790 return kIgnoreError_PdfResult;
794 } 791 }
795 792
796 PdfOp_q(pdfContext, canvas, NULL); 793 PdfOp_q(pdfContext, canvas, NULL);
797 794
798 canvas->save();
799
800 795
801 if (skobj->Resources(pdfContext->fPdfDoc)) { 796 if (skobj->Resources(pdfContext->fPdfDoc)) {
802 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd fDoc); 797 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd fDoc);
803 } 798 }
804 799
805 SkTraceMatrix(pdfContext->fGraphicsState.fContentStreamMatrix, "Current Cont ent stream matrix"); 800 SkTraceMatrix(pdfContext->fGraphicsState.fContentStreamMatrix, "Current Cont ent stream matrix");
806 801
807 if (skobj->has_Matrix()) { 802 if (skobj->has_Matrix()) {
808 pdfContext->fGraphicsState.fContentStreamMatrix.preConcat(skobj->Matrix( pdfContext->fPdfDoc)); 803 pdfContext->fGraphicsState.fContentStreamMatrix.preConcat(skobj->Matrix( pdfContext->fPdfDoc));
809 } 804 }
(...skipping 15 matching lines...) Expand all
825 pdfContext->fPdfDoc->tokenizerOfStream(stream, pdfContext->fTmpPageA llocator); 820 pdfContext->fPdfDoc->tokenizerOfStream(stream, pdfContext->fTmpPageA llocator);
826 if (tokenizer != NULL) { 821 if (tokenizer != NULL) {
827 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); 822 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas);
828 looper.loop(); 823 looper.loop();
829 delete tokenizer; 824 delete tokenizer;
830 } 825 }
831 826
832 // TODO(edisonn): should we restore the variable stack at the same state? 827 // TODO(edisonn): should we restore the variable stack at the same state?
833 // There could be operands left, that could be consumed by a parent tokenize r when we pop. 828 // There could be operands left, that could be consumed by a parent tokenize r when we pop.
834 829
835 canvas->restore();
836 PdfOp_Q(pdfContext, canvas, NULL); 830 PdfOp_Q(pdfContext, canvas, NULL);
837 return kPartial_PdfResult; 831 return kPartial_PdfResult;
838 } 832 }
839 833
840 834
841 //static PdfResult doXObject_PS(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObject* obj) { 835 //static PdfResult doXObject_PS(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObject* obj) {
842 // return kNYI_PdfResult; 836 // return kNYI_PdfResult;
843 //} 837 //}
844 838
845 PdfResult doType3Char(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObjec t* skobj, SkRect bBox, SkMatrix matrix, double textSize) { 839 PdfResult doType3Char(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObjec t* skobj, SkRect bBox, SkMatrix matrix, double textSize) {
846 if (!skobj || !skobj->hasStream()) { 840 if (!skobj || !skobj->hasStream()) {
847 return kIgnoreError_PdfResult; 841 return kIgnoreError_PdfResult;
848 } 842 }
849 843
850 PdfOp_q(pdfContext, canvas, NULL); 844 PdfOp_q(pdfContext, canvas, NULL);
851 canvas->save();
852 845
853 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); 846 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix);
854 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk DoubleToScalar(textSize)); 847 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk DoubleToScalar(textSize));
855 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrixTm ; 848 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrixTm ;
856 849
857 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm; 850 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm;
858 pdfContext->fGraphicsState.fCTM.preScale(SkDoubleToScalar(1), SkDoubleToScal ar(-1)); 851 pdfContext->fGraphicsState.fCTM.preScale(SkDoubleToScalar(1), SkDoubleToScal ar(-1));
859 852
860 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix"); 853 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix");
861 854
(...skipping 14 matching lines...) Expand all
876 SkPdfNativeTokenizer* tokenizer = 869 SkPdfNativeTokenizer* tokenizer =
877 pdfContext->fPdfDoc->tokenizerOfStream(stream, pdfContext->fTmpPageA llocator); 870 pdfContext->fPdfDoc->tokenizerOfStream(stream, pdfContext->fTmpPageA llocator);
878 if (tokenizer != NULL) { 871 if (tokenizer != NULL) {
879 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); 872 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas);
880 looper.loop(); 873 looper.loop();
881 delete tokenizer; 874 delete tokenizer;
882 } 875 }
883 876
884 // TODO(edisonn): should we restore the variable stack at the same state? 877 // TODO(edisonn): should we restore the variable stack at the same state?
885 // There could be operands left, that could be consumed by a parent tokenize r when we pop. 878 // There could be operands left, that could be consumed by a parent tokenize r when we pop.
886 canvas->restore();
887 PdfOp_Q(pdfContext, canvas, NULL); 879 PdfOp_Q(pdfContext, canvas, NULL);
888 880
889 return kPartial_PdfResult; 881 return kPartial_PdfResult;
890 } 882 }
891 883
892 884
893 // TODO(edisonn): make sure the pointer is unique 885 // TODO(edisonn): make sure the pointer is unique
894 std::set<const SkPdfObject*> gInRendering; 886 std::set<const SkPdfObject*> gInRendering;
895 887
896 class CheckRecursiveRendering { 888 class CheckRecursiveRendering {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 1269
1278 canvas->drawPath(path, paint); 1270 canvas->drawPath(path, paint);
1279 } else { 1271 } else {
1280 if (fill) { 1272 if (fill) {
1281 if (strncmp((char*)pdfContext->fGraphicsState.fNonStroking.fColorSpa ce.fBuffer, "Pattern", strlen("Pattern")) == 0 && 1273 if (strncmp((char*)pdfContext->fGraphicsState.fNonStroking.fColorSpa ce.fBuffer, "Pattern", strlen("Pattern")) == 0 &&
1282 pdfContext->fGraphicsState.fNonStroking.fPattern != NULL) { 1274 pdfContext->fGraphicsState.fNonStroking.fPattern != NULL) {
1283 1275
1284 // TODO(edisonn): we can use a shader here, like imageshader to draw fast. ultimately, 1276 // TODO(edisonn): we can use a shader here, like imageshader to draw fast. ultimately,
1285 // if this is not possible, and we are in rasper mode, and the c ells don't intersect, we could even have multiple cpus. 1277 // if this is not possible, and we are in rasper mode, and the c ells don't intersect, we could even have multiple cpus.
1286 1278
1287 canvas->save();
1288 PdfOp_q(pdfContext, canvas, NULL); 1279 PdfOp_q(pdfContext, canvas, NULL);
1289 1280
1290 if (evenOdd) { 1281 if (evenOdd) {
1291 path.setFillType(SkPath::kEvenOdd_FillType); 1282 path.setFillType(SkPath::kEvenOdd_FillType);
1292 } 1283 }
1293 canvas->clipPath(path); 1284 canvas->clipPath(path);
1294 1285
1295 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(pdf Context->fGraphicsState.fNonStroking.fPattern) != kNone_SkPdfObjectType) { 1286 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(pdf Context->fGraphicsState.fNonStroking.fPattern) != kNone_SkPdfObjectType) {
1296 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDic tionary*)pdfContext->fGraphicsState.fNonStroking.fPattern; 1287 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDic tionary*)pdfContext->fGraphicsState.fNonStroking.fPattern;
1297 1288
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 y += SkIntToScalar(yStep); 1324 y += SkIntToScalar(yStep);
1334 } 1325 }
1335 pdfContext->fGraphicsState.fContentStreamMatrix.preTrans late(SkIntToScalar(0), SkIntToScalar(totaly)); 1326 pdfContext->fGraphicsState.fContentStreamMatrix.preTrans late(SkIntToScalar(0), SkIntToScalar(totaly));
1336 } 1327 }
1337 } 1328 }
1338 1329
1339 // apply matrix 1330 // apply matrix
1340 // get xstep, y step, bbox ... for cliping, and bos of the path 1331 // get xstep, y step, bbox ... for cliping, and bos of the path
1341 1332
1342 PdfOp_Q(pdfContext, canvas, NULL); 1333 PdfOp_Q(pdfContext, canvas, NULL);
1343 canvas->restore();
1344 } else { 1334 } else {
1345 paint.setStyle(SkPaint::kFill_Style); 1335 paint.setStyle(SkPaint::kFill_Style);
1346 if (evenOdd) { 1336 if (evenOdd) {
1347 path.setFillType(SkPath::kEvenOdd_FillType); 1337 path.setFillType(SkPath::kEvenOdd_FillType);
1348 } 1338 }
1349 1339
1350 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); 1340 pdfContext->fGraphicsState.applyGraphicsState(&paint, false);
1351 1341
1352 canvas->drawPath(path, paint); 1342 canvas->drawPath(path, paint);
1353 } 1343 }
(...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 2653
2664 rect = SkRect::MakeWH(width, height); 2654 rect = SkRect::MakeWH(width, height);
2665 2655
2666 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght)); 2656 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght));
2667 2657
2668 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); 2658 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output)));
2669 SkCanvas canvas(device); 2659 SkCanvas canvas(device);
2670 2660
2671 return renderer.renderPage(page, &canvas, rect); 2661 return renderer.renderPage(page, &canvas, rect);
2672 } 2662 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698