SVG using Inkscape

From PostgreSQL wiki
Jump to: navigation, search

Inkscape SVG vs. Optimized SVG

Inkscape supports different file formats to serialize its graphics. Inkscape SVG is the product specific format which stores the complete information about the actual graphic - including those concepts which not part of the SVG standard. Therefore this file is huge and not portable to other tools. In contrast Optimized SVG (dont't confuse it with Plain SVG) creates a small file containing only those parts which are necessary for final rendering. This format even performs optimizations by collecting common definitions into higher level elements.

There are two sets of parameters which influence the behaviour of Inkscape.

New File

First, you can choose diverse parameters concerning the actual graphic, e.g. it’s size, default measurement in px, pt, em or something else, scaling factor, metadata, grid on/off, and many more. To support a consistent usage of those parameters across our graphics, they can be stored at a central place. Whenever you create a new graphic, they are read from $HOME/.config/inkscape/templates/default.svg. (Technically this is the default template for all new graphics. If you want to keep the previous Inkscape behaviour for other tasks, you shall create a file postgres.svg in the template directory and create new files with the command: File / New from Template / postgres.) Here is the recommended content:

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
  viewBox="0 0 580 280">
  <defs id="defs1" />

    inkscape:window-maximized="false" >
    <inkscape:grid type="xygrid" id="grid1" />

      <cc:Work rdf:about="">
        <dc:type rdf:resource="" />

<!-- border and background -->
  <rect x="1" y="1" width="99.4%" height="99.4%" rx="1%" 
        fill="whitesmoke" stroke="#CCCCCC" /> <!-- fill="hsl(0, 0%, 97%)" stroke="hsl(0, 0%, 80%)" /> -->


Save As

Second, you can choose how to generate the Optimized SVG format. Select the following options after: File / Save As

InkscapeSaveFile 1.png

InkscapeSaveFile 2.png

InkscapeSaveFile 3.png

InkscapeSaveFile 4.png

Using symbols

You can define graphical elements which are used multiple times within one (or in different) files in a <defs><symbols> construction and refere them from any position within the SVG file. SVG 1.1 (and the SVG 1.2 draft) proposed a XLink syntax:

<use xlink:href="filename#symbol_id"/>

In the comming SVG 2.0 standard XLink is deprecated in favor of a no-namespace syntax:

<use href="filename#symbol_id">

Inkscape (in version 0.92) does not accept the new syntax. But if you receive an SVG file from any other tool, it is possible that the new syntax is used. In this case you must manually correct the file - and don't forget to declare the namespace: xmlns:xlink="" in the root element.

Manual corrections

Control the optimized file with an XML- or text-editor and perform some manual corrections. In addition to the hints shown here there are some general hints for this step.

  • Sometimes there are a lot of identical and therefore unnecessary <marker> elements (Inkscape 0.92). Purge them manually.
  • Sometimes there is a scale(0) attribute which leads to invisibility of its element. Change it to something like scale(0.5).
  • text elements are always created with an additional tspan element. This happens in regard to multiline texts. An example:
<text ... >
  <tspan x="50" y="20" ... >line one</tspan>
  <tspan x="50" y="40" ... >line two</tspan>
  <tspan x="50" dy="20" ... >line three</tspan>

If you create a single line text, please use the much simpler syntax:

<text ... >One line</text>