From 8e6912cef76398a4e0a804b869b3925d3cbba08a Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Wed, 5 Apr 2017 22:16:20 +0200 Subject: Symbols/VSS: Use the actual name of Visio stencils if possible (before a generic name was derived from the .vss file name) Fixed bugs: - https://launchpad.net/bugs/1676144 (bzr r15615) --- src/ui/dialog/symbols.cpp | 56 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 740ff4f39..ef17367d5 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -57,7 +57,10 @@ #include using librevenge::RVNGFileStream; + using librevenge::RVNGString; using librevenge::RVNGStringVector; + using librevenge::RVNGPropertyList; + using librevenge::RVNGSVGDrawingGenerator; #else #include @@ -451,6 +454,31 @@ void SymbolsDialog::iconChanged() { } #ifdef WITH_LIBVISIO + +#if WITH_LIBVISIO01 +// Extend libvisio's native RVNGSVGDrawingGenerator with support for extracting stencil names (to be used as ID/title) +class REVENGE_API RVNGSVGDrawingGenerator_WithTitle : public RVNGSVGDrawingGenerator { + public: + RVNGSVGDrawingGenerator_WithTitle(RVNGStringVector &output, RVNGStringVector &titles, const RVNGString &nmSpace) + : RVNGSVGDrawingGenerator(output, nmSpace) + , _titles(titles) + {} + + void startPage(const RVNGPropertyList &propList) + { + RVNGSVGDrawingGenerator::startPage(propList); + if (propList["draw:name"]) { + _titles.append(propList["draw:name"]->getStr()); + } else { + _titles.append(""); + } + } + + private: + RVNGStringVector &_titles; +}; +#endif + // Read Visio stencil files SPDocument* read_vss( gchar* fullname, Glib::ustring name ) { @@ -472,8 +500,9 @@ SPDocument* read_vss( gchar* fullname, Glib::ustring name ) { } RVNGStringVector output; + RVNGStringVector titles; #if WITH_LIBVISIO01 - librevenge::RVNGSVGDrawingGenerator generator(output, "svg"); + RVNGSVGDrawingGenerator_WithTitle generator(output, titles, "svg"); if (!libvisio::VisioDocument::parseStencils(&input, &generator)) { #else @@ -488,7 +517,7 @@ SPDocument* read_vss( gchar* fullname, Glib::ustring name ) { // prepare a valid title for the symbol file Glib::ustring title = Glib::Markup::escape_text(name); - // prepare a valid id prefix for the symbols (unfortunately libvisio doesn't give us a name) + // prepare a valid id prefix for symbols libvisio doesn't give us a name for Glib::RefPtr regex1 = Glib::Regex::create("[^a-zA-Z0-9_-]"); Glib::ustring id = regex1->replace(name, 0, "_", Glib::REGEX_MATCH_PARTIAL); @@ -505,25 +534,28 @@ SPDocument* read_vss( gchar* fullname, Glib::ustring name ) { tmpSVGOutput += "\n"; tmpSVGOutput += " \n"; - // Each "symbol" is in it's own SVG file, we wrap with and merge into one file. + // Each "symbol" is in its own SVG file, we wrap with and merge into one file. for (unsigned i=0; ireplace(titles[i].cstr(), 0, "_", Glib::REGEX_MATCH_PARTIAL); + } else { + ss << id << "_" << i; + } + + tmpSVGOutput += " \n"; - tmpSVGOutput += " \n"; + if (titles.size() == output.size() && titles[i] != "") { + tmpSVGOutput += " " + Glib::ustring(RVNGString::escapeXML(titles[i].cstr()).cstr()) + "\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 += " " + line + "\n"; } } -- cgit v1.2.3