From 1dbe6c746f9f5b0ddbce22e228835010c000d67b Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Tue, 17 Jan 2017 23:06:15 +0100 Subject: Partially fix opening of librevenge based input formats (cdr/vsd/wpg) on Windows if the filename contains non-ASCII characters The problem is that "RVNGFileStream" uses "fopen()" internally which only supports ANSI filenames on Windows (i.e. a complete fix would require upstream code changes). By using "g_win32_locale_filename_from_utf8()" the problem can be worked around in most cases, though: * the filename is converted to the current codepage (i.e. all 255 characters that are available in the current character encoding are allowed in the filename) * even if the filename contains a character that's not available in the current character encoding it's attempted to use the alternative short (8.3) file name instead Therefore the input operation will only fail in the unlikely case that the filename contains a character not available in the current ANSI code page while at the same time short file names are disabled on the file system (which is not the case in standard configurations). Fixed bugs: - https://launchpad.net/bugs/1656763 - https://launchpad.net/bugs/1656763 (bzr r15421) --- src/extension/internal/cdr-input.cpp | 7 +++++++ src/extension/internal/vsd-input.cpp | 7 +++++++ src/extension/internal/wpg-input.cpp | 7 +++++++ 3 files changed, 21 insertions(+) (limited to 'src/extension') diff --git a/src/extension/internal/cdr-input.cpp b/src/extension/internal/cdr-input.cpp index 92a11a6ac..0435f1396 100644 --- a/src/extension/internal/cdr-input.cpp +++ b/src/extension/internal/cdr-input.cpp @@ -214,6 +214,13 @@ void CdrImportDialog::_setPreviewPage() SPDocument *CdrInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { + #ifdef WIN32 + // RVNGFileStream uses fopen() internally which unfortunately only uses ANSI encoding on Windows + // therefore attempt to convert uri to the system codepage + // even if this is not possible the alternate short (8.3) file name will be used if available + uri = g_win32_locale_filename_from_utf8(uri); + #endif + RVNGFileStream input(uri); if (!libcdr::CDRDocument::isSupported(&input)) { diff --git a/src/extension/internal/vsd-input.cpp b/src/extension/internal/vsd-input.cpp index 2fb4acf22..78783aa2d 100644 --- a/src/extension/internal/vsd-input.cpp +++ b/src/extension/internal/vsd-input.cpp @@ -216,6 +216,13 @@ void VsdImportDialog::_setPreviewPage() SPDocument *VsdInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { + #ifdef WIN32 + // RVNGFileStream uses fopen() internally which unfortunately only uses ANSI encoding on Windows + // therefore attempt to convert uri to the system codepage + // even if this is not possible the alternate short (8.3) file name will be used if available + uri = g_win32_locale_filename_from_utf8(uri); + #endif + RVNGFileStream input(uri); if (!libvisio::VisioDocument::isSupported(&input)) { diff --git a/src/extension/internal/wpg-input.cpp b/src/extension/internal/wpg-input.cpp index 54a14fc72..12457791b 100644 --- a/src/extension/internal/wpg-input.cpp +++ b/src/extension/internal/wpg-input.cpp @@ -81,6 +81,13 @@ namespace Internal { SPDocument *WpgInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { + #ifdef WIN32 + // RVNGFileStream uses fopen() internally which unfortunately only uses ANSI encoding on Windows + // therefore attempt to convert uri to the system codepage + // even if this is not possible the alternate short (8.3) file name will be used if available + uri = g_win32_locale_filename_from_utf8(uri); + #endif + RVNGInputStream* input = new RVNGFileStream(uri); #if WITH_LIBWPG03 if (input->isStructured()) { -- cgit v1.2.3