diff --git a/platform/platform-tests/testData/ui/myIcon_xml_20x10.svg b/platform/platform-tests/testData/ui/myIcon_xml_20x10.svg new file mode 100644 index 000000000000..cfcf5bf6055d --- /dev/null +++ b/platform/platform-tests/testData/ui/myIcon_xml_20x10.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/platform/platform-tests/testSrc/com/intellij/util/ui/SvgIconSizeTest.java b/platform/platform-tests/testSrc/com/intellij/util/ui/SvgIconSizeTest.java index 99a410131d03..767c6fdafa3f 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/ui/SvgIconSizeTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/ui/SvgIconSizeTest.java @@ -10,6 +10,7 @@ import org.junit.Test; import org.junit.rules.ExternalResource; import java.awt.*; +import java.awt.geom.Dimension2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; @@ -50,6 +51,22 @@ public class SvgIconSizeTest { image = ImageUtil.toBufferedImage(image); assertEquals("wrong image width", pixScale * 25, (double)image.getWidth(null)); assertEquals("wrong image height", pixScale * 15, (double)image.getHeight(null)); + + /* + * Test SVGLoader.getDocumentSize for SVG starting with header) and parse only it. StringBuilder builder = new StringBuilder(100); + byte[] bytes = new byte[3]; + boolean checkClosingBracket = false; int ch; while((ch = stream.read()) != -1) { builder.append((char)ch); - if (ch == '>') { - //noinspection SSBasedInspection + if (ch == '<') { + if (stream.read(bytes, 0, 3) == -1) { + break; + } + String str = new String(bytes); + builder.append(str); + checkClosingBracket = "svg".equals(str); + } + else if (checkClosingBracket && ch == '>') { return new SVGLoader(url, new ByteArrayInputStream(builder.append("").toString().getBytes()), scale).getDocumentSize(); } }