Skip to content

Commit 0217fe4

Browse files
authored
Add SVG demo (#140)
1 parent 9a53b1d commit 0217fe4

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

src/SVG/image.svg

Lines changed: 46 additions & 0 deletions
Loading

src/SVG/main.blp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.StatusPage {
5+
title: _("SVG");
6+
description: _("Display vectorial images at arbitrary sizes");
7+
8+
Box {
9+
halign: center;
10+
orientation: vertical;
11+
12+
DrawingArea drawing_area {
13+
width-request: 128;
14+
height-request: 128;
15+
}
16+
17+
LinkButton {
18+
label: _("Librsvg documentation");
19+
uri: "https://gnome.pages.gitlab.gnome.org/librsvg/Rsvg-2.0/index.html";
20+
}
21+
}
22+
}

src/SVG/main.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Rsvg from "gi://Rsvg?version=2.0";
2+
3+
const drawing_area = workbench.builder.get_object("drawing_area");
4+
const svg = workbench.resolve("image.svg");
5+
6+
const handle = Rsvg.Handle.new_from_file(svg);
7+
8+
const [, width, height] = handle.get_intrinsic_size_in_pixels();
9+
console.log("SVG intrisic size", { width, height });
10+
11+
function draw(_self, cr, width, height) {
12+
console.log("drawing SVG at", { width, height });
13+
handle.render_document(cr, new Rsvg.Rectangle({ x: 0, y: 0, width, height }));
14+
cr.$dispose();
15+
}
16+
drawing_area.set_draw_func(draw);

src/SVG/main.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "user_interface",
3+
"description": "Display vectorial images at arbitrary sizes",
4+
"panels": ["ui", "code", "preview"],
5+
"autorun": true
6+
}

0 commit comments

Comments
 (0)