Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QWebView undersampled SVG rendering

I'd like to use QWebView for an SVG thumbnailing job because it supports filters (unlike QSvgRender which only supports SVG Tiny 1.2). It seems to work quite well except for font rendering but that can be tweaked using fontconfig package. The problem is that it seems to be undersampling elements with filters. Elements without filters look good and sharp, while those with filters are pixelated and blurry.

from  PyQt4.QtGui import *
from  PyQt4.QtCore import *
from PyQt4.QtSvg import *
from PyQt4.QtWebKit import *
import sys
import time

if __name__ == '__main__':

    app = QApplication(sys.argv)

    data = open('/home/xxx/workspace/yyy/zzz/out.svg').read()

    # svg = QSvgRenderer(QByteArray(data))
    qim = QImage(int(1024), int(768), QImage.Format_ARGB32)                                                                                                                                                                                 
    web = QWebView()
    web.setRenderHint(QPainter.SmoothPixmapTransform)
    web.setRenderHint(QPainter.Antialiasing)
    web.setRenderHint(QPainter.TextAntialiasing)
    painter = QPainter()

    def load_finished(ok):
        web.resize(1024,768)
        painter.begin(qim)
        # svg.render(painter)
        web.render(painter)
        painter.end()

        print "null:", qim.isNull()
        qim.save('test2.png')
        sys.exit()

    web.connect(web, SIGNAL('loadFinished(bool)'), load_finished)
    web.load(QUrl('file:///home/xxx/workspace/yyy/zzz/out.svg'))
    sys.exit(app.exec_())

Qt 4.7. Same SVG file looks OK when rendered using Inkscape, rsvg or in Chrome, Firefox.

result

like image 638
skrat Avatar asked May 14 '11 15:05

skrat


1 Answers

Try rendering using QWebPage (the non-GUI renderer), see if that helps. I can't see any setting that would affect the rendering.

Code would be something like this (not checked):

QWebPage page
QWebFrame frame = page.mainFrame()
frame.load(url)
frame.render(painter)
like image 76
Silas Parker Avatar answered Oct 11 '22 14:10

Silas Parker