mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Don't use third-party library for Dimension2DDouble class, inline relevant class
GitOrigin-RevId: d343615f048b5338d645912a78664993d0cdea28
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e26d2a7bba
commit
228f63ae83
@@ -16,6 +16,7 @@
|
||||
package org.intellij.images.util;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.ImageLoader;
|
||||
import com.intellij.util.SVGLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -24,7 +25,6 @@ import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.awt.geom.Dimension2D;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@@ -72,7 +72,7 @@ public class ImageInfoReader {
|
||||
|
||||
private static Info getSvgSize(byte[] data) {
|
||||
try {
|
||||
Dimension2D size = SVGLoader.getDocumentSize(null, new ByteArrayInputStream(data), 1.0f);
|
||||
ImageLoader.Dimension2DDouble size = SVGLoader.getDocumentSize(null, new ByteArrayInputStream(data), 1.0f);
|
||||
return new Info((int)Math.round(size.getWidth()), (int)Math.round(size.getHeight()), 32, true);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
|
||||
@@ -5,13 +5,13 @@ import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.ui.RestoreScaleRule;
|
||||
import com.intellij.ui.scale.JBUIScale;
|
||||
import com.intellij.ui.scale.ScaleContext;
|
||||
import com.intellij.util.ImageLoader;
|
||||
import com.intellij.util.SVGLoader;
|
||||
import org.junit.ClassRule;
|
||||
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;
|
||||
@@ -67,7 +67,7 @@ public class SvgIconSizeTest {
|
||||
* Test SVGLoader.getDocumentSize for SVG starting with <svg.
|
||||
*/
|
||||
url = new File(getSvgIconPath("20x10")).toURI().toURL();
|
||||
Dimension2D size = SVGLoader.getDocumentSize(url, url.openStream(), 1);
|
||||
ImageLoader.Dimension2DDouble size = SVGLoader.getDocumentSize(url, url.openStream(), 1);
|
||||
assertEquals("wrong svg doc width", 20d, size.getWidth());
|
||||
assertEquals("wrong svg doc height", 10d, size.getHeight());
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util" />
|
||||
<orderEntry type="library" name="batik-transcoder" level="project" />
|
||||
<orderEntry type="library" name="xmlgraphics-commons" level="project" />
|
||||
<orderEntry type="library" name="imgscalr" level="project" />
|
||||
<orderEntry type="library" name="jna" level="project" />
|
||||
<orderEntry type="library" name="xml-apis-ext" level="project" />
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import com.intellij.util.ui.ImageUtil;
|
||||
import com.intellij.util.ui.StartupUiUtil;
|
||||
import org.apache.xmlgraphics.java2d.Dimension2DDouble;
|
||||
import org.imgscalr.Scalr;
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -23,7 +22,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Dimension2D;
|
||||
import java.awt.image.BufferedImageOp;
|
||||
import java.awt.image.ImageFilter;
|
||||
import java.io.*;
|
||||
@@ -54,7 +52,7 @@ public final class ImageLoader implements Serializable {
|
||||
}
|
||||
|
||||
public static final long CACHED_IMAGE_MAX_SIZE = (long)(SystemProperties.getFloatProperty("ide.cached.image.max.size", 1.5f) * 1024 * 1024);
|
||||
private static final ConcurrentMap<String, Pair<Image, Dimension2D>> ourCache = ContainerUtil.createConcurrentSoftValueMap();
|
||||
private static final ConcurrentMap<String, Pair<Image, Dimension2DDouble>> ourCache = ContainerUtil.createConcurrentSoftValueMap();
|
||||
|
||||
public static void clearCache() {
|
||||
ourCache.clear();
|
||||
@@ -71,6 +69,34 @@ public final class ImageLoader implements Serializable {
|
||||
Image load(@Nullable LoadFunction delegate, @NotNull ImageDesc.Type type) throws IOException;
|
||||
}
|
||||
|
||||
public static class Dimension2DDouble {
|
||||
private double myWidth;
|
||||
private double myHeight;
|
||||
|
||||
public Dimension2DDouble(double width, double height) {
|
||||
myWidth = width;
|
||||
myHeight = height;
|
||||
}
|
||||
|
||||
public void setSize(Dimension2DDouble size) {
|
||||
myWidth = size.myWidth;
|
||||
myHeight = size.myHeight;
|
||||
}
|
||||
|
||||
public void setSize(double width, double height) {
|
||||
myWidth = width;
|
||||
myHeight = height;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return myWidth;
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return myHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ImageDesc {
|
||||
public enum Type {IMG, SVG}
|
||||
|
||||
@@ -80,7 +106,7 @@ public final class ImageLoader implements Serializable {
|
||||
final boolean original; // path is not altered
|
||||
// The original user space size of the image. In case of SVG it's the size specified in the SVG doc.
|
||||
// Otherwise it's the size of the original image divided by the image's scale (defined by the extension @2x).
|
||||
final @NotNull Dimension2D origUsrSize;
|
||||
final @NotNull Dimension2DDouble origUsrSize;
|
||||
|
||||
public ImageDesc(@NotNull String path, double scale, @NotNull Type type) {
|
||||
this(path, scale, type, false);
|
||||
@@ -126,7 +152,7 @@ public final class ImageLoader implements Serializable {
|
||||
if (stream == null) {
|
||||
if (useCache) {
|
||||
cacheKey = path + (type == SVG ? "_@" + scale + "x" : "");
|
||||
Pair<Image, Dimension2D> pair = ourCache.get(cacheKey);
|
||||
Pair<Image, Dimension2DDouble> pair = ourCache.get(cacheKey);
|
||||
if (pair != null) {
|
||||
origUsrSize.setSize(pair.second);
|
||||
return pair.first;
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.apache.batik.bridge.BridgeContext;
|
||||
import org.apache.batik.bridge.GVTBuilder;
|
||||
import org.apache.batik.transcoder.TranscoderException;
|
||||
import org.apache.batik.transcoder.TranscoderInput;
|
||||
import org.apache.xmlgraphics.java2d.Dimension2DDouble;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -49,7 +48,7 @@ public final class SVGLoader {
|
||||
return load(url, stream, scale, null);
|
||||
}
|
||||
|
||||
static Image load(@Nullable URL url, @NotNull InputStream stream, double scale, @Nullable Dimension2D docSize /*OUT*/) throws IOException {
|
||||
static Image load(@Nullable URL url, @NotNull InputStream stream, double scale, @Nullable ImageLoader.Dimension2DDouble docSize /*OUT*/) throws IOException {
|
||||
try {
|
||||
MyTranscoder transcoder = MyTranscoder.createImage(scale, createTranscodeInput(url, stream));
|
||||
if (docSize != null) {
|
||||
@@ -106,7 +105,7 @@ public final class SVGLoader {
|
||||
return loadHiDPI(url, stream, (ScaleContext)ctx);
|
||||
}
|
||||
|
||||
public static Dimension2D getDocumentSize(@Nullable URL url, @NotNull InputStream stream, double scale) throws IOException {
|
||||
public static ImageLoader.Dimension2DDouble getDocumentSize(@Nullable URL url, @NotNull InputStream stream, double scale) throws IOException {
|
||||
// In order to get the size we parse the whole document and build a tree ("GVT"), what might be too expensive.
|
||||
// So, to optimize we extract the svg header (possibly prepended with <?xml> header) and parse only it.
|
||||
// Assumes 8-bit encoding of the input stream (no one in theirs right mind would use wide characters for SVG anyway).
|
||||
@@ -127,11 +126,11 @@ public final class SVGLoader {
|
||||
return getDocumentSize(scale, createTranscodeInput(url, new ByteArrayInputStream(buffer.getInternalBuffer(), 0, buffer.size())));
|
||||
}
|
||||
}
|
||||
return new Dimension2DDouble(ICON_DEFAULT_SIZE * scale, ICON_DEFAULT_SIZE * scale);
|
||||
return new ImageLoader.Dimension2DDouble(ICON_DEFAULT_SIZE * scale, ICON_DEFAULT_SIZE * scale);
|
||||
}
|
||||
|
||||
public static double getMaxZoomFactor(@Nullable URL url, @NotNull InputStream stream, @NotNull ScaleContext ctx) throws IOException {
|
||||
Dimension2D size = getDocumentSize(ctx.getScale(DerivedScaleType.PIX_SCALE), createTranscodeInput(url, stream));
|
||||
ImageLoader.Dimension2DDouble size = getDocumentSize(ctx.getScale(DerivedScaleType.PIX_SCALE), createTranscodeInput(url, stream));
|
||||
double iconMaxSize = MyTranscoder.getIconMaxSize();
|
||||
return Math.min(iconMaxSize / size.getWidth(), iconMaxSize / size.getHeight());
|
||||
}
|
||||
@@ -169,13 +168,12 @@ public final class SVGLoader {
|
||||
IconLoader.clearCache();
|
||||
}
|
||||
|
||||
private static Dimension2D getDocumentSize(double scale, @NotNull TranscoderInput input) {
|
||||
private static ImageLoader.Dimension2DDouble getDocumentSize(double scale, @NotNull TranscoderInput input) {
|
||||
SVGOMDocument document = (SVGOMDocument)input.getDocument();
|
||||
BridgeContext ctx = new MyTranscoder(scale).createBridgeContext(document);
|
||||
new GVTBuilder().build(ctx, document);
|
||||
Dimension2D size = ctx.getDocumentSize();
|
||||
size.setSize(size.getWidth() * scale, size.getHeight() * scale);
|
||||
return size;
|
||||
return new ImageLoader.Dimension2DDouble(size.getWidth() * scale, size.getHeight() * scale);
|
||||
}
|
||||
|
||||
public interface SvgColorPatcher {
|
||||
|
||||
Reference in New Issue
Block a user