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

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

Issue 20810002: pdfviewer: (draft, not to be checked in, just for backup online) gs implementation (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
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 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 591
592 static PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, SkPdf ImageDictionary* skpdfimage) { 592 static PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, SkPdf ImageDictionary* skpdfimage) {
593 if (skpdfimage == NULL) { 593 if (skpdfimage == NULL) {
594 return kIgnoreError_PdfResult; 594 return kIgnoreError_PdfResult;
595 } 595 }
596 596
597 SkBitmap image = getImageFromObject(pdfContext, skpdfimage, false); 597 SkBitmap image = getImageFromObject(pdfContext, skpdfimage, false);
598 SkBitmap sMask = getSmaskFromObject(pdfContext, skpdfimage); 598 SkBitmap sMask = getSmaskFromObject(pdfContext, skpdfimage);
599 599
600 canvas->save(); 600 canvas->save();
601 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); 601 canvas->setMatrix(pdfContext->fGraphicsState.fCTM);
602 602
603 #if 1 603 #if 1
604 SkScalar z = SkIntToScalar(0); 604 SkScalar z = SkIntToScalar(0);
605 SkScalar one = SkIntToScalar(1); 605 SkScalar one = SkIntToScalar(1);
606 606
607 SkPoint from[4] = {SkPoint::Make(z, z), SkPoint::Make(one, z), SkPoint::Make (one, one), SkPoint::Make(z, one)}; 607 SkPoint from[4] = {SkPoint::Make(z, z), SkPoint::Make(one, z), SkPoint::Make (one, one), SkPoint::Make(z, one)};
608 SkPoint to[4] = {SkPoint::Make(z, one), SkPoint::Make(one, one), SkPoint::Ma ke(one, z), SkPoint::Make(z, z)}; 608 SkPoint to[4] = {SkPoint::Make(z, one), SkPoint::Make(one, one), SkPoint::Ma ke(one, z), SkPoint::Make(z, z)};
609 SkMatrix flip; 609 SkMatrix flip;
610 SkAssertResult(flip.setPolyToPoly(from, to, 4)); 610 SkAssertResult(flip.setPolyToPoly(from, to, 4));
611 SkMatrix solveImageFlip = pdfContext->fGraphicsState.fMatrix; 611 SkMatrix solveImageFlip = pdfContext->fGraphicsState.fCTM;
612 solveImageFlip.preConcat(flip); 612 solveImageFlip.preConcat(flip);
613 canvas->setMatrix(solveImageFlip); 613 canvas->setMatrix(solveImageFlip);
614 #endif 614 #endif
615 615
616 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0), SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); 616 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0), SkDoubleToScalar(1.0), SkDoubleToScalar(1.0));
617 617
618 if (sMask.empty()) { 618 if (sMask.empty()) {
619 canvas->drawBitmapRect(image, dst, NULL); 619 canvas->drawBitmapRect(image, dst, NULL);
620 } else { 620 } else {
621 canvas->saveLayer(&dst, NULL); 621 canvas->saveLayer(&dst, NULL);
(...skipping 19 matching lines...) Expand all
641 } 641 }
642 642
643 PdfOp_q(pdfContext, canvas, NULL); 643 PdfOp_q(pdfContext, canvas, NULL);
644 canvas->save(); 644 canvas->save();
645 645
646 646
647 if (skobj->Resources(pdfContext->fPdfDoc)) { 647 if (skobj->Resources(pdfContext->fPdfDoc)) {
648 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd fDoc); 648 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd fDoc);
649 } 649 }
650 650
651 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Current matrix"); 651 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix");
652 652
653 if (skobj->has_Matrix()) { 653 if (skobj->has_Matrix()) {
654 pdfContext->fGraphicsState.fMatrix.preConcat(skobj->Matrix(pdfContext->f PdfDoc)); 654 pdfContext->fGraphicsState.fCTM.preConcat(skobj->Matrix(pdfContext->fPdf Doc));
655 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fMatri x; 655 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fCTM;
656 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatr ix; 656 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM;
657 // TODO(edisonn) reset matrixTm and matricTlm also? 657 // TODO(edisonn) reset matrixTm and matricTlm also?
658 } 658 }
659 659
660 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Total matrix"); 660 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix");
661 661
662 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); 662 canvas->setMatrix(pdfContext->fGraphicsState.fCTM);
663 663
664 if (skobj->has_BBox()) { 664 if (skobj->has_BBox()) {
665 canvas->clipRect(skobj->BBox(pdfContext->fPdfDoc), SkRegion::kIntersect_ Op, true); // TODO(edisonn): AA from settings. 665 canvas->clipRect(skobj->BBox(pdfContext->fPdfDoc), SkRegion::kIntersect_ Op, true); // TODO(edisonn): AA from settings.
666 } 666 }
667 667
668 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go. 668 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go.
669 // For this PdfContentsTokenizer needs to be extended. 669 // For this PdfContentsTokenizer needs to be extended.
670 670
671 SkPdfStream* stream = (SkPdfStream*)skobj; 671 SkPdfStream* stream = (SkPdfStream*)skobj;
672 672
(...skipping 20 matching lines...) Expand all
693 if (!skobj || !skobj->hasStream()) { 693 if (!skobj || !skobj->hasStream()) {
694 return kIgnoreError_PdfResult; 694 return kIgnoreError_PdfResult;
695 } 695 }
696 696
697 PdfOp_q(pdfContext, canvas, NULL); 697 PdfOp_q(pdfContext, canvas, NULL);
698 canvas->save(); 698 canvas->save();
699 699
700 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); 700 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix);
701 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk DoubleToScalar(textSize)); 701 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk DoubleToScalar(textSize));
702 702
703 pdfContext->fGraphicsState.fMatrix = pdfContext->fGraphicsState.fMatrixTm; 703 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm;
704 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrix; 704 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM;
705 705
706 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Total matrix"); 706 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix");
707 707
708 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); 708 canvas->setMatrix(pdfContext->fGraphicsState.fCTM);
709 709
710 SkRect rm = bBox; 710 SkRect rm = bBox;
711 pdfContext->fGraphicsState.fMatrix.mapRect(&rm); 711 pdfContext->fGraphicsState.fCTM.mapRect(&rm);
712 712
713 SkTraceRect(rm, "bbox mapped"); 713 SkTraceRect(rm, "bbox mapped");
714 714
715 canvas->clipRect(bBox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA from settings. 715 canvas->clipRect(bBox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA from settings.
716 716
717 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go. 717 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go.
718 // For this PdfContentsTokenizer needs to be extended. 718 // For this PdfContentsTokenizer needs to be extended.
719 719
720 SkPdfStream* stream = (SkPdfStream*)skobj; 720 SkPdfStream* stream = (SkPdfStream*)skobj;
721 721
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 803
804 // 0 1 804 // 0 1
805 // 2 3 805 // 2 3
806 // 4 5 806 // 4 5
807 807
808 // sx ky 808 // sx ky
809 // kx sy 809 // kx sy
810 // tx ty 810 // tx ty
811 SkMatrix matrix = SkMatrixFromPdfMatrix(array); 811 SkMatrix matrix = SkMatrixFromPdfMatrix(array);
812 812
813 pdfContext->fGraphicsState.fMatrix.preConcat(matrix); 813 pdfContext->fGraphicsState.fCTM.preConcat(matrix);
814 814
815 #ifdef PDF_TRACE 815 #ifdef PDF_TRACE
816 printf("cm "); 816 printf("cm ");
817 for (int i = 0 ; i < 6 ; i++) { 817 for (int i = 0 ; i < 6 ; i++) {
818 printf("%f ", array[i]); 818 printf("%f ", array[i]);
819 } 819 }
820 printf("\n"); 820 printf("\n");
821 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "cm"); 821 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "cm");
822 #endif 822 #endif
823 823
824 return kOK_PdfResult; 824 return kOK_PdfResult;
825 } 825 }
826 826
827 //leading TL Set the text leading, Tl 827 //leading TL Set the text leading, Tl
828 //, to leading, which is a number expressed in unscaled text 828 //, to leading, which is a number expressed in unscaled text
829 //space units. Text leading is used only by the T*, ', and " operators. Initial value: 0. 829 //space units. Text leading is used only by the T*, ', and " operators. Initial value: 0.
830 static PdfResult PdfOp_TL(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 830 static PdfResult PdfOp_TL(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
831 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fOb jectStack.pop(); 831 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fOb jectStack.pop();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 882
883 double array[6]; 883 double array[6];
884 array[0] = a; 884 array[0] = a;
885 array[1] = b; 885 array[1] = b;
886 array[2] = c; 886 array[2] = c;
887 array[3] = d; 887 array[3] = d;
888 array[4] = e; 888 array[4] = e;
889 array[5] = f; 889 array[5] = f;
890 890
891 SkMatrix matrix = SkMatrixFromPdfMatrix(array); 891 SkMatrix matrix = SkMatrixFromPdfMatrix(array);
892 matrix.postConcat(pdfContext->fGraphicsState.fMatrix); 892 matrix.postConcat(pdfContext->fGraphicsState.fCTM);
893 893
894 // TODO(edisonn): Text positioning. 894 // TODO(edisonn): Text positioning.
895 pdfContext->fGraphicsState.fMatrixTm = matrix; 895 pdfContext->fGraphicsState.fMatrixTm = matrix;
896 pdfContext->fGraphicsState.fMatrixTlm = matrix;; 896 pdfContext->fGraphicsState.fMatrixTlm = matrix;;
897 897
898 return kPartial_PdfResult; 898 return kPartial_PdfResult;
899 } 899 }
900 900
901 //— T* Move to the start of the next line. This operator has the same effect as the code 901 //— T* Move to the start of the next line. This operator has the same effect as the code
902 //0 Tl Td 902 //0 Tl Td
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 return kOK_PdfResult; 1037 return kOK_PdfResult;
1038 } 1038 }
1039 1039
1040 static PdfResult PdfOp_fillAndStroke(PdfContext* pdfContext, SkCanvas* canvas, b ool fill, bool stroke, bool close, bool evenOdd) { 1040 static PdfResult PdfOp_fillAndStroke(PdfContext* pdfContext, SkCanvas* canvas, b ool fill, bool stroke, bool close, bool evenOdd) {
1041 SkPath path = pdfContext->fGraphicsState.fPath; 1041 SkPath path = pdfContext->fGraphicsState.fPath;
1042 1042
1043 if (close) { 1043 if (close) {
1044 path.close(); 1044 path.close();
1045 } 1045 }
1046 1046
1047 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); 1047 canvas->setMatrix(pdfContext->fGraphicsState.fCTM);
1048 1048
1049 SkPaint paint; 1049 SkPaint paint;
1050 1050
1051 SkPoint line[2]; 1051 SkPoint line[2];
1052 if (fill && !stroke && path.isLine(line)) { 1052 if (fill && !stroke && path.isLine(line)) {
1053 paint.setStyle(SkPaint::kStroke_Style); 1053 paint.setStyle(SkPaint::kStroke_Style);
1054 1054
1055 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); 1055 pdfContext->fGraphicsState.applyGraphicsState(&paint, false);
1056 paint.setStrokeWidth(SkDoubleToScalar(0)); 1056 paint.setStrokeWidth(SkDoubleToScalar(0));
1057 1057
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 1124
1125 static PdfResult PdfOp_b(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1125 static PdfResult PdfOp_b(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1126 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, true, false); 1126 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, true, false);
1127 } 1127 }
1128 1128
1129 static PdfResult PdfOp_b_star(PdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1129 static PdfResult PdfOp_b_star(PdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1130 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, true, true); 1130 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, true, true);
1131 } 1131 }
1132 1132
1133 static PdfResult PdfOp_n(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1133 static PdfResult PdfOp_n(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1134 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); 1134 canvas->setMatrix(pdfContext->fGraphicsState.fCTM);
1135 if (pdfContext->fGraphicsState.fHasClipPathToApply) { 1135 if (pdfContext->fGraphicsState.fHasClipPathToApply) {
1136 #ifndef PDF_DEBUG_NO_CLIPING 1136 #ifndef PDF_DEBUG_NO_CLIPING
1137 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters ect_Op, true); 1137 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters ect_Op, true);
1138 #endif 1138 #endif
1139 } 1139 }
1140 1140
1141 //pdfContext->fGraphicsState.fClipPath.reset(); 1141 //pdfContext->fGraphicsState.fClipPath.reset();
1142 pdfContext->fGraphicsState.fHasClipPathToApply = false; 1142 pdfContext->fGraphicsState.fHasClipPathToApply = false;
1143 1143
1144 pdfContext->fGraphicsState.fPathClosed = true; 1144 pdfContext->fGraphicsState.fPathClosed = true;
1145 1145
1146 return kOK_PdfResult; 1146 return kOK_PdfResult;
1147 } 1147 }
1148 1148
1149 static PdfResult PdfOp_BT(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1149 static PdfResult PdfOp_BT(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1150 pdfContext->fGraphicsState.fTextBlock = true; 1150 pdfContext->fGraphicsState.fTextBlock = true;
1151 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fMatrix; 1151 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fCTM;
1152 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrix; 1152 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM;
1153 1153
1154 return kPartial_PdfResult; 1154 return kPartial_PdfResult;
1155 } 1155 }
1156 1156
1157 static PdfResult PdfOp_ET(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1157 static PdfResult PdfOp_ET(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1158 if (!pdfContext->fGraphicsState.fTextBlock) { 1158 if (!pdfContext->fGraphicsState.fTextBlock) {
1159 return kIgnoreError_PdfResult; 1159 return kIgnoreError_PdfResult;
1160 } 1160 }
1161 // TODO(edisonn): anything else to be done once we are done with draw text? Like restore stack? 1161 // TODO(edisonn): anything else to be done once we are done with draw text? Like restore stack?
1162 return kPartial_PdfResult; 1162 return kPartial_PdfResult;
1163 } 1163 }
1164 1164
1165 //font size Tf Set the text font, Tf 1165 PdfResult skpdfGraphicsStateApplyFontCore(PdfContext* pdfContext, const SkPdfObj ect* fontName, double fontSize) {
1166 //, to font and the text font size, Tfs, to size. font is the name of a
1167 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is
1168 //a number representing a scale factor. There is no initial value for either fon t or
1169 //size; they must be specified explicitly using Tf before any text is shown.
1170 static PdfResult PdfOp_Tf(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1171 pdfContext->fGraphicsState.fCurFontSize = pdfContext->fObjectStack.top()->nu mberValue(); pdfContext->fObjectStack.pop();
1172 SkPdfObject* fontName = pdfContext->fObjectStack.top(); pdfContext->fObjectStack.pop();
1173
1174 #ifdef PDF_TRACE 1166 #ifdef PDF_TRACE
1175 printf("font name: %s\n", fontName->nameValue2().c_str()); 1167 printf("font name: %s\n", fontName->nameValue2().c_str());
1176 #endif 1168 #endif
1177 1169
1178 if (pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) { 1170 if (pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) {
1179 SkPdfObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdfCo ntext->fPdfDoc)->get(fontName); 1171 SkPdfObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdfCo ntext->fPdfDoc)->get(fontName);
1180 objFont = pdfContext->fPdfDoc->resolveReference(objFont); 1172 objFont = pdfContext->fPdfDoc->resolveReference(objFont);
1181 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapFontDicti onary(objFont)) { 1173 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapFontDicti onary(objFont)) {
1182 // TODO(edisonn): try to recover and draw it any way? 1174 // TODO(edisonn): try to recover and draw it any way?
1183 return kIgnoreError_PdfResult; 1175 return kIgnoreError_PdfResult;
1184 } 1176 }
1185 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont; 1177 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont;
1186 1178
1187 SkPdfFont* skfont = SkPdfFont::fontFromPdfDictionary(pdfContext->fPdfDoc , fd); 1179 SkPdfFont* skfont = SkPdfFont::fontFromPdfDictionary(pdfContext->fPdfDoc , fd);
1188 1180
1189 if (skfont) { 1181 if (skfont) {
1190 pdfContext->fGraphicsState.fSkFont = skfont; 1182 pdfContext->fGraphicsState.fSkFont = skfont;
1191 } 1183 }
1192 } 1184 }
1185 pdfContext->fGraphicsState.fCurFontSize = fontSize;
1193 return kIgnoreError_PdfResult; 1186 return kIgnoreError_PdfResult;
1194 } 1187 }
1195 1188
1189 //font size Tf Set the text font, Tf
1190 //, to font and the text font size, Tfs, to size. font is the name of a
1191 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is
1192 //a number representing a scale factor. There is no initial value for either fon t or
1193 //size; they must be specified explicitly using Tf before any text is shown.
1194 static PdfResult PdfOp_Tf(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1195 double fontSize = pdfContext->fObjectStack.top()->numberValue(); pdfCont ext->fObjectStack.pop();
1196 SkPdfObject* fontName = pdfContext->fObjectStack.top(); pdfContext->fObjectStack.pop();
1197 return skpdfGraphicsStateApplyFontCore(pdfContext, fontName, fontSize);
1198 }
1199
1196 static PdfResult PdfOp_Tj(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1200 static PdfResult PdfOp_Tj(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1197 if (!pdfContext->fGraphicsState.fTextBlock) { 1201 if (!pdfContext->fGraphicsState.fTextBlock) {
1198 // TODO(edisonn): try to recover and draw it any way? 1202 // TODO(edisonn): try to recover and draw it any way?
1199 return kIgnoreError_PdfResult; 1203 return kIgnoreError_PdfResult;
1200 } 1204 }
1201 1205
1202 PdfResult ret = DrawText(pdfContext, 1206 PdfResult ret = DrawText(pdfContext,
1203 pdfContext->fObjectStack.top(), 1207 pdfContext->fObjectStack.top(),
1204 canvas); 1208 canvas);
1205 pdfContext->fObjectStack.pop(); 1209 pdfContext->fObjectStack.pop();
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 1516
1513 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1, “Flatness 1517 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1, “Flatness
1514 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci- 1518 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci-
1515 //fies the output device’s default flatness tolerance. 1519 //fies the output device’s default flatness tolerance.
1516 static PdfResult PdfOp_i(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1520 static PdfResult PdfOp_i(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1517 pdfContext->fObjectStack.pop(); 1521 pdfContext->fObjectStack.pop();
1518 1522
1519 return kNYI_PdfResult; 1523 return kNYI_PdfResult;
1520 } 1524 }
1521 1525
1526
1527 // TODO(edisonn): security review here, make sure all parameters are valid, and safe.
1528 void skpdfGraphicsStateApply_ca(PdfContext* pdfContext, double ca) {
1529 pdfContext->fGraphicsState.fNonStroking.fOpacity = ca;
1530 }
1531
1532 void skpdfGraphicsStateApply_CA(PdfContext* pdfContext, double CA) {
1533 pdfContext->fGraphicsState.fStroking.fOpacity = CA;
1534 }
1535
1536 void skpdfGraphicsStateApplyLW(PdfContext* pdfContext, double lineWidth) {
1537 pdfContext->fGraphicsState.fLineWidth = lineWidth;
1538 }
1539
1540 void skpdfGraphicsStateApplyLC(PdfContext* pdfContext, int64_t lineCap) {
1541 pdfContext->fGraphicsState.fLineCap = (int)lineCap;
1542 }
1543
1544 void skpdfGraphicsStateApplyLJ(PdfContext* pdfContext, int64_t lineJoin) {
1545 pdfContext->fGraphicsState.fLineJoin = (int)lineJoin;
1546 }
1547
1548 void skpdfGraphicsStateApplyML(PdfContext* pdfContext, double miterLimit) {
1549 pdfContext->fGraphicsState.fMiterLimit = miterLimit;
1550 }
1551
1552 void skpdfGraphicsStateApplyD(PdfContext* pdfContext, SkPdfArray* dash) {
1553 // TODO(edisonn): verify input
1554 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)-> isArray() || !dash->objAtAIndex(1)->isNumber()) {
1555 // TODO(edisonn): report error/warning
1556 return;
1557 }
1558
1559 SkPdfArray* intervals = (SkPdfArray*)dash->objAtAIndex(0);
1560 int cnt = intervals->size();
1561 if (cnt >= 256) {
1562 // TODO(edisonn): report error/warning, unsuported;
1563 // TODO(edisonn): alloc memory
1564 return;
1565 }
1566 for (int i = 0; i < cnt; i++) {
1567 if (!intervals->objAtAIndex(i)->isNumber()) {
1568 // TODO(edisonn): report error/warning
1569 return;
1570 }
1571 }
1572
1573 pdfContext->fGraphicsState.fDashPhase = dash->objAtAIndex(1)->scalarValue();
1574 pdfContext->fGraphicsState.fDashArrayLength = cnt;
1575 for (int i = 0 ; i < cnt; i++) {
1576 pdfContext->fGraphicsState.fDashArray[i] = intervals->objAtAIndex(i)->sc alarValue();
1577 }
1578 }
1579
1580 void skpdfGraphicsStateApplyFont(PdfContext* pdfContext, SkPdfArray* fontAndSize ) {
1581 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber() ) {
1582 // TODO(edisonn): report error/warning
1583 return;
1584 }
1585 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon tAndSize->objAtAIndex(1)->numberValue());
1586 }
1587
1588 void skpdfGraphicsStateApplyBM_name(PdfContext* pdfContext, const std::string& b lendMode) {
1589 // TODO(edisonn): verify input
1590 }
1591
1592 void skpdfGraphicsStateApplyBM_array(PdfContext* pdfContext, SkPdfArray* blendMo des) {
1593 // TODO(edisonn): verify input
1594 }
1595
1596 void skpdfGraphicsStateApplySMask_name(PdfContext* pdfContext, const std::string & sMask) {
1597 // TODO(edisonn): verify input
1598 }
1599
1600 void skpdfGraphicsStateApplySMask_dict(PdfContext* pdfContext, SkPdfDictionary* sMask) {
1601 // TODO(edisonn): verify input
1602 }
1603
1604 void skpdfGraphicsStateApplyAIS(PdfContext* pdfContext, bool alphaSource) {
1605 pdfContext->fGraphicsState.fAlphaSource = alphaSource;
1606 }
1607
1608
1522 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is 1609 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is
1523 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section). 1610 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section).
1524 static PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1611 static PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1525 SkPdfObject* name = pdfContext->fObjectStack.top(); pdfContext->fObjectSt ack.pop(); 1612 SkPdfObject* name = pdfContext->fObjectStack.top(); pdfContext->fObjectSt ack.pop();
1526 1613
1527 #ifdef PDF_TRACE 1614 #ifdef PDF_TRACE
1528 std::string str; 1615 std::string str;
1529 #endif 1616 #endif
1530 1617
1531 //Next, get the ExtGState Dictionary from the Resource Dictionary: 1618 //Next, get the ExtGState Dictionary from the Resource Dictionary:
(...skipping 11 matching lines...) Expand all
1543 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapGraphicsState Dictionary(value)) { 1630 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapGraphicsState Dictionary(value)) {
1544 return kIgnoreError_PdfResult; 1631 return kIgnoreError_PdfResult;
1545 } 1632 }
1546 SkPdfGraphicsStateDictionary* gs = (SkPdfGraphicsStateDictionary*)value; 1633 SkPdfGraphicsStateDictionary* gs = (SkPdfGraphicsStateDictionary*)value;
1547 1634
1548 // TODO(edisonn): now load all those properties in graphic state. 1635 // TODO(edisonn): now load all those properties in graphic state.
1549 if (gs == NULL) { 1636 if (gs == NULL) {
1550 return kIgnoreError_PdfResult; 1637 return kIgnoreError_PdfResult;
1551 } 1638 }
1552 1639
1553 if (gs->has_CA()) { 1640 if (gs->has_LW()) {
1554 pdfContext->fGraphicsState.fStroking.fOpacity = gs->CA(pdfContext->fPdfD oc); 1641 skpdfGraphicsStateApplyLW(pdfContext, gs->LW(pdfContext->fPdfDoc));
1642 }
1643
1644 if (gs->has_LC()) {
1645 skpdfGraphicsStateApplyLC(pdfContext, gs->LC(pdfContext->fPdfDoc));
1646 }
1647
1648 if (gs->has_LJ()) {
1649 skpdfGraphicsStateApplyLJ(pdfContext, gs->LJ(pdfContext->fPdfDoc));
1650 }
1651
1652 if (gs->has_ML()) {
1653 skpdfGraphicsStateApplyML(pdfContext, gs->ML(pdfContext->fPdfDoc));
1654 }
1655
1656 if (gs->has_D()) {
1657 skpdfGraphicsStateApplyD(pdfContext, gs->D(pdfContext->fPdfDoc));
1658 }
1659
1660 if (gs->has_Font()) {
1661 skpdfGraphicsStateApplyFont(pdfContext, gs->Font(pdfContext->fPdfDoc));
1662 }
1663
1664 if (gs->has_BM()) {
1665 if (gs->isBMAName(pdfContext->fPdfDoc)) {
1666 skpdfGraphicsStateApplyBM_name(pdfContext, gs->getBMAsName(pdfContex t->fPdfDoc));
1667 } else if (gs->isBMAArray(pdfContext->fPdfDoc)) {
1668 skpdfGraphicsStateApplyBM_array(pdfContext, gs->getBMAsArray(pdfCont ext->fPdfDoc));
1669 } else {
1670 // TODO(edisonn): report/warn
1671 }
1672 }
1673
1674 if (gs->has_SMask()) {
1675 if (gs->isSMaskAName(pdfContext->fPdfDoc)) {
1676 skpdfGraphicsStateApplySMask_name(pdfContext, gs->getSMaskAsName(pdf Context->fPdfDoc));
1677 } else if (gs->isSMaskADictionary(pdfContext->fPdfDoc)) {
1678 skpdfGraphicsStateApplySMask_dict(pdfContext, gs->getSMaskAsDictiona ry(pdfContext->fPdfDoc));
1679 } else {
1680 // TODO(edisonn): report/warn
1681 }
1555 } 1682 }
1556 1683
1557 if (gs->has_ca()) { 1684 if (gs->has_ca()) {
1558 pdfContext->fGraphicsState.fNonStroking.fOpacity = gs->ca(pdfContext->fP dfDoc); 1685 skpdfGraphicsStateApply_ca(pdfContext, gs->ca(pdfContext->fPdfDoc));
1559 } 1686 }
1560 1687
1561 if (gs->has_LW()) { 1688 if (gs->has_CA()) {
1562 pdfContext->fGraphicsState.fLineWidth = gs->LW(pdfContext->fPdfDoc); 1689 skpdfGraphicsStateApply_CA(pdfContext, gs->CA(pdfContext->fPdfDoc));
1690 }
1691
1692 if (gs->has_AIS()) {
1693 skpdfGraphicsStateApplyAIS(pdfContext, gs->AIS(pdfContext->fPdfDoc));
1563 } 1694 }
1564 1695
1565 return kNYI_PdfResult; 1696 return kNYI_PdfResult;
1566 } 1697 }
1567 1698
1568 //charSpace Tc Set the character spacing, Tc 1699 //charSpace Tc Set the character spacing, Tc
1569 //, to charSpace, which is a number expressed in unscaled text space units. Char acter spacing is used by the Tj, TJ, and ' operators. 1700 //, to charSpace, which is a number expressed in unscaled text space units. Char acter spacing is used by the Tj, TJ, and ' operators.
1570 //Initial value: 0. 1701 //Initial value: 0.
1571 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1702 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1572 double charSpace = pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop(); 1703 double charSpace = pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop();
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 //SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(z, h)}; 2117 //SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(z, h)};
1987 //SkPoint skiaSpace[2] = {SkPoint::Make(z, h), SkPoint::Make(z, z)}; 2118 //SkPoint skiaSpace[2] = {SkPoint::Make(z, h), SkPoint::Make(z, z)};
1988 2119
1989 //SkPoint pdfSpace[3] = {SkPoint::Make(z, z), SkPoint::Make(z, h), SkPoint:: Make(w, h)}; 2120 //SkPoint pdfSpace[3] = {SkPoint::Make(z, z), SkPoint::Make(z, h), SkPoint:: Make(w, h)};
1990 //SkPoint skiaSpace[3] = {SkPoint::Make(z, h), SkPoint::Make(z, z), SkPoint: :Make(w, 0)}; 2121 //SkPoint skiaSpace[3] = {SkPoint::Make(z, h), SkPoint::Make(z, z), SkPoint: :Make(w, 0)};
1991 2122
1992 SkAssertResult(pdfContext.fOriginalMatrix.setPolyToPoly(pdfSpace, skiaSpace, 4)); 2123 SkAssertResult(pdfContext.fOriginalMatrix.setPolyToPoly(pdfSpace, skiaSpace, 4));
1993 SkTraceMatrix(pdfContext.fOriginalMatrix, "Original matrix"); 2124 SkTraceMatrix(pdfContext.fOriginalMatrix, "Original matrix");
1994 2125
1995 2126
1996 pdfContext.fGraphicsState.fMatrix = pdfContext.fOriginalMatrix; 2127 pdfContext.fGraphicsState.fCTM = pdfContext.fOriginalMatrix;
1997 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState.fMatrix; 2128 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState.fCTM;
1998 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState.fMatrix; 2129 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState.fCTM;
1999 2130
2000 #ifndef PDF_DEBUG_NO_PAGE_CLIPING 2131 #ifndef PDF_DEBUG_NO_PAGE_CLIPING
2001 canvas->clipRect(dst, SkRegion::kIntersect_Op, true); 2132 canvas->clipRect(dst, SkRegion::kIntersect_Op, true);
2002 #endif 2133 #endif
2003 2134
2004 canvas->setMatrix(pdfContext.fOriginalMatrix); 2135 canvas->setMatrix(pdfContext.fOriginalMatrix);
2005 2136
2006 // erase with red before? 2137 // erase with red before?
2007 // SkPaint paint; 2138 // SkPaint paint;
2008 // paint.setColor(SK_ColorRED); 2139 // paint.setColor(SK_ColorRED);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 2212
2082 rect = SkRect::MakeWH(width, height); 2213 rect = SkRect::MakeWH(width, height);
2083 2214
2084 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght)); 2215 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght));
2085 2216
2086 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); 2217 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output)));
2087 SkCanvas canvas(device); 2218 SkCanvas canvas(device);
2088 2219
2089 return renderer.renderPage(page, &canvas, rect); 2220 return renderer.renderPage(page, &canvas, rect);
2090 } 2221 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkPdfBasics.cpp ('k') | experimental/PdfViewer/pdfparser/native/SkPdfObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698