diff options
author | Paul Gardiner <paul@glidos.net> | 2012-06-12 15:49:11 +0100 |
---|---|---|
committer | Paul Gardiner <paul@glidos.net> | 2012-06-12 15:49:11 +0100 |
commit | 69c38a0d23c39432ff19e1e20f1e398a14d8c648 (patch) | |
tree | 604d6d23a5a24adacd2065493107ea49e21eda50 /pdf/pdf_form.c | |
parent | 97ca857023f9c8b4f9dedabaf710bc575664cd3e (diff) | |
download | mupdf-69c38a0d23c39432ff19e1e20f1e398a14d8c648.tar.xz |
Forms: handle carriage control in multiline text widget
Diffstat (limited to 'pdf/pdf_form.c')
-rw-r--r-- | pdf/pdf_form.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index abee963d..66ce4ed3 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -558,7 +558,15 @@ static int text_splitter_layout(fz_context *ctx, text_splitter *splitter) text = splitter->text + splitter->text_start; room = splitter->unscaled_width - splitter->x; - if (text[0] == ' ') + if (strchr("\r\n", text[0])) + { + /* Consume return chars and report end of line */ + splitter->text_end += strspn(text, "\r\n"); + splitter->text_start = splitter->text_end; + splitter->done = (splitter->text[splitter->text_end] == '\0'); + return 0; + } + else if (text[0] == ' ') { /* Treat each space as a word */ len = 1; @@ -566,7 +574,7 @@ static int text_splitter_layout(fz_context *ctx, text_splitter *splitter) else { len = 0; - while (text[len] != '\0' && text[len] != ' ') + while (text[len] != '\0' && !strchr(" \r\n", text[len])) len ++; } @@ -629,6 +637,24 @@ static void text_splitter_move(text_splitter *splitter, float newy, float *relx, splitter->y_orig = newy; } +static void text_splitter_retry(text_splitter *splitter) +{ + if (splitter->retry) + { + /* Already tried expanding lines. Overflow must + * be caused by carriage control */ + splitter->max_lines ++; + splitter->retry = 0; + splitter->unscaled_width = splitter->width * splitter->max_lines * splitter->fontsize + / splitter->height; + splitter->scale = splitter->width / splitter->unscaled_width; + } + else + { + splitter->retry = 1; + } +} + static void fzbuf_print_text_start(fz_context *ctx, fz_buffer *fzbuf, fz_rect *clip, font_info *font, fz_matrix *tm) { fz_buffer_printf(ctx, fzbuf, fmt_Tx_BMC); @@ -749,7 +775,7 @@ fz_buffer *create_text_appearance(pdf_document *doc, fz_rect *bbox, fz_matrix *o } if (!splitter.done) - splitter.retry = 1; + text_splitter_retry(&splitter); } fzbuf = fz_new_buffer(ctx, 0); |