693f749
From 7f5ccdee1f8a990e1cd675bd1a7ab4673e797f46 Mon Sep 17 00:00:00 2001
693f749
Message-Id: <7f5ccdee1f8a990e1cd675bd1a7ab4673e797f46.1542275308.git.mjg@fedoraproject.org>
693f749
From: Tor Andersson <tor.andersson@artifex.com>
693f749
Date: Wed, 7 Nov 2018 19:46:54 +0100
693f749
Subject: [PATCH] Write placeholder appearance streams for digital signatures.
693f749
693f749
A proper appearance stream is written when signing with a certificate.
693f749
This is just to create a placeholder appearance when the original document
693f749
did not write one.
693f749
---
693f749
 source/pdf/pdf-appearance.c | 23 +++++++++++++++++++++++
693f749
 1 file changed, 23 insertions(+)
693f749
693f749
diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c
693f749
index ceadfd09..c18d5860 100644
693f749
--- a/source/pdf/pdf-appearance.c
693f749
+++ b/source/pdf/pdf-appearance.c
693f749
@@ -1066,6 +1066,25 @@ pdf_write_ch_widget_appearance(fz_context *ctx, pdf_annot *annot, fz_buffer *buf
693f749
 	pdf_write_tx_widget_appearance(ctx, annot, buf, rect, bbox, matrix, res, text, ff);
693f749
 }
693f749
 
693f749
+static void
693f749
+pdf_write_sig_widget_appearance(fz_context *ctx, pdf_annot *annot, fz_buffer *buf,
693f749
+	fz_rect *rect, fz_rect *bbox, fz_matrix *matrix, pdf_obj **res)
693f749
+{
693f749
+	float x0 = rect->x0 + 1;
693f749
+	float y0 = rect->y0 + 1;
693f749
+	float x1 = rect->x1 - 1;
693f749
+	float y1 = rect->y1 - 1;
693f749
+	float w = x1 - x0;
693f749
+	float h = y1 - y0;
693f749
+	fz_append_printf(ctx, buf, "1 w\n0 G\n");
693f749
+	fz_append_printf(ctx, buf, "%g %g %g %g re\n", x0, y0, w, h);
693f749
+	fz_append_printf(ctx, buf, "%g %g m %g %g l\n", x0, y0, x1, y1);
693f749
+	fz_append_printf(ctx, buf, "%g %g m %g %g l\n", x1, y0, x0, y1);
693f749
+	fz_append_printf(ctx, buf, "s\n");
693f749
+	*bbox = *rect;
693f749
+	*matrix = fz_identity;
693f749
+}
693f749
+
693f749
 static void
693f749
 pdf_write_widget_appearance(fz_context *ctx, pdf_annot *annot, fz_buffer *buf,
693f749
 	fz_rect *rect, fz_rect *bbox, fz_matrix *matrix, pdf_obj **res)
693f749
@@ -1115,6 +1134,10 @@ pdf_write_widget_appearance(fz_context *ctx, pdf_annot *annot, fz_buffer *buf,
693f749
 		fz_catch(ctx)
693f749
 			fz_rethrow(ctx);
693f749
 	}
693f749
+	else if (pdf_name_eq(ctx, ft, PDF_NAME(Sig)))
693f749
+	{
693f749
+		pdf_write_sig_widget_appearance(ctx, annot, buf, rect, bbox, matrix, res);
693f749
+	}
693f749
 	else
693f749
 	{
693f749
 		fz_throw(ctx, FZ_ERROR_GENERIC, "cannot create appearance stream for %s widgets", pdf_to_name(ctx, ft));
693f749
-- 
693f749
2.19.1.1238.g4b45f61cc0
693f749