Last active
January 4, 2017 23:07
-
-
Save pashango2/83c15ff82995e012d8900ec8b3c68a27 to your computer and use it in GitHub Desktop.
SVGをお手軽に出力するならQtが最強のライブラリではないか? ref: http://qiita.com/pashango2/items/b9f61ab06c78a3e2ccdd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! usr/bin/python | |
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals, print_function, absolute_import | |
import sys | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from PySide.QtSvg import * | |
app = QApplication(sys.argv) | |
svg_gen = QSvgGenerator() | |
svg_gen.setFileName("hello.svg") | |
svg_gen.setSize(QSize(200, 80)) | |
svg_gen.setViewBox(QRect(0, 0, 200, 80)) | |
svg_gen.setTitle("hello svg") | |
svg_gen.setDescription("this is sample svg.") | |
painter = QPainter() | |
painter.begin(svg_gen) | |
rect = QRect(0, 0, 200, 80) | |
painter.fillRect(rect, Qt.yellow) | |
painter.setPen(Qt.blue) | |
painter.setFont(QFont("Arial", 30)) | |
painter.drawText(rect, Qt.AlignCenter, "Hello SVG") | |
painter.end() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scene = QGraphicsScene() | |
rect = QRect(0, 0, 200, 80) | |
scene.setSceneRect(rect) | |
scene.addRect(rect, QPen(Qt.transparent), QBrush(Qt.yellow)) | |
text_item = scene.addText("Hello SVG", QFont("Arial", 30)) | |
text_item.setDefaultTextColor(Qt.blue) | |
painter = QPainter() | |
painter.begin(svg_gen) | |
scene.render(painter) | |
painter.end() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment