From 15b9f2bf1d1b9f889fcf6e53e271fb78a769f70a Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Sun, 10 Mar 2019 10:27:54 +0100 Subject: [PATCH 1/7] add symbolic icon --- src/style.css | 2 +- src/views/colour.vala | 2 +- src/views/colourpane.ui | 48 ++++++++++++++++++++++------ src/views/colourpane.vala | 64 +++++++++++++++++++++++++++++++------ src/views/symbolicpane.vala | 3 ++ src/window.vala | 12 +++---- 6 files changed, 103 insertions(+), 28 deletions(-) diff --git a/src/style.css b/src/style.css index 25359be..990b00d 100644 --- a/src/style.css +++ b/src/style.css @@ -45,7 +45,7 @@ colour-view .wallpaper label:backdrop { background-image: url('resource://org/gnome/IconPreview/wallpapers/Adwaita-dark.jpg'); } -colour-view image, .initial-state .shadow-icon { +colour-view image:not(.symbolic), .initial-state .shadow-icon { -gtk-icon-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 1px 8px rgba(0,0,0,0.2); } diff --git a/src/views/colour.vala b/src/views/colour.vala index 9efa8ec..3a67907 100644 --- a/src/views/colour.vala +++ b/src/views/colour.vala @@ -16,7 +16,7 @@ namespace IconPreview { } set { _icon = value; - light.icon = dark.icon = new FileIcon(_icon); + light.file = dark.file = _icon; } } diff --git a/src/views/colourpane.ui b/src/views/colourpane.ui index cbf159d..cf6fbc7 100644 --- a/src/views/colourpane.ui +++ b/src/views/colourpane.ui @@ -25,10 +25,21 @@ org.gnome.IconPreview - 2 + 3 0 + + + True + False + 128 + + + 3 + 1 + + True @@ -39,10 +50,21 @@ org.gnome.IconPreview - 1 + 2 0 + + + True + False + 64 + + + 2 + 1 + + True @@ -53,7 +75,7 @@ org.gnome.IconPreview - 0 + 1 0 @@ -64,29 +86,35 @@ 32 - 0 + 1 1 - + True False - 128 + center + end + 16 + org.gnome.IconPreview-symbolic + - 2 - 1 + 0 + 0 True False - 64 + symbolic - 1 + 0 1 diff --git a/src/views/colourpane.vala b/src/views/colourpane.vala index e872f13..7394c59 100644 --- a/src/views/colourpane.vala +++ b/src/views/colourpane.vala @@ -2,7 +2,7 @@ using Gtk; namespace IconPreview { public class DemoIcon : Box { - private Image image = new Image(); + public Image image = new Image(); private Label label = new Label(null); public Icon icon { get; set; } @@ -53,7 +53,7 @@ namespace IconPreview { CssProvider provider = null; List randoms; - public Icon icon { get; set; default = new ThemedIcon("start-here-symbolic");} + public File file { get; set; }//default = new ThemedIcon("start-here-symbolic");} private string _theme = "Adwaita"; public string theme { @@ -83,9 +83,24 @@ namespace IconPreview { construct { DemoIcon ico; - for (var i = 0; i < 3; i++) { - bind_property("icon", sizes.get_child_at(i, 0), "gicon"); + notify["file"].connect(() => { + int[] size = { 16, 32, 64, 128 }; + string[] ids = { "#symbolic", "#hicolor", "#hicolor", "#hicolor" }; + for (var i = 0; i < 4; i++) { + var image = sizes.get_child_at(i, 0) as Image; + var svg = new Rsvg.Handle.from_gfile_sync(file, FLAGS_NONE); + var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, size[i], size[i]); + var cr = new Cairo.Context(surface); + Rsvg.Rectangle ink; + svg.get_geometry_sub(out ink, null, ids[i]); + cr.scale(size[i]/ink.width, size[i]/ink.height); + cr.translate(-ink.x, -ink.y); + //svg.render_cairo_sub(cr, "#hicolor"); + //cr.paint_with_alpha(0.0); + svg.render_cairo(cr); + image.set_from_surface(surface); } + }); /* 64px */ for (var i = 0; i < 2; i++) { @@ -94,9 +109,25 @@ namespace IconPreview { randoms.append(ico); } - ico = new DemoIcon(64); - bind_property("icon", ico, "icon"); - small.add(ico); + var ico2 = new DemoIcon(64); + + notify["file"].connect(() => { + ico2.icon = new FileIcon(file); + var svg = new Rsvg.Handle.from_gfile_sync(file, FLAGS_NONE); + var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 64, 64); + var cr = new Cairo.Context(surface); + Rsvg.Rectangle ink; + svg.get_geometry_sub(out ink, null, "#hicolor"); + cr.scale(64/ink.width, 64/ink.height); + //cr.translate(ink.x, ink.y); + //svg.render_cairo_sub(cr, "#hicolor"); + //cr.paint_with_alpha(0.0); + svg.render_cairo(cr); + ico2.image.set_from_surface(surface); + }); + //bind_property("icon", ico, "icon"); + //bind_property("file", ico.icon, "icon"); + small.add(ico2); for (var i = 3; i < 5; i++) { ico = new DemoIcon(64); @@ -112,9 +143,22 @@ namespace IconPreview { grid.add(ico); randoms.append(ico); - ico = new DemoIcon(96); - bind_property("icon", ico, "icon"); - grid.add(ico); + var ico3 = new DemoIcon(96); + notify["file"].connect(() => { + ico3.icon = new FileIcon(file); + var svg = new Rsvg.Handle.from_gfile_sync(file, FLAGS_NONE); + var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 96, 96); + var cr = new Cairo.Context(surface); + Rsvg.Rectangle ink; + svg.get_geometry_sub(out ink, null, "#hicolor"); + cr.scale(96/ink.width, 96/ink.height); + //cr.translate(ink.x, ink.y); + //svg.render_cairo_sub(cr, "#hicolor"); + //cr.paint_with_alpha(0.0); + svg.render_cairo(cr); + ico3.image.set_from_surface(surface); + }); + grid.add(ico3); ico = new DemoIcon(96); grid.add(ico); diff --git a/src/views/symbolicpane.vala b/src/views/symbolicpane.vala index 1a36b43..a9e5157 100644 --- a/src/views/symbolicpane.vala +++ b/src/views/symbolicpane.vala @@ -37,7 +37,10 @@ namespace IconPreview { return _theme; } set { + var context = get_style_context(); + context.remove_class("theme-" + _theme); _theme = value; + context.add_class("theme-" + _theme); var parts = _theme.split("-"); if (parts.length > 1 && parts[1] == "dark") { provider = CssProvider.get_named(parts[0], "dark"); diff --git a/src/window.vala b/src/window.vala index c355375..b7611da 100644 --- a/src/window.vala +++ b/src/window.vala @@ -37,14 +37,14 @@ namespace IconPreview { // Hopefully this doesn't render the SVG? var svg = new Rsvg.Handle.from_gfile_sync(value, FLAGS_NONE); - var width = 0; - var height = 0; + var width = 0.0; + var height = 0.0; - // Rsvg.Rectangle logical; - // svg.get_geometry_sub(null, out logical, null); + Rsvg.Rectangle ink; + svg.get_geometry_sub(out ink, null, "#hicolor"); - width = svg.width; - height = svg.height; + width = ink.width; + height = ink.height; // Colour (App) icons must be 128 by 128 if (height == 128 && width == 128) { -- GitLab From cae91fd1e0201d3627696c7c07a575525da8df7b Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Sun, 10 Mar 2019 13:02:22 +0100 Subject: [PATCH 2/7] cleanup code and replace Icon with File --- src/views/colour.vala | 4 +- src/views/colourpane.vala | 90 +++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 54 deletions(-) diff --git a/src/views/colour.vala b/src/views/colour.vala index 3a67907..ca99e2f 100644 --- a/src/views/colour.vala +++ b/src/views/colour.vala @@ -54,10 +54,10 @@ namespace IconPreview { public void shuffle () { var samples_names = random_selection(colours, 6); - var samples = new Icon[6]; + var samples = new File[6]; for (var j = 0; j < 6; j++) { - samples[j] = new FileIcon(File.new_for_uri("resource:/" + RES_PATH + samples_names[j])); + samples[j] = File.new_for_uri("resource:/" + RES_PATH + samples_names[j]); } light.load_samples(samples); diff --git a/src/views/colourpane.vala b/src/views/colourpane.vala index 7394c59..88c43bd 100644 --- a/src/views/colourpane.vala +++ b/src/views/colourpane.vala @@ -4,10 +4,10 @@ namespace IconPreview { public class DemoIcon : Box { public Image image = new Image(); private Label label = new Label(null); + public File ?file { get; construct set; } - public Icon icon { get; set; } + public bool rsvg { get; construct set; default = false; } public int size { get; construct set; default = 96; } - class construct { set_css_name("demo-icon"); } @@ -21,21 +21,36 @@ namespace IconPreview { label.ellipsize = END; label.max_width_chars = 30; - bind_property("icon", image, "gicon"); bind_property("size", image, "pixel_size"); - notify["icon"].connect(() => { - var basename = Path.get_basename(IconTheme.get_default().lookup_by_gicon(icon, 96, FORCE_SVG).get_filename()); + notify["file"].connect((s, p) => { + var icon = s as DemoIcon; + if (icon.file != null) { + var basename = icon.file.get_basename(); var parts = basename.split("."); label.label = parts[parts.length - 2]; label.tooltip_text = basename; + /* render svg file */ + if (icon.rsvg) { + var svg = new Rsvg.Handle.from_gfile_sync(_file, FLAGS_NONE); + var surface = new Cairo.SvgSurface(null, icon.size, icon.size); + var cr = new Cairo.Context(surface); + Rsvg.Rectangle ink; + svg.get_geometry_sub(out ink, null, "#hicolor"); + cr.scale(icon.size/ink.width, icon.size/ink.height); + svg.render_cairo(cr); + image.set_from_surface(surface); + } else { + icon.image.gicon = new FileIcon(file); + } + } }); pack_start(image); pack_end(label); } - public DemoIcon (int size) { - Object (size: size); + public DemoIcon (int size, bool rsvg) { + Object (rsvg: rsvg, size: size); } } @@ -86,17 +101,15 @@ namespace IconPreview { notify["file"].connect(() => { int[] size = { 16, 32, 64, 128 }; string[] ids = { "#symbolic", "#hicolor", "#hicolor", "#hicolor" }; + var svg = new Rsvg.Handle.from_gfile_sync(file, FLAGS_NONE); for (var i = 0; i < 4; i++) { var image = sizes.get_child_at(i, 0) as Image; - var svg = new Rsvg.Handle.from_gfile_sync(file, FLAGS_NONE); - var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, size[i], size[i]); + var surface = new Cairo.SvgSurface(null, size[i], size[i]); var cr = new Cairo.Context(surface); Rsvg.Rectangle ink; svg.get_geometry_sub(out ink, null, ids[i]); cr.scale(size[i]/ink.width, size[i]/ink.height); cr.translate(-ink.x, -ink.y); - //svg.render_cairo_sub(cr, "#hicolor"); - //cr.paint_with_alpha(0.0); svg.render_cairo(cr); image.set_from_surface(surface); } @@ -104,33 +117,18 @@ namespace IconPreview { /* 64px */ for (var i = 0; i < 2; i++) { - ico = new DemoIcon(64); + ico = new DemoIcon(64, false); small.add(ico); randoms.append(ico); } - var ico2 = new DemoIcon(64); - - notify["file"].connect(() => { - ico2.icon = new FileIcon(file); - var svg = new Rsvg.Handle.from_gfile_sync(file, FLAGS_NONE); - var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 64, 64); - var cr = new Cairo.Context(surface); - Rsvg.Rectangle ink; - svg.get_geometry_sub(out ink, null, "#hicolor"); - cr.scale(64/ink.width, 64/ink.height); - //cr.translate(ink.x, ink.y); - //svg.render_cairo_sub(cr, "#hicolor"); - //cr.paint_with_alpha(0.0); - svg.render_cairo(cr); - ico2.image.set_from_surface(surface); - }); - //bind_property("icon", ico, "icon"); - //bind_property("file", ico.icon, "icon"); - small.add(ico2); + /* add 64x64 users icon preivew */ + ico = new DemoIcon(64, true); + bind_property("file", ico, "file"); + small.add(ico); for (var i = 3; i < 5; i++) { - ico = new DemoIcon(64); + ico = new DemoIcon(64, false); small.add(ico); randoms.append(ico); } @@ -139,28 +137,16 @@ namespace IconPreview { /* 64px */ /* 96px */ - ico = new DemoIcon(96); + ico = new DemoIcon(96, false); grid.add(ico); randoms.append(ico); - var ico3 = new DemoIcon(96); - notify["file"].connect(() => { - ico3.icon = new FileIcon(file); - var svg = new Rsvg.Handle.from_gfile_sync(file, FLAGS_NONE); - var surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 96, 96); - var cr = new Cairo.Context(surface); - Rsvg.Rectangle ink; - svg.get_geometry_sub(out ink, null, "#hicolor"); - cr.scale(96/ink.width, 96/ink.height); - //cr.translate(ink.x, ink.y); - //svg.render_cairo_sub(cr, "#hicolor"); - //cr.paint_with_alpha(0.0); - svg.render_cairo(cr); - ico3.image.set_from_surface(surface); - }); - grid.add(ico3); + /* add 96x96 users icon preivew */ + ico = new DemoIcon(96, true); + bind_property("file", ico, "file"); + grid.add(ico); - ico = new DemoIcon(96); + ico = new DemoIcon(96, false); grid.add(ico); randoms.append(ico); grid.show_all(); @@ -169,11 +155,11 @@ namespace IconPreview { theme = theme; } - public void load_samples (Icon[] samples) requires (samples.length == randoms.length()) { + public void load_samples (File[] samples) requires (samples.length == randoms.length()) { // Don't like how much of this is hardcoded var idx = 0; foreach (var sample in randoms) { - sample.icon = samples[idx]; + sample.file = samples[idx]; idx++; } } -- GitLab From 3453d02d583b0933cc2f3fb2cd1954403bd24266 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Wed, 8 May 2019 13:58:16 +0200 Subject: [PATCH 3/7] check if hicolor is avaible --- org.gnome.IconPreview.json | 2 +- src/views/colourpane.vala | 26 +++++++++++++++++++++++--- src/window.vala | 18 +++++++----------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/org.gnome.IconPreview.json b/org.gnome.IconPreview.json index 416320d..15bd5b2 100644 --- a/org.gnome.IconPreview.json +++ b/org.gnome.IconPreview.json @@ -1,7 +1,7 @@ { "app-id" : "org.gnome.IconPreview", "runtime" : "org.gnome.Platform", - "runtime-version" : "master", + "runtime-version" : "3.32", "sdk" : "org.gnome.Sdk", "command" : "gnome-icon-preview", "finish-args" : [ diff --git a/src/views/colourpane.vala b/src/views/colourpane.vala index 88c43bd..a087419 100644 --- a/src/views/colourpane.vala +++ b/src/views/colourpane.vala @@ -35,7 +35,11 @@ namespace IconPreview { var surface = new Cairo.SvgSurface(null, icon.size, icon.size); var cr = new Cairo.Context(surface); Rsvg.Rectangle ink; - svg.get_geometry_sub(out ink, null, "#hicolor"); + if (svg.has_sub("#hicolor")) { + svg.get_geometry_sub(out ink, null, "#hicolor"); + } else { + svg.get_geometry_sub(out ink, null, null); + } cr.scale(icon.size/ink.width, icon.size/ink.height); svg.render_cairo(cr); image.set_from_surface(surface); @@ -99,15 +103,31 @@ namespace IconPreview { DemoIcon ico; notify["file"].connect(() => { + int[] size = { 16, 32, 64, 128 }; string[] ids = { "#symbolic", "#hicolor", "#hicolor", "#hicolor" }; var svg = new Rsvg.Handle.from_gfile_sync(file, FLAGS_NONE); - for (var i = 0; i < 4; i++) { + int start_point = 0; + if (!svg.has_sub("#symbolic")) { + // skip the symbolic icon in the preview + start_point = 1; + sizes.get_child_at(0, 0).hide(); + sizes.get_child_at(0, 1).hide(); + } else { + //show the symbolic icon in the preview + sizes.get_child_at(0, 0).show(); + sizes.get_child_at(0, 1).show(); + } + for (var i = start_point; i < ids.length; i++) { var image = sizes.get_child_at(i, 0) as Image; var surface = new Cairo.SvgSurface(null, size[i], size[i]); var cr = new Cairo.Context(surface); Rsvg.Rectangle ink; - svg.get_geometry_sub(out ink, null, ids[i]); + if (svg.has_sub(ids[i])) { + svg.get_geometry_sub(out ink, null, ids[i]); + } else { + svg.get_geometry_sub(out ink, null, null); + } cr.scale(size[i]/ink.width, size[i]/ink.height); cr.translate(-ink.x, -ink.y); svg.render_cairo(cr); diff --git a/src/window.vala b/src/window.vala index b7611da..bcf5bda 100644 --- a/src/window.vala +++ b/src/window.vala @@ -37,20 +37,16 @@ namespace IconPreview { // Hopefully this doesn't render the SVG? var svg = new Rsvg.Handle.from_gfile_sync(value, FLAGS_NONE); - var width = 0.0; - var height = 0.0; + Rsvg.Rectangle hicolor; + svg.get_geometry_sub(null, out hicolor, "#hicolor"); - Rsvg.Rectangle ink; - svg.get_geometry_sub(out ink, null, "#hicolor"); - - width = ink.width; - height = ink.height; - - // Colour (App) icons must be 128 by 128 - if (height == 128 && width == 128) { + // Colour (App) icons must be 128 by 128 and + // and can contain a simbolic icon + if ((hicolor.height == 128 && hicolor.width == 128) || + (svg.height == 128 && svg.height == 128)) { mode = COLOUR; // Whereas symbolics are 16 by 16 - } else if (height == 16 && width == 16) { + } else if (svg.height == 16 && svg.width == 16) { mode = SYMBOLIC; // And anything else is unsupported } else { -- GitLab From a562a857afc39f77a2620996607921e0f5853576 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Fri, 10 May 2019 13:16:32 +0200 Subject: [PATCH 4/7] add support for single file for hicolor and symbolic --- src/views/colour.vala | 30 ++++++++++- src/views/colourpane.vala | 110 ++++++++++++++++---------------------- src/window.vala | 11 ++-- 3 files changed, 82 insertions(+), 69 deletions(-) diff --git a/src/views/colour.vala b/src/views/colour.vala index ca99e2f..8d97bf6 100644 --- a/src/views/colour.vala +++ b/src/views/colour.vala @@ -16,7 +16,18 @@ namespace IconPreview { } set { _icon = value; - light.file = dark.file = _icon; + var svg = new Rsvg.Handle.from_gfile_sync(_icon, FLAGS_NONE); + var hicolor = split_svg(svg, "#hicolor"); + var symbolic = split_svg(svg, "#symbolic"); + + light.name = dark.name = _icon.get_basename(); + + if (hicolor != null) { + light.hicolor = dark.hicolor = hicolor; + } else { + light.hicolor = dark.hicolor = _icon; + } + light.symbolic = dark.symbolic = symbolic; } } @@ -117,5 +128,22 @@ namespace IconPreview { return Gdk.pixbuf_get_from_surface (surface, 0, 0, w, h); } + + private File? split_svg(Rsvg.Handle svg, string id) { + if (svg.has_sub(id)) { + FileIOStream stream; + var temp_file = File.new_tmp("XXXXXX-" + id.substring(1, -1) +".svg", out stream); + Rsvg.Rectangle size; + Rsvg.Rectangle viewport = { 0.0, 0.0, svg.width, svg.height }; + svg.get_geometry_for_element(id, viewport, null, out size); + var surface = new Cairo.SvgSurface(temp_file.get_path(), 128, 128); + var cr = new Cairo.Context(surface); + cr.scale(128/size.width, 128/size.height); + cr.translate(-size.x, -size.y); + svg.render_cairo(cr); + return temp_file; + } + return null; + } } } diff --git a/src/views/colourpane.vala b/src/views/colourpane.vala index a087419..0986f9a 100644 --- a/src/views/colourpane.vala +++ b/src/views/colourpane.vala @@ -5,8 +5,8 @@ namespace IconPreview { public Image image = new Image(); private Label label = new Label(null); public File ?file { get; construct set; } + public string ?name { get; set; } - public bool rsvg { get; construct set; default = false; } public int size { get; construct set; default = 96; } class construct { set_css_name("demo-icon"); @@ -23,29 +23,11 @@ namespace IconPreview { bind_property("size", image, "pixel_size"); notify["file"].connect((s, p) => { - var icon = s as DemoIcon; - if (icon.file != null) { - var basename = icon.file.get_basename(); - var parts = basename.split("."); - label.label = parts[parts.length - 2]; - label.tooltip_text = basename; - /* render svg file */ - if (icon.rsvg) { - var svg = new Rsvg.Handle.from_gfile_sync(_file, FLAGS_NONE); - var surface = new Cairo.SvgSurface(null, icon.size, icon.size); - var cr = new Cairo.Context(surface); - Rsvg.Rectangle ink; - if (svg.has_sub("#hicolor")) { - svg.get_geometry_sub(out ink, null, "#hicolor"); - } else { - svg.get_geometry_sub(out ink, null, null); - } - cr.scale(icon.size/ink.width, icon.size/ink.height); - svg.render_cairo(cr); - image.set_from_surface(surface); - } else { - icon.image.gicon = new FileIcon(file); - } + if (name != null) { + var parts = name.split("."); + label.label = parts[parts.length - 2]; + label.tooltip_text = name; + image.gicon = new FileIcon(file); } }); @@ -53,8 +35,8 @@ namespace IconPreview { pack_end(label); } - public DemoIcon (int size, bool rsvg) { - Object (rsvg: rsvg, size: size); + public DemoIcon (int size) { + Object (size: size); } } @@ -72,7 +54,9 @@ namespace IconPreview { CssProvider provider = null; List randoms; - public File file { get; set; }//default = new ThemedIcon("start-here-symbolic");} + public File hicolor { get; set; } + public File ?symbolic { get; set; } + public string name { get; set; } private string _theme = "Adwaita"; public string theme { @@ -102,53 +86,49 @@ namespace IconPreview { construct { DemoIcon ico; - notify["file"].connect(() => { - - int[] size = { 16, 32, 64, 128 }; - string[] ids = { "#symbolic", "#hicolor", "#hicolor", "#hicolor" }; - var svg = new Rsvg.Handle.from_gfile_sync(file, FLAGS_NONE); - int start_point = 0; - if (!svg.has_sub("#symbolic")) { - // skip the symbolic icon in the preview - start_point = 1; - sizes.get_child_at(0, 0).hide(); - sizes.get_child_at(0, 1).hide(); - } else { - //show the symbolic icon in the preview - sizes.get_child_at(0, 0).show(); - sizes.get_child_at(0, 1).show(); - } - for (var i = start_point; i < ids.length; i++) { - var image = sizes.get_child_at(i, 0) as Image; - var surface = new Cairo.SvgSurface(null, size[i], size[i]); - var cr = new Cairo.Context(surface); - Rsvg.Rectangle ink; - if (svg.has_sub(ids[i])) { - svg.get_geometry_sub(out ink, null, ids[i]); + notify["hicolor"].connect(() => { + if (symbolic == null) { + //hide the symbolic icon in the preview + sizes.get_child_at(0, 0).hide(); + sizes.get_child_at(0, 1).hide(); + } + FileIcon icon = new FileIcon(hicolor); + // Three different sizes {32, 64, 128}; + for (var i = 0; i < 3; i++) { + var image = sizes.get_child_at(i + 1, 0) as Image; + image.set_from_gicon(icon, IconSize.BUTTON); + } + }); + + notify["symbolic"].connect(() => { + if (symbolic != null) { + sizes.get_child_at(0, 1).show(); + var image = sizes.get_child_at(0, 0) as Image; + image.show(); + FileIcon icon = new FileIcon(symbolic); + image.set_from_gicon(icon, IconSize.BUTTON); } else { - svg.get_geometry_sub(out ink, null, null); + //hide the symbolic icon in the preview + sizes.get_child_at(0, 0).hide(); + sizes.get_child_at(0, 1).hide(); } - cr.scale(size[i]/ink.width, size[i]/ink.height); - cr.translate(-ink.x, -ink.y); - svg.render_cairo(cr); - image.set_from_surface(surface); - } }); /* 64px */ for (var i = 0; i < 2; i++) { - ico = new DemoIcon(64, false); + ico = new DemoIcon(64); small.add(ico); randoms.append(ico); } /* add 64x64 users icon preivew */ - ico = new DemoIcon(64, true); - bind_property("file", ico, "file"); + ico = new DemoIcon(64); + bind_property("hicolor", ico, "file"); + bind_property("name", ico, "name"); small.add(ico); for (var i = 3; i < 5; i++) { - ico = new DemoIcon(64, false); + ico = new DemoIcon(64); small.add(ico); randoms.append(ico); } @@ -157,16 +137,17 @@ namespace IconPreview { /* 64px */ /* 96px */ - ico = new DemoIcon(96, false); + ico = new DemoIcon(96); grid.add(ico); randoms.append(ico); /* add 96x96 users icon preivew */ - ico = new DemoIcon(96, true); - bind_property("file", ico, "file"); + ico = new DemoIcon(96); + bind_property("hicolor", ico, "file"); + bind_property("name", ico, "name"); grid.add(ico); - ico = new DemoIcon(96, false); + ico = new DemoIcon(96); grid.add(ico); randoms.append(ico); grid.show_all(); @@ -179,6 +160,7 @@ namespace IconPreview { // Don't like how much of this is hardcoded var idx = 0; foreach (var sample in randoms) { + sample.name = samples[idx].get_basename(); sample.file = samples[idx]; idx++; } diff --git a/src/window.vala b/src/window.vala index bcf5bda..c1a27b1 100644 --- a/src/window.vala +++ b/src/window.vala @@ -37,13 +37,16 @@ namespace IconPreview { // Hopefully this doesn't render the SVG? var svg = new Rsvg.Handle.from_gfile_sync(value, FLAGS_NONE); - Rsvg.Rectangle hicolor; - svg.get_geometry_sub(null, out hicolor, "#hicolor"); + Rsvg.Rectangle hicolor = { 0.0, 0.0, svg.width, svg.height }; + + Rsvg.Rectangle viewport = { 0.0, 0.0, svg.width, svg.height }; + if (svg.has_sub("#hicolor")) { + svg.get_geometry_for_element("#hicolor", viewport, null ,out hicolor); + } // Colour (App) icons must be 128 by 128 and // and can contain a simbolic icon - if ((hicolor.height == 128 && hicolor.width == 128) || - (svg.height == 128 && svg.height == 128)) { + if (hicolor.height == 128 && hicolor.width == 128) { mode = COLOUR; // Whereas symbolics are 16 by 16 } else if (svg.height == 16 && svg.width == 16) { -- GitLab From dbcc7e596e30854077cea4905157837f82874f23 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Fri, 10 May 2019 13:52:43 +0200 Subject: [PATCH 5/7] use nightly flatpak sdk --- org.gnome.IconPreview.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.gnome.IconPreview.json b/org.gnome.IconPreview.json index 15bd5b2..416320d 100644 --- a/org.gnome.IconPreview.json +++ b/org.gnome.IconPreview.json @@ -1,7 +1,7 @@ { "app-id" : "org.gnome.IconPreview", "runtime" : "org.gnome.Platform", - "runtime-version" : "3.32", + "runtime-version" : "master", "sdk" : "org.gnome.Sdk", "command" : "gnome-icon-preview", "finish-args" : [ -- GitLab From 9b9c4bfc8a7d776db6556450077593225d27f21e Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Fri, 10 May 2019 13:58:26 +0200 Subject: [PATCH 6/7] Add new template for hicolor --- src/templates/colour.svg | 104 +++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/templates/colour.svg b/src/templates/colour.svg index c68576b..de64bf3 100644 --- a/src/templates/colour.svg +++ b/src/templates/colour.svg @@ -17,7 +17,7 @@ height="128" id="svg11300" sodipodi:version="0.32" - inkscape:version="0.92.3 (2405546, 2018-03-11)" + inkscape:version="0.92.4 (5da689c313, 2019-01-14)" sodipodi:docname="template.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape" version="1.0" @@ -590,10 +590,10 @@ borderopacity="0.25490196" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="1" - inkscape:cx="-51.790628" - inkscape:cy="-54.117604" - inkscape:current-layer="layer9" + inkscape:zoom="2" + inkscape:cx="10.408975" + inkscape:cy="101.10726" + inkscape:current-layer="layer3" showgrid="false" inkscape:grid-bbox="true" inkscape:document-units="px" @@ -1010,7 +1010,7 @@ inkscape:export-ydpi="12" /> - - - - - - - + + + + + + + -- GitLab From eb7efae3d62174ec21da37a8706f1fc0207a6955 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Sat, 11 May 2019 21:19:12 +0200 Subject: [PATCH 7/7] fix template and fix code style --- src/templates/colour.svg | 146 ++++++++++++++++++++++---------------- src/views/colourpane.vala | 6 +- 2 files changed, 89 insertions(+), 63 deletions(-) diff --git a/src/templates/colour.svg b/src/templates/colour.svg index de64bf3..328a68b 100644 --- a/src/templates/colour.svg +++ b/src/templates/colour.svg @@ -13,8 +13,8 @@ inkscape:export-ydpi="96" inkscape:export-xdpi="96" inkscape:export-filename="Template.png" - width="128" - height="128" + width="192" + height="152" id="svg11300" sodipodi:version="0.32" inkscape:version="0.92.4 (5da689c313, 2019-01-14)" @@ -22,7 +22,7 @@ inkscape:output_extension="org.inkscape.output.svg.inkscape" version="1.0" style="display:inline;enable-background:new" - viewBox="0 0 128 128"> + viewBox="0 0 192 152"> Adwaita Icon Template - - @@ -580,6 +561,25 @@ y1="619.96387" x2="568" y2="619.96387" /> + + + inkscape:snap-text-baseline="true" + borderlayer="true"> + originx="8" + originy="8" /> + dotted="true" + originx="8" + originy="8" /> + transform="translate(8,-156)"> + + + + + inkscape:label="0" /> Hicolor + y="167">Hicolor + style="opacity:1;vector-effect:none;fill:url(#linearGradient1278);fill-opacity:1;stroke:none;stroke-width:0.01184966px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal" />