Extend PDF_DEBUG_APPEARANCE_SYNTHESIS printouts.
authorRobin Watts <[email protected]>
Wed, 21 Jul 2021 15:32:14 +0000 (16:32 +0100)
committerRobin Watts <[email protected]>
Wed, 21 Jul 2021 17:34:05 +0000 (18:34 +0100)
Disabled by default, obviously.

source/pdf/pdf-appearance.c

index 52f128da61d5f4291d9c87b4f6aea5aee6b1181e..954a845554d39bef4d6fc524da5481194b5b79dd 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "annotation-icons.h"
 
+/* #define PDF_DEBUG_APPEARANCE_SYNTHESIS */
+
 #define REPLACEMENT 0xB7
 #define CIRCLE_MAGIC 0.551915f
 
@@ -2567,6 +2569,10 @@ pdf_annot_push_local_xref(fz_context *ctx, pdf_annot *annot)
 {
        pdf_document *doc = annot->page->doc;
 
+#ifdef PDF_DEBUG_APPEARANCE_SYNTHESIS
+       if (doc->local_xref_nesting == 0 && doc->local_xref)
+               fz_write_printf(ctx, fz_stddbg(ctx), "push local_xref for annot\n");
+#endif
        doc->local_xref_nesting++;
 }
 
@@ -2578,6 +2584,10 @@ pdf_annot_ensure_local_xref(fz_context *ctx, pdf_annot *annot)
        if (doc->local_xref != NULL)
                return;
 
+#ifdef PDF_DEBUG_APPEARANCE_SYNTHESIS
+       fz_write_printf(ctx, fz_stddbg(ctx), "creating local_xref\n");
+#endif
+
        /* We have no local_xref, but we want to be using one. */
        /* First off, create one. */
        doc->local_xref = pdf_new_local_xref(ctx, doc);
@@ -2589,12 +2599,20 @@ pdf_annot_pop_local_xref(fz_context *ctx, pdf_annot *annot)
        pdf_document *doc = annot->page->doc;
 
        --doc->local_xref_nesting;
+#ifdef PDF_DEBUG_APPEARANCE_SYNTHESIS
+       if (doc->local_xref_nesting == 0 && doc->local_xref)
+               fz_write_printf(ctx, fz_stddbg(ctx), "pop local_xref for annot\n");
+#endif
 }
 
 void pdf_annot_pop_and_discard_local_xref(fz_context *ctx, pdf_annot *annot)
 {
        pdf_document *doc = annot->page->doc;
 
+#ifdef PDF_DEBUG_APPEARANCE_SYNTHESIS
+       if (doc->local_xref)
+               fz_write_printf(ctx, fz_stddbg(ctx), "pop and discard local_xref for annot\n");
+#endif
        --doc->local_xref_nesting;
        assert(doc->local_xref_nesting == 0);
        pdf_purge_local_font_resources(ctx, doc);
@@ -2703,18 +2721,15 @@ void pdf_update_appearance(fz_context *ctx, pdf_annot *annot)
 
                        pdf_set_annot_resynthesised(ctx, annot);
 
-                       /* Special case for Btn widgets that need multiple appearance streams. */
                        if (subtype == PDF_NAME(Widget) && ft == PDF_NAME(Btn))
                        {
+                               /* Special case for Btn widgets that need multiple appearance streams. */
                                pdf_update_button_appearance(ctx, annot);
-                               pdf_clean_obj(ctx, annot->obj);
-                               break; /* all done here */
                        }
-
-                       /* Special case for unsigned signature widgets,
-                        * which are most easily created via a display list. */
-                       if (subtype == PDF_NAME(Widget) && ft == PDF_NAME(Sig))
+                       else if (subtype == PDF_NAME(Widget) && ft == PDF_NAME(Sig))
                        {
+                               /* Special case for unsigned signature widgets,
+                                * which are most easily created via a display list. */
                                rect = pdf_annot_rect(ctx, annot);
                                dlist = pdf_signature_appearance_unsigned(ctx, rect, pdf_annot_language(ctx, annot));
                                fz_try(ctx)
@@ -2723,29 +2738,37 @@ void pdf_update_appearance(fz_context *ctx, pdf_annot *annot)
                                        fz_drop_display_list(ctx, dlist);
                                fz_catch(ctx)
                                        fz_rethrow(ctx);
-                               pdf_clean_obj(ctx, annot->obj);
-                               break; /* all done here */
-                       }
-
-                       buf = fz_new_buffer(ctx, 1024);
-                       fz_try(ctx)
-                       {
-                               fz_matrix matrix = fz_identity;
-                               rect = pdf_dict_get_rect(ctx, annot->obj, PDF_NAME(Rect));
-                               pdf_write_appearance(ctx, annot, buf, &rect, &bbox, &matrix, &res);
-                               pdf_dict_put_rect(ctx, annot->obj, PDF_NAME(Rect), rect);
-                               pdf_set_annot_appearance(ctx, annot, "N", NULL, matrix, bbox, res, buf);
-                       }
-                       fz_always(ctx)
-                       {
-                               fz_drop_buffer(ctx, buf);
-                               pdf_drop_obj(ctx, res);
-                               pdf_drop_obj(ctx, new_ap_n);
                        }
-                       fz_catch(ctx)
+                       else
                        {
-                               fz_warn(ctx, "cannot create appearance stream");
+                               buf = fz_new_buffer(ctx, 1024);
+                               fz_try(ctx)
+                               {
+                                       fz_matrix matrix = fz_identity;
+                                       rect = pdf_dict_get_rect(ctx, annot->obj, PDF_NAME(Rect));
+                                       pdf_write_appearance(ctx, annot, buf, &rect, &bbox, &matrix, &res);
+                                       pdf_dict_put_rect(ctx, annot->obj, PDF_NAME(Rect), rect);
+                                       pdf_set_annot_appearance(ctx, annot, "N", NULL, matrix, bbox, res, buf);
+                               }
+                               fz_always(ctx)
+                               {
+                                       fz_drop_buffer(ctx, buf);
+                                       pdf_drop_obj(ctx, res);
+                                       pdf_drop_obj(ctx, new_ap_n);
+                               }
+                               fz_catch(ctx)
+                               {
+                                       fz_warn(ctx, "cannot create appearance stream");
+                               }
                        }
+
+#ifdef PDF_DEBUG_APPEARANCE_SYNTHESIS
+                       fz_write_printf(ctx, fz_stddbg(ctx), "Annot obj after synthesis\n");
+                       pdf_debug_obj(ctx, annot->obj);
+                       fz_write_printf(ctx, fz_stddbg(ctx), "\nAppearance after synthesis\n");
+                       pdf_debug_obj(ctx, pdf_dict_getp(ctx, annot->obj, "AP/N"));
+                       fz_write_printf(ctx, fz_stddbg(ctx), "\n");
+#endif
                }
 
                pdf_clean_obj(ctx, annot->obj);