SPDocument *VsdInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { RVNGFileStream input(uri); if (!libvisio::VisioDocument::isSupported(&input)) { return NULL; } RVNGStringVector output; #if WITH_LIBVISIO01 librevenge::RVNGSVGDrawingGenerator generator(output, "svg"); if (!libvisio::VisioDocument::parse(&input, &generator)) { #else if (!libvisio::VisioDocument::generateSVG(&input, output)) { #endif return NULL; } if (output.empty()) { return NULL; } std::vector<RVNGString> tmpSVGOutput; for (unsigned i=0; i<output.size(); ++i) { RVNGString tmpString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); tmpString.append(output[i]); tmpSVGOutput.push_back(tmpString); } unsigned page_num = 1; // If only one page is present, import that one without bothering user if (tmpSVGOutput.size() > 1) { VsdImportDialog *dlg = 0; if (inkscape_use_gui()) { dlg = new VsdImportDialog(tmpSVGOutput); if (!dlg->showDialog()) { delete dlg; return NULL; } } // Get needed page if (dlg) { page_num = dlg->getSelectedPage(); if (page_num < 1) page_num = 1; if (page_num > tmpSVGOutput.size()) page_num = tmpSVGOutput.size(); } } SPDocument * doc = SPDocument::createNewDocFromMem(tmpSVGOutput[page_num-1].cstr(), strlen(tmpSVGOutput[page_num-1].cstr()), TRUE); // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); } return doc; } #include "clear-n_.h" void VsdInput::init(void) { /* VSD */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("VSD Input") "</name>\n" "<id>org.inkscape.input.vsd</id>\n" "<input>\n" "<extension>.vsd</extension>\n" "<mimetype>application/vnd.visio</mimetype>\n" "<filetypename>" N_("Microsoft Visio Diagram (*.vsd)") "</filetypename>\n" "<filetypetooltip>" N_("File format used by Microsoft Visio 6 and later") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new VsdInput()); /* VDX */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("VDX Input") "</name>\n" "<id>org.inkscape.input.vdx</id>\n" "<input>\n" "<extension>.vdx</extension>\n" "<mimetype>application/vnd.visio</mimetype>\n" "<filetypename>" N_("Microsoft Visio XML Diagram (*.vdx)") "</filetypename>\n" "<filetypetooltip>" N_("File format used by Microsoft Visio 2010 and later") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new VsdInput()); /* VSDM */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("VSDM Input") "</name>\n" "<id>org.inkscape.input.vsdm</id>\n" "<input>\n" "<extension>.vsdm</extension>\n" "<mimetype>application/vnd.visio</mimetype>\n" "<filetypename>" N_("Microsoft Visio 2013 drawing (*.vsdm)") "</filetypename>\n" "<filetypetooltip>" N_("File format used by Microsoft Visio 2013 and later") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new VsdInput()); /* VSDX */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("VSDX Input") "</name>\n" "<id>org.inkscape.input.vsdx</id>\n" "<input>\n" "<extension>.vsdx</extension>\n" "<mimetype>application/vnd.visio</mimetype>\n" "<filetypename>" N_("Microsoft Visio 2013 drawing (*.vsdx)") "</filetypename>\n" "<filetypetooltip>" N_("File format used by Microsoft Visio 2013 and later") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new VsdInput()); return; } // init
SPDocument * GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) { // Determine whether the image should be embedded Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool ask = prefs->getBool("/dialogs/import/ask"); Glib::ustring link = prefs->getString("/dialogs/import/link"); bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi"); Glib::ustring scale = prefs->getString("/dialogs/import/scale"); // std::cout << "GkdpixbufInput::open: " // << " ask: " << ask // << ", link: " << link // << ", forcexdpi: " << forcexdpi // << ", scale: " << scale << std::endl; // std::cout << " in preferences: " // << " ask: " << !mod->get_param_bool("do_not_ask") // << ", link: " << mod->get_param_optiongroup("link") // << ", mod_dpi: " << mod->get_param_optiongroup("dpi") // << ", scale: " << mod->get_param_optiongroup("scale") << std::endl; if( ask ) { Glib::ustring mod_link = mod->get_param_optiongroup("link"); Glib::ustring mod_dpi = mod->get_param_optiongroup("dpi"); bool mod_forcexdpi = ( mod_dpi.compare( "from_default" ) == 0 ); Glib::ustring mod_scale = mod->get_param_optiongroup("scale"); if( link.compare( mod_link ) != 0 ) { link = mod_link; } prefs->setString("/dialogs/import/link", link ); if( forcexdpi != mod_forcexdpi ) { forcexdpi = mod_forcexdpi; } prefs->setBool("/dialogs/import/forcexdpi", forcexdpi ); if( scale.compare( mod_scale ) != 0 ) { scale = mod_scale; } prefs->setString("/dialogs/import/scale", scale ); prefs->setBool("/dialogs/import/ask", !mod->get_param_bool("do_not_ask") ); } bool embed = ( link.compare( "embed" ) == 0 ); SPDocument *doc = NULL; boost::scoped_ptr<Inkscape::Pixbuf> pb(Inkscape::Pixbuf::create_from_file(uri)); // TODO: the pixbuf is created again from the base64-encoded attribute in SPImage. // Find a way to create the pixbuf only once. if (pb) { doc = SPDocument::createNewDoc(NULL, TRUE, TRUE); bool saved = DocumentUndo::getUndoSensitive(doc); DocumentUndo::setUndoSensitive(doc, false); // no need to undo in this temporary document double width = pb->width(); double height = pb->height(); double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", Inkscape::Util::Quantity::convert(1, "in", "px")); //bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi"); ImageResolution *ir = 0; double xscale = 1; double yscale = 1; if (!ir && !forcexdpi) { ir = new ImageResolution(uri); } if (ir && ir->ok()) { xscale = 900.0 / floor(10.*ir->x() + .5); // round-off to 0.1 dpi yscale = 900.0 / floor(10.*ir->y() + .5); } else { xscale = 90.0 / defaultxdpi; yscale = 90.0 / defaultxdpi; } width *= xscale; height *= yscale; delete ir; // deleting NULL is safe // Create image node Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *image_node = xml_doc->createElement("svg:image"); sp_repr_set_svg_double(image_node, "width", width); sp_repr_set_svg_double(image_node, "height", height); // Added 11 Feb 2014 as we now honor "preserveAspectRatio" and this is // what Inkscaper's expect. image_node->setAttribute("preserveAspectRatio", "none"); if( scale.compare( "auto" ) != 0 ) { SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "image-rendering", scale.c_str()); sp_repr_css_set(image_node, css, "style"); sp_repr_css_attr_unref( css ); } if (embed) { sp_embed_image(image_node, pb.get()); } else { // convert filename to uri gchar* _uri = g_filename_to_uri(uri, NULL, NULL); if(_uri) { image_node->setAttribute("xlink:href", _uri); g_free(_uri); } else { image_node->setAttribute("xlink:href", uri); } } // Add it to the current layer doc->getRoot()->appendChildRepr(image_node); Inkscape::GC::release(image_node); fit_canvas_to_drawing(doc); // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { //std::cout << "Viewbox not set, setting" << std::endl; doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); } // restore undo, as now this document may be shown to the user if a bitmap was opened DocumentUndo::setUndoSensitive(doc, saved); } else { printf("GdkPixbuf loader failed\n"); } return doc; }
SPDocument *CdrInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { RVNGFileStream input(uri); if (!libcdr::CDRDocument::isSupported(&input)) { return NULL; } RVNGStringVector output; #if WITH_LIBCDR01 librevenge::RVNGSVGDrawingGenerator generator(output, "svg"); if (!libcdr::CDRDocument::parse(&input, &generator)) { #else if (!libcdr::CDRDocument::generateSVG(&input, output)) { #endif return NULL; } if (output.empty()) { return NULL; } std::vector<RVNGString> tmpSVGOutput; for (unsigned i=0; i<output.size(); ++i) { RVNGString tmpString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); tmpString.append(output[i]); tmpSVGOutput.push_back(tmpString); } unsigned page_num = 1; // If only one page is present, import that one without bothering user if (tmpSVGOutput.size() > 1) { CdrImportDialog *dlg = 0; if (inkscape_use_gui()) { dlg = new CdrImportDialog(tmpSVGOutput); if (!dlg->showDialog()) { delete dlg; return NULL; } } // Get needed page if (dlg) { page_num = dlg->getSelectedPage(); if (page_num < 1) page_num = 1; if (page_num > tmpSVGOutput.size()) page_num = tmpSVGOutput.size(); } } SPDocument * doc = SPDocument::createNewDocFromMem(tmpSVGOutput[page_num-1].cstr(), strlen(tmpSVGOutput[page_num-1].cstr()), TRUE); // Set viewBox if it doesn't exist if (doc && !doc->getRoot()->viewBox_set) { doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); } return doc; } #include "clear-n_.h" void CdrInput::init(void) { /* CDR */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("Corel DRAW Input") "</name>\n" "<id>org.inkscape.input.cdr</id>\n" "<input>\n" "<extension>.cdr</extension>\n" "<mimetype>image/x-xcdr</mimetype>\n" "<filetypename>" N_("Corel DRAW 7-X4 files (*.cdr)") "</filetypename>\n" "<filetypetooltip>" N_("Open files saved in Corel DRAW 7-X4") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new CdrInput()); /* CDT */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("Corel DRAW templates input") "</name>\n" "<id>org.inkscape.input.cdt</id>\n" "<input>\n" "<extension>.cdt</extension>\n" "<mimetype>application/x-xcdt</mimetype>\n" "<filetypename>" N_("Corel DRAW 7-13 template files (*.cdt)") "</filetypename>\n" "<filetypetooltip>" N_("Open files saved in Corel DRAW 7-13") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new CdrInput()); /* CCX */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("Corel DRAW Compressed Exchange files input") "</name>\n" "<id>org.inkscape.input.ccx</id>\n" "<input>\n" "<extension>.ccx</extension>\n" "<mimetype>application/x-xccx</mimetype>\n" "<filetypename>" N_("Corel DRAW Compressed Exchange files (*.ccx)") "</filetypename>\n" "<filetypetooltip>" N_("Open compressed exchange files saved in Corel DRAW") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new CdrInput()); /* CMX */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("Corel DRAW Presentation Exchange files input") "</name>\n" "<id>org.inkscape.input.cmx</id>\n" "<input>\n" "<extension>.cmx</extension>\n" "<mimetype>application/x-xcmx</mimetype>\n" "<filetypename>" N_("Corel DRAW Presentation Exchange files (*.cmx)") "</filetypename>\n" "<filetypetooltip>" N_("Open presentation exchange files saved in Corel DRAW") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new CdrInput()); return; } // init