Editable texts in SVG templates

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Editable texts in SVG templates

Post by yorik »

Hmm interesting... It looks like proper XML rules ask that when you use a prefix, you define it first:
http://www.w3schools.com/xml/xml_namespaces.asp

Indeed inkscape defines its inkscape: prefix, at the beginning of inkscape-generated files, there is:

Code: Select all

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
So we would just need to add: xmlns:freecad="http://some/url"

I'll setup a page on the wiki on the model of the inkscape page... *EDIT* Ah! the inkscape page doesn't exist :( we can do better...

*EDIT2* Done! the line to insert is:

Code: Select all

xmlns:freecad="http://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Svg_Namespace"
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Editable texts in SVG templates

Post by triplus »

yorikvanhavre wrote:Hmm interesting... It looks like proper XML rules ask that when you use a prefix, you define it first:
http://www.w3schools.com/xml/xml_namespaces.asp

Indeed inkscape defines its inkscape: prefix, at the beginning of inkscape-generated files, there is:

Code: Select all

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
So we would just need to add: xmlns:freecad="http://some/url"

I'll setup a page on the wiki on the model of the inkscape page... *EDIT* Ah! the inkscape page doesn't exist :( we can do better...

*EDIT2* Done! the line to insert is:

Code: Select all

xmlns:freecad="http://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Svg_Namespace"
Great and there is one more feature now, before if SVG template was edited in Inkscape and then saved:
- in your SVG templates, add freecad:editable="TextName" attributes to <text> entities, to mark them as editable
This was lost but now it persist if it's saved as Inkscape SVG and not Plain SVG. Without namespace URI this was lost if it was saved as Inkscape SVG too, but now it persists.
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Editable texts in SVG templates

Post by yorik »

triplus wrote:This was lost but now it persist if it's saved as Inkscape SVG and not Plain SVG. Without namespace URI this was lost if it was saved as Inkscape SVG too, but now it persists.
Great! I hadn't noticed that...
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Editable texts in SVG templates

Post by NormandC »

The sodipodi link is dead too. Actually, I don't understand why there are Sodipodi:prefix namespaces in Inkscape documents, that software has been dead for almost 8 years, they should had replaced them by Inkscape:prefix... (Sodipodi was the predecessor to Inkscape)
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Editable texts in SVG templates

Post by jriegel »

They keep the sodiposi name-space for back wards compatibility.
Stop whining - start coding!
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Editable texts in SVG templates

Post by triplus »

normandc wrote:Hi triplus,

How about sharing your template (if you don't mind)? :)

The Drawing Templates wiki page could use some A4 templates! ;)

(and some A and B too for people in North America, but I'm slowly working on it!)
My drawing templates are very specific and because of that i made two more simple/generic/standard ones for other to use in A4 Portrait and A3 Landscape sizes.

This are the rules i followed:
One pixel = one millimeter
Add proper "namespace URI" inside (at the beginning of) <svg> tag:
Add attributes to <text> entities, to mark them as editable:
freecad:editable="TextName"
Insert just before the last </svg> tag
<!-- DrawingContent -->
Important: If u edit drawing template in for example Inkscape save it as Inkscape SVG and not Plain SVG if u want all FreeCAD specific changes to persist!

Remove (rename file) the .zip extension from the SVG file. SVG file is not compressed i just can't upload it as .svg file.
Attachments
a3_landscape.svg.zip
A3 Landscape Drawing Template
(9.83 KiB) Downloaded 319 times
a4_portrait.svg.zip
A4 Portrait Drawing Template
(9.81 KiB) Downloaded 311 times
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Editable texts in SVG templates

Post by triplus »

I assumed 1px = 1mm rule should be used in this templates but i guess i was wrong the template should use mm by default! It does work but exported .SVG must always be resized in Inkscape for example to get correct output size (print).

viewtopic.php?f=10&t=4182&start=10#p32837
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Editable texts in SVG templates

Post by jriegel »

I'm not able to open the zip files?
Stop whining - start coding!
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Editable texts in SVG templates

Post by wmayer »

jriegel wrote:I'm not able to open the zip files?
Remove the ".zip" suffix.
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Editable texts in SVG templates

Post by jriegel »

Ups :oops:
Stop whining - start coding!
Locked