コード例 #1
0
ファイル: image_popup.py プロジェクト: zmshan2008/calibre
 def rotate_image(self):
     pm = self.label.pixmap()
     t = QTransform()
     t.rotate(90)
     pm = self.current_img = pm.transformed(t)
     self.label.setPixmap(pm)
     self.label.adjustSize()
     if self.fit_image.isChecked():
         self.set_to_viewport_size()
     else:
         self.factor = 1
         for sb in (self.scrollarea.horizontalScrollBar(),
                    self.scrollarea.verticalScrollBar()):
             sb.setValue(0)
コード例 #2
0
    def resolve_fill(self, rect, pdf_system, qt_system):
        '''
        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.
        '''
        if not hasattr(self, '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)
コード例 #3
0
 def corner():
     b = QBrush(self.ccolor1)
     p.fillPath(path, b)
     p.rotate(90), p.translate(100, -100), p.scale(1, -1), p.translate(
         -103, -97)
     p.fillPath(path, b)
     p.setWorldTransform(QTransform())
コード例 #4
0
 def copy(self):
     ans = GraphicsState()
     ans.fill = QBrush(self.fill)
     ans.stroke = QPen(self.stroke)
     ans.opacity = self.opacity
     ans.transform = self.transform * QTransform()
     ans.brush_origin = QPointF(self.brush_origin)
     ans.clip_updated = self.clip_updated
     ans.do_fill, ans.do_stroke = self.do_fill, self.do_stroke
     return ans
コード例 #5
0
 def __init__(self):
     self.fill = QBrush(Qt.GlobalColor.white)
     self.stroke = QPen()
     self.opacity = 1.0
     self.transform = QTransform()
     self.brush_origin = QPointF()
     self.clip_updated = False
     self.do_fill = False
     self.do_stroke = True
     self.qt_pattern_cache = {}
コード例 #6
0
    def convert_brush(self, brush, brush_origin, global_opacity, pdf_system,
                      qt_system):
        # Convert a QBrush to PDF operators
        style = brush.style()
        pdf = self.pdf

        pattern = color = pat = None
        opacity = global_opacity
        do_fill = True

        matrix = (
            QTransform.fromTranslate(brush_origin.x(), brush_origin.y()) *
            pdf_system * qt_system.inverted()[0])
        vals = list(brush.color().getRgbF())
        self.brushobj = None

        if style <= Qt.BrushStyle.DiagCrossPattern:
            opacity *= vals[-1]
            color = vals[:3]

            if style > Qt.BrushStyle.SolidPattern:
                pat = QtPattern(style, matrix)

        elif style == Qt.BrushStyle.TexturePattern:
            pat = TexturePattern(brush.texture(), matrix, pdf)
            if pat.paint_type == 2:
                opacity *= vals[-1]
                color = vals[:3]

        elif style == Qt.BrushStyle.LinearGradientPattern:
            pat = LinearGradientPattern(brush, matrix, pdf, self.page_width_px,
                                        self.page_height_px)
            opacity *= pat.const_opacity
        # TODO: Add support for radial/conical gradient fills

        if opacity < 1e-4 or style == Qt.BrushStyle.NoBrush:
            do_fill = False
        self.brushobj = Brush(brush_origin, pat, color)

        if pat is not None:
            pattern = pdf.add_pattern(pat)
        return color, opacity, pattern, do_fill
コード例 #7
0
 def __call__(self, canvas):
     img = canvas.current_image
     m = QTransform()
     m.rotate(90)
     return img.transformed(m, Qt.TransformationMode.SmoothTransformation)
コード例 #8
0
ファイル: img.py プロジェクト: Sabesan2000/SOFE-QUAILTY-FINAL
def rotate_image(img, degrees):
    t = QTransform()
    t.rotate(degrees)
    return image_from_data(img).transformed(t)