Hans Hagen schrieb:
Peter Rolf wrote:
Hi,
can one of the experienced lua programmers here think about a special version of format()? This function in general is of great help (short, good readable code), but in combination with direct written pdf code (like in mlib-pdf.lua) is has a major drawback. All numbers are written with fixed size (as normally intended in formatted output). As a result you get '0.000000' instead of a short '0'. Look in an uncompressed pdf and you will see how much space is wasted there in total.
it's a trade off; %g is not usable because we then get e notation
and postprocessing is no option either because it's a waste of cpu cycles
stupid me (a much simpler approach is possible). just looked deeper in mlib-pdf.lua. i simply added '%.3f' on all positions, where coordinates/measures are written. same for integer ('%.0f' or as in the pdf reference '%.1f'). much shorter and better readability of the unpacked pdf. so there is no really need for an *optimal* solution with an adapted format function. sorry for the noise.
With enabled compression things don't look that bad (regarding to file size), but it's still a unnecessary waste.
indeed, such sequences compress well
yes <sigh>. i optimized some code and saved around 18k in the final uncompressed pdf (3% smaller). took me some time and i was a little proud of myself. after compressing all saving that was left were 1.111 bytes. <sigh again> :) but this is not only a file size issue. you have to represent the data in some way in memory. less memory usage, less time for data scanning means faster viewing.
adding special formatter function has a low priority .. maybe some day
Hans
so can you please simply limit the number of digits after the point in mlib-pdf.lua? you have already done this for colors at the end of the source. if i have to patch one more file, i can make my own distribution ;) regards, peter
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------