[Interest] QSvgRenderer::defaultSize() is wrong?

John Weeks john at wavemetrics.com
Fri Jun 3 00:22:10 CEST 2016


I have an SVG file (that happens to have been generated using QSvgGenerator) that has this at the start:

<svg width="139.347mm" height="73.3778mm"

So the units are millimeters. During loading by QSvgRenderer, the size of the image is initialized from those values by a process that includes this:

// this should really be called convertToDefaultCoordinateSystem
// and convert when type != QSvgHandler::defaultCoordinateSystem
static qreal convertToPixels(qreal len, bool , QSvgHandler::LengthType type)
{

    switch (type) {
    case QSvgHandler::LT_PERCENT:
        break;
    case QSvgHandler::LT_PX:
        break;
    case QSvgHandler::LT_PC:
        break;
    case QSvgHandler::LT_PT:
        return len * 1.25;
        break;
    case QSvgHandler::LT_MM:
        return len * 3.543307;
        break;
    case QSvgHandler::LT_CM:
        return len * 35.43307;
        break;
    case QSvgHandler::LT_IN:
        return len * 90;
        break;
    case QSvgHandler::LT_OTHER:
        break;
    default:
        break;
    }
    return len;
}

This implies that the default coordinate system is one in which a unit is 1/90 inch. The fact that LT_PX units are not scaled seems to indicate that unitless <svg width height> values will be interpreted as if the system is 90 DPI. My reading here: http://www.w3.org/TR/SVG/coords.html#Units seems to indicate that unitless width and height should indicate some sort of "pixels".

This seems wrong. It seems likely that the 90 DPI thing comes from http://www.w3.org/TR/SVG/coords.html#Units where 90 DPI is used *as an example*. But maybe it's I that is wrong- is there somewhere in the SVG standard that indicates that these should be interpreted at 90 DPI units?

So, finally, my questions:

1) Am I right that this is wrong?

2) If it is just an assumption used to produce a consistent answer internally, then can I assume that QSvgRenderer::defaultSize() will always embody that assumption? If so, then I can scale my pictures based on a 90 DPI unit and be assured that it will always be that way.

-John Weeks




More information about the Interest mailing list