'Qt\'s paint system does not update brushOrigin when using
TexturePatterns and it also uses TexturePatterns to emulate gradients,
leading to brokenness. So this method allows the paint engine to update
the brush origin before painting an object. While not perfect, this is
better than nothing. The problem is that if the rect being filled has a
border, then QtWebKit generates an image of the rect size - border but
fills the full rect, and there\'s no way for the paint engine to know
that and adjust the brush origin.'

def resolve_fill(self, rect, pdf_system, qt_system):

    if ((not hasattr(self, u'last_fill')) or (not self.current_state.do_fill)):
        return
    if isinstance(self.last_fill.brush, TexturePattern):
        tl = rect.topLeft()
        if (tl == self.last_fill.origin):
            return
        matrix = ((QTransform.fromTranslate(tl.x(), tl.y()) * pdf_system) * qt_system.inverted()[0])
        pat = TexturePattern(None, matrix, self.pdf, clone=self.last_fill.brush)
        pattern = self.pdf.add_pattern(pat)
        self.pdf.apply_fill(self.last_fill.color, pattern)
