GithubHelp home page GithubHelp logo

kakwa / libvisio2svg Goto Github PK

View Code? Open in Web Editor NEW
109.0 7.0 21.0 164 KB

Library/Tools to convert Microsoft (MS) Visio documents (VSS and VSD) to SVG

License: GNU General Public License v2.0

CMake 19.50% Shell 13.13% C++ 67.36%
vss visio-documents svg stencil vsd visio svg-conversion-library microsoft c-plus-plus

libvisio2svg's Introduction

Libvisio2svg

Build Status

Library/Utilities to convert Microsoft (MS) Visio Documents and Stencils (VSS and VSD) to SVG.

Motivation

There are tons of publicly available MS Visio stencils, for example the Cisco ones or the stencils from VisioCafe. This library and utilities were created to be able to convert these stencils to SVG and reuse them outside of Microsoft Visio, in programs like yEd, Inkscape, Dia, Calligra Flow...

This library is mainly the glue between librevenge/libvisio, libemf2svg and libwmf.

About libemf2svg

libemf2svg is another library of mine. It was developed to handle MS EMF (Enhanced Metafile) blobs which constitute most of Visio VSS shapes.

Librevenge/Libvisio would otherwise only dump the EMF blob as base64 in an <image> SVG tag, which most viewer/editor/browser would be unable to display.

License

Libvisio2svg is licensed under GPLv2.

Dependencies

Building

Commands to build this project:

# CMAKE_INSTALL_PREFIX is optional, default is /usr/local/
$ cmake . -DCMAKE_INSTALL_PREFIX=/usr/

# compilation
$ make

# installation
$ make install

Regex

The vss2svg and vsd2svg utilities rely on regular expressions to construct safe file names from stencils/sheets names. It will replace anything that is not matching [A-Za-z0-9-] by an underscore.

This functionality relies on regexp from libstdc++ (c++11 standard), but older libraries doesn't support regex.

Yet you can compile without this file name sanitization:

$ cmake . -DUNSAFE_FILENAME=ON
$ make

However, be cautious with the stencil/sheet names, otherwise some files might be written outside the output directory.

Usage

Command Line

Convert VSS:

# conversion
$ vss2svg-conv -i ./2960CX.vss -o ./out/ -s 4.5

$ ls out/
'Cisco R42610 Front.svg'      'WS-C2960CX-8PC-L Rear.svg'   'WS-C2960CX-8TC-L Rear.svg'
'WS-C2960CX-8PC-L Front.svg'  'WS-C2960CX-8TC-L Front.svg'

# help
$ vss2svg-conv --help

Convert VSD:

# conversion
$ vsd2svg-conv -i ./my.VSD -o ./out/ -s 7

$ ls out/
Page-1.svg  Page-2.svg  Page-3.svg  Page-4.svg

# help
$ vsd2svg-conv --help

Library

Convert Visio Documents

example:

#include <fstream>
#include <iostream>
#include <unordered_map>
#include <visio2svg/Visio2Svg.h>

int main(int argc, char **argv) {
    // Put visio file in an std::string
    // (no error checking, should be done in actual code)
    std::ifstream stin(argv[1]);

    std::string visio_in((std::istreambuf_iterator<char>(stin)),
                         std::istreambuf_iterator<char>());

    // Initialize converter and output map
    visio2svg::Visio2Svg converter;
    std::unordered_map<std::string, std::string> out;

    // return code
    int ret = 0;

    // Pick one of the following

    // Convert vsd documents
    ret = converter.vsd2svg(visio_in, out);

    // Convert vss (Stencils) documents
    ret = converter.vss2svg(visio_in, out);

    // or with rescaling
    ret = converter.vsd2svg(visio_in, out, 4.5);
    ret = converter.vss2svg(visio_in, out, 4.5);

    if (ret)
        std::cerr << "Conversion errors occured"
                  << "\n";

    // Do something with the output
    for (const auto &rule_pair : out) {
        std::cout << "Sheet Title: " << rule_pair.first << std::endl;
        std::cout << rule_pair.second << std::endl;
    }
}

Recover symbol titles

This library also comes with a RVNG generator to recover symbol titles:

#include <iostream>
#include <librevenge-generators/librevenge-generators.h>
#include <librevenge-stream/librevenge-stream.h>
#include <librevenge/librevenge.h>
#include <libvisio/libvisio.h>
#include <visio2svg/TitleGenerator.h>

int main(int argc, char **argv) {
    // put the Visio document in an RVNGFileStream 
    // (no error checking, should be done in actual code)
    librevenge::RVNGFileStream input(argv[1]);

    /* String stream version (need to be set)
    librevenge::RVNGStringStream input;
    */

    // Recover Titles of each sheets
    librevenge::RVNGStringVector output_names;
    visio2svg::TitleGenerator generator_names(output_names);

    bool ret = libvisio::VisioDocument::parseStencils(&input, &generator_names);
    /* or this for vsd
    ret = libvisio::VisioDocument::parse(&input, &generator_names);
    */

    if (!ret || output_names.empty()) {
        std::cerr << "ERROR: Failed to recover sheets titles failed!"
                  << std::endl;
        return 1;
    }

    // do something with the names
    for (unsigned k = 0; k < output_names.size(); ++k) {
        std::cout << "Title of stencil " << std::to_string(k) << std::endl;
        if (output_names[k].empty()) {
            std::cout << "no title set in stencil number " << std::to_string(k)
                      << std::endl;
        } else {
            std::cout << output_names[k].cstr() << std::endl;
        }
    }
}

Changelog

0.5.5

  • add LIB_INSTALL_DIR variable in cmake

0.5.4

  • fix freetype discovery in cmake

0.5.3

  • fix segfault if shape doesn't contain title

0.5.2

  • fix error in setting title field with titles containing "&"
  • add XML_PARSE_HUGE in xml parsing to allow big image blobs.
  • better precision for image dimensions (keep 10 decimals)

0.5.1

  • add support for OSX

0.5.0

  • adding support to convert wmf blob (using libwmf)
  • requires new libraries as dependencies: libwmf and freetype)
  • requires libemf2svg version >= 1.0.0
  • cleaner and more explicit dependencies resolving in cmake

0.4.1

  • adding safeguard regarding unsafe output file paths

0.3.0

  • better error handling

0.2.0

  • add rescaling option + title

0.1.0

  • first release

libvisio2svg's People

Contributors

kakwa avatar marioapardo avatar spike77453 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

libvisio2svg's Issues

ERROR: font.c (1334): wmf_ipa_font_map: failed to load *any* font!

Hi,

I can't fix an issue with the wmf API.

When I try to convert a vss file I got this message.
Looks like an issue with libwmf and map fonts.

vss2svg-conv -i X430.vss 
ERROR: font.c (1334): wmf_ipa_font_map: failed to load *any* font!

I tried on Arch with this https://aur.archlinux.org/packages/libvisio2svg/
And on Debian with

apt update
apt install -y gcc g++ make cmake libpng-dev libc6-dev libfontconfig1-dev libfreetype6-dev git libxml2-dev libwmf-dev libtool automake libvisio-dev libboost1.55-dev libcppunit-dev wget unzip doxygen

git clone https://github.com/kakwa/libvisio2svg.git /root/libvisio2svg
git clone https://github.com/kakwa/libemf2svg.git /root/libemf2svg
git clone http://git.code.sf.net/p/libwpd/librevenge /root/librevenge

cd /root/libemf2svg
cmake . -DCMAKE_INSTALL_PREFIX=/usr/
make
make install

cd /root/librevenge
./autogen.sh
./configure
make
make install

cd /root/libvisio2svg
cmake . -DCMAKE_INSTALL_PREFIX=/usr/
make
make install

Have I miss something?
Many thanks

Commit 7da4205 Breaks Build

Hello there,
I was unable to build successfully with commit 7da4205 in place. After reverting, the build went fine. Looks like there is an issue with the regex_replace call this commit adds. Since it's just a safeguard, I'll sanitize my filenames before running as a workaround.

That said, figured you might want to know this issue is present. Is it a version issue perhaps? I'm assuming this builds fine on other (perhaps more updated) systems. I didn't dig into it further, but I wanted to drop this here as FYI for @kakwa and anyone else who might encounter this issue.

Otherwise, very useful little tool! Thanks!

Here's some system/version info:

Ubuntu 14.04 i686 (x32 virtual machine)
g++ 4.8.2
libstdc++-4.8-dev (4.8.2-19ubuntu1)

Windows support?

Does this project support building in Windows? Is there any plan to get this building in Windows? Thanks,

Windows bundle

Hi, it is longer time when I worked with Visual Studio, but having 2015 and being interested to build Windows bundle of this tool with dependencies, is there any easy out-of-the box way?

Thanks for hints.

I'm getting errors when trying to build this on ubuntu 16.04

When i run the cmake command i get the following. I'm very new to building projects any and all help would be awesome! thank you

$ cmake . -DCMAKE_INSTALL_PREFIX=/usr/
-- Find Header Directory for libemf2svg: LIBEMF2SVG_INCLUDE_DIR-NOTFOUND
-- Find Dynamic Library for libemf2svg:  LIBEMF2SVG_LIBRARIES-NOTFOUND
-- Find Header Directory for libwmf: LIBWMF_INCLUDE_DIR-NOTFOUND
-- Find Dynamic Library for libwmf:  LIBWMF_LIBRARIES-NOTFOUND
-- Find Dynamic Library for libwmflite:  LIBWMFLITE_LIBRARIES-NOTFOUND
-- Find Header Directory for librevenge: LIBREVENGE_INCLUDE_DIR-NOTFOUND
-- Find Header Directory for librevenge: LIBREVENGE_STREAM_INCLUDE_DIR-NOTFOUND
-- Find Dynamic Library for librevenge:  LIBREVENGE_LIBRARIES-NOTFOUND
-- Find Dynamic Library for librevenge:  LIBREVENGE_STREAM_LIBRARY-NOTFOUND
-- Find Header Directory for libvisio: LIBVISIO_INCLUDE_DIR-NOTFOUND
-- Find Dynamic Library for libvisio:  
CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find Freetype (missing: FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS)
Call Stack (most recent call first):
  /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.5/Modules/FindFreetype.cmake:151 (find_package_handle_standard_args)
  CMakeLists.txt:12 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/<USER>/libvisio2svg/CMakeFiles/CMakeOutput.log".

Conversion Error (Shifted Images)

Hi,

When converting some VSS stencils for a project I'm working on, most of the stencils come out fine.
Sometimes, they don't come out fine, and are shifted down by about half of the height of the image.

A particular example I have found, from here: https://www.juniper.net/assets/visio-icons/juniper-mx-series-icons.zip

If you extract the zip, and then convert the file, the 10x10GE_MIC.svg file will be incorrectly positioned, with the beginning of the top of the image halfway down the image "space". If I open it in ImageMagic, I can shift it to fit correctly into the viewport, but for the number of conversions I want to do, it's not practical to fix the SVG's individually.

I am entering the following to convert the vss file to svg's:

mkdir outputFolder
vss2svg-conv -i input.vss -o outputFolder

If you could find a fix, that would be super wonderful.

Thanks!

PS. Nice tool/library by the way, it is really helpful. I can't find anything else like it.

Homebrew formula

I would like to create and Homebrew formula for libvisio2svg and submit it to homebrew-core. I've also created issue #19 for libemf2svg which would be a dependency for this. Once I built libemf2svg, the build on macOS Sierra was very straight-forward with the other dependencies already in Homebrew. Before I do this though, I want to make sure you, @kakwa, are OK with me submitting a formula for your project. Also, I have two questions:

  1. Are there any known restrictions on dependency versions, OS X versions, or architectures?
  2. Would it be acceptable to create and distribute "bottles", i.e. binary packages, given your license and the project's dependency licenses? If you're unsure, I'm happy to dig into it.

Error on MAKE

Hi,
I'm trying to install libvisio2svg on my MAC M1 but I'm encountering a problem that I don't know how to solve.

brew install git

=> OK

brew install librevenge libwmf libvisio libemf2svg argp-standalone

=> OK

git clone https://github.com/kakwa/libvisio2svg

=> OK

cd libvisio2svg

=> OK

~/libvisio2svg $ cmake . -DCMAKE_INSTALL_PREFIX=/usr/local
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The C compiler identification is AppleClang 15.0.0.15000040
-- The CXX compiler identification is AppleClang 15.0.0.15000040
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Find Header Directory for libemf2svg: /opt/homebrew/include
-- Find Dynamic Library for libemf2svg:  /opt/homebrew/lib/libemf2svg.dylib
-- Find Header Directory for libwmf: /opt/homebrew/include
-- Find Dynamic Library for libwmf:  /opt/homebrew/lib/libwmf.dylib
-- Find Dynamic Library for libwmflite:  /opt/homebrew/lib/libwmflite.dylib
-- Find Header Directory for librevenge: /opt/homebrew/include/librevenge-0.0
-- Find Header Directory for librevenge: /opt/homebrew/include/librevenge-0.0
-- Find Dynamic Library for librevenge:  /opt/homebrew/lib/librevenge-0.0.dylib
-- Find Dynamic Library for librevenge:  /opt/homebrew/lib/librevenge-stream-0.0.dylib
-- Find Header Directory for libvisio: /opt/homebrew/include/libvisio-0.1
-- Find Dynamic Library for libvisio:  /opt/homebrew/lib/libvisio-0.1.dylib
-- Found LibXml2: /Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/lib/libxml2.tbd (found version "2.9.13") 
-- Found Freetype: /opt/homebrew/lib/libfreetype.dylib (found version "2.13.2") 
-- Configuring done (1.2s)
CMake Warning (dev):
  Policy CMP0042 is not set: MACOSX_RPATH is enabled by default.  Run "cmake
  --help-policy CMP0042" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  MACOSX_RPATH is not specified for the following targets:

   TitleGenerator
   Visio2Svg

This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done (0.0s)
-- Build files have been written to: /Users/romain/libvisio2svg

=> NOK

~/libvisio2svg $ make
[ 12%] Building CXX object CMakeFiles/TitleGenerator.dir/src/lib/visio2svg/TitleGenerator.cpp.o
[ 25%] Linking CXX shared library libTitleGenerator.dylib
[ 25%] Built target TitleGenerator
[ 37%] Building CXX object CMakeFiles/Visio2Svg.dir/src/lib/visio2svg/Visio2Svg.cpp.o
In file included from /Users/romain/libvisio2svg/src/lib/visio2svg/Visio2Svg.cpp:3:
In file included from /Users/romain/libvisio2svg/inc/visio2svg/Visio2Svg.h:7:
/opt/homebrew/include/libwmf/ipa.h:72:15: warning: 'wmf_ipa_bmp_copy' has C-linkage specified, but returns incomplete type 'wmfBMP' (aka '_wmfBMP') which could be incompatible with C [-Wreturn-type-c-linkage]
extern wmfBMP wmf_ipa_bmp_copy (wmfAPI*,wmfBMP*,unsigned int,unsigned int);
              ^
/opt/homebrew/include/libwmf/ipa.h:89:15: warning: 'wmf_rgb_white' has C-linkage specified, but returns incomplete type 'wmfRGB' (aka '_wmfRGB') which could be incompatible with C [-Wreturn-type-c-linkage]
extern wmfRGB wmf_rgb_white (wmfAPI*);
              ^
/opt/homebrew/include/libwmf/ipa.h:90:15: warning: 'wmf_rgb_black' has C-linkage specified, but returns incomplete type 'wmfRGB' (aka '_wmfRGB') which could be incompatible with C [-Wreturn-type-c-linkage]
extern wmfRGB wmf_rgb_black (wmfAPI*);
              ^
/opt/homebrew/include/libwmf/ipa.h:91:15: warning: 'wmf_rgb_color' has C-linkage specified, but returns incomplete type 'wmfRGB' (aka '_wmfRGB') which could be incompatible with C [-Wreturn-type-c-linkage]
extern wmfRGB wmf_rgb_color (wmfAPI*,float,float,float);
              ^
4 warnings generated.
[ 50%] Linking CXX shared library libVisio2Svg.dylib
ld: library 'argp' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libVisio2Svg.0.5.5.dylib] Error 1
make[1]: *** [CMakeFiles/Visio2Svg.dir/all] Error 2
make: *** [all] Error 2

=> NOK ...

I get empty files

Hello,

i use version 0.2.1. When i use this vss file, most of the outputfiles are empty. If i run in verbose mode there is no more output.

Blank/image offset SVG files when converting Office VSS files

Some symbols from the "Office Symbols" stencil are not converted correctly.

Steps to reproduce:

Download stencils from https://www.microsoft.com/en-gb/download/details.aspx?id=35772

Run

vss2svg-conv -i ./2012_Stencil_121412.vss -o ./out/

Most of the files are converted, but some files have blank images e.g.

Active_Directory_Federation_Services_Proxy.svg
Address_Book_Policies.svg
Address_Book_Store.svg

etc.

These display correctly in Inkscape using libvisio, so I don'ŧ think this is a libvisio issue.

Thanks.

Christopher Hoskin

open_memstream is not supported on macOS

When I try to build, I receive an error because open_memstream is not supported on macOS.

Visio2Svg.cpp:194:13: error: use of undeclared identifier 'open_memstream' out_f = open_memstream(out, out_length);

Is there a potential workaround?

Error at Compiling time

Hi, thank you very much for your effort into creating this tool,

Im getting the next error at compiling time: (Im sorry if Im asking at the wrong place, Im an Operations guy trying to compile this.)

x@x /tmp/vss/libvisio2svg » make
Scanning dependencies of target TitleGenerator
[ 12%] Building CXX object CMakeFiles/TitleGenerator.dir/src/lib/visio2svg/TitleGenerator.cpp.o
[ 25%] Linking CXX shared library libTitleGenerator.so
[ 25%] Built target TitleGenerator
Scanning dependencies of target Visio2Svg
[ 37%] Building CXX object CMakeFiles/Visio2Svg.dir/src/lib/visio2svg/Visio2Svg.cpp.o
[ 50%] Linking CXX shared library libVisio2Svg.so
[ 50%] Built target Visio2Svg
Scanning dependencies of target vsd2svg-conv
[ 62%] Building CXX object CMakeFiles/vsd2svg-conv.dir/src/conv/vsd2svg.cpp.o
[ 75%] Linking CXX executable vsd2svg-conv

/bin/ld: CMakeFiles/vsd2svg-conv.dir/src/conv/vsd2svg.cpp.o: undefined reference to symbol '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3'
/usr/lib64/libstdc++.so.6: error adding symbols: DSO missing from command line

collect2: error: ld returned 1 exit status
CMakeFiles/vsd2svg-conv.dir/build.make:103: recipe for target 'vsd2svg-conv' failed
make[2]: *** [vsd2svg-conv] Error 1
CMakeFiles/Makefile2:174: recipe for target 'CMakeFiles/vsd2svg-conv.dir/all' failed
make[1]: *** [CMakeFiles/vsd2svg-conv.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2  

I guess, I have some wrong version of the Libraries linked, but again I know very little about compiling, the version of the libraries used are:

libwmf-devel-0.2.8.4-46.fc22.x86_64
libvisio-tools-0.1.5-1.fc22.x86_64
librevenge-devel-0.0.4-1.fc22.x86_64
libvisio-devel-0.1.5-1.fc22.x86_64
librevenge-0.0.4-1.fc22.x86_64
libwmf-0.2.8.4-46.fc22.x86_64
libvisio-0.1.5-1.fc22.x86_64
libwmf-lite-0.2.8.4-46.fc22.x86_64

I compiled your libemf2svg from git today and I got this:

x@x /tmp/vss/libvisio2svg » ls -lha /opt/visio/libemf2svg/lib/
lrwxrwxrwx. 1 x x     15 Jul 25 16:53 libemf2svg.so -> libemf2svg.so.1
lrwxrwxrwx. 1 x x     19 Jul 25 16:53 libemf2svg.so.1 -> libemf2svg.so.1.0.1
-rwxr-xr-x. 1 x x   2.7M Jul 25 16:53 libemf2svg.so.1.0.1

Any help in regards of what could be wrong? Im setting up a VM to download and compile all the libraries stated at README.md to see if that helps but in the meantime i thought why not to also ask xD

Thank you very much.

vss files partially unconverted

I noticed while converting a vss file that while the output files are indeed svg, the main content for some of the resulting files merely contain an image tag whose contents are still base64-encoded image/wmf data. One such example vss that exhibits this behavior is this one.

Running the vss2svg command resulted in no output to the terminal, so no errors were displayed or anything.

Segmentation fault on some vss

I'm trying to convert a vss file from Cisco, but console prints "Segmentation fault" right after execution. By thinning the stencils included in the vss down, I've been able to identify the exact ones vss2svg-conv seem unable to convert. I do not think this is related to how the stencils are named (I've tried renaming).

Attached are some sample vss files

I'm curious as to what makes these stencils "special", or "incompatible" with vss2svg-conv.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.