issue134:inkscape
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue134:inkscape [2018/07/18 14:38] – d52fr | issue134:inkscape [2018/07/25 13:11] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
**Last time I showed you the basics of including an Inkscape image in a web page by treating it as an image object in an HTML <img> tag or via CSS, either by exporting as a PNG, or by linking directly to the original SVG image. This time I’m going to consider the other two methods of getting an Inkscape image into a web page: via the < | **Last time I showed you the basics of including an Inkscape image in a web page by treating it as an image object in an HTML <img> tag or via CSS, either by exporting as a PNG, or by linking directly to the original SVG image. This time I’m going to consider the other two methods of getting an Inkscape image into a web page: via the < | ||
- | At first glance the HTML < | + | At first glance the HTML < |
- | **< | + | < |
< | < | ||
Ligne 19: | Ligne 19: | ||
</ | </ | ||
+ | |||
+ | La dernière fois, je vous ai montré les bases de l' | ||
+ | |||
+ | Au premier coup d' | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | |||
+ | <object type=" | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
**SVG as an <img> is sandboxed by the browser such that any JavaScript in the file won’t run and no external resources can be loaded (i.e. no web fonts). Even code in the hosting page won’t be able to dig into the contents of the SVG to dynamically change the image. In fact the SVG image behaves largely the same as a rasterised version of the same picture. | **SVG as an <img> is sandboxed by the browser such that any JavaScript in the file won’t run and no external resources can be loaded (i.e. no web fonts). Even code in the hosting page won’t be able to dig into the contents of the SVG to dynamically change the image. In fact the SVG image behaves largely the same as a rasterised version of the same picture. | ||
With the change from <img> to < | With the change from <img> to < | ||
+ | |||
+ | Dans un < | ||
+ | |||
+ | Le passage de <img> à < | ||
**The fourth and final approach to including SVG in your web page is so-called “inline SVG”. Inline, in this case, simply refers to directly intermingling the XML code of your SVG file with the HTML code of your web page. For example, here’s the code for an HTML page with an inline SVG image of a red circle with a thick black stroke: | **The fourth and final approach to including SVG in your web page is so-called “inline SVG”. Inline, in this case, simply refers to directly intermingling the XML code of your SVG file with the HTML code of your web page. For example, here’s the code for an HTML page with an inline SVG image of a red circle with a thick black stroke: | ||
Ligne 44: | Ligne 70: | ||
</ | </ | ||
+ | |||
+ | La quatrième et dernière approche pour inclure un SVG dans votre page Web est ce qui est appelé le « inline SVG ». « Inline », dans ce cas, fait simplement référence à l' | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | fill=" | ||
+ | stroke=" | ||
+ | stroke-width=" | ||
+ | cx=" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
**At a glance the code looks pretty straightforward. Most of it is just the sort of content you would expect of a typical web page, except that the contents in the < | **At a glance the code looks pretty straightforward. Most of it is just the sort of content you would expect of a typical web page, except that the contents in the < | ||
This code was hand crafted to ensure that only the bare minimum appears in the SVG block. A typical SVG file from Inkscape, on the other hand, is filled with all manner of extra content, most of which isn’t necessary when using it in this way. Here’s a screenshot from an HTML page that contains both the hand-crafted code above, and a copy of the XML created by Inkscape for the same basic shape:** | This code was hand crafted to ensure that only the bare minimum appears in the SVG block. A typical SVG file from Inkscape, on the other hand, is filled with all manner of extra content, most of which isn’t necessary when using it in this way. Here’s a screenshot from an HTML page that contains both the hand-crafted code above, and a copy of the XML created by Inkscape for the same basic shape:** | ||
+ | |||
+ | À première vue, le code paraît plutôt simple. Majoritairement, | ||
+ | |||
+ | Ce code a été fait à la main pour s' | ||
**Can you spot the difference? No, me neither. But the top circle required SVG code amounting to 107 characters, whereas the second used 2118 – nearly twenty times as much code for the same result! Surely Inkscape can do better than that? | **Can you spot the difference? No, me neither. But the top circle required SVG code amounting to 107 characters, whereas the second used 2118 – nearly twenty times as much code for the same result! Surely Inkscape can do better than that? | ||
There are two reasons for the bloated file size. The first is simply that a hand-coded SVG image always has the potential to be smaller than a computer-created equivalent. Inkscape is a general purpose tool used for all manner of tasks, so it creates general purpose files which are good enough for most circumstances, | There are two reasons for the bloated file size. The first is simply that a hand-coded SVG image always has the potential to be smaller than a computer-created equivalent. Inkscape is a general purpose tool used for all manner of tasks, so it creates general purpose files which are good enough for most circumstances, | ||
+ | |||
+ | Pouvez-vous voir la différence ? Non, moi non plus. Mais le cercle du haut nécessite un code SVG comptant 107 caractères, | ||
+ | |||
+ | Il y a deux raisons à cette taille boursouflée du fichier. La première est tout simplement qu'une image SVG codée à la main a toujours la capacité d' | ||
**XML stands for eXtensible Markup Language. Yes, I know. I can only guess it’s because “.eml” was already taken as a file extension for email files, and “X” is way cooler than “E”. But that X or, more to the point, extensibility, | **XML stands for eXtensible Markup Language. Yes, I know. I can only guess it’s because “.eml” was already taken as a file extension for email files, and “X” is way cooler than “E”. But that X or, more to the point, extensibility, | ||
+ | |||
+ | XML veut dire « eXtensible Markup Language » (Langage de balisage extensible). Oui, je sais. Je ne peux que supposer que c'est parce que « .eml » était déjà pris comme extension de fichier pour les fichiers de mails, et X est bien plus cool que E. Mais ce X, ou plus précisément, | ||
**Let’s imagine that we wish to combine two XML languages in a single document. The first is our old friend SVG. The second is a new language I’ve just made up for garden designers – let’s call it GardenML. Before you cry foul, XML is explicitly intended to allow you to create your own domain-specific languages, so although my example is a little contrived, it’s not without precedent in the real world. So, back to the plot: we’ve got an SVG file, filled with < | **Let’s imagine that we wish to combine two XML languages in a single document. The first is our old friend SVG. The second is a new language I’ve just made up for garden designers – let’s call it GardenML. Before you cry foul, XML is explicitly intended to allow you to create your own domain-specific languages, so although my example is a little contrived, it’s not without precedent in the real world. So, back to the plot: we’ve got an SVG file, filled with < | ||
+ | |||
+ | Imaginons que nous voulions combiner deux langages XML dans un seul document. Le premier est notre vieil ami SVG. Le second est un nouveau langage que je viens de créer pour les concepteurs de jardin (garden) - appelons-le GardenML. Avant que vous ne criiez au fou, XML est explicitement conçu pour vous permettre de créer vos propres langages spécifiques d'un domaine ; aussi, bien que mon exemple soit un petit peu artificiel, il n'est pas sans précédent dans la vraie vie. Bon, revenons au sujet : nous avons un fichier SVG, plein d' | ||
**How does an XML consuming program reconcile these different uses of the same element. How does it know when you’re using an SVG < | **How does an XML consuming program reconcile these different uses of the same element. How does it know when you’re using an SVG < | ||
Ligne 66: | Ligne 126: | ||
</ | </ | ||
+ | |||
+ | Comment fait un programme utilisant beaucoup de XML pour réconcilier les différentes utilisations du même élément ? Comment sait-il quand vous utilisez une < | ||
+ | |||
+ | <svg xmlns=" | ||
+ | |||
+ | <path d="M 130,70 A 60,60 0 1,1 130,69.9 Z" | ||
+ | |||
+ | fill=" | ||
+ | |||
+ | </ | ||
**Notice the “xmlns” (XML NameSpace) attribute in the <svg> tag? That defines the default namespace for the document. The value is a URI – a Uniform Resource Identifier. It may look like a web address, also known as a URL (Uniform Resource Location), but it’s subtly different. Whereas a URL points to the location of a resource such as a web page, a URI is just a unique identifier which doesn’t have to have a corresponding resource at the specified address (though they often do). In other words, a URL is a path to a real document, whilst a URI is a unique string used to make sure that each namespace is distinct from all the others. A URI may also be a URL, but doesn’t have to be.** | **Notice the “xmlns” (XML NameSpace) attribute in the <svg> tag? That defines the default namespace for the document. The value is a URI – a Uniform Resource Identifier. It may look like a web address, also known as a URL (Uniform Resource Location), but it’s subtly different. Whereas a URL points to the location of a resource such as a web page, a URI is just a unique identifier which doesn’t have to have a corresponding resource at the specified address (though they often do). In other words, a URL is a path to a real document, whilst a URI is a unique string used to make sure that each namespace is distinct from all the others. A URI may also be a URL, but doesn’t have to be.** | ||
+ | |||
+ | Avez-vous noté l' | ||
**When a browser sees that the document’s default namespace is “http:// | **When a browser sees that the document’s default namespace is “http:// | ||
Ligne 82: | Ligne 154: | ||
</ | </ | ||
+ | |||
+ | Quand un navigateur voit que l' | ||
+ | |||
+ | <svg | ||
+ | xmlns=" | ||
+ | xmlns: | ||
+ | |||
+ | <path d="M 130,70 A 60,60 0 1,1 130,69.9 Z" | ||
+ | |||
+ | fill=" | ||
+ | |||
+ | < | ||
+ | |||
+ | </ | ||
**This time the default namespace is still SVG, so the < | **This time the default namespace is still SVG, so the < | ||
+ | |||
+ | Cette fois-ci, l' | ||
**By default attributes are in the same namespace as their element – so in the previous example the “d” attribute is in the SVG namespace, whereas the “start” attribute is in the GardenML namespace. But you can prefix individual attributes as well, should you need to. In this example we’ve got an SVG path to which I’ve added some custom attributes of my own: | **By default attributes are in the same namespace as their element – so in the previous example the “d” attribute is in the SVG namespace, whereas the “start” attribute is in the GardenML namespace. But you can prefix individual attributes as well, should you need to. In this example we’ve got an SVG path to which I’ve added some custom attributes of my own: | ||
Ligne 94: | Ligne 182: | ||
garden: | garden: | ||
/>** | />** | ||
+ | |||
+ | Par défaut, les attributs sont dans le même espace de nommage que leurs éléments, ainsi, dans l' | ||
+ | |||
+ | <path d="M 130,70 A 60,60 0 1,1 130,69.9 Z" | ||
+ | |||
+ | fill=" | ||
+ | garden: | ||
+ | garden: | ||
+ | garden: | ||
+ | /> | ||
**Now all of this might seem a little esoteric, but there are two reasons for explaining it. The first is that namespaces are integral to XML documents, so when we get round to manipulating Inkscape files using JavaScript a little later in this series you’ll be glad of a good grounding in the topic. The second is that it explains why our Inkscape generated files are so much larger than a hand-crafted version. Here’s the opening <svg> element of a typical Inkscape file: | **Now all of this might seem a little esoteric, but there are two reasons for explaining it. The first is that namespaces are integral to XML documents, so when we get round to manipulating Inkscape files using JavaScript a little later in this series you’ll be glad of a good grounding in the topic. The second is that it explains why our Inkscape generated files are so much larger than a hand-crafted version. Here’s the opening <svg> element of a typical Inkscape file: | ||
Notice all the different namespaces being defined, and a couple of them being used on the last two attributes. The “svg” namespace you now know about, but what of the others? The “inkscape” namespace is used to store extra attributes that hold Inkscape-specific data. Without these, Inkscape would be limited to the features defined in the SVG spec, and wouldn’t be able to provide extra capabilities such as Live Path Effects. The “sodipodi” namespace serves a similar purpose – Inkscape was forked from the Sodipodi program many years ago, but its history lives on in attributes that date from before the split.** | Notice all the different namespaces being defined, and a couple of them being used on the last two attributes. The “svg” namespace you now know about, but what of the others? The “inkscape” namespace is used to store extra attributes that hold Inkscape-specific data. Without these, Inkscape would be limited to the features defined in the SVG spec, and wouldn’t be able to provide extra capabilities such as Live Path Effects. The “sodipodi” namespace serves a similar purpose – Inkscape was forked from the Sodipodi program many years ago, but its history lives on in attributes that date from before the split.** | ||
+ | |||
+ | Tout cela peut vous paraître un peu ésotérique, | ||
+ | |||
+ | Notez que tous les espaces de nommage sont définis et que deux d' | ||
**The remaining namespaces are used for the metadata about your document that you can enter into the Document Properties dialog. There are several of them because they each refer to a different XML language. Inkscape could have just used it’s own namespace for all of them, but by referring to other well-known languages it improves the ability of the metadata to be automatically parsed and understood by indexing programs or other XML tools. It does bloat the size of the file quite considerably, | **The remaining namespaces are used for the metadata about your document that you can enter into the Document Properties dialog. There are several of them because they each refer to a different XML language. Inkscape could have just used it’s own namespace for all of them, but by referring to other well-known languages it improves the ability of the metadata to be automatically parsed and understood by indexing programs or other XML tools. It does bloat the size of the file quite considerably, | ||
An obvious way to reduce the file size, therefore, is to remove the additional namespaces, elements and attributes. Doing this obviously compromises the SVG file in various ways, from removing the editability of Inkscape-specific features, to loss of metadata. Inkscape does, however, provide a couple of options for doing this for you. They’re both alternative formats in the File > Save As… dialog, but in practice I recommend still saving a normal Inkscape SVG file, then creating your slimline version using File > Save A Copy…. This approach avoids the problem of forgetting to save in the full-fat format when you’ve made an edit, and losing data in the process.** | An obvious way to reduce the file size, therefore, is to remove the additional namespaces, elements and attributes. Doing this obviously compromises the SVG file in various ways, from removing the editability of Inkscape-specific features, to loss of metadata. Inkscape does, however, provide a couple of options for doing this for you. They’re both alternative formats in the File > Save As… dialog, but in practice I recommend still saving a normal Inkscape SVG file, then creating your slimline version using File > Save A Copy…. This approach avoids the problem of forgetting to save in the full-fat format when you’ve made an edit, and losing data in the process.** | ||
+ | |||
+ | Les espaces de nommage restants sont utilisés pour les métadonnées de votre document que vous pouvez saisir dans le dialogue Propriétés du document. Il y en a plusieurs car chacun fait référence à un langage XML différent. Inkscape aurait pu utiliser son propre espace de nommage pour tous, mais, en faisant référence à d' | ||
+ | |||
+ | Par conséquent, | ||
**Your first choice is to save as “Plain SVG”. This strips out the proprietary Inkscape and Sodipodi namespaces, and their associated elements and attributes. It still leaves the other namespaces intact, so the file will still contain any metadata you entered into the Document Properties dialog. This option is ideal for use when linking to an SVG file via the <img> or < | **Your first choice is to save as “Plain SVG”. This strips out the proprietary Inkscape and Sodipodi namespaces, and their associated elements and attributes. It still leaves the other namespaces intact, so the file will still contain any metadata you entered into the Document Properties dialog. This option is ideal for use when linking to an SVG file via the <img> or < | ||
The other choice is to save as “Optimised SVG”. This presents an additional dialog that lets you choose from a wide range of optimisations that can potentially reduce the file size. Be warned that this option can lead to quite extensive changes in the structure and content of your SVG file, so always test the resultant file to make sure you haven’t optimised away something important. Be particularly wary of reducing the number of significant digits too far, as this will affect the fidelity of your image.** | The other choice is to save as “Optimised SVG”. This presents an additional dialog that lets you choose from a wide range of optimisations that can potentially reduce the file size. Be warned that this option can lead to quite extensive changes in the structure and content of your SVG file, so always test the resultant file to make sure you haven’t optimised away something important. Be particularly wary of reducing the number of significant digits too far, as this will affect the fidelity of your image.** | ||
+ | |||
+ | La première option est de sauvegarder en « SVG simple ». Dans celui-ci, les espaces de nommage propriétaires d' | ||
+ | |||
+ | L' | ||
**When it comes to the additional namespace-related data, there are a couple of key fields to pay attention to. On the first tab, the “Keep editor data” checkbox determines whether the Inkscape and Sodipodi namespaces are preserved. | **When it comes to the additional namespace-related data, there are a couple of key fields to pay attention to. On the first tab, the “Keep editor data” checkbox determines whether the Inkscape and Sodipodi namespaces are preserved. | ||
Ligne 112: | Ligne 222: | ||
Also on the second tab, pay attention to the Pretty-printing options. Turning this off can reduce the size further, but if you’re trying to create a file to put inline in an HTML page, a little formatting can make it a lot easier to work with.** | Also on the second tab, pay attention to the Pretty-printing options. Turning this off can reduce the size further, but if you’re trying to create a file to put inline in an HTML page, a little formatting can make it a lot easier to work with.** | ||
+ | |||
+ | Quant aux données additionnelles en lien avec les espaces de nommage, une attention particulière doit être portée à quelques champs clés. Sur le premier onglet, la case « Conserver les données d' | ||
+ | |||
+ | Dans le deuxième onglet, l' | ||
+ | |||
+ | Toujours dans le deuxième onglet, faites attention aux options d' | ||
**So how well does Optimised SVG stack up against hand-written code? It doesn’t reach the 107 characters of my carefully crafted version, but at 277 characters of fairly readable SVG it doesn’t do too bad a job. For most cases where you want to inline your image into an HTML page it will be good enough, with far less scope for errors than trying to write everything by hand. | **So how well does Optimised SVG stack up against hand-written code? It doesn’t reach the 107 characters of my carefully crafted version, but at 277 characters of fairly readable SVG it doesn’t do too bad a job. For most cases where you want to inline your image into an HTML page it will be good enough, with far less scope for errors than trying to write everything by hand. | ||
Phew! We’ve covered quite a lot this month, from < | Phew! We’ve covered quite a lot this month, from < | ||
+ | |||
+ | Et comment le SVG optimisé se compare-t-il au code écrit à la main ? Il n' | ||
+ | |||
+ | Ouf ! Nous en avons traité pas mal ce mois-ci, des balises < | ||
+ |
issue134/inkscape.1531917502.txt.gz · Dernière modification : 2018/07/18 14:38 de d52fr