summaryrefslogtreecommitdiff
path: root/src/cairo-png.c
diff options
context:
space:
mode:
authorTom Schoonjans <Tom.Schoonjans@diamond.ac.uk>2017-11-02 16:55:22 +0000
committerAdrian Johnson <ajohnson@redneon.com>2017-11-26 20:16:43 +1030
commit84fc0ce91d1a57d20500f710abc0e17de82c67df (patch)
tree34acae66eba9dd6051787cc4717232a9144f592f /src/cairo-png.c
parente5532f5ad7f5493d703f9a7110b0816b5fa33e54 (diff)
downloadcairo-84fc0ce91d1a57d20500f710abc0e17de82c67df.tar.gz
Use UTF-8 filenames on Windows
Until now fopen was used on Windows to open files for reading and writing. This assumed however that the filename would be encoded in the current codepage, which is a major inconvenience and makes it even impossible to use filenames that use characters from more than one codepage. This patch enforces the use of UTF-8 filenames on all platforms. Based on the work of Owen Taylor (https://lists.cairographics.org/archives/cairo/2007-February/009591.html)
Diffstat (limited to 'src/cairo-png.c')
-rw-r--r--src/cairo-png.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/cairo-png.c b/src/cairo-png.c
index 5ea49f097..fe23fcf9d 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -345,7 +345,8 @@ stdio_write_func (png_structp png, png_bytep data, png_size_t size)
/**
* cairo_surface_write_to_png:
* @surface: a #cairo_surface_t with pixel contents
- * @filename: the name of a file to write to
+ * @filename: the name of a file to write to; on Windows this filename
+ * is encoded in UTF-8.
*
* Writes the contents of @surface to a new file @filename as a PNG
* image.
@@ -373,7 +374,11 @@ cairo_surface_write_to_png (cairo_surface_t *surface,
if (surface->finished)
return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED);
- fp = fopen (filename, "wb");
+ status = _cairo_fopen (filename, "wb", &fp);
+
+ if (status != CAIRO_STATUS_SUCCESS)
+ return _cairo_error (status);
+
if (fp == NULL) {
switch (errno) {
case ENOMEM:
@@ -738,7 +743,8 @@ read_png (struct png_read_closure_t *png_closure)
/**
* cairo_image_surface_create_from_png:
- * @filename: name of PNG file to load
+ * @filename: name of PNG file to load. On Windows this filename
+ * is encoded in UTF-8.
*
* Creates a new image surface and initializes the contents to the
* given PNG file.
@@ -764,10 +770,14 @@ cairo_image_surface_create_from_png (const char *filename)
{
struct png_read_closure_t png_closure;
cairo_surface_t *surface;
+ cairo_status_t status;
+
+ status = _cairo_fopen (filename, "rb", (FILE **) &png_closure.closure);
+
+ if (status != CAIRO_STATUS_SUCCESS)
+ return _cairo_surface_create_in_error (status);
- png_closure.closure = fopen (filename, "rb");
if (png_closure.closure == NULL) {
- cairo_status_t status;
switch (errno) {
case ENOMEM:
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);