Font error in parts editor when reading schematic svg which is edited with inkscape

Hi.

Now I am trying to edit parts schematic svg data.

When I tried to edit parts schematic svg without changing any font element with Inkscape. And read the svg file into parts-editor(schematic pane).
Then font-error is occured like this.

I compared the ‘before’ and ‘after’ svg files, There are differences in how to descript font names around ‘text’ elements.

In ‘before’ svg file, font names are descripted like this.

g-
text-
font-family=“Droid Sans”

In ‘after’ svg file, font names are descripted like this.

g-
text-
style=“font-family:Droid Sans;text-anchor:middle;”

In ‘after’ svg file, the font names are descripted as ‘font-family’ parameters in ‘style’ elements. Not in ‘font-family’ elements.
And some parameters are concatenated with semicolons.

I guess fritzing could not pick out the font names from ‘style’ elements, thus font names are ignored. Hence the error is occured.

Why can’t Fritzing recognize font namesin such svg files?
And how can I fix it?

Is this a bug in Fritzing? or Inkscape?

By the way, the svg file (for schematic) is made from copy of existing parts like ‘ICs’, not from scratch svg.

I received this error and did some investigation. Fritzing has various font handling workarounds for SVGs. It does handle font-family defined inside the style attribute; however, it doesn’t handle a ‘quoted’ font in that case. InkScape exports quoted font names in some cases (but not all).

I think you’ll find it was e.g. style="…font-family:‘Droid Sans’…" that causes the error.

I’ve submitted a pull request with fix: https://github.com/fritzing/fritzing-app/pull/3343

The error was harmless in my case, as it will fall back to Droid Sans anyway, but certainly it was confusing! There appears to be other font handling issues which I’ll look into if I have the time.

Hi Historic_bruno.

Thank you for your hard work.

Now I’m looking foward to the next update.

By the way,
I have tried deleting all ‘px’ units in ‘style’ elements from the SVG file with text-editor.

When fritzing reads the file, it causes a warning message,too.
But the part-data works well without strange phenomenon / broken figure / strange size font.

If you don’t mind displaying the warning message, I think this modification can be a temporary method for this matter.

Regards.

Been 2 years after and problem still remain. Where is a bug fix?

FZ is unsupported, it’s just some enthusiasts trying to get it up and running again.

@historic_bruno You are using opening and closing single quotes here. Was this some forum UI replacement, or do you really have a file like that?

While I’m not the OP, I’ve seen this construct (this was likely converted via the check parts script to remove the styles, note the double quotes on the Droid Sans which was likely added by lxml during conversion):

    <text
  font-family="'Droid Sans'"
  id="text17-2"
  x="102.34126"
  text-anchor="start"
  gorn="0.3.1"
  font-size="60"
  y="216.83516"
  fill="#ffffff">32K</text>

Editing this in Inkscape and selecting this item then in xml editor select font-family and hit set (with no changes) causes Inkscape to convert it to a style (for CSS compliance) and removes the double quotes like this:

    <text
    style="font-size:60px;font-family:'Droid Sans';text-anchor:start;fill:#ffffff"
    y="216.83516"
    font-size="60"
    gorn="0.3.1"
    x="102.34126"
    id="text17-2">32K</text>
<text

Some parts of Fritzing (most notably bendable legs) don’t support style commands (this is why the check script converts style commands to inline xml) so it is possible this issue is hitting one of those parts.

Peter

I am fairly new to fritzing, but have been creating many different parts this week. I came across this issue, and I wanted to show y’all my fix because deleting all the ‘px’ values can be cumbersome. Also, it looks like this won’t be fixed in Fritzing anytime soon.

Run this python script:

# Removes all 'px' text so that fritzing can properly read the svg file
from tkinter import filedialog
import re
import os

file = filedialog.askopenfilename(title='Select SVG File', filetypes=[('SVG Files', '*.svg')])

if not file:
    exit()

with open(file, 'r') as f:
    content = f.read()

px_pattern = re.compile(r'(\d+)px;')
cleaned = px_pattern.subn(r'\1;', content)[0]

name = os.path.splitext(file)[0]
with open(f'{name}-cleaned.svg', 'w') as f:
    f.write(cleaned)

The code will generate a new file ending in ‘-cleaned.svg’.

This same functionality might be present in this repo, but for something simple like this, I didn’t want to have to go through the cloning process for this one feature.

And if you keep continually running this script like I have been, create a .bat file in your desktop so that it will run the script when you click on it. It would look something like this:

python <full file path.py>

Thanks for all y’all’s help!

You can also use FritzingCheckPart.py which will do a bunch of error checking as well as inlineing style commands and removing px from the font-size available here:

Peter