Svg Namespace/en: Difference between revisions

From FreeCAD Documentation
(Importing a new version from external source)
 
(Updating to match new version of source page)
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
In the [http://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] documents exported by FreeCAD's [[Drawing Module|Drawing Module]] and used as page [[Drawing templates|templates]], several custom [http://www.w3schools.com/xml/xml_attributes.asp attributes] can be used, originally for FreeCAD's own internal use, but could also be used by other FreeCAD-aware applications in the future. These attributes all use the '''freecad:''' [http://www.w3schools.com/xml/xml_namespaces.asp namespace] prefix. The namespace URL defined in those SVG documents refers to this page.

{{VeryImportantMessage|Development of the [[Drawing_Workbench|Drawing Workbench]] stopped in FreeCAD 0.16, and the new [[TechDraw_Workbench|TechDraw Workbench]] aiming to replace it was introduced in v0.17. Both workbenches were provided from v0.17 to v0.20, but since v0.21 the Drawing Workbench is no longer included.}}
{{Message|Currently the TechDraw workbench still uses the '''freecad:EditableText'''attribute and the related name space declaration in its current templates.}}

{{TOCright}}

==Introduction==

FreeCAD can import and export [http://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] documents containing code that belongs to a certain '''namespace''' which is a sub-set of XML instructions.

Like any XML document an SVG document consist of two sections:
* Head: just one line to declare which version of the XML language is used for the instructions in the body of this document.
* Body: a list of instructions. SVG documents enclose all instructions in <svg>-tags.
: The opening tag contains information about the size and the used SVG namespaces.

==Default namespace==

The default SVG namespace used by FreeCAD is declared with this line:

{{Code|lang=xml|code=
xmlns="http://www.w3.org/2000/svg" version="1.1"
}}

The external link leads to a web site containing information about the namespace and its set of instructions. Attributes of this namespace are used without prefix.

==Namespace extension==

Attributes missing from the SVG namespace can be added by namespace extensions. FreeCAD uses such an extension for drawing templates. Templates for the Drawing workbench used four custom attributes which are marked with a "freecad:" prefix:
* [[#freecad:EditableText|freecad:EditableText]], this is still used with templates for the TechDraw workbench.
* [[#freecad:basepoint1|freecad:basepoint1]]
* [[#freecad:basepoint2|freecad:basepoint2]]
* [[#freecad:dimpoint|freecad:dimpoint]]

A namespace declaration is used to introduce the prefix and the link to the related web site, '''this page''':

{{Code|lang=xml|code=
xmlns:freecad="http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace"
}}

The link is not used to retrieve information or values at runtime, but it is the key to activate the custom attributes.

===Drawing templates===

In the [http://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] documents exported by FreeCAD's [[Drawing_Workbench|Drawing Workbench]] and used as (Drawing) page [[Drawing_templates|templates]], the custom [http://www.w3schools.com/xml/xml_attributes.asp attributes] can be used, originally for FreeCAD's own internal use, but could also be used by other FreeCAD-aware applications in the future. These attributes all use the '''freecad:''' [http://www.w3schools.com/xml/xml_namespaces.asp namespace] prefix. The namespace URL defined in those SVG documents refers to this page.
: The Drawing workbench is no longer included in FreeCAD {{VersionPlus|0.21}} and so these Drawing templates are obsolate now.

===TechDraw templates===

The TechDraw workbench also uses SVG templates but can not create and export templates. It relies on [[#freecad:EditableText|freecad:EditableText]] for entries in title blocks.

===Migration to freecad.org===

Since the FreeCAD wiki, including '''this page''', was migrated from '''freecadweb.org''' to '''freecad.org''' in version 0.21 the link has to be updated accordingly to:

{{Code|lang=xml|code=
xmlns:freecad="http://www.freecad.org/wiki/index.php?title=Svg_Namespace"
}}

Updated TechDraw templates now contain a key that can not activate the custom attributes when used with FreeCAD {{VersionMinus|0.20}} and as a result editable texts of recent templates are not recognised and so handled as plain text.
: In such cases the "web" has to be manually re-inserted into the namespace declaration of the template.

It seems like {{VersionPlus|0.21}} can deal with either link address.


==Usage==
==Usage==
Line 7: Line 69:
You must insert, somewhere inside your svg code, where you want the contents of the drawing to appear (for example at the end of the file, just before the last '''</svg>''' tag), the following line:
You must insert, somewhere inside your svg code, where you want the contents of the drawing to appear (for example at the end of the file, just before the last '''</svg>''' tag), the following line:


<syntaxhighlight>
<syntaxhighlight lang="xml">
<!-- DrawingContent -->
<!-- DrawingContent -->
</syntaxhighlight>
</syntaxhighlight>


<syntaxhighlight lang="xml">

<syntaxhighlight>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
<svg
xmlns:freecad="http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace"
xmlns:freecad="http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace"
</syntaxhighlight>

In order to enable up to scale printing, the real word size has to be given in the width and height attributes of the SVG-Tag. The size of the document in user units, (px), has to be given in the viewBox attribute.

The following is to be formatted like the example below where:
* xxx = pixel width
* yyy = pixel height

<syntaxhighlight lang="xml">
width="xxxmm"
height="yyymm"
viewBox="0 0 xxx yyy"
</syntaxhighlight>
</syntaxhighlight>


Additional information for Working space and Title block may be added, and is defined on the [[Drawing templates]] page.
Additional information for Working space and Title block may be added, and is defined on the [[Drawing_templates|Drawing templates]] page.


==Attributes==
==Attributes==
Line 30: Line 103:
Example:
Example:


<syntaxhighlight>
<syntaxhighlight lang="xml">
<text freecad:EditableText="MyTitleText">

<tspan>This is a title</tspan>
<text freecad:EditableText="MyTitleText">
</text>
<tspan>This is a title</tspan>
</text>
</syntaxhighlight>
</syntaxhighlight>

===freecad:basepoint1===
===freecad:basepoint1===


Defines the first point of a [[Draft Dimension]] object (represented as a group in a SVG document). This attribute is used when importing the SVG fragment in FreeCAD, in order to recreate the dimension object. The group contains paths and other graphical items to correctly render the dimension object in other SVG applications.
Defines the first point of a [[Draft_Dimension|Draft Dimension]] object (represented as a group in a SVG document). This attribute is used when importing the SVG fragment in FreeCAD, in order to recreate the dimension object. The group contains paths and other graphical items to correctly render the dimension object in other SVG applications.


Example:
Example:

<syntaxhighlight>
<syntaxhighlight lang="xml">
<g freecad:basepoint1="0.5 4.34" freecad:basepoint2="2.4 5.8" dimpoint="3.2 7.76">
<g freecad:basepoint1="0.5 4.34" freecad:basepoint2="2.4 5.8" dimpoint="3.2 7.76">
<path d="...">
<path d="...">
</g>
</g>
</syntaxhighlight>
</syntaxhighlight>

===freecad:basepoint2===
===freecad:basepoint2===


Defines the second point of a [[Draft Dimension|Draft Dimension]] object (represented as a group in a SVG document). This attribute is used when importing the SVG fragment in FreeCAD, in order to recreate the dimension object. The group contains paths and other graphical items to correctly render the dimension object in other SVG applications.
Defines the second point of a [[Draft_Dimension|Draft Dimension]] object (represented as a group in a SVG document). This attribute is used when importing the SVG fragment in FreeCAD, in order to recreate the dimension object. The group contains paths and other graphical items to correctly render the dimension object in other SVG applications.


Example: see [[#freecad:basepoint1|freecad:basepoint1]]
Example: see [[#freecad:basepoint1|freecad:basepoint1]]
Line 54: Line 129:
===freecad:dimpoint===
===freecad:dimpoint===


Defines the point of a [[Draft Dimension]] object through which the dimension line passes. This attribute is used when importing the SVG fragment in FreeCAD, in order to recreate the dimension object. The group contains paths and other graphical items to correctly render the dimension object in other SVG applications.
Defines the point of a [[Draft_Dimension|Draft Dimension]] object through which the dimension line passes. This attribute is used when importing the SVG fragment in FreeCAD, in order to recreate the dimension object. The group contains paths and other graphical items to correctly render the dimension object in other SVG applications.


Example: see [[#freecad:basepoint1|freecad:basepoint1]]
Example: see [[#freecad:basepoint1|freecad:basepoint1]]
Line 65: Line 140:


[[Image:Svg Namespace 01.png|300px]]
[[Image:Svg Namespace 01.png|300px]]
<syntaxhighlight>


<syntaxhighlight lang="xml">
<g
<g
id="g3587">
id="g3587">
Line 82: Line 157:


</syntaxhighlight>
</syntaxhighlight>

====2 : Title with textedit====
====2 : Title with textedit====


[[Image:Svg Namespace 02.png|300px]]
[[Image:Svg Namespace 02.png|300px]]

<syntaxhighlight>
<syntaxhighlight lang="xml">
<g
<g
style="fill:none;stroke:#000000;stroke-width:0.13;stroke-linecap:butt;stroke-linejoin:miter"
style="fill:none;stroke:#000000;stroke-width:0.13;stroke-linecap:butt;stroke-linejoin:miter"
Line 110: Line 187:
</g>
</g>
</syntaxhighlight>
</syntaxhighlight>

====Explanations====
====Explanations====

<syntaxhighlight>
<syntaxhighlight lang="xml">
<g
<g
</syntaxhighlight>
</syntaxhighlight>

Beginning of the framework
Beginning of the framework

<syntaxhighlight>
<syntaxhighlight lang="xml">
style="fill:none;stroke:#000000;stroke-width:0.13;stroke-linecap:butt;stroke-linejoin:miter"
style="fill:none;stroke:#000000;stroke-width:0.13;stroke-linecap:butt;stroke-linejoin:miter"
id="g578-7"
id="g578-7"
transform="translate(0,4)">
transform="translate(0,4)">
</syntaxhighlight>
</syntaxhighlight>

Data on the framework
Data on the framework

<syntaxhighlight>
<syntaxhighlight lang="xml">
<text
<text
</syntaxhighlight>
</syntaxhighlight>

Beginning of the text block
Beginning of the text block

<syntaxhighlight>
<syntaxhighlight lang="xml">
xml:space="preserve"
xml:space="preserve"
style="font-size:4px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans;-inkscape-font-specification:sans"
style="font-size:4px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans;-inkscape-font-specification:sans"
</syntaxhighlight>
</syntaxhighlight>

All the information about the text that will be displayed
All the information about the text that will be displayed

<syntaxhighlight>
<syntaxhighlight lang="xml">
x="220.9935"
x="220.9935"
y="228.95425"
y="228.95425"
Line 136: Line 223:
sodipodi:linespacing="125%"
sodipodi:linespacing="125%"
</syntaxhighlight>
</syntaxhighlight>

Coordinates and identity where the text will appear
Coordinates and identity where the text will appear

<syntaxhighlight>
<syntaxhighlight lang="xml">
freecad:editable="AuthorName"><tspan
freecad:editable="AuthorName"><tspan
</syntaxhighlight>
</syntaxhighlight>

Here '''AuthorName''' is the var managed by '''freecad:editable''' who saves the string to change that will be displayed
Here '''AuthorName''' is the var managed by '''freecad:editable''' who saves the string to change that will be displayed

<syntaxhighlight>
<syntaxhighlight lang="xml">
sodipodi:role="line"
sodipodi:role="line"
id="tspan3333"
id="tspan3333"
Line 147: Line 238:
y="228.95425">AUTHOR NAME</tspan></text>
y="228.95425">AUTHOR NAME</tspan></text>
</syntaxhighlight>
</syntaxhighlight>

Coordinates and identity of the text that is displayed by default and '''</text>''' means the end of the block text
Coordinates and identity of the text that is displayed by default and '''</text>''' means the end of the block text

<syntaxhighlight>
<syntaxhighlight lang="xml">
<text
<text
...
...
Line 156: Line 249:
</g>
</g>
</syntaxhighlight>
</syntaxhighlight>

Other blocks texts and end '''</g>''' the framework grouping text blocks
Other blocks texts and end '''</g>''' the framework grouping text blocks


Line 168: Line 262:
==Other attributes availlables==
==Other attributes availlables==


See [[Drawing_templates]]
See [[Drawing_templates|Drawing templates]]



<languages/>
{{Drawing Tools navi{{#translation:}}}}
[[Category:Poweruser_Documentation{{#translation:}}]]
[[Category:Developer{{#translation:}}]]
[[Category:Python_Code{{#translation:}}]]
[[Category:Macros{{#translation:}}]]

Latest revision as of 19:13, 30 August 2023

Development of the Drawing Workbench stopped in FreeCAD 0.16, and the new TechDraw Workbench aiming to replace it was introduced in v0.17. Both workbenches were provided from v0.17 to v0.20, but since v0.21 the Drawing Workbench is no longer included.
Currently the TechDraw workbench still uses the freecad:EditableTextattribute and the related name space declaration in its current templates.


Introduction

FreeCAD can import and export SVG documents containing code that belongs to a certain namespace which is a sub-set of XML instructions.

Like any XML document an SVG document consist of two sections:

  • Head: just one line to declare which version of the XML language is used for the instructions in the body of this document.
  • Body: a list of instructions. SVG documents enclose all instructions in <svg>-tags.
The opening tag contains information about the size and the used SVG namespaces.

Default namespace

The default SVG namespace used by FreeCAD is declared with this line:

xmlns="http://www.w3.org/2000/svg" version="1.1"

The external link leads to a web site containing information about the namespace and its set of instructions. Attributes of this namespace are used without prefix.

Namespace extension

Attributes missing from the SVG namespace can be added by namespace extensions. FreeCAD uses such an extension for drawing templates. Templates for the Drawing workbench used four custom attributes which are marked with a "freecad:" prefix:

A namespace declaration is used to introduce the prefix and the link to the related web site, this page:

xmlns:freecad="http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace"

The link is not used to retrieve information or values at runtime, but it is the key to activate the custom attributes.

Drawing templates

In the SVG documents exported by FreeCAD's Drawing Workbench and used as (Drawing) page templates, the custom attributes can be used, originally for FreeCAD's own internal use, but could also be used by other FreeCAD-aware applications in the future. These attributes all use the freecad: namespace prefix. The namespace URL defined in those SVG documents refers to this page.

The Drawing workbench is no longer included in FreeCAD version 0.21 and above and so these Drawing templates are obsolate now.

TechDraw templates

The TechDraw workbench also uses SVG templates but can not create and export templates. It relies on freecad:EditableText for entries in title blocks.

Migration to freecad.org

Since the FreeCAD wiki, including this page, was migrated from freecadweb.org to freecad.org in version 0.21 the link has to be updated accordingly to:

xmlns:freecad="http://www.freecad.org/wiki/index.php?title=Svg_Namespace"

Updated TechDraw templates now contain a key that can not activate the custom attributes when used with FreeCAD version 0.20 and below and as a result editable texts of recent templates are not recognised and so handled as plain text.

In such cases the "web" has to be manually re-inserted into the namespace declaration of the template.

It seems like version 0.21 and above can deal with either link address.

Usage

One pixel = one millimeter.

You must insert, somewhere inside your svg code, where you want the contents of the drawing to appear (for example at the end of the file, just before the last </svg> tag), the following line:

<!-- DrawingContent -->
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
    xmlns:freecad="http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace"

In order to enable up to scale printing, the real word size has to be given in the width and height attributes of the SVG-Tag. The size of the document in user units, (px), has to be given in the viewBox attribute.

The following is to be formatted like the example below where:

  • xxx = pixel width
  • yyy = pixel height
width="xxxmm"
height="yyymm"
viewBox="0 0 xxx yyy"

Additional information for Working space and Title block may be added, and is defined on the Drawing templates page.

Attributes

freecad:EditableText

To use any of the freecad: attributes in your SVG documents, you must first define the freecad namespace as an attribute of the opening <svg> tag:

Defines a text in a template that can be edited by FreeCAD.

Example:

<text freecad:EditableText="MyTitleText">
    <tspan>This is a title</tspan>
</text>

freecad:basepoint1

Defines the first point of a Draft Dimension object (represented as a group in a SVG document). This attribute is used when importing the SVG fragment in FreeCAD, in order to recreate the dimension object. The group contains paths and other graphical items to correctly render the dimension object in other SVG applications.

Example:

<g freecad:basepoint1="0.5 4.34" freecad:basepoint2="2.4 5.8" dimpoint="3.2 7.76">
    <path d="...">
</g>

freecad:basepoint2

Defines the second point of a Draft Dimension object (represented as a group in a SVG document). This attribute is used when importing the SVG fragment in FreeCAD, in order to recreate the dimension object. The group contains paths and other graphical items to correctly render the dimension object in other SVG applications.

Example: see freecad:basepoint1

freecad:dimpoint

Defines the point of a Draft Dimension object through which the dimension line passes. This attribute is used when importing the SVG fragment in FreeCAD, in order to recreate the dimension object. The group contains paths and other graphical items to correctly render the dimension object in other SVG applications.

Example: see freecad:basepoint1

Example of code freecad:EditableText

This example is taken from a cartridge to a sheet A3_Landscape

1 : Title without textedit

  <g
     id="g3587">
    <text
       sodipodi:linespacing="119.00001%"
       id="text3482"
       y="229.10912"
       x="220.8476"
       style="font-size:1.97555566px;font-style:normal;font-weight:normal;line-height:119.00000572%;letter-spacing:0.01975556px;word-spacing:0.00846667px;writing-mode:lr-tb;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
       xml:space="preserve"><tspan
         y="229.10912"
         x="220.8476"
         id="tspan3484"
         sodipodi:role="line">AUTHOR NAME :</tspan></text>

2 : Title with textedit

  <g
     style="fill:none;stroke:#000000;stroke-width:0.13;stroke-linecap:butt;stroke-linejoin:miter"
     id="g578-7"
     transform="translate(0,4)">
    <text
       xml:space="preserve"
       style="font-size:4px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans;-inkscape-font-specification:sans"
       x="220.9935"
       y="228.95425"
       id="text3331"
       sodipodi:linespacing="125%"
       freecad:editable="AuthorName"><tspan
         sodipodi:role="line"
         id="tspan3333"
         x="220.9935"
         y="228.95425">AUTHOR NAME</tspan></text>
    <text
    ...
    ...
    ...
    ... </text>
  
  </g>

Explanations

  <g

Beginning of the framework

     style="fill:none;stroke:#000000;stroke-width:0.13;stroke-linecap:butt;stroke-linejoin:miter"
     id="g578-7"
     transform="translate(0,4)">

Data on the framework

    <text

Beginning of the text block

       xml:space="preserve"
       style="font-size:4px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans;-inkscape-font-specification:sans"

All the information about the text that will be displayed

       x="220.9935"
       y="228.95425"
       id="text3331"
       sodipodi:linespacing="125%"

Coordinates and identity where the text will appear

       freecad:editable="AuthorName"><tspan

Here AuthorName is the var managed by freecad:editable who saves the string to change that will be displayed

         sodipodi:role="line"
         id="tspan3333"
         x="220.9935"
         y="228.95425">AUTHOR NAME</tspan></text>

Coordinates and identity of the text that is displayed by default and </text> means the end of the block text

    <text
    ...
    ...
    ...
    ... </text>
  </g>

Other blocks texts and end </g> the framework grouping text blocks

It is possible after having worked the Inkscape SVG file as the file no longer works, it is possible that information has gone missing.

Then check that the edit text is not modified

Example :

  • editable = "AuthorName"
  • replace by freecad:editable = "AuthorName"

Other attributes availlables

See Drawing templates