From 65d12cd5b97b4b6b43767713917bb422e7e1a834 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Mon, 18 Mar 2013 10:59:43 +0000 Subject: Auto-generate appearance streams for strikeout, underline, highlight This fixes bug #693664, and also simplifies app code. The example file attached to the bug produces strange results, but that is because the QuadPoint information is incorrect. --- pdf/pdf_form.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'pdf/pdf_form.c') diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index 118c818f..168e56aa 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -3,6 +3,11 @@ #define MATRIX_COEFS (6) +#define STRIKE_HEIGHT (0.375f) +#define UNDERLINE_HEIGHT (0.075f) +#define LINE_THICKNESS (0.07f) +#define SMALL_FLOAT (0.00001) + enum { F_Invisible = 1 << (1-1), @@ -1713,12 +1718,55 @@ static void execute_action(pdf_document *doc, pdf_obj *obj, pdf_obj *a) } } +static void update_text_markup_appearance(pdf_document *doc, pdf_obj *annot, fz_annot_type type) +{ + fz_context *ctx = doc->ctx; + float color[3]; + float alpha; + float line_height; + float line_thickness; + + switch (type) + { + case FZ_ANNOT_HIGHLIGHT: + color[0] = 1.0; + color[1] = 1.0; + color[2] = 0.0; + alpha = 0.5; + line_thickness = 1.0; + line_height = 0.5; + break; + case FZ_ANNOT_UNDERLINE: + color[0] = 0.0; + color[1] = 0.0; + color[2] = 1.0; + alpha = 1.0; + line_thickness = LINE_THICKNESS; + line_height = UNDERLINE_HEIGHT; + break; + case FZ_ANNOT_STRIKEOUT: + color[0] = 1.0; + color[1] = 0.0; + color[2] = 0.0; + alpha = 1.0; + line_thickness = LINE_THICKNESS; + line_height = STRIKE_HEIGHT; + break; + default: + return; + } + + pdf_set_markup_obj_appearance(doc, annot, color, alpha, line_thickness, line_height); +} + void pdf_update_appearance(pdf_document *doc, pdf_obj *obj) { if (!pdf_dict_gets(obj, "AP") || pdf_dict_gets(obj, "Dirty")) { - if (!strcmp(pdf_to_name(pdf_dict_gets(obj, "Subtype")), "Widget")) + fz_annot_type type = pdf_annot_obj_type(obj); + switch (type) { + case FZ_ANNOT_WIDGET: switch(pdf_field_type(doc, obj)) { case FZ_WIDGET_TYPE_TEXT: @@ -1753,6 +1801,12 @@ void pdf_update_appearance(pdf_document *doc, pdf_obj *obj) update_combobox_appearance(doc, obj); break; } + break; + case FZ_ANNOT_STRIKEOUT: + case FZ_ANNOT_UNDERLINE: + case FZ_ANNOT_HIGHLIGHT: + update_text_markup_appearance(doc, obj, type); + break; } pdf_dict_dels(obj, "Dirty"); -- cgit v1.2.3