From 621cde3d3c739995f29deedd3e17e9bfff2de464 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 19 Jun 2018 16:13:12 +0200 Subject: Size singleline widget text to fit both width and height. --- source/pdf/pdf-appearance.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'source') 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); -- cgit v1.2.3