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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With