summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-form.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-03-15 22:42:15 +0100
committerTor Andersson <tor.andersson@artifex.com>2018-06-22 17:05:04 +0200
commit8fc19912a4898ca6993a2acf92116e621d140f7a (patch)
tree5f85f35767de47bcd7b7a3e32ce4fb867f7735db /source/pdf/pdf-form.c
parent7d2407571d8c8851b67af5ddd0429467c7048b16 (diff)
downloadmupdf-8fc19912a4898ca6993a2acf92116e621d140f7a.tar.xz
Create appearance streams for annotations.
Now handles more annotation types, and does not use the pdf-write device. Handles many of the usual annotation properties, such as border width, color, interior color, line ending styles. * Ink * Highlight, Underline, Strike-Out, Squiggly * Line (with arrow-heads) * Polygon * PolyLine * Square * Circle * Caret * Text (needs better icons) * FileAttachment (needs better icons) * Sound (needs better icons) * Stamp * FreeText Partially complete: * Widget (treats everything like a plain text field) Not done, but on the to-do list: * /BS style (solid/dashed/bevel/inset/underline) * /BS dash pattern Not done and not on the list: * Movie * Screen * Printer's Mark * Trap Network * Watermark * /Border corner radii (ignored by acrobat) * /BE cloudy border effect
Diffstat (limited to 'source/pdf/pdf-form.c')
-rw-r--r--source/pdf/pdf-form.c61
1 files changed, 26 insertions, 35 deletions
diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c
index 96b8d652..167e1729 100644
--- a/source/pdf/pdf-form.c
+++ b/source/pdf/pdf-form.c
@@ -976,45 +976,36 @@ void pdf_field_set_fill_color(fz_context *ctx, pdf_document *doc, pdf_obj *field
void pdf_field_set_text_color(fz_context *ctx, pdf_document *doc, pdf_obj *field, pdf_obj *col)
{
- pdf_da_info di;
- fz_buffer *fzbuf = NULL;
- char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, field, PDF_NAME(DA)));
- unsigned char *buf;
- int ilen;
- size_t len;
- pdf_obj *daobj;
-
- memset(&di, 0, sizeof(di));
-
- fz_var(fzbuf);
- fz_var(di);
- fz_try(ctx)
- {
- int i;
+ char buf[100];
+ const char *font;
+ float size, color[3], black;
+ const char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, field, PDF_NAME(DA)));
- pdf_parse_da(ctx, da, &di);
- di.col_size = pdf_array_len(ctx, col);
+ pdf_parse_default_appearance(ctx, da, &font, &size, color);
- ilen = fz_mini(di.col_size, (int)nelem(di.col));
- for (i = 0; i < ilen; i++)
- di.col[i] = pdf_array_get_real(ctx, col, i);
-
- fzbuf = fz_new_buffer(ctx, 0);
- pdf_fzbuf_print_da(ctx, fzbuf, &di);
- len = fz_buffer_storage(ctx, fzbuf, &buf);
- daobj = pdf_new_string(ctx, (char *)buf, len);
- pdf_dict_put_drop(ctx, field, PDF_NAME(DA), daobj);
- pdf_field_mark_dirty(ctx, doc, field);
- }
- fz_always(ctx)
+ switch (pdf_array_len(ctx, col))
{
- pdf_da_info_fin(ctx, &di);
- fz_drop_buffer(ctx, fzbuf);
- }
- fz_catch(ctx)
- {
- fz_warn(ctx, "%s", fz_caught_message(ctx));
+ default:
+ color[0] = color[1] = color[2] = 0;
+ case 1:
+ color[0] = color[1] = color[2] = pdf_array_get_real(ctx, col, 0);
+ break;
+ case 3:
+ color[0] = pdf_array_get_real(ctx, col, 0);
+ color[1] = pdf_array_get_real(ctx, col, 1);
+ color[2] = pdf_array_get_real(ctx, col, 2);
+ break;
+ case 4:
+ black = pdf_array_get_real(ctx, col, 3);
+ color[0] = 1 - fz_min(1, pdf_array_get_real(ctx, col, 0) + black);
+ color[1] = 1 - fz_min(1, pdf_array_get_real(ctx, col, 1) + black);
+ color[2] = 1 - fz_min(1, pdf_array_get_real(ctx, col, 2) + black);
+ break;
}
+
+ pdf_print_default_appearance(ctx, buf, sizeof buf, font, size, color);
+ pdf_dict_put_string(ctx, field, PDF_NAME(DA), buf, strlen(buf));
+ pdf_field_mark_dirty(ctx, doc, field);
}
fz_rect *pdf_bound_widget(fz_context *ctx, pdf_widget *widget, fz_rect *rect)