Browse code

Add support for noting which objects have Colors properties greater than 2**24

Shawn Webb authored on 2014/06/20 06:41:15
Showing 1 changed files
... ...
@@ -116,6 +116,8 @@ static void ModificationDate_cb(struct pdf_struct *, struct pdf_obj *, struct pd
116 116
 static void Title_cb(struct pdf_struct *, struct pdf_obj *, struct pdf_action *);
117 117
 static void Subject_cb(struct pdf_struct *, struct pdf_obj *, struct pdf_action *);
118 118
 static void Keywords_cb(struct pdf_struct *, struct pdf_obj *, struct pdf_action *);
119
+static void Pages_cb(struct pdf_struct *, struct pdf_obj *, struct pdf_action *);
120
+static void Colors_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_action *act);
119 121
 /* End PDF statistics callbacks and related */
120 122
 
121 123
 static int xrefCheck(const char *xref, const char *eof)
... ...
@@ -1409,7 +1411,9 @@ static struct pdfname_action pdfname_actions[] = {
1409 1409
     {"Creator", OBJ_DICT, STATE_NONE, STATE_NONE, Creator_cb},
1410 1410
     {"Title", OBJ_DICT, STATE_NONE, STATE_NONE, Title_cb},
1411 1411
     {"Keywords", OBJ_DICT, STATE_NONE, STATE_NONE, Keywords_cb},
1412
-    {"Subject", OBJ_DICT, STATE_NONE, STATE_NONE, Subject_cb}
1412
+    {"Subject", OBJ_DICT, STATE_NONE, STATE_NONE, Subject_cb},
1413
+    {"Pages", OBJ_DICT, STATE_NONE, STATE_NONE, Pages_cb},
1414
+    {"Colors", OBJ_DICT, STATE_NONE, STATE_NONE, Colors_cb}
1413 1415
 };
1414 1416
 
1415 1417
 #define KNOWN_FILTERS ((1 << OBJ_FILTER_AH) | (1 << OBJ_FILTER_RL) | (1 << OBJ_FILTER_A85) | (1 << OBJ_FILTER_FLATE) | (1 << OBJ_FILTER_LZW) | (1 << OBJ_FILTER_FAX) | (1 << OBJ_FILTER_DCT) | (1 << OBJ_FILTER_JPX) | (1 << OBJ_FILTER_CRYPT))
... ...
@@ -3399,6 +3403,59 @@ static void Subject_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_a
3399 3399
 #endif
3400 3400
 }
3401 3401
 
3402
+static void Pages_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_action *act)
3403
+{
3404
+#if HAVE_JSON
3405
+#endif
3406
+}
3407
+
3408
+static void Colors_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_action *act)
3409
+{
3410
+#if HAVE_JSON
3411
+    json_object *colorsobj, *pdfobj;
3412
+    unsigned long ncolors;
3413
+    char *start, *p1;
3414
+    size_t objsz = obj_size(pdf, obj, 1);
3415
+
3416
+    if (!(pdf) || !(pdf->ctx) || !(pdf->ctx->wrkproperty))
3417
+        return;
3418
+
3419
+    start = obj->start + pdf->map;
3420
+
3421
+    p1 = cli_memstr(start, objsz, "/Colors", 7);
3422
+    if (!(p1))
3423
+        return;
3424
+
3425
+    p1 += 7;
3426
+
3427
+    /* Ensure that we have at least one whitespace character plus at least one number */
3428
+    if (objsz - (p1 - start) < 2)
3429
+        return;
3430
+
3431
+    while (p1 - start < objsz && isspace(p1[0]))
3432
+        p1++;
3433
+
3434
+    if (p1 - start == objsz)
3435
+        return;
3436
+
3437
+    ncolors = strtoul(p1, NULL, 10);
3438
+
3439
+    /* We only care if the number of colors > 2**24 */
3440
+    if (ncolors < 1<<24)
3441
+        return;
3442
+
3443
+    pdfobj = cli_jsonobj(pdf->ctx->wrkproperty, "PDFStats");
3444
+    if (!(pdfobj))
3445
+        return;
3446
+
3447
+    colorsobj = cli_jsonarray(pdfobj, "BigColors");
3448
+    if (!(colorsobj))
3449
+        return;
3450
+
3451
+    cli_jsonint_array(colorsobj, obj->id>>8);
3452
+#endif
3453
+}
3454
+
3402 3455
 static void print_pdf_stats(struct pdf_struct *pdf)
3403 3456
 {
3404 3457
     if (!(pdf))