Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSvgRenderer draw text incorrect after QDomDocument.
Forum Updated to NodeBB v4.3 + New Features

QSvgRenderer draw text incorrect after QDomDocument.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RazrFalcon
    wrote on last edited by
    #1

    I try to draw SVG image over QPrintPreviewWidget.
    If I simply loads SVG image via QSvgRenderer - all works fine.
    But if I at first load this file to the QDomDocument, for edit, and then convert it to QByteArray - text on image goes wrong.
    Can I fix it or it's a bug?

    @void PrintPreviewWidget::doPaint(QPrinter *printer)
    {
    QString str("../test/test.svg");

    QFile file(str);
    QString src;
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
        src = file.readAll();
    QDomDocument doc;
    doc.setContent(src);
    
    // document editing
    
    // didn't work
    QSvgRenderer renderer(doc.toByteArray());
    // works good
    

    // QSvgRenderer renderer(str);

    QPainter painter(printer);
    QRectF rect(0, 0, printer->width(), printer->height());
    renderer.render(&painter, rect);
    painter.end();
    

    }@

    !http://storage3.static.itmages.ru/i/12/1124/h_1353705790_9196847_73481a1a77.png(1)!
    !http://storage4.static.itmages.ru/i/12/1124/h_1353705823_2938344_62c09f5615.png(2)!

    "Code example":http://rghost.ru/41768863

    Qt 4.8.3, Gentoo Linux, KDE

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dcbasso
      wrote on last edited by
      #2

      Well to use moe resources of SVG I have used the WebKit, QWebKit!
      Using the Webkit suck things like JavaScript on SVG would be possible to use and link the JS with C++ code!
      I think that QWebKit have a better support to SVG Files!

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RazrFalcon
        wrote on last edited by
        #3

        Fixed by:
        @doc.toString(0).replace(">\n<tspan", "><tspan")@

        QDomDocument by default write each tag on new line, but by "SVG spec":http://www.w3.org/TR/SVGTiny12/text.html#TSpanElement <tspan> on new line equated to space.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved