示例#1
0
    def send_report(self):
        from AnyQt.QtSvg import QSvgGenerator

        if self.model:
            self.reportSection("Tree")
            _, filefn = self.getUniqueImageName(ext=".svg")
            svg = QSvgGenerator()
            svg.setFileName(filefn)
            ssize = self.scene.sceneRect().size()
            w, h = ssize.width(), ssize.height()
            fact = 600 / w
            svg.setSize(QSize(600, h * fact))
            painter = QPainter()
            painter.begin(svg)
            self.scene.render(painter)
            painter.end()
示例#2
0
def grab_svg(scene):
    """
    Return a SVG rendering of the scene contents.

    Parameters
    ----------
    scene : :class:`CanvasScene`

    """
    from AnyQt.QtSvg import QSvgGenerator
    svg_buffer = QBuffer()
    gen = QSvgGenerator()
    gen.setOutputDevice(svg_buffer)

    items_rect = scene.itemsBoundingRect().adjusted(-10, -10, 10, 10)

    if items_rect.isNull():
        items_rect = QRectF(0, 0, 10, 10)

    width, height = items_rect.width(), items_rect.height()
    rect_ratio = float(width) / height

    # Keep a fixed aspect ratio.
    aspect_ratio = 1.618
    if rect_ratio > aspect_ratio:
        height = int(height * rect_ratio / aspect_ratio)
    else:
        width = int(width * aspect_ratio / rect_ratio)

    target_rect = QRectF(0, 0, width, height)
    source_rect = QRectF(0, 0, width, height)
    source_rect.moveCenter(items_rect.center())

    gen.setSize(target_rect.size().toSize())
    gen.setViewBox(target_rect)

    painter = QPainter(gen)

    # Draw background.
    painter.setBrush(QBrush(Qt.white))
    painter.drawRect(target_rect)

    # Render the scene
    scene.render(painter, target_rect, source_rect)
    painter.end()

    buffer_str = bytes(svg_buffer.buffer())
    return buffer_str.decode("utf-8")
示例#3
0
文件: scene.py 项目: benzei/orange3
def grab_svg(scene):
    """
    Return a SVG rendering of the scene contents.

    Parameters
    ----------
    scene : :class:`CanvasScene`

    """
    from AnyQt.QtSvg import QSvgGenerator
    svg_buffer = QBuffer()
    gen = QSvgGenerator()
    gen.setOutputDevice(svg_buffer)

    items_rect = scene.itemsBoundingRect().adjusted(-10, -10, 10, 10)

    if items_rect.isNull():
        items_rect = QRectF(0, 0, 10, 10)

    width, height = items_rect.width(), items_rect.height()
    rect_ratio = float(width) / height

    # Keep a fixed aspect ratio.
    aspect_ratio = 1.618
    if rect_ratio > aspect_ratio:
        height = int(height * rect_ratio / aspect_ratio)
    else:
        width = int(width * aspect_ratio / rect_ratio)

    target_rect = QRectF(0, 0, width, height)
    source_rect = QRectF(0, 0, width, height)
    source_rect.moveCenter(items_rect.center())

    gen.setSize(target_rect.size().toSize())
    gen.setViewBox(target_rect)

    painter = QPainter(gen)

    # Draw background.
    painter.setBrush(QBrush(Qt.white))
    painter.drawRect(target_rect)

    # Render the scene
    scene.render(painter, target_rect, source_rect)
    painter.end()

    buffer_str = bytes(svg_buffer.buffer())
    return buffer_str.decode("utf-8")
示例#4
0
    def send_report(self):
        from AnyQt.QtSvg import QSvgGenerator

        if self.model:
            self.reportSection("Tree")
            _, filefn = self.getUniqueImageName(ext=".svg")
            svg = QSvgGenerator()
            svg.setFileName(filefn)
            ssize = self.scene.sceneRect().size()
            w, h = ssize.width(), ssize.height()
            fact = 600 / w
            svg.setSize(QSize(600, h * fact))
            painter = QPainter()
            painter.begin(svg)
            self.scene.render(painter)
            painter.end()
示例#5
0
 def metric(self, metric):
     if metric == QSvgGenerator.PdmDevicePixelRatioScaled:
         return int(1 * QSvgGenerator.devicePixelRatioFScale())
     else:
         return super().metric(metric)
示例#6
0
    if font is None:
        font = QFont()
    else:
        font = QFont(font)

    if "family" in font_dict:
        font.setFamily(font_dict["family"])

    if "size" in font_dict:
        font.setPixelSize(font_dict["size"])

    return font


if QT_VERSION >= 0x50900 and \
      QSvgGenerator().metric(QSvgGenerator.PdmDevicePixelRatioScaled) == 1:
    # QTBUG-63159
    class QSvgGenerator(QSvgGenerator):
        def metric(self, metric):
            if metric == QSvgGenerator.PdmDevicePixelRatioScaled:
                return int(1 * QSvgGenerator.devicePixelRatioFScale())
            else:
                return super().metric(metric)


def grab_svg(scene):
    """
    Return a SVG rendering of the scene contents.

    Parameters
    ----------
def font_from_dict(font_dict, font=None):
    if font is None:
        font = QFont()
    else:
        font = QFont(font)

    if "family" in font_dict:
        font.setFamily(font_dict["family"])

    if "size" in font_dict:
        font.setPixelSize(font_dict["size"])

    return font


if (QT_VERSION >= 0x50900 and QSvgGenerator().metric(
        QSvgGenerator.PdmDevicePixelRatioScaled) == 1):
    # QTBUG-63159
    class QSvgGenerator(QSvgGenerator):
        def metric(self, metric):
            if metric == QSvgGenerator.PdmDevicePixelRatioScaled:
                return int(1 * QSvgGenerator.devicePixelRatioFScale())
            else:
                return super().metric(metric)


def grab_svg(scene):
    """
    Return a SVG rendering of the scene contents.

    Parameters
    ----------