Qt SVG renderer

Richard Dale rdale at foton.es
Thu Jul 31 20:16:12 BST 2008


On Thursday 31 July 2008 19:31:46 Matthew Woehlke wrote:
> Thiago Macieira wrote:
> > On Thursday 31 July 2008 13:54:22 Rafael Fernández López wrote:
> >> Matthew Woehlke wrote:
> >>> @ereslibre:
> >>> It would be REALLY helpful if you could somehow provide the
> >>> mis-rendering svg's as well (link to websvn is probably ok); I'm sure
> >>> this would be a tremendous help to the Qt folk.
> >>
> >> Hmm, yes... let's see if I can do it ASAP.
> >
> > There's no rush for us.
>
> Well *I'm* still curious. So I dug out where in svn the .svg's are...
> and at least for media-flash-memory-stick, there is indeed *not* junk in
> the file... all the background garbage is indeed the fault of the
> renderer, not the svg. (I wonder if Ariya might be onto something, if
> maybe something is being reused without being cleared, rather than a Qt
> problem. I must admit, it's hard to imagine how Qt would manage to
> render bunches of other icons behind the 'right' one.)
I think the images were generated with a QtRuby program as I helped ruphy get 
it working on the #plasma irc channel. Sorry this has only just occured to 
me, although I've been reading the thread.

It renders all the "*.svg"s in a directory to .pngs. However, if I've just run 
it with just a single svg at a time, and I get different results. So I 
suspect this a more likely a bug in QtRuby than Qt itself.

Here is the QtRuby program:

require 'Qt4'

class Renderer
  def initialize
    @renderer = Qt::SvgRenderer.new
  end
  
  def render(file)
    pic = Qt::Image.new(256, 256, Qt::Image::Format_ARGB32_Premultiplied)
    painter = Qt::Painter.new
    painter.begin(pic)
    @renderer.load file
    @renderer.render painter
    painter.end
    pic.save(get_png_name(file))
  end

  def get_png_name(name)
    info = Qt::FileInfo.new(name)
    return info.completeBaseName + ".png"
  end
end

app = Qt::Application.new(ARGV)
r = Renderer.new

Dir['/home/rdale/kde/inst/kde4/share/apps/desktoptheme/default/widgets/*.svg'].each 
do |file|
  puts "Rendering "+file+"...."
  r.render file
end

I've tried creating a new Qt::SvgRenderer for each image, and also calling 
dispose() on the painter, pic and renderer after creating each image to 
explicitely delete them rather than wait for garbage collection, and it 
doesn't make any difference.

So I think we should do the same thing with a C++ program before reporting any 
bugs to Trolltech/Nokia.

-- Richard




More information about the kde-core-devel mailing list