| 1 |
SVG Images |
| 2 |
---------- |
| 3 |
|
| 4 |
.. image:: ../../../docs/user/rst/images/biohazard.svg |
| 5 |
:width: 48 px |
| 6 |
:height: 48 px |
| 7 |
:align: left |
| 8 |
|
| 9 |
Scalable vector graphics (SVG) images are the only standards-compatible |
| 10 |
way to include vector graphics in HTML documents. However, they are not |
| 11 |
supported by all backends/output formats (LaTeX, e.g., supports the PDF |
| 12 |
or Postscript formats for vector graphics instead). Rendering behaviour |
| 13 |
varies, depending on the SVG image itself, the method used to put the |
| 14 |
image in the document, and the viewing agent. |
| 15 |
|
| 16 |
.. figure:: ../../../docs/user/rst/images/title-scaling.svg |
| 17 |
:width: 40% |
| 18 |
:figwidth: 75% |
| 19 |
:align: center |
| 20 |
|
| 21 |
Figure with image occupying 40% of the figure width. |
| 22 |
|
| 23 |
The `viewBox` attribute in the image file enables scaling |
| 24 |
also in ``<object>`` and ``<svg>`` nodes. |
| 25 |
|
| 26 |
All up-to-date HTML browsers support SVG, however not all do this fully |
| 27 |
and in the same manner. Some older browsers, especially IE < 9, have |
| 28 |
deficiencies or require plug-ins (i.e. don't support the ``<img>`` tag). |
| 29 |
Older versions of `webkit` based browsers (chromium, safari, midori, |
| 30 |
konqueror) support the ``<img>`` tag but don't display contained bitmap |
| 31 |
images. |
| 32 |
|
| 33 |
The "html4css1" writer includes SVG images as ``<object>`` elements, |
| 34 |
the "html5" writer uses ``<svg>`` for embedded images and ``<img>`` |
| 35 |
else. The element type influences several aspects of image behaviour: |
| 36 |
|
| 37 |
* Due to security/privacy considerations, browsers may block ``<object>`` |
| 38 |
data from 3rd party sources. |
| 39 |
|
| 40 |
* If an image is included as ``<object>`` or ``<svg>``, |
| 41 |
it depends on the `viewBox` declaration of the root ``<svg>`` element |
| 42 |
whether it is scaled or clipped/padded. |
| 43 |
Images in ``<img>`` elements are always scaled. |
| 44 |
|
| 45 |
.. image:: ../../../docs/user/rst/images/biohazard-scaling.svg |
| 46 |
:height: 1.2 em |
| 47 |
:align: left |
| 48 |
|
| 49 |
Image with `viewBox`, 1.2 em high, left aligned and |inline-svg| inline. |
| 50 |
|
| 51 |
.. |inline-svg| image:: ../../../docs/user/rst/images/biohazard-scaling.svg |
| 52 |
:height: 1.2 em |
| 53 |
|
| 54 |
.. image:: ../../../docs/user/rst/images/biohazard-scaling.svg |
| 55 |
:height: 5 mm |
| 56 |
:width: 15 mm |
| 57 |
:align: left |
| 58 |
|
| 59 |
Image with `viewBox`, 5 mm x 15 mm. |
| 60 |
|
| 61 |
.. image:: ../../../docs/user/rst/images/biohazard.svg |
| 62 |
:height: 5 mm |
| 63 |
:width: 15 mm |
| 64 |
:align: left |
| 65 |
|
| 66 |
Image without `viewBox`, 5 mm x 15 mm. |
| 67 |
|
| 68 |
.. image:: ../../../docs/user/rst/images/biohazard-bitmap-scaling.svg |
| 69 |
:width: 2 em |
| 70 |
:align: left |
| 71 |
|
| 72 |
Image with embedded bitmap and `viewBox`, 2 em wide. |
| 73 |
|
| 74 |
.. image:: ../../../docs/user/rst/images/biohazard-bitmap.svg |
| 75 |
:width: 2 em |
| 76 |
:align: left |
| 77 |
|
| 78 |
Image with embedded bitmap without `viewBox`. |
| 79 |
|
| 80 |
* SVG images with `viewBox` keep the aspect ratio unless the |
| 81 |
`preserveAspectRatio` attribute is ``"none"``. |
| 82 |
The following two images are 25% wide and 1 em high: |
| 83 |
|
| 84 |
.. image:: ../../../docs/user/rst/images/title-scaling.svg |
| 85 |
:width: 25 % |
| 86 |
:height: 1 em |
| 87 |
:align: left |
| 88 |
|
| 89 |
Image with `viewBox`. |
| 90 |
|
| 91 |
.. image:: ../../../docs/user/rst/images/title.svg |
| 92 |
:width: 25 % |
| 93 |
:height: 1 em |
| 94 |
:align: left |
| 95 |
|
| 96 |
Image without `viewBox`. |
| 97 |
|
| 98 |
|
| 99 |
.. image:: http://oreillymedia.github.io/svg-essentials-examples/ch14/ |
| 100 |
animated_clock_js.svg |
| 101 |
:target: http://oreillymedia.github.io/svg-essentials-examples/ch14/ |
| 102 |
animated_clock_js.svg |
| 103 |
:alt: [animated clock] |
| 104 |
:height: 3em |
| 105 |
:align: right |
| 106 |
|
| 107 |
* Hyperlinks and script actions attached to SVG elements are ignored in |
| 108 |
images included as ``<img>``. Hyperlinks in images included as |
| 109 |
``<object>`` are opened in the "object frame". Hyperlinks specified in |
| 110 |
the rST source (with the ``:target:`` directive option) work in |
| 111 |
``<img>`` and ``<svg>`` elements but are ignored in images included as |
| 112 |
``<object>`` (unless the object is blocked). |
| 113 |
|
| 114 |
.. image:: ../input/data/object-with-hyperlink.svg |
| 115 |
:width: 2.4 em |
| 116 |
:align: left |
| 117 |
:target: `SVG Images`_ |
| 118 |
|
| 119 |
.. image:: ../input/data/interactive-button.svg |
| 120 |
:class: align-right |
| 121 |
:target: `SVG Images`_ |
| 122 |
|
| 123 |
Image with a link attached to the upper rectangle; |
| 124 |
interactive clock and button aligned to the right. |
| 125 |
|
| 126 |
.. image:: ../input/data/object-with-hyperlink.svg |
| 127 |
:width: 2.4 em |
| 128 |
:class: align-left |
| 129 |
:loading: embed |
| 130 |
:target: `SVG images`_ |
| 131 |
|
| 132 |
.. image:: ../input/data/interactive-button.svg |
| 133 |
:class: align-right |
| 134 |
:loading: embed |
| 135 |
:target: `SVG images`_ |
| 136 |
|
| 137 |
Embedded interactive SVG images. |