Skip to content

Commit

Permalink
Fix locale support (Issue michaelrsweet#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Jan 27, 2024
1 parent c13b5a5 commit e882622
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Changes in PDFio
================


v1.2.1 (Month DD, YYYY)
-----------------------

- Updated number support to avoid locale issues (Issue #61)


v1.2.0 (January 24, 2024)
-------------------------

Expand Down
4 changes: 2 additions & 2 deletions pdfio-common.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Common support functions for pdfio.
//
// Copyright © 2021-2023 by Michael R Sweet.
// Copyright © 2021-2024 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
Expand Down Expand Up @@ -261,7 +261,7 @@ _pdfioFilePrintf(pdfio_file_t *pdf, // I - PDF file

// Format the string...
va_start(ap, format);
vsnprintf(buffer, sizeof(buffer), format, ap);
_pdfio_vsnprintf(pdf, buffer, sizeof(buffer), format, ap);
va_end(ap);

// Write it...
Expand Down
27 changes: 25 additions & 2 deletions pdfio-file.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// PDF file functions for PDFio.
//
// Copyright © 2021-2023 by Michael R Sweet.
// Copyright © 2021-2024 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
Expand All @@ -20,6 +20,7 @@
static pdfio_obj_t *add_obj(pdfio_file_t *pdf, size_t number, unsigned short generation, off_t offset);
static int compare_objmaps(_pdfio_objmap_t *a, _pdfio_objmap_t *b);
static const char *get_info_string(pdfio_file_t *pdf, const char *key);
static struct lconv *get_lconv(void);
static bool load_obj_stream(pdfio_obj_t *obj);
static bool load_pages(pdfio_file_t *pdf, pdfio_obj_t *obj, size_t depth);
static bool load_xref(pdfio_file_t *pdf, off_t xref_offset, pdfio_password_cb_t password_cb, void *password_data);
Expand Down Expand Up @@ -217,6 +218,7 @@ pdfioFileCreate(
return (NULL);
}

pdf->loc = get_lconv();
pdf->filename = strdup(filename);
pdf->version = strdup(version);
pdf->mode = _PDFIO_MODE_WRITE;
Expand Down Expand Up @@ -259,7 +261,7 @@ pdfioFileCreate(
}

// Write a standard PDF header...
if (!_pdfioFilePrintf(pdf, "%%PDF-%s\n%%\342\343\317\323\n", version))
if (!_pdfioFilePrintf(pdf, "%%PDF-%s\n%%PDF\303\254o\n", version))
goto error;

// Create the pages object...
Expand Down Expand Up @@ -1218,6 +1220,7 @@ pdfioFileOpen(
return (NULL);
}

pdf->loc = get_lconv();
pdf->filename = strdup(filename);
pdf->mode = _PDFIO_MODE_READ;
pdf->error_cb = error_cb;
Expand Down Expand Up @@ -1576,6 +1579,26 @@ get_info_string(pdfio_file_t *pdf, // I - PDF file
}


//
// 'get_lconv()' - Get any locale-specific numeric information.
//

static struct lconv * // O - Locale information or `NULL`
get_lconv(void)
{
struct lconv *loc; // Locale information


if ((loc = localeconv()) != NULL)
{
if (!loc->decimal_point || !strcmp(loc->decimal_point, "."))
loc = NULL;
}

return (loc);
}


//
// 'load_obj_stream()' - Load an object stream.
//
Expand Down
7 changes: 6 additions & 1 deletion pdfio-private.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Private header file for PDFio.
//
// Copyright © 2021-2023 by Michael R Sweet.
// Copyright © 2021-2024 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
Expand All @@ -20,6 +20,7 @@
# include <errno.h>
# include <inttypes.h>
# include <fcntl.h>
# include <locale.h>
# ifdef _WIN32
# include <io.h>
# include <direct.h>
Expand Down Expand Up @@ -224,6 +225,7 @@ typedef struct _pdfio_objmap_s // PDF object map
struct _pdfio_file_s // PDF file structure
{
char *filename; // Filename
struct lconv *loc; // Locale data
char *version; // Version number
pdfio_rect_t media_box, // Default MediaBox value
crop_box; // Default CropBox value
Expand Down Expand Up @@ -322,6 +324,9 @@ struct _pdfio_stream_s // Stream
// Functions...
//

extern double _pdfio_strtod(pdfio_file_t *pdf, const char *s) _PDFIO_INTERNAL;
extern ssize_t _pdfio_vsnprintf(pdfio_file_t *pdf, char *buffer, size_t bufsize, const char *format, va_list ap) _PDFIO_INTERNAL;

extern bool _pdfioArrayDecrypt(pdfio_file_t *pdf, pdfio_obj_t *obj, pdfio_array_t *a, size_t depth) _PDFIO_INTERNAL;
extern void _pdfioArrayDebug(pdfio_array_t *a, FILE *fp) _PDFIO_INTERNAL;
extern void _pdfioArrayDelete(pdfio_array_t *a) _PDFIO_INTERNAL;
Expand Down
4 changes: 2 additions & 2 deletions pdfio-stream.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// PDF stream functions for PDFio.
//
// Copyright © 2021-2023 by Michael R Sweet.
// Copyright © 2021-2024 by Michael R Sweet.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
Expand Down Expand Up @@ -687,7 +687,7 @@ pdfioStreamPrintf(

// Format the string...
va_start(ap, format);
vsnprintf(buffer, sizeof(buffer), format, ap);
_pdfio_vsnprintf(st->pdf, buffer, sizeof(buffer), format, ap);
va_end(ap);

// Write the string...
Expand Down
Loading

0 comments on commit e882622

Please sign in to comment.