Fritzing Export SVG problem exploring

This github repository and associated githubio pages track and document exploration of what works, and does not work, creating Fritzing parts, then attempting to export the views as svg images.

The Problem

When creating Fritzing documents of circuits, then exporting the views to svg images, some content gets dropped. This is seen mostly for custom parts. Since the content does get included when exporting to png or jpeg images, there appears to be a problem with the svg export code. However, since most parts export correctly, there is also some interaction with the way the parts have been created. This is some exploration of that. The svg and fzp files that go into an fzpz part file are manipulated in various ways.

The svg export also gets the automatic text rotation wrong for both part rotations and flips. The schematic view, and png export look correct.

Environment

The Process

Setup

Getting a working part

Testing process

Testing History

Testing log

Discoveries

fzp

See FZP format for a lot of useful details.

General SVG

Typically SVG files use 90 pixels per inch, but Illustrator uses 72 pixels per inch. Fritzing might figure it out correctly, but editing the svg element to set the width and height attributes in inches (in) can work around the difference.1

Terminal elements are optional in breadboard view.2 When they do not exist, the centre point of the connector pin graphics is used.

See About SVGs

html style comments in the source svg file get carried through to the view export svg.

Breadboard svg file

the snapped 'zero' position varies a small amount from build to build, although the breadboard svg file was not touched.

Schematic svg file

From the supplied svg template file
<!-- Generator: Adobe Illustrator 15.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->

The template does not include a doctype, but does have the xmlns:inkscape attribute in the svg tag.

The template does not include an enable-background attribute

The svg element has a Layer_1 id

There are 3 top level groups, with ids of background, help, and schematic

There are no references to connector or terminal

From the base working svg file
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->

Despite that, the svg tag includes an xmlns:inkscape attribute. The x, y, width, height attributes are in pixels (px), starting from (0,0). The viewBox and enable-background use the same coordinates, without units.

The top level group wrapper <g id="schematic"> contains a single group <g id="layer1"> plus a pair of rectangle objects for each connection pin. The rectangles have ids of "connector«pinNumber»" and "connector«pinNumber»terminal". These are NOT part of the layer1 group, and do not have any stroke or style information. Fill is set to none. The pin numbers are not sequential, but match the (zero based) pin positions for a 14 pin DIP chip. Other svg files have connector«n» ids, but only svg also has the terminals.

The layer1 group has a transform attribute that translates by a fairly large amount (-202,-376). In addition to the graphics for the part, it contains line elements (nested in more groups) with stroke="#787878" for the connector lines. These do NOT have an id

To match the standard 0.1 inch snap grid, the complete schematic graphics should start at (0,0), and be multiples of 0.1 in width and height. That will be multiples of 7.2 or 9.0 px. Rectangular schematic symbols that have pin connections around the outside should have a background rectangle that matches the viewBox, but inset by 0.1 inch on each side that any connection pins exist. That inset needs to be adjusted by an addition 0.5 of the background rectangle stroke width (which could be zero). That means adding 0.5 * stroke width to the x and y rect element coordinates, and subtracting 1.0 * stroke width from the width and height.

Fritzing aligns (at least) the schematic symbol position (origin) based on the (first?) detected pin location. Not on the viewBox origin. Symptoms make it look like the viewBox origin is not on a grid boundary, but the terminal end of the first pin is.

Graphics content in the schematic svg file that is NOT inside of the schematic (id) group is visible in the Fritzing view, but does not get exported to the svg image. However, it DOES get exported to png. Exporting to png even includes the current highlight / selected element dashed border. Is the whole problem simply graphics that is not inside the appropriate view/layer group? connector«n»terminal graphics is fine outside of the group, because that is functionality for Fritzing, and does not show on the export anyway.

If there are no top or bottom schematic pin connections, the height of the graphics does not need to be a multiple of 0.1 inch, and the side pin connections do not need to be a multiple of 0.1 inch from the top. They still needed to be separated vertically by multiples of 0.1 inch.

defs and use tags give in file reusable block, and look good in Fritzing. However, the defs element does not get exported with the rest of the view svg. The use elements do (assuming other constraints valid), but without the defs, they are invisible.

After rotate, drag to make sure pin locations get snapped to grid.

Example data values

PCB svg file

See More SVG topics for a few PCB specific svg rules and options.