Suppose I have an SVG something like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
viewBox="0 0 100 200"
height="600mm"
width="300mm">
...
Using QSvgRenderer::viewBoxF() I can obtain the 0 0 100 200 viewbox, but is there any way to obtain the width="300mm" and height="600mm"?
(Other than the obvious thing of parsing the XML myself.)
I've read the source code. See
QSvgHandler::createSvgNode(). The behaviour is something like this:QSvgRenderer::viewBoxF()returns theviewBoxattribute in user-defined units.QSvgRenderer::defaultSize()reads thewidthandheightattributes (if present). If the units arecm,inormmthey it is multiplied by an appropriate value to give pixels at a resolution of 90 DPI. For example ifinthen it is multiplied by 90,mmby 90/25.4 and so on. Other units -px,ptand even%are left as-is.defaultSize()uses integers so its resolution is 1/90 inch.If the
widthandheightare not present thendefaultSize()returns the size of the viewBox in user-defined units.This is rather ad-hoc and complex behaviour and doesn't fit my use case so I think I will just have to parse the XML twice (or the first bit of it anyway).