• Stars
    star
    109
  • Rank 312,531 (Top 7 %)
  • Language
    C++
  • License
    GNU General Publi...
  • Created over 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

ldapcherry

Web UI for managing users and groups in multiple directory services.
Python
219
star
2

py-ascii-graph

A simple python lib to print data as ascii histograms
Python
117
star
3

kakwafont

Kakwafont, a 12px monospace bitmap font based on Terminus
Makefile
88
star
4

libemf2svg

Microsoft (MS) EMF to SVG conversion library
C
87
star
5

uts-server

Micro RFC 3161 Time-Stamp server written in C.
C
74
star
6

pylogic

Python Module for Logical Validation (forked from Rob Truxler library)
Python
24
star
7

pygraph_redis

Simple python library to manipulate directed graphs in redis
Python
24
star
8

dnscherry

Small cherrypy application to manage dns zones.
CSS
11
star
9

puppet-samba

Puppet samba module ⛺
Puppet
9
star
10

amkecpak

Amkecpak, a makefile based packaging framework.
Shell
6
star
11

htpasswd-editor

htpasswd-editor is a simple Perl CGI to manage htpasswd files
Perl
6
star
12

dwm-desktop

dwm + configuration + mods + shell utilities
C
6
star
13

talend-codegen

Command line code generation (job export) plugin for talend
Java
5
star
14

wifish

wifish are small scripts to get ride of wicd/NetworkManager
Shell
4
star
15

genautoo

Genautoo: an automated installer for gentoo
Shell
3
star
16

git-create.cgi

Simple CGI to create git repositories
Perl
3
star
17

debian-rpm-build-tools

Debian Packaging of various RPM build tools and dependencies (mock, dnf, etc)
Shell
2
star
18

fradomus

Python library to query french real estate ads website such seloger, pap, etc
Python
2
star
19

cinclude2svg

cinclude2dot + mods + helper script + static site generator
JavaScript
2
star
20

sytadin-scraper

sytadin traffic info scraper written in perl
Perl
2
star
21

mkcomment

mkcomment is a really simple script to make nicely centered comment line
1
star
22

wows-whaling-simulator

Simulator estimating how much you need to whale to get one or more specific ships in Christmas Containers
Go
1
star
23

validate-puppet

Small shell script to validate puppet and erb source code
Shell
1
star
24

python-hoi4tools

Python
1
star
25

mk-sh-skel

just a simple script skeleton initializer
Shell
1
star
26

wows-geometry

World of Warships .geometry (3D model) parser
C
1
star
27

dmenu-user

A small launcher menu based on dmenu
Shell
1
star
28

image-writer

playing around old image writer and appletalk
C
1
star
29

gen-badge

Small shell script to generate a "Travis-CI" like SVG status badges/shields
Shell
1
star
30

thinkfan-sh

simple fan control script for thinkpad
Shell
1
star
31

mystarred

1
star
32

ldapcherry-ppolicy-cracklib

Cracklib password policy plugin for LdapCherry
Python
1
star
33

supybot-plugin-seloger

supybot plugin for seloger
Python
1
star
34

radiateur-linux

A simple linux iso builder transforming a computer into a radiator (boot -> launch stress, that's all)
Shell
1
star
35

tapemgr-124t

Utilities and library to manage a Dell PowerVault 124-t from command line
Perl
1
star
36

trc

tar revision control
Shell
1
star
37

puppet-auto_update

A puppet module auto-updating your Debian/CentOS daily
Puppet
1
star
38

hoi4-production-calculator

HOI4 editor to optimize military factory allocation
Python
1
star
39

collectd-opentsdb

Alternative TSDB writer with inclusion of tag logic and http API support
C
1
star
40

curriculum-vitae

My curriculum vitae
TeX
1
star
41

ansible

My Ansible configuration
Shell
1
star