Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printf style format specifier %f #12

Closed
mikerayborn opened this issue Nov 3, 2018 · 3 comments
Closed

printf style format specifier %f #12

mikerayborn opened this issue Nov 3, 2018 · 3 comments

Comments

@mikerayborn
Copy link

Guys, I appreciate all the work you've done for the PDFGen code base. However I have one small observation regarding the use of the "%f" format specifier. By default I've noticed on some platforms this formats the value 0.0 as "0.000000" which adds unnecessary "0" bytes to the PDF stream.

My local testing has shown that using the "%g" format specifier results in a much more compact "0" for a 0.0 value saving several bytes in many places throughout the PDF stream.

FYI, I ported the PDFGen code base to my legacy mainframe project (MVS 3.8J operating system running on the Hercules emulator) with a bit of effort to deal with EBCDIC code as input the code generating a PDF file. Let's just say that mainframes don't know much about ASCII and/or UTF8 characters ;)

Thanks for your time and effort. The code overall is very nice and easy to work with. Best wishes to all.
--Mike Rayborn

@AndreRenaud
Copy link
Owner

Thanks for the feedback - sounds like a difficult environment to port software to :)

Regarding %g, I think making that change might result in scientific notation output (ie: 3.9265e+2), which I don't think is valid for a PDF. I don't think printf has a precision specifier for %f to tell it to strip trailing zeros unfortunately. Without putting our own special formatter in for this, there doesn't seem to be an easy way to get the desired output.

In general the PDFGen output is not super size optimised, it's more about simplicity & readability (although obviously dropping trailing zeros would benefit both of those if it were easy to implement)

@mikerayborn
Copy link
Author

Thanks Andre. Good point about the possibility of scientific notation in the output. We wouldn't want that in a PDF document. I'm guessing a better solution would be to use a PDF specific formatting routine that could format a floating point number with %f and remove any trailing zeros. I'll have to give that some more thought.

I have to wonder if there will be edge cases in which the use of %g would actually format a float with scientific output for a PDF document. I don't really know, so I have to admit the use of %g would not be the safest thing as different implementations of the standard C library functions could cause it to not work, that is not have scientific notation, in all cases.

Thanks again. I appreciate the feedback. Best Wishes.
--Mike

@AndreRenaud
Copy link
Owner

I'll close this for now then, since it doesn't look like %g is going to work in all cases. Let me know if you want to reopen it or have some other thoughts on the matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants