Importing vector files with holes in them get filled

I’d like to rekindle this discussion which crops up from time to time.

Back then, in KiCad 6.0.2, importing an SVG that contains polygons with internal holes would import the polygon without the hole. Something relevant was fixed in #6739, and now importing SVGs like these works as expected:

fillrule-evenodd
opqrs

But the story doesn’t stop there, as I discovered trying to import this project. The importer does a really, really impressive job, but the silkscreen suffers the filled-hole symptom:

Just an importer issue you might think. But the issue remains no matter which way I slice it.

For example, the gerber for that layer renders just fine in Gerber Viewer:

but exporting from there to an SVG file suffers the same fate, despite the SVG itself rendering correctly in any of the several viewers I tried (ha! but not the KiCad forum apparently!!)

n21-evt_Legend_Top.gbr

So I tried some other tools. gerber-to-svg and tracespace produced svgs with the same symptoms. I found tracespace view a handy way to produce the files. I tried various SVG export/manipulation/conversion techniques and couldn’t find a workaround.

Okay, so what about exporting from the Altium original? I could only find a DXF exporter, and alas it only gives me outlines.

Okay, one last option: gerber to Gerber Viewer to pcbnew file. It produced the same result just as you would expect, with one important difference: the polygons for inner holes are there! They’re additive instead of subtractive, but at least we’re not entirely lost.

After exhausting any option I could think of, I came back to this as the best starting point. Thanks to the glorious text file formats of KiCad documents, I was able to create a footprint with these graphics, and then stitch together the inner and outer polygons point by point!

Fortunately, the inner polygons were always already running in the opposite direction, so with just a couple of extra points to join the two together, I’m home.

So ultimately, I think my workaround was just to manually do what SVG is supposed to do automatically (but often doesn’t due to an exceptionally complicated standard). But while the solution is similar, I’m not sure if this is a different issue to #6739, given it affects a path that ostensibly doesn’t involve SVG (ie. gerber straight to pcbnew).

Is this a bug?

I does seems like it, because as I remember it has been tackled before. You forgot to write your KiCad version (Help->About KiCad->Copy version info).

EDIT: I imported the different SVG from the bug report in KiCAD (v7.0.2) and they worked as expected, I imported your svg (it is hidden) and I got the result that you show, however, I also got the same result when opening it with Inkscape.

EDIT2: The file exported directly from tracespace or gerbv, are open correctly in Inkscape but not in KiCAD.

SVG:
n21-evt.GTO

Import in KiCAD:

Application: KiCad PCB Editor x64 on x64

Version: 7.0.2, release build

Libraries:
	wxWidgets 3.2.2
	FreeType 2.12.1
	HarfBuzz 6.0.0
	FontConfig 2.14.1
	libcurl/7.88.1-DEV Schannel zlib/1.2.13

Platform: Windows 10 (build 19045), 64-bit edition, 64 bit, Little endian, wxMSW

Build Info:
	Date: Apr 15 2023 19:18:27
	wxWidgets: 3.2.2 (wchar_t,wx containers)
	Boost: 1.81.0
	OCC: 7.6.3
	Curl: 7.88.1-DEV
	ngspice: 40
	Compiler: Visual C++ 1934 without C++ ABI

Build settings:
	KICAD_SPICE=ON

I stick with v6 and in v6, setting this fixed DXF and Text (graphics). Perhaps it will help you…

File>Editt_Text_and_Graphic_Properties

FYI … imported into different Layers…

Oh! Something happened to it during its journey through the forum! Very strange - the original file is fine, but same as you, if I download from my post I get the filled holes. How bizarre. Let me try attaching the original again by compressing it first:

n21-evt_Legend_Top.gbr.svg.zip (37.4 KB)

Good suggestion. Alas, I just tried with 6.0.9 and got the same results. Can you try the file in the zip with your v6? Do you see different behaviour?

Thanks for the reminder:

Application: KiCad arm64 on arm64

Version: 7.0.2-0, release build

Libraries:
	wxWidgets 3.2.2
	FreeType 2.12.1
	HarfBuzz 5.3.1
	FontConfig 2.14.0
	libcurl/7.87.0 SecureTransport (LibreSSL/3.3.6) zlib/1.2.11 nghttp2/1.51.0

Platform: macOS Ventura Version 13.3.1 (Build 22E261), 64 bit, Little endian, wxMac

Build Info:
	Date: Apr 17 2023 07:41:02
	wxWidgets: 3.2.2 (wchar_t,wx containers)
	Boost: 1.80.0
	OCC: 7.6.3
	Curl: 7.77.0
	ngspice: 38
	Compiler: Clang 13.0.0 with C++ ABI 1002

Build settings:
	KICAD_SPICE=ON

The ‘Upshot’ is your file is Not fully SVG readable by all Graphic Apps. It looks like the Pathing function did not work (i.e., Pathing done by a ‘Path’ tool in many graphic programs takes various items and puts them nicely on a Path. Also, some characters are Not path-able. Some characters are Glyph’s… some are Fonts of different types…

As-Is, your graphic loaded in Kicad with the Same problem of filled-in characters.

It opens fine in BBedit and Libre’s Draw. But, some others open with same problem.

Please understand that not all SVG’s are equal. The first thing I would do is to make sure you’ve “Pathed” your artwork (Inkscacape and others can do that for you.) and are using good Font’s.

I’ve written SVG graphic apps and understand SVG well enough to say there are quite a few different SVG requirements for obtaining desired results. Some of the rqmt’s are embedded in the SVG format and I suggest you try different ones… Some require clicking Checkbox’s for various attributes. Screenshot example from EZdraw…

Attached info may/may-not help to inform you about Saving your Artwork…
svg_Info.txt.zip (217.8 KB)

1 Like

I forgot a useful approach:

I imported your SVG into Kicad.
I copied the Graphic and pasted it.
I typed in New Text.
I Transferred them to user-Eco layer so I could Plot only them.
I ‘Plotted’ it as DXF (using Kicad’s Plot).
I Imported the DXF back into Kicad and set them to Front Cu layer.

Sure, the Font is not your original but, I imagine you can find a Font that will be okay. I did set their Size and Line dimension such as to have ‘blues’ a tad heavier…

The List of Fonts in FreeCAD is quite long… I typed the Text, set the Font and clicked the ‘DXF’ icon at top. Then, imported into Kicad…

1 Like

My posts are getting messy so, this should be the last (I hope).

I showed the DXF usage. Kicad does Not differentiate DXF fonts so, Now, below shows SVG with the Text converted to a Bizer-Path (I used EZdraw but, other apps can do the same…)

Call it Perfect! Shows Fonts as intended…

Thanks @BlackCoffee , that interesting. Just to be clear, my interest wasn’t in recreating the original or designing SVGs - my workaround already solved my particular problem (the result is available here if you’re interested). I just came here later to point out a potential (fixable) flaw in KiCad’s ability to import vectors. To recap, I think the scorecard is:

  • PcbDoc → open in pcbnew : fail
  • PcbDoc → export to DXF → import into pcbnew : fail
  • gerber → Gerber Viewer → export SVG → import into pcbnew : fail
  • gerber → gerber-to-svg → import into pcbnew : fail
  • gerber → tracespace → import into pcbnew : fail
  • gerber → Gerber Viewer → export to pcbnew : fail, but recoverable because at least the hole polygons are there.

And this is all despite each of those routes producing artefacts that appear okay in other viewers (well some, but not all because ergh, SVG in web land is hard).

1 Like

I found another instance of the same phenomena (holes getting filled) and this time there’s no apparent SVG involvement.

If I open TOP.art in Gerber Viewer from the gerbers here I see this section, which is correct:

If I “Export to PCB editor” and then open in pcbnew, I see this:

Screenshot 2023-05-19 at 10.40.17 pm

The three clearance gaps near the middle of the picture are missing!

Again, the polygons are there, they just don’t make holes. Here, to demonstrate, I’ve deleted the big fill and then selected the feature inside one of the polygons that should be a hole.

Screenshot 2023-05-19 at 10.41.58 pm

So there still seems to be some disagreement between intent and the way pcbnew interprets vectors with holes.

The problem is, your original SVG file does not contain any holes - i.e. the polygons representing the letters are not defined as closed paths with holes. Instead, the holes in letters ‘e’ and ‘b’ are done using a mask feature of the SVG file format (select the whole logo in Inkscape and then ungroup - the holes will disappear). KiCad does not and likely will not support SVG layers/masks as it doesn’t have a notion of a graphical mask (we are an EDA/CAD tool, not a competitor of Inkscape or Corel :smiley: ). The easiest way to fix your file is to redo the logo text in Inkscape (you can use WhatTheFont or a similar site to identify the original font) and then save the SVG file with “convert text to curves” option on.

T.

1 Like

Ah! A “mask”. That makes sense.

I guess my original point stands then. I’m not interested in fixing my lettering issue - I solved that ages ago (towards the bottom of the first post). I’m interested in whether pcbnew can support vector files with “masks” (as I now understand them to be). Whether they’re gerbers or SVGs the result is currently the same. Looks right in KiCad Gerber Viewer. Quietly looks wrong in KiCad pcbnew.

I think what I’ve learned is “no, pcbnew doesn’t support masks”, which makes sense given it generally doesn’t support negative/void features, and is certainly good to know. Ideally it might throw up a warning when it encounters them during import. And given they seem a “standard” (to whatever extent gerbers are standard!) way to represent pcb layers, maybe one day support could be added (perhaps using the reverse-direction-inner-polygon method I outlined). Or… it might even be possible for a third party service to convert masks to reverse-direction-inner-polygons prior to import…

But just knowing it’s a missing feature at the moment is satisfying.

I have NO problem Importing an SVG (with Letter’s having holes in them) into the Mask Layers… As I previously posted, just convert to a Path. Example show three identical character strings - pure SVG done in Libre Office’s Draw

Top is ‘AS-IS’ - Result is BAD
Middle is Converted to ‘Curve’
Bottom is Converted to ‘Contour’

Then, imported into PCB’s front Mask Layer…

No, the issue isn’t importing SVGs into mask layers of KiCad.

SVGs have their own function called a mask which works very differently from anything KiCad does. A mask in SVG is essentially a “subtractive” layer and it subtracts from the content below it.

We don’t support that kind of generic graphical behavior as we aren’t a graphic editing software.

1 Like

I won 't argue but will say that for several years I wrote and published SVG codes for App’s (as a consultant) - it was a few years ago and what things get called may have changed and I don’t keep-up with the changes. But, as far as I ‘knew’ there was never anything in SVG Spec called ‘Mask’. In the beginning something was called ‘Intrinsic Subtraction’ that changed to ‘Winding’ then to ‘Fill-Rule’ .

https://www.w3.org/TR/SVG11/masking.html#Masking

1 Like

Thanks - the world moves forward (while at 74, I’m looking for the Exit… :joy:

That part of the spec is circa 2003

Clipping, Masking and Compositing - SVG 1.1 - 20030114 (2003 version of the spec)

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.