Add pdf_debug_doc_changes debug function.
authorRobin Watts <[email protected]>
Wed, 21 Jul 2021 15:31:40 +0000 (16:31 +0100)
committerRobin Watts <[email protected]>
Wed, 21 Jul 2021 17:34:05 +0000 (18:34 +0100)
include/mupdf/pdf/xref.h
source/pdf/pdf-xref.c

index 8acce92d45e383a81287fb47ad31abcfd492b54e..41b06ffb21a56f509e8b94a63cc6e7eb8de05e33 100644 (file)
@@ -218,4 +218,8 @@ pdf_xref *pdf_new_local_xref(fz_context *ctx, pdf_document *doc);
 
 void pdf_drop_local_xref(fz_context *ctx, pdf_xref *xref);
 
+/* Debug call to dump the incremental/local xrefs to the
+ * debug channel. */
+void pdf_debug_doc_changes(fz_context *ctx, pdf_document *doc);
+
 #endif
index fe491770227fdab7942a4056d04f1841bad280f3..29a773e9c6185d9210404d68782f92e6ae464ca0 100644 (file)
@@ -4599,3 +4599,62 @@ void pdf_drop_local_xref(fz_context *ctx, pdf_xref *xref)
 
        fz_free(ctx, xref);
 }
+
+void
+pdf_debug_doc_changes(fz_context *ctx, pdf_document *doc)
+{
+       int i, j;
+
+       if (doc->num_incremental_sections == 0)
+               fz_write_printf(ctx, fz_stddbg(ctx), "No incremental xrefs");
+       else
+       {
+               for (i = 0; i < doc->num_incremental_sections; i++)
+               {
+                       pdf_xref *xref = &doc->xref_sections[i];
+                       pdf_xref_subsec *sub;
+
+                       fz_write_printf(ctx, fz_stddbg(ctx), "Incremental xref:\n");
+                       for (sub = xref->subsec; sub != NULL; sub = sub->next)
+                       {
+                               fz_write_printf(ctx, fz_stddbg(ctx), "  Objects %d->%d\n", sub->start, sub->start + sub->len - 1);
+                               for (j = 0; j < sub->len; j++)
+                               {
+                                       pdf_xref_entry *e = &sub->table[j];
+                                       if (e->type == 0)
+                                               continue;
+                                       fz_write_printf(ctx, fz_stddbg(ctx), "%d %d obj (%c)\n", j + sub->start, e->gen, e->type);
+                                       pdf_debug_obj(ctx, e->obj);
+                                       fz_write_printf(ctx, fz_stddbg(ctx), "\nendobj\n");
+                               }
+                       }
+               }
+       }
+
+       if (doc->local_xref == NULL)
+               fz_write_printf(ctx, fz_stddbg(ctx), "No local xref");
+       else
+       {
+               for (i = 0; i < doc->num_incremental_sections; i++)
+               {
+                       pdf_xref *xref = doc->local_xref;
+                       pdf_xref_subsec *sub;
+
+                       fz_write_printf(ctx, fz_stddbg(ctx), "Local xref (%sin force):\n", doc->local_xref_nesting == 0 ? "not " : "");
+                       for (sub = xref->subsec; sub != NULL; sub = sub->next)
+                       {
+                               fz_write_printf(ctx, fz_stddbg(ctx), "  Objects %d->%d\n", sub->start, sub->start + sub->len - 1);
+                               for (j = 0; j < sub->len; j++)
+                               {
+                                       pdf_xref_entry *e = &sub->table[j];
+                                       if (e->type == 0)
+                                               continue;
+                                       fz_write_printf(ctx, fz_stddbg(ctx), "%d %d obj (%c)\n", j + sub->start, e->gen, e->type);
+                                       pdf_debug_obj(ctx, e->obj);
+                                       fz_write_printf(ctx, fz_stddbg(ctx), "\nendobj\n");
+                               }
+                       }
+               }
+       }
+
+}