Python:将 svg 字符串复制到 windows 剪贴板中的 "image/svg+xml" 格式,因此可以将其粘贴为 svg 图像
Python: copy svg string to "image/svg+xml" format in windows clipboard, so can paste it as an svg image
假设我有这样一个 svg 文件的 xml 内容:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Created with matplotlib (http://matplotlib.org/) -->
<svg height="344.88pt" version="1.1" viewBox="0 0 460.8 344.88" width="460.8pt"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
...
我的问题是,如何将此字符串复制到 windows 剪贴板,而不是作为字符串,而是作为 "image/svg+xml" 数据类型,可以将其作为 svg 图像粘贴到 powerpoint 中?
据我所知,唯一支持 Mime 类型的剪贴板库是 QtClipboard:https://doc.qt.io/qtforpython/PySide2/QtGui/QClipboard.html
你可能想看一看。
可能在您可以使用 setMimeData
设置的 Mime 类型中,还有 image/svg+xml
示例:
from PyQt5 import QtCore
d = QtCore.QMimeData()
print(d.formats()) # Now it is an empty list "[]" because you still didn't set the data and the mime type
# Set data in the object with the required mime type
d.setData("image/svg+xml", b'<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><!-- Created with matplotlib (http://matplotlib.org/) --><svg height="344.88pt" version="1.1" viewBox="0 0 460.8 344.88" width="460.8pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">')
print(d.formats()) # Now it prints: ['image/svg+xml']
从这里你可以把它带到QClipboard。
我引用文档:http://doc.qt.io/archives/qt-4.8/qclipboard.html
The setMimeData() function is the ultimate in flexibility: it allows
you to add any QMimeData into the clipboard.
假设我有这样一个 svg 文件的 xml 内容:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Created with matplotlib (http://matplotlib.org/) -->
<svg height="344.88pt" version="1.1" viewBox="0 0 460.8 344.88" width="460.8pt"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
...
我的问题是,如何将此字符串复制到 windows 剪贴板,而不是作为字符串,而是作为 "image/svg+xml" 数据类型,可以将其作为 svg 图像粘贴到 powerpoint 中?
据我所知,唯一支持 Mime 类型的剪贴板库是 QtClipboard:https://doc.qt.io/qtforpython/PySide2/QtGui/QClipboard.html
你可能想看一看。
可能在您可以使用 setMimeData
设置的 Mime 类型中,还有 image/svg+xml
示例:
from PyQt5 import QtCore
d = QtCore.QMimeData()
print(d.formats()) # Now it is an empty list "[]" because you still didn't set the data and the mime type
# Set data in the object with the required mime type
d.setData("image/svg+xml", b'<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><!-- Created with matplotlib (http://matplotlib.org/) --><svg height="344.88pt" version="1.1" viewBox="0 0 460.8 344.88" width="460.8pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">')
print(d.formats()) # Now it prints: ['image/svg+xml']
从这里你可以把它带到QClipboard。
我引用文档:http://doc.qt.io/archives/qt-4.8/qclipboard.html
The setMimeData() function is the ultimate in flexibility: it allows you to add any QMimeData into the clipboard.