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

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

Issue 23038021: pdfviewer: add macros to automatically check number and type of parameters (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 * - encapsulate native in the pdf api so the skpdf does not know anything about native ... in progress 64 * - encapsulate native in the pdf api so the skpdf does not know anything about native ... in progress
65 * - load gs/ especially smask and already known prop (skp) ... in progress 65 * - load gs/ especially smask and already known prop (skp) ... in progress
66 * - wrapper on classes for customizations? e.g. 66 * - wrapper on classes for customizations? e.g.
67 * SkPdfPageObjectVanila - has only the basic loaders/getters 67 * SkPdfPageObjectVanila - has only the basic loaders/getters
68 * SkPdfPageObject : public SkPdfPageObjectVanila, extends, and I can add custom izations here 68 * SkPdfPageObject : public SkPdfPageObjectVanila, extends, and I can add custom izations here
69 * need to find a nice object model for all this with constructors and factories 69 * need to find a nice object model for all this with constructors and factories
70 * - deal with inheritable automatically ? 70 * - deal with inheritable automatically ?
71 * - deal with specific type in spec directly, add all dictionary types to known types 71 * - deal with specific type in spec directly, add all dictionary types to known types
72 */ 72 */
73 73
74 #define EXPECT_OPERANDS(pdfContext,n) \
75 bool __failed = pdfContext->fObjectStack.count() < n; \
76 SkDEBUGCODE(int __cnt = n);
77
78 #define POP_OBJ(pdfContext,name) \
79 SkDEBUGCODE(__cnt--); \
80 SkASSERT(__cnt >= 0); \
81 SkPdfNativeObject* name = NULL; \
82 __failed = __failed || pdfContext->fObjectStack.count() == 0; \
83 if (pdfContext->fObjectStack.count() > 0) { \
84 name = pdfContext->fObjectStack.top(); \
85 pdfContext->fObjectStack.pop(); \
86 }
87
88 #define POP_NUMBER(pdfContext,name) \
89 SkDEBUGCODE(__cnt--); \
90 SkASSERT(__cnt >= 0); \
91 double name = 0; \
92 __failed = __failed || pdfContext->fObjectStack.count() == 0; \
93 if (pdfContext->fObjectStack.count() > 0) { \
94 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \
95 pdfContext->fObjectStack.pop(); \
96 if (!tmp || !tmp->isNumber()) { \
97 __failed = true;\
98 } else { \
99 name = tmp->numberValue(); \
100 } \
101 }
102
103 #define POP_INTEGER(pdfContext,name) \
104 SkDEBUGCODE(__cnt--); \
105 SkASSERT(__cnt >= 0); \
106 int64_t name = 0; \
107 __failed = __failed || pdfContext->fObjectStack.count() == 0; \
108 if (pdfContext->fObjectStack.count() > 0) { \
109 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \
110 pdfContext->fObjectStack.pop(); \
111 if (!tmp || !tmp->isInteger()) { \
112 __failed = true;\
113 } else { \
114 name = tmp->intValue(); \
115 } \
116 }
117
118 #define POP_NUMBER_INTO(pdfContext,var) \
119 SkDEBUGCODE(__cnt--); \
120 SkASSERT(__cnt >= 0); \
121 __failed = __failed || pdfContext->fObjectStack.count() == 0; \
122 if (pdfContext->fObjectStack.count() > 0) { \
123 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \
124 pdfContext->fObjectStack.pop(); \
125 if (!tmp || !tmp->isNumber()) { \
126 __failed = true;\
127 } else { \
128 var = tmp->numberValue(); \
129 } \
130 }
131
132
133 #define POP_NAME(pdfContext,name) \
134 SkDEBUGCODE(__cnt--); \
135 SkASSERT(__cnt >= 0); \
136 SkPdfNativeObject* name = NULL; \
137 __failed = __failed || pdfContext->fObjectStack.count() == 0; \
138 if (pdfContext->fObjectStack.count() > 0) { \
139 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \
140 pdfContext->fObjectStack.pop(); \
141 if (!tmp || !tmp->isName()) { \
142 __failed = true;\
143 } else { \
144 name = tmp; \
145 } \
146 }
147
148 #define POP_STRING(pdfContext,name) \
149 SkDEBUGCODE(__cnt--); \
150 SkASSERT(__cnt >= 0); \
151 SkPdfNativeObject* name = NULL; \
152 __failed = __failed || pdfContext->fObjectStack.count() == 0; \
153 if (pdfContext->fObjectStack.count() > 0) { \
154 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \
155 pdfContext->fObjectStack.pop(); \
156 if (!tmp || !tmp->isAnyString()) { \
157 __failed = true;\
158 } else { \
159 name = tmp; \
160 } \
161 }
162
163 #define POP_ARRAY(pdfContext,name) \
164 SkDEBUGCODE(__cnt--); \
165 SkASSERT(__cnt >= 0); \
166 SkPdfArray* name = NULL; \
167 __failed = __failed || pdfContext->fObjectStack.count() == 0; \
168 if (pdfContext->fObjectStack.count() > 0) { \
169 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \
170 pdfContext->fObjectStack.pop(); \
171 if (!tmp || !tmp->isArray()) { \
172 __failed = true;\
173 } else { \
174 name = (SkPdfArray*)tmp; \
175 } \
176 }
177
178 // TODO(edisonn): ability to turn on asserts for known good files
179 // log error - add name of function? location in file?
180 #define CHECK_PARAMETERS() \
181 SkASSERT(__cnt == 0); \
182 if (__failed) return kIgnoreError_SkPdfResult;
183
74 NotOwnedString strings_DeviceRGB; 184 NotOwnedString strings_DeviceRGB;
75 NotOwnedString strings_DeviceCMYK; 185 NotOwnedString strings_DeviceCMYK;
76 186
77 class StringsInit { 187 class StringsInit {
78 public: 188 public:
79 StringsInit() { 189 StringsInit() {
80 NotOwnedString::init(&strings_DeviceRGB, "DeviceRGB"); 190 NotOwnedString::init(&strings_DeviceRGB, "DeviceRGB");
81 NotOwnedString::init(&strings_DeviceCMYK, "DeviceCMYK"); 191 NotOwnedString::init(&strings_DeviceCMYK, "DeviceCMYK");
82 } 192 }
83 }; 193 };
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 } 1074 }
965 1075
966 // TODO(edisonn): should we restore the variable stack at the same state? 1076 // TODO(edisonn): should we restore the variable stack at the same state?
967 // There could be operands left, that could be consumed by a parent tokenize r when we pop. 1077 // There could be operands left, that could be consumed by a parent tokenize r when we pop.
968 canvas->restore(); 1078 canvas->restore();
969 PdfOp_Q(pdfContext, canvas, NULL); 1079 PdfOp_Q(pdfContext, canvas, NULL);
970 return kPartial_SkPdfResult; 1080 return kPartial_SkPdfResult;
971 } 1081 }
972 1082
973 SkPdfResult PdfOp_q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) { 1083 SkPdfResult PdfOp_q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) {
1084 // TODO(edisonn): create a new stack of parameters, so once we start a q,
1085 // it is not possible to see under the previous q?
974 pdfContext->fStateStack.push(pdfContext->fGraphicsState); 1086 pdfContext->fStateStack.push(pdfContext->fGraphicsState);
975 canvas->save(); 1087 canvas->save();
976 return kOK_SkPdfResult; 1088 return kOK_SkPdfResult;
977 } 1089 }
978 1090
979 SkPdfResult PdfOp_Q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) { 1091 SkPdfResult PdfOp_Q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) {
980 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); 1092 pdfContext->fGraphicsState = pdfContext->fStateStack.top();
981 pdfContext->fStateStack.pop(); 1093 pdfContext->fStateStack.pop();
982 canvas->restore(); 1094 canvas->restore();
983 return kOK_SkPdfResult; 1095 return kOK_SkPdfResult;
984 } 1096 }
985 1097
986 static SkPdfResult PdfOp_cm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1098 static SkPdfResult PdfOp_cm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
987 double array[6]; 1099 EXPECT_OPERANDS(pdfContext, 6);
988 for (int i = 0 ; i < 6 ; i++) { 1100 POP_NUMBER(pdfContext, f);
989 array[5 - i] = pdfContext->fObjectStack.top()->numberValue(); 1101 POP_NUMBER(pdfContext, e);
990 pdfContext->fObjectStack.pop(); 1102 POP_NUMBER(pdfContext, d);
991 } 1103 POP_NUMBER(pdfContext, c);
1104 POP_NUMBER(pdfContext, b);
1105 POP_NUMBER(pdfContext, a);
1106 CHECK_PARAMETERS();
1107 double array[6] = {a, b, c, d, e, f};
992 1108
993 // a b 1109 // a b
994 // c d 1110 // c d
995 // e f 1111 // e f
996 1112
997 // 0 1 1113 // 0 1
998 // 2 3 1114 // 2 3
999 // 4 5 1115 // 4 5
1000 1116
1001 // sx ky 1117 // sx ky
(...skipping 12 matching lines...) Expand all
1014 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "cm"); 1130 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "cm");
1015 #endif 1131 #endif
1016 1132
1017 return kOK_SkPdfResult; 1133 return kOK_SkPdfResult;
1018 } 1134 }
1019 1135
1020 //leading TL Set the text leading, Tl 1136 //leading TL Set the text leading, Tl
1021 //, to leading, which is a number expressed in unscaled text 1137 //, to leading, which is a number expressed in unscaled text
1022 //space units. Text leading is used only by the T*, ', and " operators. Initial value: 0. 1138 //space units. Text leading is used only by the T*, ', and " operators. Initial value: 0.
1023 static SkPdfResult PdfOp_TL(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1139 static SkPdfResult PdfOp_TL(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1024 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fOb jectStack.pop(); 1140 EXPECT_OPERANDS(pdfContext, 1)
1141 POP_NUMBER(pdfContext, ty);
1142 CHECK_PARAMETERS();
1025 1143
1026 pdfContext->fGraphicsState.fTextLeading = ty; 1144 pdfContext->fGraphicsState.fTextLeading = ty;
1027 1145
1028 return kOK_SkPdfResult; 1146 return kOK_SkPdfResult;
1029 } 1147 }
1030 1148
1031 static SkPdfResult PdfOp_Td(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1149 static SkPdfResult PdfOp_Td(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1032 #ifdef PDF_TRACE 1150 EXPECT_OPERANDS(pdfContext, 2);
1033 printf("stack size = %i\n", (int)pdfContext->fObjectStack.size()); 1151 POP_NUMBER(pdfContext, ty);
1034 #endif 1152 POP_NUMBER(pdfContext, tx);
1035 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje ctStack.pop(); 1153 CHECK_PARAMETERS();
1036 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje ctStack.pop();
1037 1154
1038 double array[6] = {1, 0, 0, 1, tx, -ty}; 1155 double array[6] = {1, 0, 0, 1, tx, -ty};
1039 SkMatrix matrix = SkMatrixFromPdfMatrix(array); 1156 SkMatrix matrix = SkMatrixFromPdfMatrix(array);
1040 1157
1041 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); 1158 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix);
1042 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); 1159 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix);
1043 1160
1044 return kPartial_SkPdfResult; 1161 return kPartial_SkPdfResult;
1045 } 1162 }
1046 1163
1047 static SkPdfResult PdfOp_TD(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1164 static SkPdfResult PdfOp_TD(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1048 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje ctStack.pop(); 1165 EXPECT_OPERANDS(pdfContext, 2)
1049 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje ctStack.pop(); 1166 POP_NUMBER(pdfContext, ty);
1167 POP_NUMBER(pdfContext, tx);
1168 CHECK_PARAMETERS();
1050 1169
1051 // TODO(edisonn): Create factory methods or constructors so native is hidden 1170 // TODO(edisonn): Create factory methods or constructors so native is hidden
1052 SkPdfReal* _ty = pdfContext->fPdfDoc->createReal(-ty); 1171 SkPdfReal* _ty = pdfContext->fPdfDoc->createReal(-ty);
1053 pdfContext->fObjectStack.push(_ty); 1172 pdfContext->fObjectStack.push(_ty);
1054 1173
1055 PdfOp_TL(pdfContext, canvas, looper); 1174 PdfOp_TL(pdfContext, canvas, looper);
1056 1175
1057 SkPdfReal* vtx = pdfContext->fPdfDoc->createReal(tx); 1176 SkPdfReal* vtx = pdfContext->fPdfDoc->createReal(tx);
1058 pdfContext->fObjectStack.push(vtx); 1177 pdfContext->fObjectStack.push(vtx);
1059 1178
1060 SkPdfReal* vty = pdfContext->fPdfDoc->createReal(ty); 1179 SkPdfReal* vty = pdfContext->fPdfDoc->createReal(ty);
1061 pdfContext->fObjectStack.push(vty); 1180 pdfContext->fObjectStack.push(vty);
1062 1181
1063 SkPdfResult ret = PdfOp_Td(pdfContext, canvas, looper); 1182 SkPdfResult ret = PdfOp_Td(pdfContext, canvas, looper);
1064 1183
1065 // TODO(edisonn): delete all the objects after rendering was complete, in th is way pdf is rendered faster 1184 // TODO(edisonn): delete all the objects after rendering was complete, in th is way pdf is rendered faster
1066 // and the cleanup can happen while the user looks at the image 1185 // and the cleanup can happen while the user looks at the image
1067 1186
1068 return ret; 1187 return ret;
1069 } 1188 }
1070 1189
1071 static SkPdfResult PdfOp_Tm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1190 static SkPdfResult PdfOp_Tm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1072 double f = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec tStack.pop(); 1191 EXPECT_OPERANDS(pdfContext, 6);
1073 double e = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec tStack.pop(); 1192 POP_NUMBER(pdfContext, f);
1074 double d = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec tStack.pop(); 1193 POP_NUMBER(pdfContext, e);
1075 double c = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec tStack.pop(); 1194 POP_NUMBER(pdfContext, d);
1076 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec tStack.pop(); 1195 POP_NUMBER(pdfContext, c);
1077 double a = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec tStack.pop(); 1196 POP_NUMBER(pdfContext, b);
1197 POP_NUMBER(pdfContext, a);
1198 CHECK_PARAMETERS();
1078 1199
1079 double array[6]; 1200 double array[6];
1080 array[0] = a; 1201 array[0] = a;
1081 array[1] = b; 1202 array[1] = b;
1082 array[2] = c; 1203 array[2] = c;
1083 array[3] = d; 1204 array[3] = d;
1084 array[4] = e; 1205 array[4] = e;
1085 array[5] = f; 1206 array[5] = f;
1086 1207
1087 SkMatrix matrix = SkMatrixFromPdfMatrix(array); 1208 SkMatrix matrix = SkMatrixFromPdfMatrix(array);
(...skipping 21 matching lines...) Expand all
1109 1230
1110 return ret; 1231 return ret;
1111 } 1232 }
1112 1233
1113 static SkPdfResult PdfOp_m(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1234 static SkPdfResult PdfOp_m(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1114 if (pdfContext->fGraphicsState.fPathClosed) { 1235 if (pdfContext->fGraphicsState.fPathClosed) {
1115 pdfContext->fGraphicsState.fPath.reset(); 1236 pdfContext->fGraphicsState.fPath.reset();
1116 pdfContext->fGraphicsState.fPathClosed = false; 1237 pdfContext->fGraphicsState.fPathClosed = false;
1117 } 1238 }
1118 1239
1119 pdfContext->fGraphicsState.fCurPosY = pdfContext->fObjectStack.top()->number Value(); pdfContext->fObjectStack.pop(); 1240 EXPECT_OPERANDS(pdfContext, 2);
1120 pdfContext->fGraphicsState.fCurPosX = pdfContext->fObjectStack.top()->number Value(); pdfContext->fObjectStack.pop(); 1241 POP_NUMBER(pdfContext, y);
1242 POP_NUMBER(pdfContext, x);
1243 CHECK_PARAMETERS();
1244
1245 pdfContext->fGraphicsState.fCurPosY = y;
1246 pdfContext->fGraphicsState.fCurPosX = x;
1121 1247
1122 pdfContext->fGraphicsState.fPath.moveTo(SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosX), 1248 pdfContext->fGraphicsState.fPath.moveTo(SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosX),
1123 SkDoubleToScalar(pdfContext->fGraphics State.fCurPosY)); 1249 SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosY));
1124 1250
1125 return kOK_SkPdfResult; 1251 return kOK_SkPdfResult;
1126 } 1252 }
1127 1253
1128 static SkPdfResult PdfOp_l(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1254 static SkPdfResult PdfOp_l(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1129 if (pdfContext->fGraphicsState.fPathClosed) { 1255 if (pdfContext->fGraphicsState.fPathClosed) {
1130 pdfContext->fGraphicsState.fPath.reset(); 1256 pdfContext->fGraphicsState.fPath.reset();
1131 pdfContext->fGraphicsState.fPathClosed = false; 1257 pdfContext->fGraphicsState.fPathClosed = false;
1132 } 1258 }
1133 1259
1134 pdfContext->fGraphicsState.fCurPosY = pdfContext->fObjectStack.top()->number Value(); pdfContext->fObjectStack.pop(); 1260 EXPECT_OPERANDS(pdfContext, 2);
1135 pdfContext->fGraphicsState.fCurPosX = pdfContext->fObjectStack.top()->number Value(); pdfContext->fObjectStack.pop(); 1261 POP_NUMBER(pdfContext, y);
1262 POP_NUMBER(pdfContext, x);
1263 CHECK_PARAMETERS();
1264
1265 pdfContext->fGraphicsState.fCurPosY = y;
1266 pdfContext->fGraphicsState.fCurPosX = x;
1136 1267
1137 pdfContext->fGraphicsState.fPath.lineTo(SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosX), 1268 pdfContext->fGraphicsState.fPath.lineTo(SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosX),
1138 SkDoubleToScalar(pdfContext->fGraphics State.fCurPosY)); 1269 SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosY));
1139 1270
1140 return kOK_SkPdfResult; 1271 return kOK_SkPdfResult;
1141 } 1272 }
1142 1273
1143 static SkPdfResult PdfOp_c(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1274 static SkPdfResult PdfOp_c(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1144 if (pdfContext->fGraphicsState.fPathClosed) { 1275 if (pdfContext->fGraphicsState.fPathClosed) {
1145 pdfContext->fGraphicsState.fPath.reset(); 1276 pdfContext->fGraphicsState.fPath.reset();
1146 pdfContext->fGraphicsState.fPathClosed = false; 1277 pdfContext->fGraphicsState.fPathClosed = false;
1147 } 1278 }
1148 1279
1149 double y3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1280 EXPECT_OPERANDS(pdfContext, 6);
1150 double x3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1281 POP_NUMBER(pdfContext, y3);
1151 double y2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1282 POP_NUMBER(pdfContext, x3);
1152 double x2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1283 POP_NUMBER(pdfContext, y2);
1153 double y1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1284 POP_NUMBER(pdfContext, x2);
1154 double x1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1285 POP_NUMBER(pdfContext, y1);
1286 POP_NUMBER(pdfContext, x1);
1287 CHECK_PARAMETERS();
1155 1288
1156 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1), 1289 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1),
1157 SkDoubleToScalar(x2), SkDoubleToScal ar(y2), 1290 SkDoubleToScalar(x2), SkDoubleToSca lar(y2),
1158 SkDoubleToScalar(x3), SkDoubleToScal ar(y3)); 1291 SkDoubleToScalar(x3), SkDoubleToSca lar(y3));
1159 1292
1160 pdfContext->fGraphicsState.fCurPosX = x3; 1293 pdfContext->fGraphicsState.fCurPosX = x3;
1161 pdfContext->fGraphicsState.fCurPosY = y3; 1294 pdfContext->fGraphicsState.fCurPosY = y3;
1162 1295
1163 return kOK_SkPdfResult; 1296 return kOK_SkPdfResult;
1164 } 1297 }
1165 1298
1166 static SkPdfResult PdfOp_v(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1299 static SkPdfResult PdfOp_v(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1167 if (pdfContext->fGraphicsState.fPathClosed) { 1300 if (pdfContext->fGraphicsState.fPathClosed) {
1168 pdfContext->fGraphicsState.fPath.reset(); 1301 pdfContext->fGraphicsState.fPath.reset();
1169 pdfContext->fGraphicsState.fPathClosed = false; 1302 pdfContext->fGraphicsState.fPathClosed = false;
1170 } 1303 }
1171 1304
1172 double y3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1305 EXPECT_OPERANDS(pdfContext, 4);
1173 double x3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1306 POP_NUMBER(pdfContext, y3);
1174 double y2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1307 POP_NUMBER(pdfContext, x3);
1175 double x2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1308 POP_NUMBER(pdfContext, y2);
1309 POP_NUMBER(pdfContext, x2);
1310 CHECK_PARAMETERS();
1311
1176 double y1 = pdfContext->fGraphicsState.fCurPosY; 1312 double y1 = pdfContext->fGraphicsState.fCurPosY;
1177 double x1 = pdfContext->fGraphicsState.fCurPosX; 1313 double x1 = pdfContext->fGraphicsState.fCurPosX;
1178 1314
1179 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1), 1315 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1),
1180 SkDoubleToScalar(x2), SkDoubleToScal ar(y2), 1316 SkDoubleToScalar(x2), SkDoubleToSca lar(y2),
1181 SkDoubleToScalar(x3), SkDoubleToScal ar(y3)); 1317 SkDoubleToScalar(x3), SkDoubleToSca lar(y3));
1182 1318
1183 pdfContext->fGraphicsState.fCurPosX = x3; 1319 pdfContext->fGraphicsState.fCurPosX = x3;
1184 pdfContext->fGraphicsState.fCurPosY = y3; 1320 pdfContext->fGraphicsState.fCurPosY = y3;
1185 1321
1186 return kOK_SkPdfResult; 1322 return kOK_SkPdfResult;
1187 } 1323 }
1188 1324
1189 static SkPdfResult PdfOp_y(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1325 static SkPdfResult PdfOp_y(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1190 if (pdfContext->fGraphicsState.fPathClosed) { 1326 if (pdfContext->fGraphicsState.fPathClosed) {
1191 pdfContext->fGraphicsState.fPath.reset(); 1327 pdfContext->fGraphicsState.fPath.reset();
1192 pdfContext->fGraphicsState.fPathClosed = false; 1328 pdfContext->fGraphicsState.fPathClosed = false;
1193 } 1329 }
1194 1330
1195 double y3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1331 EXPECT_OPERANDS(pdfContext, 4);
1196 double x3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1332 POP_NUMBER(pdfContext, y3);
1333 POP_NUMBER(pdfContext, x3);
1334 POP_NUMBER(pdfContext, y1);
1335 POP_NUMBER(pdfContext, x1);
1336 CHECK_PARAMETERS();
1337
1197 double y2 = pdfContext->fGraphicsState.fCurPosY; 1338 double y2 = pdfContext->fGraphicsState.fCurPosY;
1198 double x2 = pdfContext->fGraphicsState.fCurPosX; 1339 double x2 = pdfContext->fGraphicsState.fCurPosX;
1199 double y1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop();
1200 double x1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop();
1201 1340
1202 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1), 1341 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1),
1203 SkDoubleToScalar(x2), SkDoubleToScal ar(y2), 1342 SkDoubleToScalar(x2), SkDoubleToSca lar(y2),
1204 SkDoubleToScalar(x3), SkDoubleToScal ar(y3)); 1343 SkDoubleToScalar(x3), SkDoubleToSca lar(y3));
1205 1344
1206 pdfContext->fGraphicsState.fCurPosX = x3; 1345 pdfContext->fGraphicsState.fCurPosX = x3;
1207 pdfContext->fGraphicsState.fCurPosY = y3; 1346 pdfContext->fGraphicsState.fCurPosY = y3;
1208 1347
1209 return kOK_SkPdfResult; 1348 return kOK_SkPdfResult;
1210 } 1349 }
1211 1350
1212 static SkPdfResult PdfOp_re(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1351 static SkPdfResult PdfOp_re(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1213 if (pdfContext->fGraphicsState.fPathClosed) { 1352 if (pdfContext->fGraphicsState.fPathClosed) {
1214 pdfContext->fGraphicsState.fPath.reset(); 1353 pdfContext->fGraphicsState.fPath.reset();
1215 pdfContext->fGraphicsState.fPathClosed = false; 1354 pdfContext->fGraphicsState.fPathClosed = false;
1216 } 1355 }
1217 1356
1218 double height = pdfContext->fObjectStack.top()->numberValue(); pdfConte xt->fObjectStack.pop(); 1357 EXPECT_OPERANDS(pdfContext, 4);
1219 double width = pdfContext->fObjectStack.top()->numberValue(); pdfConte xt->fObjectStack.pop(); 1358 POP_NUMBER(pdfContext, height);
1220 double y = pdfContext->fObjectStack.top()->numberValue(); pdfConte xt->fObjectStack.pop(); 1359 POP_NUMBER(pdfContext, width);
1221 double x = pdfContext->fObjectStack.top()->numberValue(); pdfConte xt->fObjectStack.pop(); 1360 POP_NUMBER(pdfContext, y);
1361 POP_NUMBER(pdfContext, x);
1362 CHECK_PARAMETERS();
1222 1363
1223 pdfContext->fGraphicsState.fPath.addRect(SkDoubleToScalar(x), SkDoubleToScal ar(y), 1364 pdfContext->fGraphicsState.fPath.addRect(SkDoubleToScalar(x), SkDoubleToScal ar(y),
1224 SkDoubleToScalar(x + width), SkDouble ToScalar(y + height)); 1365 SkDoubleToScalar(x + width), SkDoub leToScalar(y + height));
1225 1366
1226 pdfContext->fGraphicsState.fCurPosX = x; 1367 pdfContext->fGraphicsState.fCurPosX = x;
1227 pdfContext->fGraphicsState.fCurPosY = y + height; 1368 pdfContext->fGraphicsState.fCurPosY = y + height;
1228 1369
1229 return kOK_SkPdfResult; 1370 return kOK_SkPdfResult;
1230 } 1371 }
1231 1372
1232 static SkPdfResult PdfOp_h(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1373 static SkPdfResult PdfOp_h(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1233 pdfContext->fGraphicsState.fPath.close(); 1374 pdfContext->fGraphicsState.fPath.close();
1234 return kOK_SkPdfResult; 1375 return kOK_SkPdfResult;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 pdfContext->fGraphicsState.fCurFontSize = fontSize; 1603 pdfContext->fGraphicsState.fCurFontSize = fontSize;
1463 return kOK_SkPdfResult; 1604 return kOK_SkPdfResult;
1464 } 1605 }
1465 1606
1466 //font size Tf Set the text font, Tf 1607 //font size Tf Set the text font, Tf
1467 //, to font and the text font size, Tfs, to size. font is the name of a 1608 //, to font and the text font size, Tfs, to size. font is the name of a
1468 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is 1609 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is
1469 //a number representing a scale factor. There is no initial value for either fon t or 1610 //a number representing a scale factor. There is no initial value for either fon t or
1470 //size; they must be specified explicitly using Tf before any text is shown. 1611 //size; they must be specified explicitly using Tf before any text is shown.
1471 static SkPdfResult PdfOp_Tf(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1612 static SkPdfResult PdfOp_Tf(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1472 double fontSize = pdfContext->fObjectStack.top()->numberValue(); pdfCont ext->fObjectStack.pop(); 1613 EXPECT_OPERANDS(pdfContext, 2);
1473 SkPdfNativeObject* fontName = pdfContext->fObjectStack.top(); pdfContext->fObjectStack.pop(); 1614 POP_NUMBER(pdfContext, fontSize);
1615 POP_NAME(pdfContext, fontName);
1616 CHECK_PARAMETERS();
1617
1474 return skpdfGraphicsStateApplyFontCore(pdfContext, fontName, fontSize); 1618 return skpdfGraphicsStateApplyFontCore(pdfContext, fontName, fontSize);
1475 } 1619 }
1476 1620
1477 static SkPdfResult PdfOp_Tj(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1621 static SkPdfResult PdfOp_Tj(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1622 EXPECT_OPERANDS(pdfContext, 1);
1623 POP_STRING(pdfContext, str);
1624 CHECK_PARAMETERS();
1625
1478 if (!pdfContext->fGraphicsState.fTextBlock) { 1626 if (!pdfContext->fGraphicsState.fTextBlock) {
1479 // TODO(edisonn): try to recover and draw it any way? 1627 // TODO(edisonn): try to recover and draw it any way?
1480 return kIgnoreError_SkPdfResult; 1628 return kIgnoreError_SkPdfResult;
1481 } 1629 }
1482 1630
1483 SkPdfResult ret = DrawText(pdfContext, 1631 SkPdfResult ret = DrawText(pdfContext, str, canvas);
1484 pdfContext->fObjectStack.top(),
1485 canvas);
1486 pdfContext->fObjectStack.pop();
1487 1632
1488 return ret; 1633 return ret;
1489 } 1634 }
1490 1635
1491 static SkPdfResult PdfOp_quote(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTo kenLooper** looper) { 1636 static SkPdfResult PdfOp_quote(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTo kenLooper** looper) {
1492 if (!pdfContext->fGraphicsState.fTextBlock) { 1637 if (!pdfContext->fGraphicsState.fTextBlock) {
1493 // TODO(edisonn): try to recover and draw it any way? 1638 // TODO(edisonn): try to recover and draw it any way?
1494 return kIgnoreError_SkPdfResult; 1639 return kIgnoreError_SkPdfResult;
1495 } 1640 }
1496 1641
1497 PdfOp_T_star(pdfContext, canvas, looper); 1642 PdfOp_T_star(pdfContext, canvas, looper);
1498 // Do not pop, and push, just transfer the param to Tj 1643 // Do not pop, and push, just transfer the param to Tj
1499 return PdfOp_Tj(pdfContext, canvas, looper); 1644 return PdfOp_Tj(pdfContext, canvas, looper);
1500 } 1645 }
1501 1646
1502 static SkPdfResult PdfOp_doublequote(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) { 1647 static SkPdfResult PdfOp_doublequote(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) {
1503 if (!pdfContext->fGraphicsState.fTextBlock) { 1648 if (!pdfContext->fGraphicsState.fTextBlock) {
1504 // TODO(edisonn): try to recover and draw it any way? 1649 // TODO(edisonn): try to recover and draw it any way?
1505 return kIgnoreError_SkPdfResult; 1650 return kIgnoreError_SkPdfResult;
1506 } 1651 }
1507 1652
1508 SkPdfNativeObject* str = pdfContext->fObjectStack.top(); pdfContext->f ObjectStack.pop(); 1653 EXPECT_OPERANDS(pdfContext, 3);
1509 SkPdfNativeObject* ac = pdfContext->fObjectStack.top(); pdfContext->f ObjectStack.pop(); 1654 POP_OBJ(pdfContext, str);
1510 SkPdfNativeObject* aw = pdfContext->fObjectStack.top(); pdfContext->f ObjectStack.pop(); 1655 POP_OBJ(pdfContext, ac);
1656 POP_OBJ(pdfContext, aw);
1657 CHECK_PARAMETERS();
1511 1658
1512 pdfContext->fObjectStack.push(aw); 1659 pdfContext->fObjectStack.push(aw);
1513 PdfOp_Tw(pdfContext, canvas, looper); 1660 PdfOp_Tw(pdfContext, canvas, looper);
1514 1661
1515 pdfContext->fObjectStack.push(ac); 1662 pdfContext->fObjectStack.push(ac);
1516 PdfOp_Tc(pdfContext, canvas, looper); 1663 PdfOp_Tc(pdfContext, canvas, looper);
1517 1664
1518 pdfContext->fObjectStack.push(str); 1665 pdfContext->fObjectStack.push(str);
1519 PdfOp_quote(pdfContext, canvas, looper); 1666 PdfOp_quote(pdfContext, canvas, looper);
1520 1667
1521 return kPartial_SkPdfResult; 1668 return kPartial_SkPdfResult;
1522 } 1669 }
1523 1670
1524 static SkPdfResult PdfOp_TJ(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1671 static SkPdfResult PdfOp_TJ(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1672 EXPECT_OPERANDS(pdfContext, 1);
1673 POP_ARRAY(pdfContext, array);
1674 CHECK_PARAMETERS();
1675
1525 if (!pdfContext->fGraphicsState.fTextBlock) { 1676 if (!pdfContext->fGraphicsState.fTextBlock) {
1526 // TODO(edisonn): try to recover and draw it any way? 1677 // TODO(edisonn): try to recover and draw it any way?
1527 return kIgnoreError_SkPdfResult; 1678 return kIgnoreError_SkPdfResult;
1528 } 1679 }
1529 1680
1530 SkPdfArray* array = (SkPdfArray*)pdfContext->fObjectStack.top();
1531 pdfContext->fObjectStack.pop();
1532
1533 if (!array->isArray()) { 1681 if (!array->isArray()) {
1534 return kIgnoreError_SkPdfResult; 1682 return kIgnoreError_SkPdfResult;
1535 } 1683 }
1536 1684
1537 for( int i=0; i<static_cast<int>(array->size()); i++ ) 1685 for( int i=0; i<static_cast<int>(array->size()); i++ )
1538 { 1686 {
1539 if( (*array)[i]->isAnyString()) { 1687 if( (*array)[i]->isAnyString()) {
1540 SkPdfNativeObject* obj = (*array)[i]; 1688 SkPdfNativeObject* obj = (*array)[i];
1541 DrawText(pdfContext, 1689 DrawText(pdfContext, obj, canvas);
1542 obj,
1543 canvas);
1544 } else if ((*array)[i]->isNumber()) { 1690 } else if ((*array)[i]->isNumber()) {
1545 double dx = (*array)[i]->numberValue(); 1691 double dx = (*array)[i]->numberValue();
1546 SkMatrix matrix; 1692 SkMatrix matrix;
1547 matrix.setAll(SkDoubleToScalar(1), 1693 matrix.setAll(SkDoubleToScalar(1),
1548 SkDoubleToScalar(0), 1694 SkDoubleToScalar(0),
1549 // TODO(edisonn): use writing mode, vertical/horizonta l. 1695 // TODO(edisonn): use writing mode, vertical/horizonta l.
1550 SkDoubleToScalar(-dx), // amount is substracted!!! 1696 SkDoubleToScalar(-dx), // amount is substracted!!!
1551 SkDoubleToScalar(0), 1697 SkDoubleToScalar(0),
1552 SkDoubleToScalar(1), 1698 SkDoubleToScalar(1),
1553 SkDoubleToScalar(0), 1699 SkDoubleToScalar(0),
1554 SkDoubleToScalar(0), 1700 SkDoubleToScalar(0),
1555 SkDoubleToScalar(0), 1701 SkDoubleToScalar(0),
1556 SkDoubleToScalar(1)); 1702 SkDoubleToScalar(1));
1557 1703
1558 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); 1704 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix);
1559 } 1705 }
1560 } 1706 }
1561 return kPartial_SkPdfResult; // TODO(edisonn): Implement fully DrawText bef ore returing OK. 1707 return kPartial_SkPdfResult; // TODO(edisonn): Implement fully DrawText bef ore returing OK.
1562 } 1708 }
1563 1709
1564 static SkPdfResult PdfOp_CS_cs(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf ColorOperator* colorOperator) { 1710 static SkPdfResult PdfOp_CS_cs(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf ColorOperator* colorOperator) {
1565 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb jectStack.pop(); 1711 EXPECT_OPERANDS(pdfContext, 1);
1712 POP_NAME(pdfContext, name);
1713 CHECK_PARAMETERS();
1566 1714
1567 //Next, get the ColorSpace Dictionary from the Resource Dictionary: 1715 //Next, get the ColorSpace Dictionary from the Resource Dictionary:
1568 SkPdfDictionary* colorSpaceResource = pdfContext->fGraphicsState.fResources- >ColorSpace(pdfContext->fPdfDoc); 1716 SkPdfDictionary* colorSpaceResource = pdfContext->fGraphicsState.fResources- >ColorSpace(pdfContext->fPdfDoc);
1569 1717
1570 SkPdfNativeObject* colorSpace = colorSpaceResource ? pdfContext->fPdfDoc->re solveReference(colorSpaceResource->get(name)) : name; 1718 SkPdfNativeObject* colorSpace = colorSpaceResource ? pdfContext->fPdfDoc->re solveReference(colorSpaceResource->get(name)) : name;
1571 1719
1572 if (colorSpace == NULL) { 1720 if (colorSpace == NULL) {
1573 colorOperator->fColorSpace = name->strRef(); 1721 colorOperator->fColorSpace = name->strRef();
1574 } else { 1722 } else {
1575 #ifdef PDF_TRACE 1723 #ifdef PDF_TRACE
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 1771
1624 bool doubles = true; 1772 bool doubles = true;
1625 if (colorOperator->fColorSpace.equals("Indexed")) { 1773 if (colorOperator->fColorSpace.equals("Indexed")) {
1626 doubles = false; 1774 doubles = false;
1627 } 1775 }
1628 1776
1629 #ifdef PDF_TRACE 1777 #ifdef PDF_TRACE
1630 printf("color space = %s, N = %i\n", colorOperator->fColorSpace.fBuffer, n); 1778 printf("color space = %s, N = %i\n", colorOperator->fColorSpace.fBuffer, n);
1631 #endif 1779 #endif
1632 1780
1781 EXPECT_OPERANDS(pdfContext, n);
1782
1633 for (int i = n - 1; i >= 0 ; i--) { 1783 for (int i = n - 1; i >= 0 ; i--) {
1634 if (doubles) { 1784 if (doubles) {
1635 c[i] = pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop(); 1785 POP_NUMBER_INTO(pdfContext, c[i]);
1636 // } else { 1786 // } else {
1637 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte xt->fObjectStack.pop(); 1787 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte xt->fObjectStack.pop();
1638 } 1788 }
1639 } 1789 }
1790 CHECK_PARAMETERS();
1640 1791
1641 // TODO(edisonn): Now, set that color. Only DeviceRGB supported. 1792 // TODO(edisonn): Now, set that color. Only DeviceRGB supported.
1642 // TODO(edisonn): do possible field values to enum at parsing time! 1793 // TODO(edisonn): do possible field values to enum at parsing time!
1643 // TODO(edisonn): support also abreviations /DeviceRGB == /RGB 1794 // TODO(edisonn): support also abreviations /DeviceRGB == /RGB
1644 if (colorOperator->fColorSpace.equals("DeviceRGB") || colorOperator->fColorS pace.equals("RGB")) { 1795 if (colorOperator->fColorSpace.equals("DeviceRGB") || colorOperator->fColorS pace.equals("RGB")) {
1645 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*c[0]), (U8CPU)(255* c[1]), (U8CPU)(255*c[2]))); 1796 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*c[0]), (U8CPU)(255* c[1]), (U8CPU)(255*c[2])));
1646 } 1797 }
1647 return kPartial_SkPdfResult; 1798 return kPartial_SkPdfResult;
1648 } 1799 }
1649 1800
1650 static SkPdfResult PdfOp_SC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1801 static SkPdfResult PdfOp_SC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1651 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 1802 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
1652 } 1803 }
1653 1804
1654 static SkPdfResult PdfOp_sc(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1805 static SkPdfResult PdfOp_sc(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1655 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing); 1806 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing);
1656 } 1807 }
1657 1808
1658 static SkPdfResult PdfOp_SCN_scn(SkPdfContext* pdfContext, SkCanvas* canvas, SkP dfColorOperator* colorOperator) { 1809 static SkPdfResult PdfOp_SCN_scn(SkPdfContext* pdfContext, SkCanvas* canvas, SkP dfColorOperator* colorOperator) {
1659 if (pdfContext->fObjectStack.top()->isName()) { 1810 if (pdfContext->fObjectStack.count() > 0 && pdfContext->fObjectStack.top()-> isName()) {
1660 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext- >fObjectStack.pop(); 1811 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext- >fObjectStack.pop();
1661 1812
1662 //Next, get the ExtGState Dictionary from the Resource Dictionary: 1813 //Next, get the ExtGState Dictionary from the Resource Dictionary:
1663 SkPdfDictionary* patternResources = pdfContext->fGraphicsState.fResource s->Pattern(pdfContext->fPdfDoc); 1814 SkPdfDictionary* patternResources = pdfContext->fGraphicsState.fResource s->Pattern(pdfContext->fPdfDoc);
1664 1815
1665 if (patternResources == NULL) { 1816 if (patternResources == NULL) {
1666 #ifdef PDF_TRACE 1817 #ifdef PDF_TRACE
1667 printf("ExtGState is NULL!\n"); 1818 printf("ExtGState is NULL!\n");
1668 #endif 1819 #endif
1669 return kIgnoreError_SkPdfResult; 1820 return kIgnoreError_SkPdfResult;
(...skipping 10 matching lines...) Expand all
1680 1831
1681 static SkPdfResult PdfOp_SCN(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) { 1832 static SkPdfResult PdfOp_SCN(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) {
1682 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fStroki ng); 1833 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fStroki ng);
1683 } 1834 }
1684 1835
1685 static SkPdfResult PdfOp_scn(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) { 1836 static SkPdfResult PdfOp_scn(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) {
1686 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStr oking); 1837 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStr oking);
1687 } 1838 }
1688 1839
1689 static SkPdfResult PdfOp_G_g(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo lorOperator* colorOperator) { 1840 static SkPdfResult PdfOp_G_g(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo lorOperator* colorOperator) {
1690 /*double gray = */pdfContext->fObjectStack.top()->numberValue(); pdfCont ext->fObjectStack.pop(); 1841 EXPECT_OPERANDS(pdfContext, 1);
1691 return kNYI_SkPdfResult; 1842 POP_NUMBER(pdfContext, gray);
1843 CHECK_PARAMETERS();
1844
1845 colorOperator->fColorSpace = strings_DeviceRGB; // TODO(edisonn): HACK - it should be device gray, but not suported right now
1846 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*gray), (U8CPU)(255*gray ), (U8CPU)(255*gray)));
1847
1848 return kPartial_SkPdfResult;
1692 } 1849 }
1693 1850
1694 static SkPdfResult PdfOp_G(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1851 static SkPdfResult PdfOp_G(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1695 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); 1852 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking);
1696 } 1853 }
1697 1854
1698 static SkPdfResult PdfOp_g(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1855 static SkPdfResult PdfOp_g(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1699 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g); 1856 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g);
1700 } 1857 }
1701 1858
1702 static SkPdfResult PdfOp_RG_rg(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf ColorOperator* colorOperator) { 1859 static SkPdfResult PdfOp_RG_rg(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf ColorOperator* colorOperator) {
1703 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1860 EXPECT_OPERANDS(pdfContext, 3);
1704 double g = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1861 POP_NUMBER(pdfContext, b);
1705 double r = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1862 POP_NUMBER(pdfContext, g);
1863 POP_NUMBER(pdfContext, r);
1864 CHECK_PARAMETERS();
1706 1865
1707 colorOperator->fColorSpace = strings_DeviceRGB; 1866 colorOperator->fColorSpace = strings_DeviceRGB;
1708 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*r), (U8CPU)(255*g), (U8 CPU)(255*b))); 1867 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*r), (U8CPU)(255*g), (U8 CPU)(255*b)));
1709 return kOK_SkPdfResult; 1868 return kOK_SkPdfResult;
1710 } 1869 }
1711 1870
1712 static SkPdfResult PdfOp_RG(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1871 static SkPdfResult PdfOp_RG(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1713 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 1872 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
1714 } 1873 }
1715 1874
1716 static SkPdfResult PdfOp_rg(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1875 static SkPdfResult PdfOp_rg(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1717 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing); 1876 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing);
1718 } 1877 }
1719 1878
1720 static SkPdfResult PdfOp_K_k(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo lorOperator* colorOperator) { 1879 static SkPdfResult PdfOp_K_k(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo lorOperator* colorOperator) {
1721 // TODO(edisonn): spec has some rules about overprint, implement them. 1880 // TODO(edisonn): spec has some rules about overprint, implement them.
1722 /*double k = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop(); 1881 EXPECT_OPERANDS(pdfContext, 4);
1723 /*double y = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop(); 1882 POP_NUMBER(pdfContext, k);
1724 /*double m = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop(); 1883 POP_NUMBER(pdfContext, y);
1725 /*double c = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop(); 1884 POP_NUMBER(pdfContext, m);
1885 POP_NUMBER(pdfContext, c);
1886 CHECK_PARAMETERS();
1726 1887
1727 colorOperator->fColorSpace = strings_DeviceCMYK; 1888 // TODO(edisonn): silly way to remove compiler warning
1889 if (k + y + m + c == 0) {
1890 return kNYI_SkPdfResult;
1891 }
1892
1893 //colorOperator->fColorSpace = strings_DeviceCMYK;
1728 // TODO(edisonn): Set color. 1894 // TODO(edisonn): Set color.
1729 return kNYI_SkPdfResult; 1895 return kNYI_SkPdfResult;
1730 } 1896 }
1731 1897
1732 static SkPdfResult PdfOp_K(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1898 static SkPdfResult PdfOp_K(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1733 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); 1899 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking);
1734 } 1900 }
1735 1901
1736 static SkPdfResult PdfOp_k(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 1902 static SkPdfResult PdfOp_k(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1737 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g); 1903 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber() ) { 2046 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber() ) {
1881 // TODO(edisonn): report error/warning 2047 // TODO(edisonn): report error/warning
1882 return; 2048 return;
1883 } 2049 }
1884 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon tAndSize->objAtAIndex(1)->numberValue()); 2050 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon tAndSize->objAtAIndex(1)->numberValue());
1885 } 2051 }
1886 2052
1887 2053
1888 //lineWidth w Set the line width in the graphics state (see “Line Width” on page 152). 2054 //lineWidth w Set the line width in the graphics state (see “Line Width” on page 152).
1889 static SkPdfResult PdfOp_w(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 2055 static SkPdfResult PdfOp_w(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1890 double lw = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 2056 EXPECT_OPERANDS(pdfContext, 1);
2057 POP_NUMBER(pdfContext, lw);
2058 CHECK_PARAMETERS();
2059
1891 return skpdfGraphicsStateApplyLW(pdfContext, lw); 2060 return skpdfGraphicsStateApplyLW(pdfContext, lw);
1892 } 2061 }
1893 2062
1894 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o n page 153). 2063 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o n page 153).
1895 static SkPdfResult PdfOp_J(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 2064 static SkPdfResult PdfOp_J(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1896 // TODO(edisonn): round/ceil to int? 2065 // TODO(edisonn): round/ceil to int?
1897 int lc = (int)pdfContext->fObjectStack.top()->numberValue(); pdfContext-> fObjectStack.pop(); 2066 EXPECT_OPERANDS(pdfContext, 1);
1898 return skpdfGraphicsStateApplyLC(pdfContext, lc); 2067 POP_NUMBER(pdfContext, lc);
2068 CHECK_PARAMETERS();
2069
2070 return skpdfGraphicsStateApplyLC(pdfContext, (int)lc);
1899 } 2071 }
1900 2072
1901 //lineJoin j Set the line join style in the graphics state (see “Line Join Style ” on page 153). 2073 //lineJoin j Set the line join style in the graphics state (see “Line Join Style ” on page 153).
1902 static SkPdfResult PdfOp_j(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 2074 static SkPdfResult PdfOp_j(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1903 // TODO(edisonn): round/ceil to int? 2075 // TODO(edisonn): round/ceil to int?
1904 int lj = (int)pdfContext->fObjectStack.top()->numberValue(); pdfContext-> fObjectStack.pop(); 2076 EXPECT_OPERANDS(pdfContext, 1);
1905 return skpdfGraphicsStateApplyLJ(pdfContext, lj); 2077 POP_NUMBER(pdfContext, lj);
2078 CHECK_PARAMETERS();
2079
2080 return skpdfGraphicsStateApplyLJ(pdfContext, (int)lj);
1906 } 2081 }
1907 2082
1908 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p age 153). 2083 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p age 153).
1909 static SkPdfResult PdfOp_M(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 2084 static SkPdfResult PdfOp_M(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1910 double ml = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 2085 EXPECT_OPERANDS(pdfContext, 1);
2086 POP_NUMBER(pdfContext, ml);
2087 CHECK_PARAMETERS();
1911 return skpdfGraphicsStateApplyML(pdfContext, ml); 2088 return skpdfGraphicsStateApplyML(pdfContext, ml);
1912 } 2089 }
1913 2090
1914 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li ne Dash Pattern” on 2091 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li ne Dash Pattern” on
1915 //page 155). 2092 //page 155).
1916 static SkPdfResult PdfOp_d(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 2093 static SkPdfResult PdfOp_d(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1917 SkPdfNativeObject* phase = pdfContext->fObjectStack.top(); pdfConte xt->fObjectStack.pop(); 2094 EXPECT_OPERANDS(pdfContext, 2);
1918 SkPdfNativeObject* array = pdfContext->fObjectStack.top(); pdfConte xt->fObjectStack.pop(); 2095 POP_OBJ(pdfContext, phase);
2096 POP_ARRAY(pdfContext, array);
2097 CHECK_PARAMETERS();
1919 2098
1920 if (!array->isArray()) { 2099 return skpdfGraphicsStateApplyD(pdfContext, array, phase);
1921 return kIgnoreError_SkPdfResult;
1922 }
1923
1924 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)array, phase);
1925 } 2100 }
1926 2101
1927 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see “Rendering Intents” on page 197). 2102 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see “Rendering Intents” on page 197).
1928 static SkPdfResult PdfOp_ri(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2103 static SkPdfResult PdfOp_ri(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1929 pdfContext->fObjectStack.pop(); 2104 pdfContext->fObjectStack.pop();
1930 2105
1931 return kNYI_SkPdfResult; 2106 return kNYI_SkPdfResult;
1932 } 2107 }
1933 2108
1934 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1, “Flatness 2109 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1, “Flatness
1935 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci- 2110 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci-
1936 //fies the output device’s default flatness tolerance. 2111 //fies the output device’s default flatness tolerance.
1937 static SkPdfResult PdfOp_i(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) { 2112 static SkPdfResult PdfOp_i(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL ooper** looper) {
1938 pdfContext->fObjectStack.pop(); 2113 EXPECT_OPERANDS(pdfContext, 1);
2114 POP_NUMBER(pdfContext, flatness);
2115 CHECK_PARAMETERS();
2116
2117 if (flatness < 0 || flatness > 100) {
2118 return kError_SkPdfResult;
2119 }
1939 2120
1940 return kNYI_SkPdfResult; 2121 return kNYI_SkPdfResult;
1941 } 2122 }
1942 2123
1943 SkTDict<SkXfermode::Mode> gPdfBlendModes(20); 2124 SkTDict<SkXfermode::Mode> gPdfBlendModes(20);
1944 2125
1945 class InitBlendModes { 2126 class InitBlendModes {
1946 public: 2127 public:
1947 InitBlendModes() { 2128 InitBlendModes() {
1948 // TODO(edisonn): use the python code generator? 2129 // TODO(edisonn): use the python code generator?
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 } 2239 }
2059 2240
2060 static void skpdfGraphicsStateApplyAIS(SkPdfContext* pdfContext, bool alphaSourc e) { 2241 static void skpdfGraphicsStateApplyAIS(SkPdfContext* pdfContext, bool alphaSourc e) {
2061 pdfContext->fGraphicsState.fAlphaSource = alphaSource; 2242 pdfContext->fGraphicsState.fAlphaSource = alphaSource;
2062 } 2243 }
2063 2244
2064 2245
2065 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is 2246 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is
2066 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section). 2247 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section).
2067 static SkPdfResult PdfOp_gs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2248 static SkPdfResult PdfOp_gs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2068 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb jectStack.pop(); 2249 EXPECT_OPERANDS(pdfContext, 1);
2250 POP_NAME(pdfContext, name);
2251 CHECK_PARAMETERS();
2069 2252
2070 #ifdef PDF_TRACE 2253 #ifdef PDF_TRACE
2071 SkString str; 2254 SkString str;
2072 #endif 2255 #endif
2073 2256
2074 //Next, get the ExtGState Dictionary from the Resource Dictionary: 2257 //Next, get the ExtGState Dictionary from the Resource Dictionary:
2075 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources ->ExtGState(pdfContext->fPdfDoc); 2258 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources ->ExtGState(pdfContext->fPdfDoc);
2076 2259
2077 if (extGStateDictionary == NULL) { 2260 if (extGStateDictionary == NULL) {
2078 #ifdef PDF_TRACE 2261 #ifdef PDF_TRACE
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 skpdfGraphicsStateApplyAIS(pdfContext, gs->AIS(pdfContext->fPdfDoc)); 2332 skpdfGraphicsStateApplyAIS(pdfContext, gs->AIS(pdfContext->fPdfDoc));
2150 } 2333 }
2151 2334
2152 return kOK_SkPdfResult; 2335 return kOK_SkPdfResult;
2153 } 2336 }
2154 2337
2155 //charSpace Tc Set the character spacing, Tc 2338 //charSpace Tc Set the character spacing, Tc
2156 //, to charSpace, which is a number expressed in unscaled text space units. Char acter spacing is used by the Tj, TJ, and ' operators. 2339 //, to charSpace, which is a number expressed in unscaled text space units. Char acter spacing is used by the Tj, TJ, and ' operators.
2157 //Initial value: 0. 2340 //Initial value: 0.
2158 SkPdfResult PdfOp_Tc(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper* * looper) { 2341 SkPdfResult PdfOp_Tc(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper* * looper) {
2159 double charSpace = pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop(); 2342 EXPECT_OPERANDS(pdfContext, 1);
2343 POP_NUMBER(pdfContext, charSpace);
2344 CHECK_PARAMETERS();
2345
2160 pdfContext->fGraphicsState.fCharSpace = charSpace; 2346 pdfContext->fGraphicsState.fCharSpace = charSpace;
2161 2347
2162 return kOK_SkPdfResult; 2348 return kOK_SkPdfResult;
2163 } 2349 }
2164 2350
2165 //wordSpace Tw Set the word spacing, T 2351 //wordSpace Tw Set the word spacing, T
2166 //w 2352 //w
2167 //, to wordSpace, which is a number expressed in unscaled 2353 //, to wordSpace, which is a number expressed in unscaled
2168 //text space units. Word spacing is used by the Tj, TJ, and ' operators. Initial 2354 //text space units. Word spacing is used by the Tj, TJ, and ' operators. Initial
2169 //value: 0. 2355 //value: 0.
2170 SkPdfResult PdfOp_Tw(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper* * looper) { 2356 SkPdfResult PdfOp_Tw(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper* * looper) {
2171 double wordSpace = pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop(); 2357 EXPECT_OPERANDS(pdfContext, 1);
2358 POP_NUMBER(pdfContext, wordSpace);
2359 CHECK_PARAMETERS();
2360
2172 pdfContext->fGraphicsState.fWordSpace = wordSpace; 2361 pdfContext->fGraphicsState.fWordSpace = wordSpace;
2173 2362
2174 return kOK_SkPdfResult; 2363 return kOK_SkPdfResult;
2175 } 2364 }
2176 2365
2177 //scale Tz Set the horizontal scaling, Th 2366 //scale Tz Set the horizontal scaling, Th
2178 //, to (scale ˜ 100). scale is a number specifying the 2367 //, to (scale ˜ 100). scale is a number specifying the
2179 //percentage of the normal width. Initial value: 100 (normal width). 2368 //percentage of the normal width. Initial value: 100 (normal width).
2180 static SkPdfResult PdfOp_Tz(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2369 static SkPdfResult PdfOp_Tz(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2181 /*double scale = */pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop(); 2370 EXPECT_OPERANDS(pdfContext, 1);
2371 POP_NUMBER(pdfContext, scale);
2372 CHECK_PARAMETERS();
2373
2374 if (scale < 0) {
2375 return kError_SkPdfResult;
2376 }
2182 2377
2183 return kNYI_SkPdfResult; 2378 return kNYI_SkPdfResult;
2184 } 2379 }
2185 2380
2186 //render Tr Set the text rendering mode, T 2381 //render Tr Set the text rendering mode, T
2187 //mode, to render, which is an integer. Initial value: 0. 2382 //mode, to render, which is an integer. Initial value: 0.
2188 static SkPdfResult PdfOp_Tr(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2383 static SkPdfResult PdfOp_Tr(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2189 /*double render = */pdfContext->fObjectStack.top()->numberValue(); pdfCo ntext->fObjectStack.pop(); 2384 EXPECT_OPERANDS(pdfContext, 1);
2385 POP_INTEGER(pdfContext, mode);
2386 CHECK_PARAMETERS();
2387
2388 if (mode < 0) { // TODO(edisonn): function/enums with supported modes
2389 return kError_SkPdfResult;
2390 }
2190 2391
2191 return kNYI_SkPdfResult; 2392 return kNYI_SkPdfResult;
2192 } 2393 }
2193 //rise Ts Set the text rise, Trise, to rise, which is a number expressed in unsc aled text space 2394 //rise Ts Set the text rise, Trise, to rise, which is a number expressed in unsc aled text space
2194 //units. Initial value: 0. 2395 //units. Initial value: 0.
2195 static SkPdfResult PdfOp_Ts(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2396 static SkPdfResult PdfOp_Ts(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2196 /*double rise = */pdfContext->fObjectStack.top()->numberValue(); pdfCont ext->fObjectStack.pop(); 2397 EXPECT_OPERANDS(pdfContext, 1);
2398 POP_NUMBER(pdfContext, rise);
2399 CHECK_PARAMETERS();
2400
2401 if (rise < 0) {
2402 return kNYI_SkPdfResult;
2403 }
2197 2404
2198 return kNYI_SkPdfResult; 2405 return kNYI_SkPdfResult;
2199 } 2406 }
2200 2407
2201 //wx wy d0 2408 //wx wy d0
2202 static SkPdfResult PdfOp_d0(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2409 static SkPdfResult PdfOp_d0(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2203 pdfContext->fObjectStack.pop(); 2410 EXPECT_OPERANDS(pdfContext, 2);
2204 pdfContext->fObjectStack.pop(); 2411 POP_NUMBER(pdfContext, wy);
2412 POP_NUMBER(pdfContext, wx);
2413 CHECK_PARAMETERS();
2414
2415 if (wx < 0 || wy < 0) {
2416 return kError_SkPdfResult;
2417 }
2205 2418
2206 return kNYI_SkPdfResult; 2419 return kNYI_SkPdfResult;
2207 } 2420 }
2208 2421
2209 //wx wy llx lly urx ury d1 2422 //wx wy llx lly urx ury d1
2210 static SkPdfResult PdfOp_d1(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2423 static SkPdfResult PdfOp_d1(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2211 pdfContext->fObjectStack.pop(); 2424 EXPECT_OPERANDS(pdfContext, 6);
2212 pdfContext->fObjectStack.pop(); 2425 POP_NUMBER(pdfContext, ury);
2213 pdfContext->fObjectStack.pop(); 2426 POP_NUMBER(pdfContext, urx);
2214 pdfContext->fObjectStack.pop(); 2427 POP_NUMBER(pdfContext, lly);
2215 pdfContext->fObjectStack.pop(); 2428 POP_NUMBER(pdfContext, llx);
2216 pdfContext->fObjectStack.pop(); 2429 POP_NUMBER(pdfContext, wy);
2430 POP_NUMBER(pdfContext, wx);
2431 CHECK_PARAMETERS();
2432
2433 if (wx + wy + llx + lly + urx + ury) {
2434 return kNYI_SkPdfResult;
2435 }
2217 2436
2218 return kNYI_SkPdfResult; 2437 return kNYI_SkPdfResult;
2219 } 2438 }
2220 2439
2221 //name sh 2440 //name sh
2222 static SkPdfResult PdfOp_sh(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2441 static SkPdfResult PdfOp_sh(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2223 pdfContext->fObjectStack.pop(); 2442 EXPECT_OPERANDS(pdfContext, 1);
2443 POP_NAME(pdfContext, name);
2444 CHECK_PARAMETERS();
2445
2446 if (name == NULL) {
2447 return kError_SkPdfResult;
2448 }
2224 2449
2225 return kNYI_SkPdfResult; 2450 return kNYI_SkPdfResult;
2226 } 2451 }
2227 2452
2228 //name Do 2453 //name Do
2229 static SkPdfResult PdfOp_Do(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2454 static SkPdfResult PdfOp_Do(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2230 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb jectStack.pop(); 2455 EXPECT_OPERANDS(pdfContext, 1);
2456 POP_NAME(pdfContext, name);
2457 CHECK_PARAMETERS();
2231 2458
2232 SkPdfDictionary* xObject = pdfContext->fGraphicsState.fResources->XObject(p dfContext->fPdfDoc); 2459 SkPdfDictionary* xObject = pdfContext->fGraphicsState.fResources->XObject(p dfContext->fPdfDoc);
2233 2460
2234 if (xObject == NULL) { 2461 if (xObject == NULL) {
2235 #ifdef PDF_TRACE 2462 #ifdef PDF_TRACE
2236 printf("XObject is NULL!\n"); 2463 printf("XObject is NULL!\n");
2237 #endif 2464 #endif
2238 return kIgnoreError_SkPdfResult; 2465 return kIgnoreError_SkPdfResult;
2239 } 2466 }
2240 2467
2241 SkPdfNativeObject* value = xObject->get(name); 2468 SkPdfNativeObject* value = xObject->get(name);
2242 value = pdfContext->fPdfDoc->resolveReference(value); 2469 value = pdfContext->fPdfDoc->resolveReference(value);
2243 2470
2244 #ifdef PDF_TRACE 2471 #ifdef PDF_TRACE
2245 // value->ToString(str); 2472 // value->ToString(str);
2246 // printf("Do object value: %s\n", str); 2473 // printf("Do object value: %s\n", str);
2247 #endif 2474 #endif
2248 2475
2249 return doXObject(pdfContext, canvas, value); 2476 return doXObject(pdfContext, canvas, value);
2250 } 2477 }
2251 2478
2252 //tag MP Designate a marked-content point. tag is a name object indicating the r ole or 2479 //tag MP Designate a marked-content point. tag is a name object indicating the r ole or
2253 //significance of the point. 2480 //significance of the point.
2254 static SkPdfResult PdfOp_MP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2481 static SkPdfResult PdfOp_MP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2255 pdfContext->fObjectStack.pop(); 2482 EXPECT_OPERANDS(pdfContext, 1);
2483 POP_OBJ(pdfContext, tag);
2484 CHECK_PARAMETERS();
2485
2486 if (tag == NULL) {
2487 return kNYI_SkPdfResult;
2488 }
2256 2489
2257 return kNYI_SkPdfResult; 2490 return kNYI_SkPdfResult;
2258 } 2491 }
2259 2492
2260 //tag properties DP Designate a marked-content point with an associated property list. tag is a 2493 //tag properties DP Designate a marked-content point with an associated property list. tag is a
2261 //name object indicating the role or significance of the point; properties is 2494 //name object indicating the role or significance of the point; properties is
2262 //either an inline dictionary containing the property list or a name object 2495 //either an inline dictionary containing the property list or a name object
2263 //associated with it in the Properties subdictionary of the current resource 2496 //associated with it in the Properties subdictionary of the current resource
2264 //dictionary (see Section 9.5.1, “Property Lists”). 2497 //dictionary (see Section 9.5.1, “Property Lists”).
2265 static SkPdfResult PdfOp_DP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 2498 static SkPdfResult PdfOp_DP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
2266 pdfContext->fObjectStack.pop(); 2499 EXPECT_OPERANDS(pdfContext, 2);
2267 pdfContext->fObjectStack.pop(); 2500 POP_OBJ(pdfContext, properties);
2501 POP_OBJ(pdfContext, tag);
2502 CHECK_PARAMETERS();
2503
2504 if (tag == NULL || properties == NULL) {
2505 return kNYI_SkPdfResult;
2506 }
2268 2507
2269 return kNYI_SkPdfResult; 2508 return kNYI_SkPdfResult;
2270 } 2509 }
2271 2510
2272 //tag BMC Begin a marked-content sequence terminated by a balancing EMC operator . 2511 //tag BMC Begin a marked-content sequence terminated by a balancing EMC operator .
2273 //tag is a name object indicating the role or significance of the sequence. 2512 //tag is a name object indicating the role or significance of the sequence.
2274 static SkPdfResult PdfOp_BMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) { 2513 static SkPdfResult PdfOp_BMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) {
2275 pdfContext->fObjectStack.pop(); 2514 EXPECT_OPERANDS(pdfContext, 1);
2515 POP_OBJ(pdfContext, tag);
2516 CHECK_PARAMETERS();
2517
2518 if (tag == NULL) {
2519 return kNYI_SkPdfResult;
2520 }
2276 2521
2277 return kNYI_SkPdfResult; 2522 return kNYI_SkPdfResult;
2278 } 2523 }
2279 2524
2280 //tag properties BDC Begin a marked-content sequence with an associated property list, terminated 2525 //tag properties BDC Begin a marked-content sequence with an associated property list, terminated
2281 //by a balancing EMCoperator. tag is a name object indicating the role or signif icance of the sequence; propertiesis either an inline dictionary containing the 2526 //by a balancing EMCoperator. tag is a name object indicating the role or signif icance of the sequence; propertiesis either an inline dictionary containing the
2282 //property list or a name object associated with it in the Properties subdiction ary of the current resource dictionary (see Section 9.5.1, “Property Lists”). 2527 //property list or a name object associated with it in the Properties subdiction ary of the current resource dictionary (see Section 9.5.1, “Property Lists”).
2283 static SkPdfResult PdfOp_BDC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) { 2528 static SkPdfResult PdfOp_BDC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) {
2284 pdfContext->fObjectStack.pop(); 2529 EXPECT_OPERANDS(pdfContext, 2);
2285 pdfContext->fObjectStack.pop(); 2530 POP_OBJ(pdfContext, properties);
2531 POP_OBJ(pdfContext, tag);
2532 CHECK_PARAMETERS();
2533
2534 if (tag == NULL || properties == NULL) {
2535 return kNYI_SkPdfResult;
2536 }
2286 2537
2287 return kNYI_SkPdfResult; 2538 return kNYI_SkPdfResult;
2288 } 2539 }
2289 2540
2290 //— EMC End a marked-content sequence begun by a BMC or BDC operator. 2541 //— EMC End a marked-content sequence begun by a BMC or BDC operator.
2291 static SkPdfResult PdfOp_EMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) { 2542 static SkPdfResult PdfOp_EMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke nLooper** looper) {
2292 return kNYI_SkPdfResult; 2543 return kNYI_SkPdfResult;
2293 } 2544 }
2294 2545
2295 static void initPdfOperatorRenderes() { 2546 static void initPdfOperatorRenderes() {
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
2639 2890
2640 rect = SkRect::MakeWH(width, height); 2891 rect = SkRect::MakeWH(width, height);
2641 2892
2642 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght)); 2893 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght));
2643 2894
2644 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); 2895 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output)));
2645 SkCanvas canvas(device); 2896 SkCanvas canvas(device);
2646 2897
2647 return renderer.renderPage(page, &canvas, rect); 2898 return renderer.renderPage(page, &canvas, rect);
2648 } 2899 }
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