PDF creation error in italian locale
Swiss army knife of image processing
Brought to you by:
bfriesen
The function FormatStringList in magick/utility.h uses vsprintf function, but it outputs decimal numbers with ',' separator instead '.' in italian (and other countries) locale. It is used in PDF output function in pdf.c and this causes PDF output to emit a bad file (usually looks blank) because the following pdf header section needs '.' decimal separator (not ','):
stream
q
841,68 0 0 595,08 0 0 cm
/Im0 Do
Q
endstream
Are you using GraphicsMagick as a command-line utility or as a library?
The first two lines of code in GraphicsMagick when run as a command-line utility are:
(void) setlocale(LC_ALL,"");
(void) setlocale(LC_NUMERIC,"C");
which should be avoiding this problem. Unfortunately, locale settings are global to the whole application and there are many other places where numbers are formatted into strings.
I would be the first to agree that the global nature of locale settings will cause usability problems if GraphicsMagick is used as a library and the locale settings are changed from the defaults that GraphicsMagick applies. This makes it difficult to create a user-friendly application for those not using the "C" locale. The only solution to this problem would be to introduce string formatters (*printf()) and string scanners (replacement for scanf()) which ignore locale settings.
We will not fix this issue in the near future since dependence on the C locale when writing/reading text-based file formats is inherent to the implementation and the impact to fix it is large. The only current solution is to use
to set the numeric locale globally in the application, or immediately before reading/writing an impacted file format. Note the the setlocale() function is not thread safe so if another thread was formatting a string for a user interface then it might produce the wrong results due to change in the locale. Due to this, it is best to add a global lock to the dependent application which is used to assure that the correct locale is used while the thread is parsing formatted decimal data, or formatting decimal data for some other purpose, or while using GraphicsMagick to read/write file formats, or render vector graphics.