summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/pdf/annot.h3
-rw-r--r--source/pdf/pdf-annot.c33
-rw-r--r--source/pdf/pdf-appearance.c47
3 files changed, 67 insertions, 16 deletions
diff --git a/include/mupdf/pdf/annot.h b/include/mupdf/pdf/annot.h
index 9ba30d1b..bd4e8722 100644
--- a/include/mupdf/pdf/annot.h
+++ b/include/mupdf/pdf/annot.h
@@ -167,6 +167,9 @@ void pdf_annot_color(fz_context *ctx, pdf_annot *annot, int *n, float color[4]);
void pdf_annot_interior_color(fz_context *ctx, pdf_annot *annot, int *n, float color[4]);
int pdf_annot_quadding(fz_context *ctx, pdf_annot *annot);
+void pdf_annot_MK_BG(fz_context *ctx, pdf_annot *annot, int *n, float color[4]);
+void pdf_annot_MK_BC(fz_context *ctx, pdf_annot *annot, int *n, float color[4]);
+
int pdf_annot_quad_point_count(fz_context *ctx, pdf_annot *annot);
void pdf_annot_quad_point(fz_context *ctx, pdf_annot *annot, int i, float qp[8]);
diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c
index b53beeb2..7dd4784e 100644
--- a/source/pdf/pdf-annot.c
+++ b/source/pdf/pdf-annot.c
@@ -668,18 +668,9 @@ void pdf_set_annot_opacity(fz_context *ctx, pdf_annot *annot, float opacity)
pdf_dirty_annot(ctx, annot);
}
-static void pdf_annot_color_imp(fz_context *ctx, pdf_annot *annot, pdf_obj *key, int *n, float color[4], pdf_obj **allowed)
+static void pdf_annot_color_imp(fz_context *ctx, pdf_obj *arr, int *n, float color[4])
{
- pdf_obj *arr;
- int len;
-
- if (allowed)
- check_allowed_subtypes(ctx, annot, key, allowed);
-
- arr = pdf_dict_get(ctx, annot->obj, key);
- len = pdf_array_len(ctx, arr);
-
- switch (len)
+ switch (pdf_array_len(ctx, arr))
{
case 0:
if (n)
@@ -763,7 +754,22 @@ static void pdf_set_annot_color_imp(fz_context *ctx, pdf_annot *annot, pdf_obj *
void
pdf_annot_color(fz_context *ctx, pdf_annot *annot, int *n, float color[4])
{
- pdf_annot_color_imp(ctx, annot, PDF_NAME(C), n, color, NULL);
+ pdf_obj *c = pdf_dict_get(ctx, annot->obj, PDF_NAME(C));
+ pdf_annot_color_imp(ctx, c, n, color);
+}
+
+void
+pdf_annot_MK_BG(fz_context *ctx, pdf_annot *annot, int *n, float color[4])
+{
+ pdf_obj *mk_bg = pdf_dict_get(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME(MK)), PDF_NAME(BG));
+ pdf_annot_color_imp(ctx, mk_bg, n, color);
+}
+
+void
+pdf_annot_MK_BC(fz_context *ctx, pdf_annot *annot, int *n, float color[4])
+{
+ pdf_obj *mk_bc = pdf_dict_get(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME(MK)), PDF_NAME(BC));
+ pdf_annot_color_imp(ctx, mk_bc, n, color);
}
void
@@ -790,7 +796,8 @@ pdf_annot_has_interior_color(fz_context *ctx, pdf_annot *annot)
void
pdf_annot_interior_color(fz_context *ctx, pdf_annot *annot, int *n, float color[4])
{
- pdf_annot_color_imp(ctx, annot, PDF_NAME(IC), n, color, interior_color_subtypes);
+ pdf_obj *ic = pdf_dict_get(ctx, annot->obj, PDF_NAME(IC));
+ pdf_annot_color_imp(ctx, ic, n, color);
}
void
diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c
index c14fc8e3..b231b6b5 100644
--- a/source/pdf/pdf-appearance.c
+++ b/source/pdf/pdf-appearance.c
@@ -65,6 +65,36 @@ static int pdf_write_interior_fill_color_appearance(fz_context *ctx, pdf_annot *
return 1;
}
+static int pdf_write_MK_BG_appearance(fz_context *ctx, pdf_annot *annot, fz_buffer *buf)
+{
+ float color[4];
+ int n;
+ pdf_annot_MK_BG(ctx, annot, &n, color);
+ switch (n)
+ {
+ default: return 0;
+ case 1: fz_append_printf(ctx, buf, "%g g\n", color[0]); break;
+ case 3: fz_append_printf(ctx, buf, "%g %g %g rg\n", color[0], color[1], color[2]); break;
+ case 4: fz_append_printf(ctx, buf, "%g %g %g %g k\n", color[0], color[1], color[2], color[3]); break;
+ }
+ return 1;
+}
+
+static int pdf_write_MK_BC_appearance(fz_context *ctx, pdf_annot *annot, fz_buffer *buf)
+{
+ float color[4];
+ int n;
+ pdf_annot_MK_BC(ctx, annot, &n, color);
+ switch (n)
+ {
+ default: return 0;
+ case 1: fz_append_printf(ctx, buf, "%g G\n", color[0]); break;
+ case 3: fz_append_printf(ctx, buf, "%g %g %g RG\n", color[0], color[1], color[2]); break;
+ case 4: fz_append_printf(ctx, buf, "%g %g %g %g K\n", color[0], color[1], color[2], color[3]); break;
+ }
+ return 1;
+}
+
static fz_point rotate_vector(float angle, float x, float y)
{
float ca = cosf(angle);
@@ -992,7 +1022,6 @@ pdf_write_tx_widget_appearance(fz_context *ctx, pdf_annot *annot, fz_buffer *buf
int q, r;
r = pdf_dict_get_int(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME(MK)), PDF_NAME(R));
- b = pdf_annot_border(ctx, annot);
q = pdf_annot_quadding(ctx, annot);
pdf_annot_default_appearance(ctx, annot, &font, &size, color);
@@ -1005,15 +1034,27 @@ pdf_write_tx_widget_appearance(fz_context *ctx, pdf_annot *annot, fz_buffer *buf
fz_append_string(ctx, buf, "/Tx BMC\nq\n");
+ if (pdf_write_MK_BG_appearance(ctx, annot, buf))
+ fz_append_printf(ctx, buf, "0 0 %g %g re\nf\n", w, h);
+
+ b = pdf_write_border_appearance(ctx, annot, buf);
+ if (b > 0)
+ {
+ if (pdf_write_MK_BC_appearance(ctx, annot, buf))
+ fz_append_printf(ctx, buf, "%g %g %g %g re\nS\n", b/2, b/2, w-b, h-b);
+ else
+ b = 0;
+ }
+
if (ff & Ff_Comb)
{
int maxlen = pdf_to_int(ctx, pdf_dict_get_inheritable(ctx, annot->obj, PDF_NAME(MaxLen)));
write_variable_text(ctx, annot, buf, res, text, font, size, color, q, w, h, 0, 0, maxlen);
}
else if (ff & Ff_Multiline)
- write_variable_text(ctx, annot, buf, res, text, font, size, color, q, w, h, 2, 1, 0);
+ write_variable_text(ctx, annot, buf, res, text, font, size, color, q, w, h, b*2, 1, 0);
else
- write_variable_text(ctx, annot, buf, res, text, font, size, color, q, w, h, 2, 0, 0);
+ write_variable_text(ctx, annot, buf, res, text, font, size, color, q, w, h, b*2, 0, 0);
fz_append_string(ctx, buf, "Q\nEMC\n");
}