From 954187d247a71d34fa3db2bea80372d79cec5add Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 6 Apr 2018 22:27:01 +0200 Subject: [PATCH] Better formatting of PDF numbers --- pdf-tools.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pdf-tools.cc b/pdf-tools.cc index 4c10313..68a8f8c 100644 --- a/pdf-tools.cc +++ b/pdf-tools.cc @@ -205,7 +205,12 @@ QPDFObjectHandle page_to_xobject(QPDF *out, QPDFObjectHandle page) string pdf_coord(double x, uint digits) { - char buf[16]; - snprintf(buf, sizeof(buf), "%.*f", digits, x); - return buf; + char buf[16]; + snprintf(buf, sizeof(buf), "%.*f", digits, x); + int n = strlen(buf); + while (n > 0 && buf[n-1] == '0') + buf[--n] = 0; + if (n > 0 && buf[n-1] == '.') + buf[--n] = 0; + return buf; } -- 2.39.2