# Pictures and SVG

Draw does not read SVG elements into rectangles, text, or arrows. An SVG file becomes a picture or a file card, based on its MIME type.

## Store a picture

When you drop or insert a file whose type is `image/svg+xml`, Draw stores a picture. The toolbar control is **Picture**. The **Insert** menu item is **Picture…**. The drop dialog asks you to choose **Keep a copy in the project** or **Only link to it**. When you paste a file, Draw skips that dialog and copies the bytes.

`readImageSize` loads the file in an image element. The stored width and height are `naturalWidth` and `naturalHeight`. If that load fails, Draw stores 320 by 240. Draw then scales the picture so the long side is at most 640 and both sides are at least 24.

## The picture shows in Chrome

When you drop or insert a PNG or an SVG, Draw lays the picture out at its stored width and height. Draw stores an 80 by 40 red PNG at 80 by 40. When you change the zoom, the picture scales with the board.

## Files dropped as image/svg+xml

These files were dropped with type `image/svg+xml`. The colour is the bitmap pixel at 2,2, read from the picture element. You see each picture on the board.

- `sized-basic.svg` set `width` 200, `height` 100, and a viewBox. Chrome reported 200 by 100. The pixel was `#ff0000`.
- `viewbox-only.svg` set a viewBox and no width or height. Chrome reported 300 by 150. The pixel was `#00ff00`.
- `no-size.svg` set neither size nor a viewBox. A rect of 200 by 100 was `#ff00ff` at the sampled pixel. Chrome reported 300 by 150.
- `percent.svg` used `width` and `height` of `100%`. Chrome reported 300 by 150. The pixel was `#ffa500`.
- `style-tag.svg` set the fill in a `style` element. The pixel was `#112233`.
- `presentation-attr.svg` set the fill in a `style` attribute. The pixel was `#445566`.
- `script.svg` started red and a script tried to turn it blue. The pixel stayed `#ff0000`. The script did not run.
- `external-image.svg` referenced another image. The rect pixel stayed `#123456`.
- `use-symbol.svg` drew a `rect` through `use`. The pixel was `#abcdef`.
- `gradient.svg` used a linear gradient. The corner pixel was `#fb0003` and the centre pixel was `#7f0080`.
- `path.svg` used `path`, `polygon`, `polyline`, `line`, and `ellipse`. The corner was `#eeeeee` and the centre was `#ffaa00`.
- `units-mm.svg` used `40mm` by `20mm`. Chrome reported 151 by 76. The pixel was `#660066`.
- `no-xmlns.svg` had no `xmlns`. The image was broken. Draw stored 320 by 240.
- `foreign.svg` included a `foreignObject`. Reading pixels failed because the canvas was tainted. You see the HTML text on the board.
- `text-only.svg` was 320 by 80. The corner pixel was `#ffffff`. A glyph pixel was not sampled on the board.

## What slide.svg did

`slide.svg` is the file checked most carefully. Chrome decoded `slide.svg` at 960 by 540. The picture element on the board had `#1f4b99` at 2,2 and `#ffffff` at the centre. Draw scaled the long side to 640, so the shape box was 640 by 360. You see the picture at 640 by 360. A separate decode of the same file, outside the board, found dark pixels in the title band.

```svg
<svg xmlns="http://www.w3.org/2000/svg" width="960" height="540" viewBox="0 0 960 540">
  <rect width="960" height="540" fill="#f4f1ea"/>
  <rect x="0" y="0" width="16" height="540" fill="#1f4b99"/>
  <text x="64" y="110" fill="#1a1a1a" font-family="Arial, Helvetica, sans-serif" font-size="54">Quarter plan</text>
  <text x="64" y="160" fill="#333333" font-family="Arial, Helvetica, sans-serif" font-size="24">Three things to show</text>
  <rect x="64" y="220" width="250" height="220" rx="16" fill="#ffffff" stroke="#1f4b99" stroke-width="4"/>
  <text x="84" y="300" fill="#1a1a1a" font-family="Arial, Helvetica, sans-serif" font-size="28">Ship the draft</text>
  <rect x="355" y="220" width="250" height="220" rx="16" fill="#ffffff" stroke="#1f4b99" stroke-width="4"/>
  <text x="375" y="300" fill="#1a1a1a" font-family="Arial, Helvetica, sans-serif" font-size="28">Review it</text>
  <rect x="646" y="220" width="250" height="220" rx="16" fill="#ffffff" stroke="#1f4b99" stroke-width="4"/>
  <text x="666" y="300" fill="#1a1a1a" font-family="Arial, Helvetica, sans-serif" font-size="28">Present it</text>
</svg>
```

## A file that is not a picture

A file whose type is empty, or whose type is `application/octet-stream`, becomes a file card, not a picture. Both test files were 280 by 72. The card for `octet.svg` showed that name, 396 B, and **Copy in project**. Pasting the SVG source as text created a text shape that contained the markup. The text shape did not draw the picture.

Write the board as a `.draw` file, as in the checked example.
