Svg Namespace

From FreeCAD Documentation
This page is a translated version of the page Svg Namespace and the translation is 50% complete.
Outdated translations are marked like this.
Lo sviluppo del modulo Drawing è stato interrotto in FreeCAD 0.16 con il proposito di sostituirlo con il nuovo modulo TechDraw che sarà introdotto nella versione 0.17. Nella versione 0.17 sono forniti entrambi i moduli, ma il modulo Drawing potrebbe essere rimosso nelle versioni future.

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. The related namespace declaration, used to introduce the freecad: prefix, links to the related web site, this page:

xmlns:freecad="http://www.freecad.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.

TechDraw templates and symbols

The TechDraw workbench uses SVG templates to create drawings. It can not create and export templates but relies on externally created templates with manually inserted attributes:

Symbols are another Type of SVG files that can be used in drawing views for e.g. stamp like annotations. They also have to be created externally and can use the above mentioned attributes, too.

Migration to freecad.org

Prior to the migration of the FreeCAD wiki, including this page from freecadweb.org to freecad.org in version 0.21 the link to this page was:

xmlns:freecad="http://www.freecadweb.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.

Utilizzo

Un pixel = un millimetro

È necessario inserire, da qualche parte dentro il codice svg, dove si desidera che appaia il contenuto del disegno (per esempio alla fine del file, appena prima dell'ultimo tag </svg>), la riga seguente :

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

Per scalare la stampa, la dimensione effettiva deve essere data negli attributi width e height del tag SVG. Le dimensioni del documento, nelle unità utilizzate (px), deve essere fornita nell'attributo Viewbox.

In questo caso deve essere formattato come nell'esempio sottostante dove:

  • xxx = pixel width (larghezza)
  • yyy = pixel height (altezza)
width="xxxmm"
height="yyymm"
viewBox="0 0 xxx yyy"

Attributi

Per utilizzare uno degli attributi freecad: nei documenti SVG, si deve prima definire il namespace freecad come attributo del tag di apertura <svg>:

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

Definisce un testo in un modello che può essere modificato da FreeCAD.

Default text has to be surrounded by tspan tags otherwise the displayed text within the template/symbol will not synchronise with modified variable content.

Esempio:

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

freecad:autofill

introduced in version 1.0: Marks an editable text in a template to be filled automatically when a template is inserted. (This is added to an existing freecad:editable attribute)

Example:

<text freecad:editable="MyTitleText"; freecad:autofill="AutofillElement" >
    <tspan>This is a title</tspan>
</text>

The following "AutofillElements" are implemented yet:

  1. freecad:autofill="author" inserts the value of BaseApp/Preferences/Document/prefAuthor.
  2. freecad:autofill="date" inserts the currentDateTime().
  3. freecad:autofill="organization" inserts the value of BaseApp/Preferences/Document/prefCompany.
  4. freecad:autofill="scale" inserts the page scale property.
  5. freecad:autofill="sheet" inserts page number / page count.
  6. freecad:autofill="title" inserts the value of the current document's Label property.

Esempio di codice freecad:EditableText

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>

Spiegazioni

  <g

Inizio del riquadro

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

I dati relativi al riquadro

    <text

Inizio del blocco di testo

       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"

Tutte le informazioni sul testo che verrà visualizzato

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

Coordinate e l'identità in cui verrà visualizzato il testo

       freecad:editable="AuthorName"><tspan

Qui AuthorName è la var gestita da freecad:editable che salva la stringa per cambiare ciò che verrà visualizzato

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

Coordinate e l'identità del testo che viene visualizzato per impostazione predefinita e </text> significa la fine del blocco di testo

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

Altri blocchi di testo e fine </g> blocca il raggruppamento del blocco di testo

È possibile che dopo aver lavorato il file SVG con Inkscape non funzioni più, è possibile che l'informazione sia scomparsa.

Quindi controllare che il testo non sia stato modificato

Esempio :

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