Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / extension / internal / pdfinput / pdf-input.cpp
index 31364f61e2b8ab1cc940bdaaccb5543675d6bfce..ae3e473a5d72d3dd187adb56505ecbe5d29b0c47 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Authors:
  *   miklos erdelyi
+ *   Abhishek Sharma
  *
  * Copyright (C) 2007 Authors
  *
@@ -36,6 +37,7 @@
 #include "pdf-parser.h"
 
 #include "document-private.h"
+#include "inkscape.h"
 
 #include "dialogs/dialog-events.h"
 #include <gtk/gtkdialog.h>
@@ -49,12 +51,14 @@ namespace Internal {
  * FIXME: Probably this should be placed into src/ui/dialog
  */
 
-static Glib::ustring crop_setting_choices[] = {
-    Glib::ustring(_("media box")),
-    Glib::ustring(_("crop box")),
-    Glib::ustring(_("trim box")),
-    Glib::ustring(_("bleed box")),
-    Glib::ustring(_("art box"))
+static const gchar * crop_setting_choices[] = {
+       //TRANSLATORS: The following are document crop settings for PDF import
+       // more info: http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/page_bounds/
+    N_("media box"),
+    N_("crop box"),
+    N_("trim box"),
+    N_("bleed box"),
+    N_("art box")
 };
 
 PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar *uri)
@@ -90,9 +94,9 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar *uri)
     _cropTypeCombo = Gtk::manage(new class Gtk::ComboBoxText());
     int num_crop_choices = sizeof(crop_setting_choices) / sizeof(crop_setting_choices[0]);
     for ( int i = 0 ; i < num_crop_choices ; i++ ) {
-        _cropTypeCombo->append_text(crop_setting_choices[i]);
+        _cropTypeCombo->append_text(_(crop_setting_choices[i]));
     }
-    _cropTypeCombo->set_active_text(crop_setting_choices[0]);
+    _cropTypeCombo->set_active_text(_(crop_setting_choices[0]));
     _cropTypeCombo->set_sensitive(false);
 
     hbox3 = Gtk::manage(new class Gtk::HBox(false, 4));
@@ -114,6 +118,7 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar *uri)
     _textHandlingCombo = Gtk::manage(new class Gtk::ComboBoxText());
     _textHandlingCombo->append_text(_("Import text as text"));
     _textHandlingCombo->set_active_text(_("Import text as text"));
+    _localFontsCheck = Gtk::manage(new class Gtk::CheckButton(_("Replace PDF fonts by closest-named installed fonts")));
 
     hbox5 = Gtk::manage(new class Gtk::HBox(false, 4));
     _embedImagesCheck = Gtk::manage(new class Gtk::CheckButton(_("Embed images")));
@@ -208,6 +213,10 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar *uri)
     _labelText->set_selectable(false);
     hbox5->pack_start(*_labelText, Gtk::PACK_SHRINK, 0);
     hbox5->pack_start(*_textHandlingCombo, Gtk::PACK_SHRINK, 0);
+    _localFontsCheck->set_flags(Gtk::CAN_FOCUS);
+    _localFontsCheck->set_relief(Gtk::RELIEF_NORMAL);
+    _localFontsCheck->set_mode(true);
+    _localFontsCheck->set_active(true);
     _embedImagesCheck->set_flags(Gtk::CAN_FOCUS);
     _embedImagesCheck->set_relief(Gtk::RELIEF_NORMAL);
     _embedImagesCheck->set_mode(true);
@@ -216,6 +225,7 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar *uri)
     vbox3->pack_start(*hbox6, Gtk::PACK_SHRINK, 0);
     vbox3->pack_start(*_labelPrecisionWarning, Gtk::PACK_SHRINK, 0);
     vbox3->pack_start(*hbox5, Gtk::PACK_SHRINK, 4);
+    vbox3->pack_start(*_localFontsCheck, Gtk::PACK_SHRINK, 0);
     vbox3->pack_start(*_embedImagesCheck, Gtk::PACK_SHRINK, 0);
     alignment4->add(*vbox3);
     _labelImportSettings->set_alignment(0.5,0.5);
@@ -266,6 +276,7 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar *uri)
     _labelText->show();
     _textHandlingCombo->show();
     hbox5->show();
+    _localFontsCheck->show();
     _embedImagesCheck->show();
     vbox3->show();
     alignment4->show();
@@ -351,7 +362,7 @@ void PdfImportDialog::getImportSettings(Inkscape::XML::Node *prefs) {
         int num_crop_choices = sizeof(crop_setting_choices) / sizeof(crop_setting_choices[0]);
         int i = 0;
         for ( ; i < num_crop_choices ; i++ ) {
-            if ( current_choice == crop_setting_choices[i] ) {
+            if ( current_choice == _(crop_setting_choices[i]) ) {
                 break;
             }
         }
@@ -361,6 +372,11 @@ void PdfImportDialog::getImportSettings(Inkscape::XML::Node *prefs) {
     }
     sp_repr_set_svg_double(prefs, "approximationPrecision",
                            _fallbackPrecisionSlider->get_value());
+    if (_localFontsCheck->get_active()) {
+        prefs->setAttribute("localFonts", "1");
+    } else {
+        prefs->setAttribute("localFonts", "0");
+    }
     if (_embedImagesCheck->get_active()) {
         prefs->setAttribute("embedImages", "1");
     } else {
@@ -375,10 +391,10 @@ void PdfImportDialog::getImportSettings(Inkscape::XML::Node *prefs) {
 void PdfImportDialog::_onPrecisionChanged() {
 
     static Glib::ustring precision_comments[] = {
-        Glib::ustring(_("rough")),
-        Glib::ustring(_("medium")),
-        Glib::ustring(_("fine")),
-        Glib::ustring(_("very fine"))
+        Glib::ustring(C_("PDF input precision", "rough")),
+        Glib::ustring(C_("PDF input precision", "medium")),
+        Glib::ustring(C_("PDF input precision", "fine")),
+        Glib::ustring(C_("PDF input precision", "very fine"))
     };
 
     double min = _fallbackPrecisionSlider_adj->get_lower();
@@ -583,7 +599,7 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) {
 #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;
+    //delete filename_goo;
 #else
     wchar_t *wfilename = (wchar_t*)g_utf8_to_utf16 (uri, -1, NULL, NULL, NULL);
 
@@ -624,22 +640,29 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) {
 
         return NULL;
     }
-    PdfImportDialog *dlg = new PdfImportDialog(pdf_doc, uri);
-    if (!dlg->showDialog()) {
-        delete dlg;
-        //delete pdf_doc;
 
-        return NULL;
+    PdfImportDialog *dlg = NULL;
+    if (inkscape_use_gui()) {
+        dlg = new PdfImportDialog(pdf_doc, uri);
+        if (!dlg->showDialog()) {
+            delete dlg;
+            delete pdf_doc;
+            return NULL;
+        }
     }
 
     // Get needed page
-    int page_num = dlg->getSelectedPage();
+    int page_num;
+    if (dlg)
+        page_num = dlg->getSelectedPage();
+    else 
+        page_num = 1;
     Catalog *catalog = pdf_doc->getCatalog();
     Page *page = catalog->getPage(page_num);
 
-    SPDocument *doc = sp_document_new(NULL, TRUE, TRUE);
-    bool saved = sp_document_get_undo_sensitive(doc);
-    sp_document_set_undo_sensitive(doc, false); // No need to undo in this temporary document
+    SPDocument *doc = SPDocument::createNewDoc(NULL, TRUE, TRUE);
+    bool saved = DocumentUndo::getUndoSensitive(doc);
+    DocumentUndo::setUndoSensitive(doc, false); // No need to undo in this temporary document
 
     // Create builder
     gchar *docname = g_path_get_basename(uri);
@@ -651,7 +674,8 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) {
 
     // Get preferences
     Inkscape::XML::Node *prefs = builder->getPreferences();
-    dlg->getImportSettings(prefs);
+    if (dlg)
+        dlg->getImportSettings(prefs);
 
     // Apply crop settings
     PDFRectangle *clipToBox = NULL;
@@ -708,10 +732,11 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) {
     delete pdf_parser;
     delete builder;
     g_free(docname);
-    //delete pdf_doc;
+    delete pdf_doc;
+    delete dlg;
 
     // Restore undo
-    sp_document_set_undo_sensitive(doc, saved);
+    DocumentUndo::setUndoSensitive(doc, saved);
 
     return doc;
 }
@@ -724,27 +749,27 @@ PdfInput::init(void) {
 
     /* PDF in */
     ext = Inkscape::Extension::build_from_mem(
-        "<inkscape-extension>\n"
-            "<name>PDF Input</name>\n"
+        "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
+            "<name>" N_("PDF Input") "</name>\n"
             "<id>org.inkscape.input.pdf</id>\n"
             "<input>\n"
                 "<extension>.pdf</extension>\n"
                 "<mimetype>application/pdf</mimetype>\n"
-                "<filetypename>Adobe PDF (*.pdf) [via poppler]</filetypename>\n"
-                "<filetypetooltip>Adobe Portable Document Format</filetypetooltip>\n"
+                "<filetypename>" N_("Adobe PDF (*.pdf)") "</filetypename>\n"
+                "<filetypetooltip>" N_("Adobe Portable Document Format") "</filetypetooltip>\n"
             "</input>\n"
         "</inkscape-extension>", new PdfInput());
 
     /* AI in */
     ext = Inkscape::Extension::build_from_mem(
-        "<inkscape-extension>\n"
-            "<name>AI Input</name>\n"
+        "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
+            "<name>" N_("AI Input") "</name>\n"
             "<id>org.inkscape.input.ai</id>\n"
             "<input>\n"
                 "<extension>.ai</extension>\n"
                 "<mimetype>image/x-adobe-illustrator</mimetype>\n"
-                "<filetypename>Adobe Illustrator (*.ai) [PDF-based]</filetypename>\n"
-                "<filetypetooltip>Open files saved with recent versions of Adobe Illustrator</filetypetooltip>\n"
+                "<filetypename>" N_("Adobe Illustrator 9.0 and above (*.ai)") "</filetypename>\n"
+                "<filetypetooltip>" N_("Open files saved in Adobe Illustrator 9.0 and newer versions") "</filetypetooltip>\n"
             "</input>\n"
         "</inkscape-extension>", new PdfInput());
 } // init