Skip to content

Ctrl+C on Windows and Linux: drawing programs paste the copied SVG as paths, at its size in millimetres - #3554

Merged
HakanSeven12 merged 6 commits into
HakanSeven12:mainfrom
jespinolao:fix/svg-clipboard-format
Nov 24, 2026
Merged

HakanSeven12 merged 6 commits into
HakanSeven12:mainfrom
jespinolao:fix/svg-clipboard-format

Conversation

@jespinolao

Copy link
Copy Markdown
Contributor

Refs #2018. This fixes the report there that pasting into Inkscape does nothing, and the size the SVG then pastes at. EMF and fills/text in the SVG, the parts the issue keeps open, are not in this PR.

How it shows up

A copy with Ctrl+C (COPYCLIP, CUTCLIP, COPYBASE) puts the selection on the system clipboard as SVG for other programs. Two things go wrong:

  1. The SVG is on the clipboard as text only. Inkscape 1.4 does not paste it. With the selector tool, Ctrl+V leaves the page empty and the status bar says that text can only be pasted with the text tool.
  2. The SVG pastes at the wrong size. Even when it reaches a program as SVG, a 60 × 40 drawing pastes at 16.1 × 10.8 mm. The SVG's user unit is the millimetre (width="60mm", viewBox="0 -40 60 40"), and drawing programs take the user unit as a CSS pixel when they paste.

Steps, on main 781582b and on this branch, release builds:

  1. New drawing, with RECTANG 0,0 60,40, LINE 0,0 60,40 and CIRCLE 30,20 12.
  2. Select the three, then COPYCLIP.
  3. In Inkscape 1.4, a new A4 document, the selector tool, then Ctrl+V.

Windows 11 (Inkscape 1.4):

main This PR
Clipboard formats after COPYCLIP CF_UNICODETEXT, CF_TEXT, CF_OEMTEXT, CF_LOCALE the same, plus image/svg+xml (UTF-8)
Ctrl+V in Inkscape nothing pasted a group of 3 objects, 60.265 × 40.265 mm (60 × 40 plus the 1 px stroke)
main on Windows: the Inkscape page stays empty this PR on Windows: the rectangle, diagonal and circle pasted at 60.265 × 40.265 mm

Linux: Zorin OS 18, GNOME 46 on Wayland, OCS through XWayland (DISPLAY=:0), Inkscape 1.4.4 Flatpak.

main This PR
xclip -selection clipboard -t TARGETS -o UTF8_STRING, text/plain;charset=utf-8, text/plain;charset=UTF-8, TARGETS, SAVE_TARGETS UTF8_STRING, text/plain;charset=utf-8, image/svg+xml, TARGETS
wl-paste --list-types the same text types, no image/svg+xml TARGETS, image/svg+xml, text/plain;charset=utf-8, UTF8_STRING
Ctrl+V in Inkscape nothing pasted, the same message a group of 3 objects, 60.265 × 40.265 mm
main on Linux: the Inkscape page stays empty this PR on Linux: the group pasted at 60.265 × 40.265 mm

On Linux, wl-paste -t image/svg+xml returns the markup, so XWayland hands the X11 target on to Wayland programs.

With only the Windows format change, the same paste gave the group at 16.140 × 10.848 mm. The size change brings it to its size.

Cause

  1. copy_svg_to_system_clipboard (src/app/commands/blocks.rs) hands the markup to iced::clipboard::write, which writes text. Its clipboard backend writes text, HTML and images, not other formats. Drawing programs read SVG under its MIME type: a registered clipboard format on Windows, a selection target on X11.
  2. wires_svg (src/io/svg_clipboard.rs) writes the coordinates and the viewBox in drawing units, with width and height in mm. A reader that applies the viewBox gets mm, but one that takes the user unit as a pixel gets 1 drawing unit = 0.2646 mm.

The change

New sys::clipboard_svg (src/sys/clipboard_svg.rs):

  • formats(svg) lists what one copy writes on each platform:
    • Windows: CF_UNICODETEXT and image/svg+xml;
    • Linux: UTF8_STRING, text/plain;charset=utf-8 and image/svg+xml.
  • write(svg) puts them there in one write:
    • Windows: opens the clipboard once, empties it, and sets each format (windows-sys, the same open-and-retry as sys::clipboard_link).
    • Linux: owns the X11 CLIPBOARD selection from a thread of its own, made at the first copy. It uses an input-only window that answers TARGETS and serves each target. When another program takes the clipboard, the copy is dropped. x11rb 0.13 is already in the tree through the toolkit's clipboard; it is now a Linux dependency of the app as well.
    • If the write fails, there is no X server, or on other platforms, the toolkit writes the text as before.
    • In tests, write keeps the formats it would have written, per thread, instead of touching the system clipboard.
  • copy_svg_to_system_clipboard uses it.

wires_svg writes the coordinates and the viewBox in CSS pixels (96 per inch); width and height stay in mm. A reader that applies the viewBox and one that takes the user unit as a pixel both get one drawing unit as one millimetre. The stroke stays 1 user unit, now one pixel.

Not touched:

  • Copy and paste between OCS drawings uses OCS's own copy.
  • Pasting SVG text from another program into OCS fits the picture to half the view (fit = 0.5 × view size in model_import.rs), whatever its units, so it pastes as before.

Tests

  • svg_clipboard_format_tests::copyclip_does_not_leave_the_svg_to_a_text_only_write (src/app/commands/blocks.rs, Windows and Linux): COPYCLIP of a line.
    • Windows, on 6b12720: the SVG went to the clipboard as text only: ["Text(\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n<svg xmlns"].
    • Linux, on c79fe6e: one write of the system clipboard, left: 0, right: 1.
    • From the changes on, it checks the one write and its formats for the platform, and that the image/svg+xml entry holds the markup.
  • svg_clipboard::tests::a_reader_taking_svg_units_as_pixels_gets_the_size_in_millimetres: a 60 × 40 outline, read at one user unit per pixel. Fails on 795ec43: a 60 × 40 mm drawing reads as 15.875 × 10.583 mm.
  • svg_clipboard::tests::a_line_becomes_a_path_in_millimetres_with_y_up moves to pixel coordinates in 5e85289.

Runs on a2cf3fb:

  • Windows 11:
    • cargo test --workspace --locked --no-fail-fast: 7,873 passed, 1 failed, 50 ignored. The failure, app::control::spellcheck::tests::speller_survives_com_unload_reload_cycles, fails the same way on main on this machine.
    • cargo check --target wasm32-unknown-unknown --lib passes.
    • clippy on the lib reports nothing in the changed files.
  • Linux (Zorin OS 18):
    • cargo test --lib svg_: 43 passed.
    • cargo test --workspace --no-fail-fast: 7,854 passed, 0 failed, 48 ignored.
    • cargo clippy --lib reports nothing in the changed files.

Limits

  • macOS is not changed: the SVG still goes there as text. It names the type public.svg-image; there was no macOS machine to try it on.
  • On Linux the copy lasts while OCS runs, as before this PR. With OCS closed, the GNOME session went back to what the clipboard held before the copy, on main too: nothing in that session takes over the selection.

OCS main at 781582b; Windows 11, and Zorin OS 18 (GNOME 46, Wayland).

🤖 Generated with Claude Code

jespinolao and others added 6 commits November 23, 2026 15:23
COPYCLIP hands the selection's SVG to the GUI toolkit's clipboard write,
which puts it on the system clipboard as text only. Drawing programs read
SVG from the clipboard under its own format, `image/svg+xml`; pasted as
text it arrives as text or not at all. The new test fails on Windows:
"the SVG went to the clipboard as text only".

Refs HakanSeven12#2018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drawing programs read SVG from the clipboard under the SVG MIME type,
which Windows has as a registered clipboard format; the GUI toolkit
writes text only, so the SVG that COPYCLIP, CUTCLIP and COPYBASE put
there for other programs was pasted as text or not at all.

On Windows, `sys::clipboard_svg::write` now opens the clipboard once and
puts the markup there as CF_UNICODETEXT and, as UTF-8, under
`image/svg+xml`. If that write fails, or on other platforms, the toolkit
writes the text as before. Tests record the write instead of touching
the system clipboard; the test checks both formats.

Refs HakanSeven12#2018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SVG put on the clipboard has width and height in millimetres and a
viewBox in drawing units, so its user unit is a millimetre. A reader that
takes the user unit as a CSS pixel, as SVG does by default and as
drawing programs do when they paste, gets a 60 x 40 drawing at
15.875 x 10.583 mm. The new test fails: "a 60 × 40 mm drawing reads as
15.875 × 10.583 mm".

Refs HakanSeven12#2018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SVG for other programs had its coordinates in drawing units and its
size in millimetres, so its user unit was a millimetre. Drawing programs
take the user unit as a CSS pixel when they paste, and pasted a 60 x 40
drawing at 15.9 x 10.6 mm. The coordinates and the viewBox are now
written in CSS pixels (96 per inch); width and height stay in
millimetres. A reader of either gets one drawing unit as one millimetre.

The stroke stays 1 user unit, now one pixel. Pasting the SVG into OCS
fits the picture to the view and does not depend on its units. The test
of a line's path moves to pixel coordinates.

Refs HakanSeven12#2018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The COPYCLIP test also runs on Linux, where the toolkit writes the
clipboard as text too. There it expects UTF8_STRING,
text/plain;charset=utf-8 and image/svg+xml in one write; on Windows,
CF_UNICODETEXT and image/svg+xml as before. On Linux the test fails:
"the SVG went to the clipboard as text only".

Refs HakanSeven12#2018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Linux the toolkit writes the clipboard as text only, so drawing
programs got the SVG a copy puts there for them as text, or not at all.

`sys::clipboard_svg` now owns the X11 CLIPBOARD selection from a thread
of its own, made at the first copy: an input-only window that answers
TARGETS and serves the markup as UTF8_STRING, text/plain;charset=utf-8
and image/svg+xml. Under Wayland, XWayland hands the selection on to
Wayland programs with the same targets. When another program takes the
clipboard the copy is dropped. With no X server, or if taking the
selection fails, the toolkit writes the text as before.

`formats` lists what one copy writes on each platform; the Windows and
X11 writers and the test record all use it. x11rb 0.13 is already in
the tree through the toolkit's clipboard; it is now a Linux dependency
of the app as well.

Refs HakanSeven12#2018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HakanSeven12
HakanSeven12 merged commit 04ced59 into HakanSeven12:main Nov 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants