Yes, agreed, that is missing from the SVG loading feature, which is currently 
exposed through ImageUtilities (which has no API to get a custom size). It will 
be needed for toolbar icons, which can be shown in two sizes (via the "Show 
Small Icons" option). Your hack is pretty much correct, though.

Side note: One annoying aesthetic issue is that even though SVG icons are 
scalable, ideally you want all icons to use a consistent border width [1]. So 
if the main IDE toolbar icons are drawn as SVG files at the 16x16 logical pixel 
size, but are scaled up to be displayed at 24x24 logical pixel size, the 
borders will look 50% too thick relative to other icons. So for the main IDE 
toolbar icons, we will have to decide whether they should look best at 16x16 or 
at 24x24, and draw them for that logical resolution. (There are currently two 
bitmap versions of every IDE toolbar icon, drawn even at different levels of 
details, but I think it's way too much work to do this for the SVG versions as 
well. We'll have to just draw one size and scale to the other, despite the 
border widths issue.)

Also note that "VectorIcon" is a separate class which is unreleated to SVG 
loading. VectorIcon is an alternative way to implement DPI-scalable icons, by 
hand-coded painting on the Graphics2D. It's used in the MacOS and Windows LAFs 
to draw "X" icons in tabs and such.

> And in the spirit of eating my own dogfood, it now has mostly SVG icons 
> (created in it, of course :-)).
Great to hear!!

-- Eirik
[1] Borders around shapes are 1 logical pixels wide in the existing bitmap 
icons and in the proposed SVG icon style guide at NETBEANS-2617.

-----Original Message-----
From: Tim Boudreau <niftin...@gmail.com> 
Sent: Monday, September 21, 2020 9:10 AM
To: dev@netbeans.apache.org
Subject: Re: API was: SVG icon graphics

 Now, while we're discussing the API for SVG icons, one thing that seems 
painfully missing from VectorIcon - I did some considerable work on Imagine 
this winter - it now is more a vector editor than image editor, and loads and 
saves SVG - though it needs some more work whenever I get back to it.
And in the spirit of eating my own dogfood, it now has mostly SVG icons 
(created in it, of course :-)).

Anyway, this is the issue:  There is no way to specify a custom size for an 
icon and get an instance of it.  Something like 
someVectorIcon.getScaledInstance (width, height).  So we have scalable 
icons...that are only available at *one fixed size?!*

The hideous workaround is to do something like:

class DoubleScaledIcon implements Icon {
     private final Icon original;
     public void paintIcon (Graphics g, Component c, int x, int y) {
          Graphics2D gg = (Graphics2d) g.create();
           try {
                gg.setTransform(AffineTransform.getScaleInstance(2, 2));
                original.paintIcon(gg, c, x, y);
           } finally {
               gg.dispose();
           }
     }
     public int getIconWidth() { return original.getIconWidth() * 2; }
     // ...
}

which is kind of ridiculous.  Yes, the idea is to have icons that scale to the 
toolkit's scale.  But if you're going to have resolution-independent, scalable 
icon objects in the first place, it seems bizarre to provide no way other than 
hacks to scale them.

-Tim

Reply via email to