Repository navigation
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 intoNov 24, 2026
Conversation
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>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
width="60mm",viewBox="0 -40 60 40"), and drawing programs take the user unit as a CSS pixel when they paste.Steps, on
main781582b and on this branch, release builds:RECTANG 0,0 60,40,LINE 0,0 60,40andCIRCLE 30,20 12.Windows 11 (Inkscape 1.4):
mainCF_UNICODETEXT,CF_TEXT,CF_OEMTEXT,CF_LOCALEimage/svg+xml(UTF-8)Linux: Zorin OS 18, GNOME 46 on Wayland, OCS through XWayland (
DISPLAY=:0), Inkscape 1.4.4 Flatpak.mainxclip -selection clipboard -t TARGETS -oUTF8_STRING,text/plain;charset=utf-8,text/plain;charset=UTF-8,TARGETS,SAVE_TARGETSUTF8_STRING,text/plain;charset=utf-8,image/svg+xml,TARGETSwl-paste --list-typesimage/svg+xmlTARGETS,image/svg+xml,text/plain;charset=utf-8,UTF8_STRINGOn Linux,
wl-paste -t image/svg+xmlreturns 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
copy_svg_to_system_clipboard(src/app/commands/blocks.rs) hands the markup toiced::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.wires_svg(src/io/svg_clipboard.rs) writes the coordinates and theviewBoxin drawing units, withwidthandheightin mm. A reader that applies theviewBoxgets 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:CF_UNICODETEXTandimage/svg+xml;UTF8_STRING,text/plain;charset=utf-8andimage/svg+xml.write(svg)puts them there in one write:windows-sys, the same open-and-retry assys::clipboard_link).CLIPBOARDselection from a thread of its own, made at the first copy. It uses an input-only window that answersTARGETSand 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.writekeeps the formats it would have written, per thread, instead of touching the system clipboard.copy_svg_to_system_clipboarduses it.wires_svgwrites the coordinates and theviewBoxin CSS pixels (96 per inch);widthandheightstay in mm. A reader that applies theviewBoxand 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:
fit = 0.5 × view sizeinmodel_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.the SVG went to the clipboard as text only: ["Text(\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n<svg xmlns"].one write of the system clipboard,left: 0,right: 1.image/svg+xmlentry 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_upmoves to pixel coordinates in 5e85289.Runs on a2cf3fb:
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 onmainon this machine.cargo check --target wasm32-unknown-unknown --libpasses.cargo test --lib svg_: 43 passed.cargo test --workspace --no-fail-fast: 7,854 passed, 0 failed, 48 ignored.cargo clippy --libreports nothing in the changed files.Limits
public.svg-image; there was no macOS machine to try it on.maintoo: 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