Svg Namespace

From FreeCAD Documentation
This page is a translated version of the page Svg Namespace and the translation is 67% 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

Nei documenti SVG esportati dal Modulo Disegno di FreeCAD e utilizzati come modelli di pagina (squadrature), si possono utilizzare diversi attributi personalizzati, originariamente per uso interno di FreeCAD, ma che, in futuro, potrebbero essere utilizzati anche da altre applicazioni oltre a FreeCAD . Tutti questi attributi utilizzano il prefisso freecad: per il namespace. L'URL del namespace definito in tali documenti SVG fa riferimento a questa pagina.

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.

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"

Possono essere aggiunte informazioni supplementari per lo spazio di lavoro e il blocco del titolo e esse sono definite nella pagina Modelli di squadrature.

Attributi

freecad:EditableText

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

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

Esempio:

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

freecad:basepoint1

Definisce il primo punto di un oggetto di Quotatura (rappresentato come un gruppo in un documento SVG). Questo attributo viene utilizzato durante l'importazione del frammento di SVG in FreeCAD, per ricreare l'oggetto Quotatura. Il gruppo contiene i percorsi e altri elementi grafici per rappresentare correttamente l'oggetto Quotatura in altre applicazioni SVG.

Esempio:

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

freecad:basepoint2

Definisce il secondo punto di un oggetto di Quotatura (rappresentato come un gruppo in un documento SVG). Questo attributo viene utilizzato durante l'importazione del frammento di SVG in FreeCAD, per ricreare l'oggetto Quotatura. Il gruppo contiene i percorsi e altri elementi grafici per rappresentare correttamente l'oggetto Quotatura in altre applicazioni SVG.

Esempio: vedere freecad:basepoint1

freecad:dimpoint

Definisce il punto di un oggetto di Quotatura attraverso il quale passa la linea di quota. Questo attributo viene utilizzato durante l'importazione del frammento di SVG in FreeCAD, per ricreare l'oggetto Quotatura. Il gruppo contiene i percorsi e altri elementi grafici per rappresentare correttamente l'oggetto Quotatura in altre applicazioni SVG.

Esempio: vedere freecad:basepoint1

Esempio di codice freecad:EditableText

Questo esempio è tratto dalla tabella del modello di squadratura 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>

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"

Altri attributi disponibili

Vedere la pagina dei Modelli di squadrature