diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-06-19 16:13:12 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2018-06-22 16:48:51 +0100 |
commit | 621cde3d3c739995f29deedd3e17e9bfff2de464 (patch) | |
tree | e87ae9d03eff2fed062ffff54f8f7958eb60ba20 /source/pdf | |
parent | 8d5e3f0b0e6e25c1e9948de0ea224769344f4ba3 (diff) | |
download | mupdf-621cde3d3c739995f29deedd3e17e9bfff2de464.tar.xz |
Size singleline widget text to fit both width and height.
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-appearance.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c index d88eed93..01c18b47 100644 --- a/source/pdf/pdf-appearance.c +++ b/source/pdf/pdf-appearance.c @@ -880,17 +880,27 @@ write_variable_text(fz_context *ctx, pdf_annot *annot, fz_buffer *buf, pdf_obj * float lineheight; float baseline; - w -= padding * 2; - h -= padding * 2; - if (size == 0) - size = multiline ? 12 : h; - - lineheight = size * 1.15f; /* empirically derived from Adobe reader */ - baseline = size * 0.8f; - font = fz_new_base14_font(ctx, full_font_name(&fontname)); fz_try(ctx) { + w -= padding * 2; + h -= padding * 2; + + if (size == 0) + { + if (multiline) + size = 12; + else + { + size = w / measure_simple_string(ctx, font, text); + if (size > h) + size = h; + } + } + + lineheight = size * 1.15f; /* empirically derived from Adobe reader */ + baseline = size * 0.8f; + /* /Resources << /Font << /Helv %d 0 R >> >> */ *res = pdf_new_dict(ctx, annot->page->doc, 1); res_font = pdf_dict_put_dict(ctx, *res, PDF_NAME(Font), 1); |