[Interest] SVG Issue.

Bill Crocker william.crocker at analog.com
Sat Oct 19 19:51:49 CEST 2013


Hello:

Summary: I create a QGraphicsScene with a piece of text and a bounding
          rectangle. I render to SVG, but the scene when viewed in Inkscape
          and Firefox does not match what I saw on the screen.

I create the text item with a font
which is known to Inkscape and Firefox.

     QFont font( "Bitstream Vera Sans", 12, QFont::Normal );
     QGraphicsItem *tp = addSimpleText( "Some long piece of text.", font );

I create the bounding rectangle.

     QRect r = tp->boundingRegion(tp->sceneTransform()).boundingRect();
     QGraphicsRectItem *rp = new QGraphicsRectItem(r);
     rp->setPen(QPen(Qt::black));
     addItem(rp);

I create the svg file:

     QSvgGenerator svg;
     QRectF sr = the_scene->sceneRect();
     svg.setSize(QSize(qRound(sr.width()),qRound(sr.height())));
     svg.setFileName("x.svg");
     QPainter pter(&svg);
     m_the_scene->render(&pter);

On screen, the rect bounds the text nicely.
However, when I open the SVG file in Inkscape (or Firefox) the
rectangle no longer bounds the text. The text is smaller (or the
rectangle is bigger). If I increase the text point size from 12 to 16
then the Inkscape picture looks like what I saw on the screen.

Since Inkscape and Firefox both show the same thing, I assume the
SVG has been created improperly by the QSvgGenerator.

Using Qt 4.7.1
On Redhat Enterprise Linux
Qt was built with -fontconfig.

Any thoughts?

Bill




More information about the Interest mailing list