issue140:inkscape
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue140:inkscape [2018/12/28 18:10] – créée auntiee | issue140:inkscape [2019/01/07 15:58] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | Last time, I showed you how you can use a fragment identifier in the URL that points to your SVG file in order to make a browser show only a small part of the whole image. With a suitably crafted string, you can precisely identify a rectangular section of the image to display by specifying the x and y coordinates of the top left of the rectangle, together with its width and height. I also demonstrated how you could create named views so that the coordinates are entirely contained within the SVG file and the enclosing web page doesn’t need to know the gory details; all it needs to know is the ID of the view to display. | + | **Last time, I showed you how you can use a fragment identifier in the URL that points to your SVG file in order to make a browser show only a small part of the whole image. With a suitably crafted string, you can precisely identify a rectangular section of the image to display by specifying the x and y coordinates of the top left of the rectangle, together with its width and height. I also demonstrated how you could create named views so that the coordinates are entirely contained within the SVG file and the enclosing web page doesn’t need to know the gory details; all it needs to know is the ID of the view to display. |
- | Through this technique, you can effectively turn a single image into a number of named tiles, spread out along the x and y plane. This month, you’ll discover that it’s possible to perform a similar trick in the z-axis. In other words, you can stack several sub-images on top of each other, and then choose to show only one of them by putting its ID into the fragment identifier. | + | Through this technique, you can effectively turn a single image into a number of named tiles, spread out along the x and y plane. This month, you’ll discover that it’s possible to perform a similar trick in the z-axis. In other words, you can stack several sub-images on top of each other, and then choose to show only one of them by putting its ID into the fragment identifier.** |
- | The starting point for this technique isn’t actually SVG, but HTML. The way this trick works relies heavily on inheriting certain behaviours from the HTML and CSS world that can be manipulated into doing something useful in SVG. Let’s start with a simple HTML file (shown top right). | + | La dernière fois, je vous ai montré comment vous pouvez utiliser un identificateur de fragment dans l'URL qui pointe vers votre fichier SVG de façon à obliger un navigateur à n' |
+ | |||
+ | Par cette technique, vous pouvez effectivement transformer une simple image en quantité de tuiles nommées, réparties sur la surface en x et y. Ce mois-ci, vous découvrirez qu'il est possible de réaliser une astuce similaire sur l'axe z. En d' | ||
+ | |||
+ | **The starting point for this technique isn’t actually SVG, but HTML. The way this trick works relies heavily on inheriting certain behaviours from the HTML and CSS world that can be manipulated into doing something useful in SVG. Let’s start with a simple HTML file (shown top right). | ||
Allowing for the requirement to keep magazine listings short, try to imagine that this page has a lot of text in each paragraph, a lot of paragraphs in each section, and more sections than I’ve included in the sample. If you’re trying out the code yourself, make sure to include enough content for you to have to scroll quite a lot to get to the bottom section. | Allowing for the requirement to keep magazine listings short, try to imagine that this page has a lot of text in each paragraph, a lot of paragraphs in each section, and more sections than I’ve included in the sample. If you’re trying out the code yourself, make sure to include enough content for you to have to scroll quite a lot to get to the bottom section. | ||
- | With a lengthy page of text, it would be nice to be able to jump straight to a section via a list of links at the top of the page – a table of contents. To do that, we use the <a> tag in two different forms: around each section to “name” the link target, and in the table of contents to create a link that will jump straight to the named target. Skipping the boilerplate code and the content of the <p> tags we get the code shown on the previous page (bottom right). | + | With a lengthy page of text, it would be nice to be able to jump straight to a section via a list of links at the top of the page – a table of contents. To do that, we use the <a> tag in two different forms: around each section to “name” the link target, and in the table of contents to create a link that will jump straight to the named target. Skipping the boilerplate code and the content of the <p> tags we get the code shown on the previous page (bottom right).** |
+ | |||
+ | Le point de départ de cette technique n'est pas vraiment le SVG, mais le HTML. Pour fonctionner, | ||
+ | |||
+ | Compte tenu du fait que les listings du magazine doivent rester courts, essayez d' | ||
+ | |||
+ | Avec une longue page de texte, il serait sympa de pouvoir sauter directement vers une section via une liste de liens en haut de page - un sommaire. Pour le faire, nous utilisons la balise <a> sous deux formes différentes : autour de chaque section pour « nommer » la cible du lien, et dans le sommaire pour créer un lien qui sautera directement à la cible nommée. En laissant tomber le code standard et le contenu des balises <p>, nous obtenons le code montré sur la page précédente (en bas à droite). | ||
- | A quick trip to a “lorem ipsum” generator to fill out the content, and the web page looks something like this when loaded into a browser: | + | **A quick trip to a “lorem ipsum” generator to fill out the content, and the web page looks something like this when loaded into a browser: |
Clicking the links in the Table of Contents will scroll the browser so that the target of the link is visible on screen. The “href” attribute in those links is essentially just the fragment identifier part of the full URL. Indeed, if we modify the full URL in the browser to append “#sec3” to the end of the URL, the browser will also jump to the third section. | Clicking the links in the Table of Contents will scroll the browser so that the target of the link is visible on screen. The “href” attribute in those links is essentially just the fragment identifier part of the full URL. Indeed, if we modify the full URL in the browser to append “#sec3” to the end of the URL, the browser will also jump to the third section. | ||
Okay, so appending the ID of an <a> element to the URL will make the page scroll to that target. What’s that got to do with SVG? To answer that we need to introduce another part of this puzzle: the CSS “: | Okay, so appending the ID of an <a> element to the URL will make the page scroll to that target. What’s that got to do with SVG? To answer that we need to introduce another part of this puzzle: the CSS “: | ||
+ | |||
+ | < | ||
+ | :target { | ||
+ | color: red; | ||
+ | }** | ||
+ | |||
+ | Un passage rapide dans un générateur de « lorem ipsum » pour remplir le contenu et la page Web ressemble à quelque chose comme ceci quand elle est chargée dans un navigateur : | ||
+ | |||
+ | En cliquant sur les liens du sommaire, le navigateur fera défiler le texte pour rendre la cible du lien visible à l' | ||
+ | |||
+ | Ainsi, l' | ||
< | < | ||
Ligne 20: | Ligne 41: | ||
} | } | ||
- | This tells the browser to run this little algorithm: | + | **This tells the browser to run this little algorithm: |
• Does the URL have a fragment identifier? | • Does the URL have a fragment identifier? | ||
• If so, does it match a target ID in the page? | • If so, does it match a target ID in the page? | ||
Ligne 26: | Ligne 47: | ||
Now, as you click the entries in the table of contents or manipulate the URL by hand, the target section is rendered with red text, rather than black. We’ve got a way to apply a style to only the element specified in the fragment identifier. Which means we can instead do something like this: | Now, as you click the entries in the table of contents or manipulate the URL by hand, the target section is rendered with red text, rather than black. We’ve got a way to apply a style to only the element specified in the fragment identifier. Which means we can instead do something like this: | ||
+ | |||
+ | < | ||
+ | a { display: none; } | ||
+ | |||
+ | :target { | ||
+ | display: initial; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Ceci dit au navigateur de lancer ce petit algorithme : | ||
+ | • L'URL a-t-elle un identificateur de fragment ? | ||
+ | • Si oui, correspond-il à un identifiant cible de la page ? | ||
+ | • Si oui, appliquer la propriété « color: red » à l' | ||
+ | |||
+ | Maintenant, quand vous cliquez sur les lignes du sommaire ou que vous bricolez l'URL à la main, la section cible est rendue avec le texte en rouge, plutôt qu'en noir. Nous avons trouvé une façon d' | ||
< | < | ||
Ligne 35: | Ligne 71: | ||
</ | </ | ||
- | This will hide all the <a> elements, and their descendants, | + | |
+ | **This will hide all the <a> elements, and their descendants, | ||
So we’ve now got a way to show only a single element (and its descendants), | So we’ve now got a way to show only a single element (and its descendants), | ||
- | The first thing we’ll need, therefore, is a type of element that can act as a container for the content we want to show and hide. In SVG terms, that would be a <g>, which in Inkscape is exposed as a group, but is also used for layers (as noted in previous instalments, | + | The first thing we’ll need, therefore, is a type of element that can act as a container for the content we want to show and hide. In SVG terms, that would be a <g>, which in Inkscape is exposed as a group, but is also used for layers (as noted in previous instalments, |
- | But layers have one big advantage: they’re much easier to show and hide when working in Inkscape. Given that this workflow requires each image to be stacked upon the others, this advantage becomes invaluable for anything more than a couple of groups. For the rest of this tutorial, therefore, I’ll be using layers. Continuing from last month’s instalment, I’m going to stack the same four objects I used previously – a circle, a star, a spiral and some text – putting them into individual layers. | + | Ceci cachera tous les éléments <a>, et leurs descendants, |
- | It’s worth reiterating at this point that each layer could contain more than a single element – I just didn’t want to clutter up the screenshots too much by introducing more content. In practice, each layer would typically be an SVG image in its own right, potentially containing multiple elements, groups, clones and filters. In a more complex situation, you can clearly see how the ability to hide and lock individual layers makes this method generally superior to just using Inkscape groups. | + | |
+ | Ainsi, nous avons trouvé une façon de ne montrer qu'un élément unique (et ses descendants), | ||
+ | |||
+ | Ainsi donc, la première chose dont nous avons besoin est un type d' | ||
+ | |||
+ | **But layers have one big advantage: they’re much easier to show and hide when working in Inkscape. Given that this workflow requires each image to be stacked upon the others, this advantage becomes invaluable for anything more than a couple of groups. For the rest of this tutorial, therefore, I’ll be using layers. Continuing from last month’s instalment, I’m going to stack the same four objects I used previously – a circle, a star, a spiral and some text – putting them into individual layers. | ||
+ | |||
+ | It’s worth reiterating at this point that each layer could contain more than a single element – I just didn’t want to clutter up the screenshots too much by introducing more content. In practice, each layer would typically be an SVG image in its own right, potentially containing multiple elements, groups, clones and filters. In a more complex situation, you can clearly see how the ability to hide and lock individual layers makes this method generally superior to just using Inkscape groups.** | ||
+ | |||
+ | Mais les calques ont un gros avantage : dans Inkscape, ils se montrent et se cachent bien plus facilement. Étant donné que notre déroulé de programme nécessite que chaque image soit placée au-dessus des autres, cet avantage devient inestimable pour celui qui a besoin de plus d'une paire de groupes. Aussi, pour le reste de ce tutoriel, j' | ||
+ | |||
+ | Je me permets de redire ici que chaque calque peut contenir plus d'un élément - je souhaitais juste ne pas trop encombrer les copies d' | ||
+ | |||
+ | **With my layers created, the next step is to open the XML Editor (Edit > XML Editor) and set the IDs for the layers. In the screenshot, you can see that I’ve already set the IDs for “circle”, | ||
- | With my layers created, the next step is to open the XML Editor (Edit > XML Editor) and set the IDs for the layers. In the screenshot, you can see that I’ve already set the IDs for “circle”, | ||
While you’ve got the XML editor open, it’s worth noting what happens when you show and hide a layer. Each layer has a “style” attribute which contains “display: inline” if it’s visible, or “display: none” if it’s hidden. We’ll come back to this later but, for now, just remember that there’s a “style” attribute that holds the “display” property directly on each layer. | While you’ve got the XML editor open, it’s worth noting what happens when you show and hide a layer. Each layer has a “style” attribute which contains “display: inline” if it’s visible, or “display: none” if it’s hidden. We’ll come back to this later but, for now, just remember that there’s a “style” attribute that holds the “display” property directly on each layer. | ||
- | Once your stack of drawings is complete, and your layer IDs have all been set, you’ll need to save the file and open it in a text editor. It’s time to add a block of CSS that will turn off the layers, then turn on only the layer specified in the fragment identifier. The placement of the CSS in the file doesn’t matter too much, but I usually put it just after the opening <svg …> tag (shown below). | + | Once your stack of drawings is complete, and your layer IDs have all been set, you’ll need to save the file and open it in a text editor. It’s time to add a block of CSS that will turn off the layers, then turn on only the layer specified in the fragment identifier. The placement of the CSS in the file doesn’t matter too much, but I usually put it just after the opening <svg …> tag (shown below).** |
- | The “svg | + | Mes calques étant créés, l' |
- | With our SVG stack set up, we can reference the images with a fragment identifier in the HTML, in a similar manner to the named views we used last time (shown top right). | + | Pendant que l' |
- | The resultant web page looks like this: | + | Une fois que votre empilage de dessins sera terminé et que vous aurez inscrit tous les identifiants des calques, vous devrez sauvegarder votre fichier et l' |
+ | |||
+ | **The “svg > g” syntax just means “this rule should affect only <g> elements that are immediate children of an <svg> element”, so it doesn’t affect any sub-layers. Otherwise, it’s pretty similar to the HTML rules we used earlier, but with the addition of “!important” on the properties. This tells the browser that these rules should take precedence over those in the “style” attributes on the layer – without them our new block of code would be ignored. You could avoid them if you manually removed the properties from the style attributes on each layer, but as Inkscape will add them back in again if you ever need to edit the file, it quickly becomes a thankless chore. Sprinkling a few “!important” declarations around isn’t particularly good coding practice, but it’s a lot more practical. | ||
+ | |||
+ | With our SVG stack set up, we can reference the images with a fragment identifier in the HTML, in a similar manner to the named views we used last time (shown top right).** | ||
+ | |||
+ | La syntaxe « svg > g » signifie simplement que « cette règle ne doit affecter que les éléments <g> qui sont des enfants directs d'un élément <svg> » ; ainsi, elle n'a pas d' | ||
+ | |||
+ | Notre pile SVG étant paramétrée, | ||
+ | |||
+ | **The resultant web page looks like this: | ||
With SVG stacks, it’s also possible to have another layer that sits behind all the others, but which is always visible, regardless of the fragment identifier. Consider a single background layer, with its ID set to “background”. This additional CSS selector would ensure that it’s always visible: | With SVG stacks, it’s also possible to have another layer that sits behind all the others, but which is always visible, regardless of the fragment identifier. Consider a single background layer, with its ID set to “background”. This additional CSS selector would ensure that it’s always visible: | ||
Ligne 61: | Ligne 120: | ||
} | } | ||
- | With named views and stacks giving broadly similar results, you might want to know which one is better to use. For many cases, either will work: named views arguably require more work to set up, but provide an advantage of being able to see all the individual images in Inkscape at once. Views also work better if your images are different sizes. Stacks, on the other hand, work well if your images require a single common background, or if it’s easier to draw each image by stacking it on top of the previous ones to help with alignment. As is so often the case, the real answer is to try both approaches and see which one works best for you. | + | With named views and stacks giving broadly similar results, you might want to know which one is better to use. For many cases, either will work: named views arguably require more work to set up, but provide an advantage of being able to see all the individual images in Inkscape at once. Views also work better if your images are different sizes. Stacks, on the other hand, work well if your images require a single common background, or if it’s easier to draw each image by stacking it on top of the previous ones to help with alignment. As is so often the case, the real answer is to try both approaches and see which one works best for you.** |
+ | |||
+ | La page Web résultante ressemble à ceci : | ||
+ | |||
+ | Avec les piles du SVG, il est aussi possible d' | ||
+ | |||
+ | #background { | ||
+ | display: initial !important; | ||
+ | } | ||
+ | |||
+ | Les vues nommées et les piles donnant en gros des résultats similaires, vous pourriez aimer savoir laquelle est la meilleure à utiliser. Dans de nombreux cas, les deux fonctionnent : les vues nommées nécessitent sans doute plus de travail pour les paramétrer, |
issue140/inkscape.1546017018.txt.gz · Dernière modification : 2018/12/28 18:10 de auntiee