Why pasting SVG as text from clipboard doesn't work?

Asked by anatoly techtonik

If you save the text below as SVG and then import it in Inkscape, it will get it successfully:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17 13"><path fill="#59a6ca" d="M15.57 2.845L14.238 1.51c-.13-.13-.353-.13-.48 0L6.66 8.623l-3.093-3.11c-.13-.13-.352-.13-.482 0L1.75 6.845c-.128.13-.128.352 0 .48l4.67 4.67c.073.055.147.092.24.092s.167-.037.24-.093l8.67-8.67c.13-.13.13-.35 0-.48z"></path></svg>

But if you copy this text to clipboard and try to paste it to Inkscape, it doesn't work. Why?

It is Inkscape 0.91 r13725

Question information

Language:
English Edit question
Status:
Solved
For:
Inkscape Edit question
Assignee:
No assignee Edit question
Solved by:
anatoly techtonik
Solved:
Last query:
Last reply:
Revision history for this message
Mc (mc...) said :
#1

Because the clipboard knows the "type" of what it contains.

if you copy this as text, the clipboard will only know that it contains "some text". Pasting it would then have the same effect whether it contains that, or "qwertyuiop" (which is not valid xml/svg). The check Inkscape does upon pasting is that the type of what is pasted is "an image" as per the clipboard definition (and if possible, "image/svg" ), otherwise it will only be allowed to be pasted in the text tool.

Revision history for this message
anatoly techtonik (techtonik) said :
#2

What prevents Inkscape to autodetect the SVG if I don't paste the text into the text tool?

I can copy Iand paste Inkscape object and it will appear as text in my editor, but I can not copy/paste edited content back.

Revision history for this message
Mc (mc...) said :
#3

same reason you cant paste the text "data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" or "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP4/x8AAwAB/2+Bq7YAAAAASUVORK5CYII=" into Paint or any other similar tool even if it would make some sense: it's not supported that way. Not that it is not doable (it certainly is) but no one has written the code for it.

The good news is Inkscape is an open source project, so if you know a bit about coding, you can make it happen ;)

Revision history for this message
anatoly techtonik (techtonik) said :
#4

> The good news is Inkscape is an open source project, so if you know a bit about coding, you can make it happen ;)

Unfortunately I know too much about coding and that means that I am slow and lack free time. Also, the C is not my language. Only Python. But if you can give an entrypoint, it may help somebody who discovers this answer to implement this feature.

Revision history for this message
anatoly techtonik (techtonik) said :
#5

The entrypoint is ::paste function form http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/view/head:/src/ui/clipboard.cpp

The quick hack seems to be to comment line `return _pasteText(desktop);` and see if SVG text will pass.