Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
b43a127b
Commit
b43a127b
authored
6 years ago
by
Anton Tarasov
Browse files
Options
Download
Email Patches
Plain Diff
Add another SVGLoader.loadHiDPI method
parent
55e4238c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java
+5
-2
...m-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java
platform/platform-impl/src/com/intellij/ui/AppUIUtil.java
+2
-1
platform/platform-impl/src/com/intellij/ui/AppUIUtil.java
platform/platform-tests/testSrc/com/intellij/util/ui/SvgIconSizeTest.java
+6
-3
...m-tests/testSrc/com/intellij/util/ui/SvgIconSizeTest.java
platform/util/src/com/intellij/util/SVGLoader.java
+16
-3
platform/util/src/com/intellij/util/SVGLoader.java
with
29 additions
and
9 deletions
+29
-9
platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java
+
5
-
2
View file @
b43a127b
...
...
@@ -20,6 +20,8 @@ import com.intellij.util.Urls;
import
com.intellij.util.io.HttpRequests
;
import
com.intellij.util.io.URLUtil
;
import
com.intellij.util.ui.JBImageIcon
;
import
com.intellij.util.ui.JBUI
;
import
com.intellij.util.ui.JBUI.ScaleContext
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
...
...
@@ -286,8 +288,9 @@ public class PluginLogo {
@Nullable
private
static
PluginLogoIconProvider
loadFileIcon
(
@NotNull
ThrowableComputable
<
InputStream
,
IOException
>
provider
)
{
try
{
Icon
logo40
=
new
JBImageIcon
(
SVGLoader
.
load
(
null
,
provider
.
compute
(),
40
,
40
));
Icon
logo80
=
new
JBImageIcon
(
SVGLoader
.
load
(
null
,
provider
.
compute
(),
80
,
80
));
ScaleContext
ctx
=
ScaleContext
.
create
();
Icon
logo40
=
new
JBImageIcon
(
SVGLoader
.
loadHiDPI
(
null
,
provider
.
compute
(),
ctx
,
40
,
40
));
Icon
logo80
=
new
JBImageIcon
(
SVGLoader
.
loadHiDPI
(
null
,
provider
.
compute
(),
ctx
,
80
,
80
));
return
new
PluginLogoIcon
(
logo40
,
Objects
.
requireNonNull
(
IconLoader
.
getDisabledIcon
(
logo40
)),
logo80
,
Objects
.
requireNonNull
(
IconLoader
.
getDisabledIcon
(
logo80
)));
...
...
This diff is collapsed.
Click to expand it.
platform/platform-impl/src/com/intellij/ui/AppUIUtil.java
+
2
-
1
View file @
b43a127b
...
...
@@ -31,6 +31,7 @@ import com.intellij.util.*;
import
com.intellij.util.containers.ContainerUtil
;
import
com.intellij.util.ui.ImageUtil
;
import
com.intellij.util.ui.JBUI
;
import
com.intellij.util.ui.JBUI.ScaleContext
;
import
com.intellij.util.ui.SwingHelper
;
import
org.jetbrains.annotations.NonNls
;
import
org.jetbrains.annotations.NotNull
;
...
...
@@ -110,7 +111,7 @@ public class AppUIUtil {
URL
url
=
AppUIUtil
.
class
.
getResource
(
svgIconUrl
);
try
{
return
SVGLoader
.
load
(
url
,
AppUIUtil
.
class
.
getResourceAsStream
(
svgIconUrl
),
JBUI
.
pixScale
(
window
)
*
size
,
JBUI
.
pixScal
e
(
window
)
*
size
);
SVGLoader
.
load
(
url
,
AppUIUtil
.
class
.
getResourceAsStream
(
svgIconUrl
),
ScaleContext
.
creat
e
(
window
)
,
size
,
size
);
}
catch
(
IOException
e
)
{
LOG
.
info
(
"Cannot load svg application icon from "
+
svgIconUrl
,
e
);
...
...
This diff is collapsed.
Click to expand it.
platform/platform-tests/testSrc/com/intellij/util/ui/SvgIconSizeTest.java
+
6
-
3
View file @
b43a127b
...
...
@@ -15,6 +15,7 @@ import java.io.File;
import
java.io.IOException
;
import
java.net.URL
;
import
static
com
.
intellij
.
util
.
ui
.
JBUI
.
ScaleType
.
PIX_SCALE
;
import
static
com
.
intellij
.
util
.
ui
.
JBUI
.
ScaleType
.
SYS_SCALE
;
import
static
com
.
intellij
.
util
.
ui
.
TestScaleHelper
.
loadImage
;
import
static
com
.
intellij
.
util
.
ui
.
TestScaleHelper
.
overrideJreHiDPIEnabled
;
...
...
@@ -42,11 +43,13 @@ public class SvgIconSizeTest {
* Test overridden size.
*/
URL
url
=
new
File
(
getSvgIconPath
(
"20x10"
)).
toURI
().
toURL
();
Image
image
=
SVGLoader
.
load
(
url
,
url
.
openStream
(),
25
,
15
);
ScaleContext
ctx
=
ScaleContext
.
create
(
SYS_SCALE
.
of
(
2
));
double
pixScale
=
ctx
.
getScale
(
PIX_SCALE
);
Image
image
=
SVGLoader
.
load
(
url
,
url
.
openStream
(),
ctx
,
25
,
15
);
assertNotNull
(
image
);
image
=
ImageUtil
.
toBufferedImage
(
image
);
assertEquals
(
"wrong image width"
,
25
,
image
.
getWidth
(
null
));
assertEquals
(
"wrong image height"
,
15
,
image
.
getHeight
(
null
));
assertEquals
(
"wrong image width"
,
pixScale
*
25
,
(
double
)
image
.
getWidth
(
null
));
assertEquals
(
"wrong image height"
,
pixScale
*
15
,
(
double
)
image
.
getHeight
(
null
));
}
private
static
void
test
(
ScaleContext
ctx
)
{
...
...
This diff is collapsed.
Click to expand it.
platform/util/src/com/intellij/util/SVGLoader.java
+
16
-
3
View file @
b43a127b
...
...
@@ -122,17 +122,30 @@ public class SVGLoader {
}
/**
* Loads an image with the specified {@code width} and {@code height}. Size specified in svg file is ignored.
* Loads an image with the specified {@code width} and {@code height}
(in user space)
. Size specified in svg file is ignored.
*/
public
static
Image
load
(
@Nullable
URL
url
,
@NotNull
InputStream
stream
,
double
width
,
double
height
)
throws
IOException
{
public
static
Image
load
(
@Nullable
URL
url
,
@NotNull
InputStream
stream
,
@NotNull
ScaleContext
ctx
,
double
width
,
double
height
)
throws
IOException
{
try
{
return
new
SVGLoader
(
url
,
stream
,
width
,
height
,
1
).
createImage
();
double
s
=
ctx
.
getScale
(
PIX_SCALE
);
return
new
SVGLoader
(
url
,
stream
,
width
*
s
,
height
*
s
,
1
).
createImage
();
}
catch
(
TranscoderException
ex
)
{
throw
new
IOException
(
ex
);
}
}
/**
* Loads a HiDPI-aware image with the specified {@code width} and {@code height} (in user space). Size specified in svg file is ignored.
*/
public
static
<
T
extends
BufferedImage
>
T
loadHiDPI
(
@Nullable
URL
url
,
@NotNull
InputStream
stream
,
ScaleContext
ctx
,
double
width
,
double
height
)
throws
IOException
{
BufferedImage
image
=
(
BufferedImage
)
load
(
url
,
stream
,
ctx
,
width
,
height
);
//noinspection unchecked
return
(
T
)
ImageUtil
.
ensureHiDPI
(
image
,
ctx
);
}
/**
* Loads a HiDPI-aware image of the size specified in the svg file.
*/
public
static
<
T
extends
BufferedImage
>
T
loadHiDPI
(
@Nullable
URL
url
,
@NotNull
InputStream
stream
,
ScaleContext
ctx
)
throws
IOException
{
BufferedImage
image
=
(
BufferedImage
)
load
(
url
,
stream
,
ctx
.
getScale
(
PIX_SCALE
));
//noinspection unchecked
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help