From 89b4cc71372b1807b53b865df075df1c6a7b8ecb Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 17 Dec 2012 15:32:08 +0100 Subject: Added support for Visio stencil files (.vss) to Symbols dialog. (bzr r11962) --- src/ui/dialog/symbols.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 4 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 9d4ab5d8a..3188f1681 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -14,6 +14,9 @@ #include #include +#include +#include +#include #include @@ -43,6 +46,11 @@ #include "sp-use.h" #include "sp-symbol.h" +#ifdef WITH_LIBVISIO +#include +#include +#endif + #include "verbs.h" #include "xml/repr.h" @@ -289,6 +297,78 @@ void SymbolsDialog::iconChanged() { } } +#ifdef WITH_LIBVISIO +// Read Visio stencil files +SPDocument* read_vss( gchar* fullname, gchar* filename ) { + + WPXFileStream input(fullname); + + if (!libvisio::VisioDocument::isSupported(&input)) { + return NULL; + } + + libvisio::VSDStringVector output; + if (!libvisio::VisioDocument::generateSVGStencils(&input, output)) { + return NULL; + } + + if (output.empty()) { + return NULL; + } + + Glib::ustring tmpSVGOutput; + tmpSVGOutput += "\n"; + tmpSVGOutput += "\n"; + tmpSVGOutput += " "; + tmpSVGOutput += filename; + tmpSVGOutput += "\n"; + tmpSVGOutput += " \n"; + + // Create a string we can use for the symbol id (libvisio doesn't give us a name) + std::string sanitized( filename ); + sanitized.erase( sanitized.find_last_of(".vss")-3 ); + sanitized.erase( std::remove_if( sanitized.begin(), sanitized.end(), ispunct ), sanitized.end() ); + std::replace( sanitized.begin(), sanitized.end(), ' ', '_' ); + // std::cout << filename << " |" << sanitized << "|" << std::endl; + + // Each "symbol" is in it's own SVG file, we wrap with and merge into one file. + for (unsigned i=0; i\n"; + + std::istringstream iss( output[i].cstr() ); + std::string line; + while( std::getline( iss, line ) ) { + // std::cout << line << std::endl; + if( line.find( "svg:svg" ) == std::string::npos ) { + tmpSVGOutput += line; + tmpSVGOutput += "\n"; + } + } + + tmpSVGOutput += " \n"; + } + + tmpSVGOutput += " \n"; + tmpSVGOutput += "\n"; + + return SPDocument::createNewDocFromMem( tmpSVGOutput.c_str(), strlen( tmpSVGOutput.c_str()), 0 ); + +} +#endif + /* Hunts preference directories for symbol files */ void SymbolsDialog::get_symbols() { @@ -317,11 +397,31 @@ void SymbolsDialog::get_symbols() { if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR ) ) { - SPDocument* symbol_doc = SPDocument::createNewDoc( fullname, FALSE ); - if( symbol_doc ) { - symbolSets[Glib::ustring(filename)]= symbol_doc; - symbolSet->append(filename); + Glib::ustring fn( filename ); + Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 ); + + SPDocument* symbol_doc = NULL; + +#ifdef WITH_LIBVISIO + if( tag.compare( "vss" ) == 0 ) { + + symbol_doc = read_vss( fullname, filename ); + if( symbol_doc ) { + symbolSets[Glib::ustring(filename)]= symbol_doc; + symbolSet->append(filename); + } } +#endif + // Try to read all remaining files as SVG + if( !symbol_doc ) { + + symbol_doc = SPDocument::createNewDoc( fullname, FALSE ); + if( symbol_doc ) { + symbolSets[Glib::ustring(filename)]= symbol_doc; + symbolSet->append(filename); + } + } + } g_free( fullname ); } -- cgit v1.2.3