Jump to content
You must now use your email address to sign in [click for more info] ×

Paste SVG text into Designer as a new SVG?


Recommended Posts

I have this SVG text in the clipboard:

<?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"><svg width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;"><rect x="0" y="0" width="200" height="200" style="fill:#f1f1f1;"/><g><text x="37.63px" y="165.586px" style="font-family:'Verdana', sans-serif;font-size:180.416px;">S</text><path d="M159.243,27.183l-118.486,145.634" style="fill:none;fill-rule:nonzero;stroke:#f00;stroke-width:12.39px;"/></g></svg>

How can I paste it as a new SVG in Designer 2.2.1?

Link to comment
Share on other sites

On Windows, this does not seem to work (at least in 2.2.1), but if I paste the referred code on an existing document and then copy the resulting SVG rendering, I can paste as a new document. 

I am not sure if this something that is dependent on some app preference affecting the SVG behavior also when pasting from (and not just when copying to) Clipboard, but I think that macOS and Windows versions have always behaved a bit differently when copy pasting SVG code via Clipboard.

Link to comment
Share on other sites

You may also want to check under the Affinity Designer Preferences, the "General section" there and if "Copy items as SVG" is enabled or disabled there.

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

On Windows, this setting only has effect on whether copied objects are placed in SVG code on Clipboard or not (image/X-inkscape-svg and Scalable Vector Graphics):

image.png.ec1e53986a8000e262f7de1b13a9c213.png

When the setting is off, only following content (when copying the same object) is placed on Clipboard:

image.png.a8385518998333eafb8cc1b60f641799.png

However, when the mere code is copied, the content of Clipboard is only as follows:

image.png.292ba2773df45a9f2951a7cf26dd1b01.png

...so the setting does not have effect on how an existing code (as plain or Unicode text) is handled: on Windows, the mere code can never create a new document. But on macOS, it can.

Link to comment
Share on other sites

22 hours ago, lacerto said:

On Windows, this does not seem to work (at least in 2.2.1), but if I paste the referred code on an existing document and then copy the resulting SVG rendering, I can paste as a new document. 

It seems that Designer currently only supports its INTERNAL CLIPBOARD. Is it that difficult to implement Windows clipboard support? I do it with my own apps all the time.

Link to comment
Share on other sites

On 10/21/2023 at 7:39 AM, Peter Panino said:

I have this SVG text in the clipboard:

...

How can I paste it as a new SVG in Designer 2.2.1?

Paste it into a Plain Text text file and change the file extension from .txt to .svg. Open the svg in Designer.

untitled text.svg

Mac Pro (Late 2013) Mac OS 12.7.4 
Affinity Designer 2.4.1 | Affinity Photo 2.4.1 | Affinity Publisher 2.4.1 | Beta versions as they appear.

I have never mastered color management, period, so I cannot help with that.

Link to comment
Share on other sites

17 minutes ago, Peter Panino said:

Is it that difficult to implement Windows clipboard support? I do it with my own apps all the time.

I am not sure what you mean. This is what Free Clipboard Viewer shows when having the code you attached copied onto Clipboard:

image.png.8f46aeec40a5d348330dfbbc14807681.png

...so basically just what Affinity apps see. CorelDRAW also only sees the text (and cannot create an SVG object or new document based on the content). Neither can Inkscape, or Illustrator CS6.

Link to comment
Share on other sites

17 minutes ago, Peter Panino said:

These are the clipboard formats when I copy the SVG text from Notepad as shown in my own clipboard app (not yet published):

https://app.screencast.com/abtGL0Cpkq1Jn

By the way, if you're going to show a screenshot, please just paste it into your post as a PNG or JPG image. Don't make us go someplace else.

-- Walt
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro, version 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro, version 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
iPad:  iPad Pro M1, 12.9": iPadOS 17.4.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.4.1

Link to comment
Share on other sites

4 minutes ago, MikeW said:

Works with AD 1.10.6 using Windows. I don't have v.2 to look at

Do you mean just pasting (this does work both in v1 and v2), or pasting as a new document? The latter shows for me the following in both 1.x and 2.x versions (Windows):

image.png.57b8fbb13b6dbf3aa05b3bb10326616f.png

On macOS it does work.

Link to comment
Share on other sites

The logic could be so simple:

If there is text in the clipboard: Check whether the text is an SVG XML. If yes, create a new SVG Designer tab and insert the SVG.

If there is a file in the clipboard, check if it is an SVG file. If yes, create a new SVG Designer tab and insert the SVG.

I could implement this in less than 30 minutes.

Link to comment
Share on other sites

7 hours ago, Peter Panino said:

Unfortunately, that does not work on Designer 2.2.1 for Windows:

https://app.screencast.com/D1ZS3UvQCAbhN

Seems to be an ADe 2.1.1 under Win problem, as under macOS and even ADe v1 it works as expected ...

 

 

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

7 hours ago, Peter Panino said:

The logic could be so simple:

If there is text in the clipboard: Check whether the text is an SVG XML. If yes, create a new SVG Designer tab and insert the SVG.

If there is a file in the clipboard, check if it is an SVG file. If yes, create a new SVG Designer tab and insert the SVG.

I could implement this in less than 30 minutes.

It would probably be a very simple task, because Affinity apps already can paste a text object on the Clipboard and render it as graphic when pasted on an existing page (or as text, if pasted within a text control).

But it is not completely clear whether the macOS versions (already 1.x versions) can create a new document based on some additional code in the app itself, or because on macOS, there is additional data that gets placed on Clipboard by the system [or perhaps by Safari EDIT: no, this happens also when copying from TextEdit] whenever copying SVG code from Safari onto Clipboard. This is a screenshot of that content:

image.thumb.png.29e321969774f36a992082aec5471c5a.png

Compare this with the screenshot made on Windows when the exactly same text block from your original post is copied from Chrome. On macOS, in addition to text formats, there is RTF document format generated, which is supported by Affinity apps and which would make it natural for Affinity apps to support directly as a document creating Clipboard format without any additional code needing to exist on the macOS platform.

I created a routine that tags existing SVG code on Clipboard as an SVG stream (basically a file object), which makes the object recognizable to Inkscape (which cannot paste SVG code as rendered graphic), but it still is not shown as Clipboard content that can create a new document in Affinity Designer (while it can be pasted as a rendered object into an existing document similarly as the mere text tagged SVG code). So when Affinity apps can do that (create a new document from Clipboard content), I think that the content already exists on Clipboard as a document (that is, using one of the supported file formats with a defined document boundary box).

In the current situation, it is easiest to simply just paste SVG code in an existing Designer document as a rendered object, then copy the pasted object onto Clipboard, and now (when the pasted content has created a PDF document), use File > New from Clipboard to create a new document encompassing just the graphic content. This works whether you have the "Copy items as SVG" preference option checked or not (since Serif always creates a PDF document format of vector graphics copied onto Clipboard).

 

Link to comment
Share on other sites

10 hours ago, Peter Panino said:

It is straightforward to handle. There are also examples

Sure, but as long as the SVG code (or its PDF translation) is not wrapped within a supported document format, it requires separate handling (basically a routine that actively looks for SVG code = text data on Clipboard to create a new document). The following clip that tags a text format as an SVG stream shows that Designer does not track specifically for SVG data content on Clipboard for new SVG file creation, but VectorStyler does (and is the only app I know that does this based on mere SVG stream):

But VectorStyler does not do this simply just with mere text item containing SVG code. It requires a specific data stream tagged as containing SVG, or a document wrapper (like PDF or RTF document), otherwise it just renders SVG data as an object on an existing document canvas. On macOS it behaves similarly as Designer (and can create a new document if SVG data exists wrapped in a supported document).

If you need to have instant preview of SVG code, you could create a Clipboard related monitor yourself that does Clipboard SVG tagging or document wrapping automatically as soon as there is text content that actually contains an SVG document. But perhaps an SVG Preview add-in e.g. in Visual Studio Code would be more convenient?

Link to comment
Share on other sites

  • Staff

Thanks for your report @Peter Panino!

I'm not entirely certain of the exact reasoning behind this currently, though I can see that Affinity macOS is able to create a New from Clipboard document using SVG data, so I would expect Affinity Windows to also support this.

I have therefore logged this as a bug with our development team for you now.

I hope this helps :)

Link to comment
Share on other sites

1 hour ago, lacerto said:

... It requires a specific data stream tagged as containing SVG ...

The by Win defined and recognized mime type for SVG here is usually "image/svg+xml" ...

mimetype.png.138541ab606eb58d673688adc89d9e8f.png

string svg = GetSvg();
byte[] bytes = Encoding.UTF8.GetBytes(svg);
MemorySteam stream = new MemoryStream(bytes);
Clipboard.SetData("image/svg+xml", stream);

Also see the Remarks -> Notes on the Clipboard class.

Quote

An object must be serializable for it to be put on the Clipboard. If you pass a non-serializable object to a Clipboard method, the method will fail without throwing an exception. See System.Runtime.Serialization for more information on serialization. If your target application requires a very specific data format, the headers added to the data in the serialization process may prevent the application from recognizing your data. To preserve your data format, add your data as a Byte array to a MemoryStream and pass the MemoryStream to the SetData method.

 

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

6 hours ago, v_kyr said:

The by Win defined and recognized mime type for SVG here is usually "image/svg+xml" ...

That works in context of VectorStyler and Inkscape, but if I add the suggested stream tag on Clipboard, Affinity apps cease to recognize SVG code on Clipboard and can no longer render items on canvas of an existing document. If I use image/x-inkscape-svg, this works in all apps at some level.

The way I added the SVG stream is according to the documentation and can be serialized.

EDIT: One further note: IMO there is no "glitch" or omission on Windows versions of Affinity apps. As mentioned, macOS seems to encapsulate text (including SVG code) -- in addition to placing it in multiple text formats -- within an .RTF block and thus wraps the code within a document format supported ty Affinity apps. As can be seen in the screenshot I included in one of my posts above, showing content of macOS Clipboard when OP's code is copied from Safari, there is no specific SVG stream / file object on Clipboard on macOs, either.

EDIT2: No, this is wrong. I now tested this with plain text, no document wrapping, and both Designer and VectorStyler can create new docments from the SVG code content as text items. Perhaps there is something in macOS Clipboard handling that allows doing that, as both Designer and VectorStyler can do that on macOS but not on Windows. Anyway, explicitly tagging SVG text as SVG stream will allow VectorStyler to do the same on Windows.

Link to comment
Share on other sites

30 minutes ago, lacerto said:

... but if I add the suggested stream tag on Clipboard, Affinity apps cease to recognize SVG code on Clipboard and can no longer render items on canvas of an existing document. If I use image/x-inkscape-svg, this works in all apps at some level ...

That's an external Inkscape defined mime type (aka Inkscape SVG flavor specific) and not the common used SVG one.

1 hour ago, lacerto said:

IMO there is no "glitch" or omission on Windows versions of Affinity apps. As mentioned, macOS seems to encapsulate text (including SVG code) -- in addition to placing it in multiple text formats -- within an .RTF block and thus wraps the code within a document format supported ty Affinity apps.

I think there is, as it otherwise would work for correctly defines SVG code -as shown above in the initial post- as expected. And in the simplest turnaround case, it could create there then a temporary SVG file (tmp.svg) from the clipboard UTF-8 text contents and open that. Beside that Windows also supports RTF (richtext) handling, so a document format which is supported by Affinity apps.

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

1 hour ago, v_kyr said:

I think there is, as it otherwise would work for correctly defines SVG code

Be it as it may, but mere SVG code (as Clipboard text element) does not create a new graphic document in any Windows graphic design app that I have (only ones specifically dealing with vector graphics mentioned and tested):

  • CorelDRAW 24.5.0.731 (cannot paste rendered in an existing document, either)
  • Illustrator CS6 (cannot paste rendered in an existing document, either)
  • Inkscape 1.3 (cannot paste rendered in an existing document, either)
  • Xara Designer Pro X 19.0.1 (cannot paste rendered in an existing document, either)
  • Designer 1.x and 2.x (can paste to existing document)
  • VectorStyler 1.1.111 (can paste to existing document)
  • LibreOffice Draw (can paste to existing document)

When tagging the exactly same code with image/x-inkscape-svg:

  • VectorStyler can create a new document and paste rendered to an existing
  • Word can paste rendered on existing document
  • Designer can paste rendered on existing document (but not from image/svg+xml)
  • Inkscape can paste rendered on existing document

When tagging the exactly same code with image/svg+xml:

  • VectorStyler can create a new document and paste rendered to en existing 
  • Word can paste rendered on existing document

On macOS I have assumed that there is better OS support for deciding whether SVG code is displayed as text or rendered as graphic when pasting from Clipboard. But it does not seem to be nearly as common as I thought so basically only Designer and VectorStyler can both paste SVG code and render it as graphics in an existing document and create a new graphic document from it. But e.g. Pages and CorelDRAW cannot render pasted SVG code, nor can Word.

In this perspective, Affinity apps work pretty well, being at least able to paste SVG code text item from Clipboard rendered as graphics in an existing document. The only app (of ones I have tested) on Windows that can create a new document from an SVG stream is VectorStyler.

Whether an omission or not, I do not think that it takes a lot to improve the code on Windows versions so that behavior will become identical with the macOS versions.

Additionally, as shown, image/x-inkscape-svg seems to be more compatible at least when using above mentioned apps, but when developing this kind of utility, both options should be made available as user-choices.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.