From: theadib Date: Sun, 16 Dec 2007 20:07:44 +0000 (+0000) Subject: [BUG #169122] PDF import doesn't work when file name has accents, partially fixed X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fcfc08059e9433aa48be7a8027fe437bf7e4b86a;p=inkscape.git [BUG #169122] PDF import doesn't work when file name has accents, partially fixed --- diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index 2d6a8ea4b..9b671a7c3 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -43,7 +43,7 @@ namespace Inkscape { namespace Extension { namespace Internal { - + /** * \brief The PDF import dialog * FIXME: Probably this should be placed into src/ui/dialog @@ -59,7 +59,7 @@ static Glib::ustring crop_setting_choices[] = { PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar *uri) { - + _poppler_doc = NULL; _pdf_doc = doc; cancelbutton = Gtk::manage(new class Gtk::Button(Gtk::StockID("gtk-cancel"))); @@ -285,7 +285,7 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar *uri) _render_thumb = true; // Create PopplerDocument gchar *doc_uri = g_filename_to_uri(uri, NULL, NULL); - if (doc_uri) { + if (doc_uri) { _poppler_doc = poppler_document_new_from_file(doc_uri, NULL, NULL); g_free(doc_uri); } @@ -444,7 +444,8 @@ static void copy_cairo_surface_to_pixbuf (cairo_surface_t *surface, src++; } } -} +} + #endif /** @@ -575,15 +576,47 @@ PdfInput::open(::Inkscape::Extension::Input * mod, const gchar * uri) { // Initialize the globalParams variable for poppler if (!globalParams) { globalParams = new GlobalParams(); - } - GooString *filename_goo = new GooString(uri); - PDFDoc *pdf_doc = new PDFDoc(filename_goo, NULL, NULL, NULL); // TODO: Could ask for password + } + // poppler does not use glib g_open. So on win32 we must use unicode call. code was copied from glib gstdio.c +#ifndef WIN32 + GooString *filename_goo = new GooString(uri); + PDFDoc *pdf_doc = new PDFDoc(filename_goo, NULL, NULL, NULL); // TODO: Could ask for password + delete filename_goo; +#else + wchar_t *wfilename = (wchar_t*)g_utf8_to_utf16 (uri, -1, NULL, NULL, NULL); + + if (wfilename == NULL) { + return NULL; + } + + PDFDoc *pdf_doc = new PDFDoc(wfilename, wcslen(wfilename), NULL, NULL, NULL); // TODO: Could ask for password + g_free (wfilename); +#endif + if (!pdf_doc->isOk()) { int error = pdf_doc->getErrorCode(); delete pdf_doc; if (error == errEncrypted) { g_message("Document is encrypted."); - } else { + } else if (error == errOpenFile) { + g_message("couldn't open the PDF file."); + } else if (error == errBadCatalog) { + g_message("couldn't read the page catalog."); + } else if (error == errDamaged) { + g_message("PDF file was damaged and couldn't be repaired."); + } else if (error == errHighlightFile) { + g_message("nonexistent or invalid highlight file."); + } else if (error == errBadPrinter) { + g_message("invalid printer."); + } else if (error == errPrinting) { + g_message("Error during printing."); + } else if (error == errPermission) { + g_message("PDF file does not allow that operation."); + } else if (error == errBadPageNum) { + g_message("invalid page number."); + } else if (error == errFileIO) { + g_message("file IO error."); + } else { g_message("Failed to load document from data (error %d)", error); }