Svg Namespace/fr: Difference between revisions

From FreeCAD Documentation
No edit summary
(Updating to match new version of source page)
Line 1: Line 1:
<languages/>
<languages/>


<div class="mw-translate-fuzzy">
{{VeryImportantMessage|Le développement de l'[[Drawing Workbench/fr|atelier Drawing]] s'est arrêté, et un nouvel atelier [[TechDraw_Workbench/fr|Techdraw]] visant à le remplacer sera introduit dans la version 0.17. Les deux ateliers seront fournis dans la version v0.17, mais l'atelier Mise en plan peut être supprimé dans les versions ultérieures.}}
{{VeryImportantMessage|Le développement de l'[[Drawing Workbench/fr|atelier Drawing]] s'est arrêté, et un nouvel atelier [[TechDraw_Workbench/fr|Techdraw]] visant à le remplacer sera introduit dans la version 0.17. Les deux ateliers seront fournis dans la version v0.17, mais l'atelier Mise en plan peut être supprimé dans les versions ultérieures.}}
</div>


{{TOCright}}
{{TOCright}}


==Introduction==
Dans les documents [https://fr.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] exportés par l'[[Drawing_Workbench/fr|atelier Drawing]] de FreeCAD et utilisés comme des pages [[Drawing_templates|modèles]], plusieurs [http://www.w3schools.com/xml/xml_attributes.asp attributs] personnalisés peuvent être utilisés, à l'origine pour l'usage interne de FreeCAD, mais pourraient également être utilisés par d'autres applications compatibles avec FreeCAD dans le futur. Ces attributs utilisent tous le préfixe '''freecad:''' [http://www.w3schools.com/xml/xml_namespaces.asp namespace]. L'URL de l'espace de nom défini dans ces documents SVG fait référence à cette page.

<div class="mw-translate-fuzzy">
Dans les documents [https://fr.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] exportés par l'[[Drawing_Workbench/fr|atelier Drawing]] de FreeCAD et utilisés comme des pages [[Drawing_templates|modèles]], plusieurs [http://www.w3schools.com/xml/xml_attributes.asp attributs] personnalisés peuvent être utilisés, à l'origine pour l'usage interne de FreeCAD, mais pourraient également être utilisés par d'autres applications compatibles avec FreeCAD dans le futur. Ces attributs utilisent tous le préfixe '''freecad:''' [http://www.w3schools.com/xml/xml_namespaces.asp namespace]. L'URL de l'espace de nom défini dans ces documents SVG fait référence à cette page.
</div>

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.


<span id="Usage"></span>
<span id="Usage"></span>

Revision as of 19:13, 30 August 2023

Le développement de l'atelier Drawing s'est arrêté, et un nouvel atelier Techdraw visant à le remplacer sera introduit dans la version 0.17. Les deux ateliers seront fournis dans la version v0.17, mais l'atelier Mise en plan peut être supprimé dans les versions ultérieures.

Introduction

Dans les documents SVG exportés par l'atelier Drawing de FreeCAD et utilisés comme des pages modèles, plusieurs attributs personnalisés peuvent être utilisés, à l'origine pour l'usage interne de FreeCAD, mais pourraient également être utilisés par d'autres applications compatibles avec FreeCAD dans le futur. Ces attributs utilisent tous le préfixe freecad: namespace. L'URL de l'espace de nom défini dans ces documents SVG fait référence à cette page.

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.

Utilisation

un pixel = un millimètre

Vous devez insérer, quelque part dans votre code svg, où vous souhaitez que le contenu du dessin apparaisse (par exemple à la fin du fichier, juste avant la derniere balise </svg>), la ligne suivante :

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

Pour obtenir une impression à l'échelle, la taille réelle doit être inscrite dans les attributs width et height du SVG-Tag. L'unité du document utilisateur doit être le pixel(px), et doit être renseigné dans l'attribut viewBox.

Ce qui suit doit être formaté comme dans l'exemple ci-dessous :

  • xxx = pixel width (largeur)
  • yyy = pixel height (hauteur)
width="xxxmm"
height="yyymm"
viewBox="0 0 xxx yyy"

Les informations complémentaires pour l'espace de travail et le bloc du titre peuvent être ajoutées et sont définies sur la page Drawing Modèles.

Attributs

freecad:EditableText

Pour utiliser l'un des attributs freecad: dans vos documents SVG, vous devez d'abord définir l'espace de nom freecad comme un attribut de la balise d'ouverture <svg> :

Définit un texte dans un modèle qui peut être édité par FreeCAD.

Exemple :

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

freecad:basepoint1

Définit le premier point d'un objet Draft Dimension (représenté comme un groupe dans un document SVG). Cet attribut est utilisé lors de l'importation du fragment SVG dans FreeCAD, afin de recréer l'objet dimension. Le groupe contient des chemins et d'autres éléments graphiques pour rendre correctement l'objet de dimension dans d'autres applications SVG.

Exemple :

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

freecad:basepoint2

Définit le deuxième point d'un objet Draft Dimension (représenté comme un groupe dans un document SVG). Cet attribut est utilisé lors de l'importation du fragment SVG dans FreeCAD, afin de recréer l'objet dimension. Le groupe contient des chemins et d'autres éléments graphiques pour rendre correctement l'objet de dimension dans d'autres applications SVG.

Exemple: voir freecad:basepoint1

freecad:dimpoint

Définit le point d'un objet Draft Dimension par lequel passe la ligne de cote. Cet attribut est utilisé lors de l'importation du fragment SVG dans FreeCAD, afin de recréer l'objet dimension. Le groupe contient des chemins et d'autres éléments graphiques pour rendre correctement l'objet de dimension dans d'autres applications SVG.

Exemple: voir freecad:basepoint1

Exemple de code freecad:EditableText

Cet exemple provient du cartouche de la feuille A3 Paysage

1 : Titre sans 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 : Titre avec 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>

Explications

  <g

Début du cadre

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

Données dans le cadre

    <text

Début du bloc de textes

       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"

Toutes les informations sur le texte qui va être affiché

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

Coordonnées et renseignements du texte qui va être affiché.

       freecad:editable="AuthorName"><tspan

Ici AuthorName est la variable qui va mémoriser la chaîne freecad:editable qui sera modifiée et affichée dans la feuille.

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

Coordonnées et renseignements sur le texte qui est affiché par défaut, la balise </text> délimite la fin du bloc texte.

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

Autres blocs textes et la balise </g> détermine la fin du groupe de textes.

Il est possible qu'après avoir travaillé dans le fichier SVG avec Inkscape le fichier ne fonctionne plus, il est possible que des informations aient disparu.

Ensuite, vérifiez que freecad:editable: n'est pas modifié.

Exemple:

  • editable = "AuthorName"
  • replacer par freecad:editable = "AuthorName"

Autres attributs disponibles

Voir Drawing Modèles