367
367
for (i = 0; i < obj->arrayGetLength(); ++i) {
368
368
obj->arrayGet(i, &obj2);
369
369
if (!obj2.isStream()) {
370
#ifdef POPPLER_NEW_ERRORAPI
371
error(errInternal, -1, "Weird page contents");
370
373
error(-1, const_cast<char*>("Weird page contents"));
376
380
} else if (!obj->isStream()) {
377
error(-1, const_cast<char*>("Weird page contents"));
381
#ifdef POPPLER_NEW_ERRORAPI
382
error(errInternal, -1, "Weird page contents");
384
error(-1, const_cast<char*>("Weird page contents"));
380
388
parser = new Parser(xref, new Lexer(xref, obj), gFalse);
420
428
// too many arguments - something is wrong
430
#ifdef POPPLER_NEW_ERRORAPI
431
error(errSyntaxError, getPos(), "Too many args in content stream");
422
433
error(getPos(), const_cast<char*>("Too many args in content stream"));
423
435
if (printCommands) {
424
436
printf("throwing away arg: ");
425
437
obj.print(stdout);
437
449
// args at end with no command
438
450
if (numArgs > 0) {
451
#ifdef POPPLER_NEW_ERRORAPI
452
error(errSyntaxError, getPos(), "Leftover args in content stream");
439
454
error(getPos(), const_cast<char*>("Leftover args in content stream"));
440
456
if (printCommands) {
441
457
printf("%d leftovers:", numArgs);
442
458
for (i = 0; i < numArgs; ++i) {
502
518
name = cmd->getCmd();
503
519
if (!(op = findOp(name))) {
504
520
if (ignoreUndef == 0)
521
#ifdef POPPLER_NEW_ERRORAPI
522
error(errSyntaxError, getPos(), "Unknown operator '{0:s}'", name);
505
524
error(getPos(), const_cast<char*>("Unknown operator '%s'"), name);
511
531
if (op->numArgs >= 0) {
512
532
if (numArgs < op->numArgs) {
533
#ifdef POPPLER_NEW_ERRORAPI
534
error(errSyntaxError, getPos(), "Too few ({0:d}) args to '{1:d}' operator", numArgs, name);
513
536
error(getPos(), const_cast<char*>("Too few (%d) args to '%s' operator"), numArgs, name);
516
540
if (numArgs > op->numArgs) {
542
#ifdef POPPLER_NEW_ERRORAPI
543
error(errSyntaxError, getPos(), "Too many ({0:d}) args to '{1:s}' operator", numArgs, name);
518
545
error(getPos(), "Too many (%d) args to '%s' operator", numArgs, name);
520
548
argPtr += numArgs - op->numArgs;
521
549
numArgs = op->numArgs;
524
552
if (numArgs > -op->numArgs) {
553
#ifdef POPPLER_NEW_ERRORAPI
554
error(errSyntaxError, getPos(), "Too many ({0:d}) args to '{1:s}' operator",
525
556
error(getPos(), const_cast<char*>("Too many (%d) args to '%s' operator"),
530
562
for (i = 0; i < numArgs; ++i) {
531
563
if (!checkArg(&argPtr[i], op->tchk[i])) {
564
#ifdef POPPLER_NEW_ERRORAPI
565
error(errSyntaxError, getPos(), "Arg #{0:d} to '{1:s}' operator is wrong type ({2:s})",
532
567
error(getPos(), const_cast<char*>("Arg #%d to '%s' operator is wrong type (%s)"),
533
569
i, name, argPtr[i].getTypeName());
692
728
if (!obj1.isDict()) {
729
#ifdef POPPLER_NEW_ERRORAPI
730
error(errSyntaxError, getPos(), "ExtGState '{0:s}' is wrong type"), args[0].getName();
693
732
error(getPos(), const_cast<char*>("ExtGState '%s' is wrong type"), args[0].getName());
705
745
if (state->parseBlendMode(&obj2, &mode)) {
706
746
state->setBlendMode(mode);
748
#ifdef POPPLER_NEW_ERRORAPI
749
error(errSyntaxError, getPos(), "Invalid blend mode in ExtGState");
708
751
error(getPos(), const_cast<char*>("Invalid blend mode in ExtGState"));
764
808
state->setTransfer(funcs);
766
810
} else if (!obj2.isNull()) {
811
#ifdef POPPLER_NEW_ERRORAPI
812
error(errSyntaxError, getPos(), "Invalid transfer function in ExtGState");
767
814
error(getPos(), const_cast<char*>("Invalid transfer function in ExtGState"));
784
832
funcs[0] = Function::parse(&obj3);
785
833
if (funcs[0]->getInputSize() != 1 ||
786
834
funcs[0]->getOutputSize() != 1) {
788
const_cast<char*>("Invalid transfer function in soft mask in ExtGState"));
835
#ifdef POPPLER_NEW_ERRORAPI
836
error(errSyntaxError, getPos(), "Invalid transfer function in soft mask in ExtGState");
838
error(getPos(), const_cast<char*>("Invalid transfer function in soft mask in ExtGState"));
809
860
blendingColorSpace = NULL;
810
861
isolated = knockout = gFalse;
811
862
if (!obj4.dictLookup(const_cast<char*>("CS"), &obj5)->isNull()) {
812
#ifdef POPPLER_NEW_COLOR_SPACE_API
863
#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI)
813
864
blendingColorSpace = GfxColorSpace::parse(&obj5, NULL);
815
866
blendingColorSpace = GfxColorSpace::parse(&obj5);
894
#ifdef POPPLER_NEW_ERRORAPI
895
error(errSyntaxError, getPos(), "Invalid soft mask in ExtGState - missing group");
843
897
error(getPos(), const_cast<char*>("Invalid soft mask in ExtGState - missing group"));
902
#ifdef POPPLER_NEW_ERRORAPI
903
error(errSyntaxError, getPos(), "Invalid soft mask in ExtGState - missing group");
847
905
error(getPos(), const_cast<char*>("Invalid soft mask in ExtGState - missing group"));
850
909
} else if (!obj2.isNull()) {
910
#ifdef POPPLER_NEW_ERRORAPI
911
error(errSyntaxError, getPos(), "Invalid soft mask in ExtGState");
851
913
error(getPos(), const_cast<char*>("Invalid soft mask in ExtGState"));
876
939
// check form type
877
940
dict->lookup(const_cast<char*>("FormType"), &obj1);
878
941
if (!(obj1.isNull() || (obj1.isInt() && obj1.getInt() == 1))) {
942
#ifdef POPPLER_NEW_ERRORAPI
943
error(errSyntaxError, getPos(), "Unknown form type");
879
945
error(getPos(), const_cast<char*>("Unknown form type"));
884
951
dict->lookup(const_cast<char*>("BBox"), &obj1);
885
952
if (!obj1.isArray()) {
954
#ifdef POPPLER_NEW_ERRORAPI
955
error(errSyntaxError, getPos(), "Bad form bounding box");
887
957
error(getPos(), const_cast<char*>("Bad form bounding box"));
890
961
for (i = 0; i < 4; ++i) {
1013
1084
state->setFillPattern(NULL);
1014
1085
res->lookupColorSpace(args[0].getName(), &obj);
1015
#ifdef POPPLER_NEW_COLOR_SPACE_API
1086
#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI)
1016
1087
if (obj.isNull()) {
1017
1088
colorSpace = GfxColorSpace::parse(&args[0], NULL);
1032
1103
state->setFillColor(&color);
1033
1104
builder->updateStyle(state);
1106
#ifdef POPPLER_NEW_ERRORAPI
1107
error(errSyntaxError, getPos(), "Bad color space (fill)");
1035
1109
error(getPos(), const_cast<char*>("Bad color space (fill)"));
1044
1119
state->setStrokePattern(NULL);
1045
1120
res->lookupColorSpace(args[0].getName(), &obj);
1046
#ifdef POPPLER_NEW_COLOR_SPACE_API
1121
#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI)
1047
1122
if (obj.isNull()) {
1048
1123
colorSpace = GfxColorSpace::parse(&args[0], NULL);
1063
1138
state->setStrokeColor(&color);
1064
1139
builder->updateStyle(state);
1141
#ifdef POPPLER_NEW_ERRORAPI
1142
error(errSyntaxError, getPos(), "Bad color space (stroke)");
1066
1144
error(getPos(), const_cast<char*>("Bad color space (stroke)"));
1074
1153
if (numArgs != state->getFillColorSpace()->getNComps()) {
1154
#ifdef POPPLER_NEW_ERRORAPI
1155
error(errSyntaxError, getPos(), "Incorrect number of arguments in 'sc' command");
1075
1157
error(getPos(), const_cast<char*>("Incorrect number of arguments in 'sc' command"));
1078
1161
state->setFillPattern(NULL);
1090
1173
if (numArgs != state->getStrokeColorSpace()->getNComps()) {
1174
#ifdef POPPLER_NEW_ERRORAPI
1175
error(errSyntaxError, getPos(), "Incorrect number of arguments in 'SC' command");
1091
1177
error(getPos(), const_cast<char*>("Incorrect number of arguments in 'SC' command"));
1094
1181
state->setStrokePattern(NULL);
1109
1196
if (!((GfxPatternColorSpace *)state->getFillColorSpace())->getUnder() ||
1110
1197
numArgs - 1 != ((GfxPatternColorSpace *)state->getFillColorSpace())
1111
1198
->getUnder()->getNComps()) {
1199
#ifdef POPPLER_NEW_ERRORAPI
1200
error(errSyntaxError, getPos(), "Incorrect number of arguments in 'scn' command");
1112
1202
error(getPos(), const_cast<char*>("Incorrect number of arguments in 'scn' command"));
1115
1206
for (i = 0; i < numArgs - 1 && i < gfxColorMaxComps; ++i) {
1120
1211
state->setFillColor(&color);
1121
1212
builder->updateStyle(state);
1123
#ifdef POPPLER_NEW_COLOR_SPACE_API
1214
#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI)
1124
1215
if (args[numArgs-1].isName() &&
1125
1216
(pattern = res->lookupPattern(args[numArgs-1].getName(), NULL))) {
1126
1217
state->setFillPattern(pattern);
1138
1229
if (numArgs != state->getFillColorSpace()->getNComps()) {
1230
#ifdef POPPLER_NEW_ERRORAPI
1231
error(errSyntaxError, getPos(), "Incorrect number of arguments in 'scn' command");
1139
1233
error(getPos(), const_cast<char*>("Incorrect number of arguments in 'scn' command"));
1142
1237
state->setFillPattern(NULL);
1161
1256
->getUnder() ||
1162
1257
numArgs - 1 != ((GfxPatternColorSpace *)state->getStrokeColorSpace())
1163
1258
->getUnder()->getNComps()) {
1259
#ifdef POPPLER_NEW_ERRORAPI
1260
error(errSyntaxError, getPos(), "Incorrect number of arguments in 'SCN' command");
1164
1262
error(getPos(), const_cast<char*>("Incorrect number of arguments in 'SCN' command"));
1167
1266
for (i = 0; i < numArgs - 1 && i < gfxColorMaxComps; ++i) {
1172
1271
state->setStrokeColor(&color);
1173
1272
builder->updateStyle(state);
1175
#ifdef POPPLER_NEW_COLOR_SPACE_API
1274
#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI)
1176
1275
if (args[numArgs-1].isName() &&
1177
1276
(pattern = res->lookupPattern(args[numArgs-1].getName(), NULL))) {
1178
1277
state->setStrokePattern(pattern);
1190
1289
if (numArgs != state->getStrokeColorSpace()->getNComps()) {
1290
#ifdef POPPLER_NEW_ERRORAPI
1291
error(errSyntaxError, getPos(), "Incorrect number of arguments in 'SCN' command");
1191
1293
error(getPos(), const_cast<char*>("Incorrect number of arguments in 'SCN' command"));
1194
1297
state->setStrokePattern(NULL);
1213
1316
void PdfParser::opLineTo(Object args[], int numArgs) {
1214
1317
if (!state->isCurPt()) {
1318
#ifdef POPPLER_NEW_ERRORAPI
1319
error(errSyntaxError, getPos(), "No current point in lineto");
1215
1321
error(getPos(), const_cast<char*>("No current point in lineto"));
1218
1325
state->lineTo(args[0].getNum(), args[1].getNum());
1222
1329
double x1, y1, x2, y2, x3, y3;
1224
1331
if (!state->isCurPt()) {
1332
#ifdef POPPLER_NEW_ERRORAPI
1333
error(errSyntaxError, getPos(), "No current point in curveto");
1225
1335
error(getPos(), const_cast<char*>("No current point in curveto"));
1228
1339
x1 = args[0].getNum();
1238
1349
double x1, y1, x2, y2, x3, y3;
1240
1351
if (!state->isCurPt()) {
1352
#ifdef POPPLER_NEW_ERRORAPI
1353
error(errSyntaxError, getPos(), "No current point in curveto1");
1241
1355
error(getPos(), const_cast<char*>("No current point in curveto1"));
1244
1359
x1 = state->getCurX();
1254
1369
double x1, y1, x2, y2, x3, y3;
1256
1371
if (!state->isCurPt()) {
1372
#ifdef POPPLER_NEW_ERRORAPI
1373
error(errSyntaxError, getPos(), "No current point in curveto2");
1257
1375
error(getPos(), const_cast<char*>("No current point in curveto2"));
1260
1379
x1 = args[0].getNum();
1283
1402
void PdfParser::opClosePath(Object args[], int numArgs) {
1284
1403
if (!state->isCurPt()) {
1404
#ifdef POPPLER_NEW_ERRORAPI
1405
error(errSyntaxError, getPos(), "No current point in closepath");
1285
1407
error(getPos(), const_cast<char*>("No current point in closepath"));
1288
1411
state->closePath();
1440
1563
doShadingPatternFillFallback((GfxShadingPattern *)pattern, gFalse, eoFill);
1566
#ifdef POPPLER_NEW_ERRORAPI
1567
error(errUnimplemented, getPos(), "Unimplemented pattern type (%d) in fill",
1443
1569
error(getPos(), const_cast<char*>("Unimplemented pattern type (%d) in fill"),
1444
1571
pattern->getType());
1459
1586
doShadingPatternFillFallback((GfxShadingPattern *)pattern, gTrue, gFalse);
1589
#ifdef POPPLER_NEW_ERRORAPI
1590
error(errUnimplemented, getPos(), "Unimplemented pattern type ({0:d}) in stroke",
1462
1592
error(getPos(), const_cast<char*>("Unimplemented pattern type (%d) in stroke"),
1463
1594
pattern->getType());
1579
1710
double *matrix = NULL;
1580
1711
GBool savedState = gFalse;
1582
#ifdef POPPLER_NEW_COLOR_SPACE_API
1713
#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI)
1583
1714
if (!(shading = res->lookupShading(args[0].getName(), NULL))) {
2157
2288
void PdfParser::opShowText(Object args[], int numArgs) {
2158
2289
if (!state->getFont()) {
2290
#ifdef POPPLER_NEW_ERRORAPI
2291
error(errSyntaxError, getPos(), "No font in show");
2159
2293
error(getPos(), const_cast<char*>("No font in show"));
2162
2297
if (fontChanged) {
2172
2307
if (!state->getFont()) {
2308
#ifdef POPPLER_NEW_ERRORAPI
2309
error(errSyntaxError, getPos(), "No font in move/show");
2173
2311
error(getPos(), const_cast<char*>("No font in move/show"));
2176
2315
if (fontChanged) {
2190
2329
if (!state->getFont()) {
2330
#ifdef POPPLER_NEW_ERRORAPI
2331
error(errSyntaxError, getPos(), "No font in move/set/show");
2191
2333
error(getPos(), const_cast<char*>("No font in move/set/show"));
2194
2337
if (fontChanged) {
2213
2356
if (!state->getFont()) {
2357
#ifdef POPPLER_NEW_ERRORAPI
2358
error(errSyntaxError, getPos(), "No font in show/space");
2214
2360
error(getPos(), const_cast<char*>("No font in show/space"));
2217
2364
if (fontChanged) {
2236
2383
} else if (obj.isString()) {
2237
2384
doShowText(obj.getString());
2386
#ifdef POPPLER_NEW_ERRORAPI
2387
error(errSyntaxError, getPos(), "Element of show/space array must be number or string");
2239
2389
error(getPos(), const_cast<char*>("Element of show/space array must be number or string"));
2334
2485
if (charProc.isStream()) {
2335
2486
//parse(&charProc, gFalse); // TODO: parse into SVG font
2488
#ifdef POPPLER_NEW_ERRORAPI
2489
error(errSyntaxError, getPos(), "Missing or bad Type3 CharProc entry");
2337
2491
error(getPos(), const_cast<char*>("Missing or bad Type3 CharProc entry"));
2339
2494
//out->endType3Char(state);
2412
2567
if (!obj1.isStream()) {
2568
#ifdef POPPLER_NEW_ERRORAPI
2569
error(errSyntaxError, getPos(), "XObject '{0:s}' is wrong type", name);
2413
2571
error(getPos(), const_cast<char*>("XObject '%s' is wrong type"), name);
2426
2585
/* out->psXObject(obj1.getStream(),
2427
2586
obj3.isStream() ? obj3.getStream() : (Stream *)NULL);*/
2428
2587
} else if (obj2.isName()) {
2588
#ifdef POPPLER_NEW_ERRORAPI
2589
error(errSyntaxError, getPos(), "Unknown XObject subtype '{0:s}'", obj2.getName());
2429
2591
error(getPos(), const_cast<char*>("Unknown XObject subtype '%s'"), obj2.getName());
2594
#ifdef POPPLER_NEW_ERRORAPI
2595
error(errSyntaxError, getPos(), "XObject subtype is missing or wrong type");
2431
2597
error(getPos(), const_cast<char*>("XObject subtype is missing or wrong type"));
2561
2728
if (!obj1.isNull()) {
2562
#ifdef POPPLER_NEW_COLOR_SPACE_API
2729
#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI)
2563
2730
colorSpace = GfxColorSpace::parse(&obj1, NULL);
2565
2732
colorSpace = GfxColorSpace::parse(&obj1);
2651
#ifdef POPPLER_NEW_COLOR_SPACE_API
2818
#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI)
2652
2819
maskColorSpace = GfxColorSpace::parse(&obj1, NULL);
2654
2821
maskColorSpace = GfxColorSpace::parse(&obj1);
2928
#ifdef POPPLER_NEW_ERRORAPI
2929
error(errSyntaxError, getPos(), "Bad image parameters");
2761
2931
error(getPos(), const_cast<char*>("Bad image parameters"));
2764
2935
void PdfParser::doForm(Object *str) {
2783
2954
// check form type
2784
2955
dict->lookup(const_cast<char*>("FormType"), &obj1);
2785
2956
if (!(obj1.isNull() || (obj1.isInt() && obj1.getInt() == 1))) {
2957
#ifdef POPPLER_NEW_ERRORAPI
2958
error(errSyntaxError, getPos(), "Unknown form type");
2786
2960
error(getPos(), const_cast<char*>("Unknown form type"));
2791
2966
dict->lookup(const_cast<char*>("BBox"), &bboxObj);
2792
2967
if (!bboxObj.isArray()) {
2793
2968
bboxObj.free();
2969
#ifdef POPPLER_NEW_ERRORAPI
2970
error(errSyntaxError, getPos(), "Bad form bounding box");
2794
2972
error(getPos(), const_cast<char*>("Bad form bounding box"));
2797
2976
for (i = 0; i < 4; ++i) {
2827
3006
if (obj1.dictLookup(const_cast<char*>("S"), &obj2)->isName(const_cast<char*>("Transparency"))) {
2828
3007
transpGroup = gTrue;
2829
3008
if (!obj1.dictLookup(const_cast<char*>("CS"), &obj3)->isNull()) {
2830
#ifdef POPPLER_NEW_COLOR_SPACE_API
3009
#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI)
2831
3010
blendingColorSpace = GfxColorSpace::parse(&obj3, NULL);
2833
3012
blendingColorSpace = GfxColorSpace::parse(&obj3);
2990
3169
parser->getObj(&obj);
2991
3170
while (!obj.isCmd(const_cast<char*>("ID")) && !obj.isEOF()) {
2992
3171
if (!obj.isName()) {
3172
#ifdef POPPLER_NEW_ERRORAPI
3173
error(errSyntaxError, getPos(), "Inline image dictionary key must be a name object");
2993
3175
error(getPos(), const_cast<char*>("Inline image dictionary key must be a name object"));
2996
3179
key = copyString(obj.getName());
3005
3188
parser->getObj(&obj);
3007
3190
if (obj.isEOF()) {
3191
#ifdef POPPLER_NEW_ERRORAPI
3192
error(errSyntaxError, getPos(), "End of file in inline image");
3008
3194
error(getPos(), const_cast<char*>("End of file in inline image"));
3022
3209
void PdfParser::opImageData(Object args[], int numArgs) {
3210
#ifdef POPPLER_NEW_ERRORAPI
3211
error(errInternal, getPos(), "Internal: got 'ID' operator");
3023
3213
error(getPos(), const_cast<char*>("Internal: got 'ID' operator"));
3026
3217
void PdfParser::opEndImage(Object args[], int numArgs) {
3218
#ifdef POPPLER_NEW_ERRORAPI
3219
error(errInternal, getPos(), "Internal: got 'EI' operator");
3027
3221
error(getPos(), const_cast<char*>("Internal: got 'EI' operator"));
3030
3225
//------------------------------------------------------------------------