Working svg renderer

This commit is contained in:
2026-02-22 16:41:26 +01:00
parent 7fc05df240
commit 66b96102f8
3 changed files with 32 additions and 26 deletions
+5 -3
View File
@@ -22,8 +22,8 @@ dependencies {
implementation 'com.github.selimaj-dev:session-java:0.1.4'
modImplementation "org.apache.xmlgraphics:batik-transcoder:1.19"
modImplementation "org.apache.xmlgraphics:batik-codec:1.19"
// implementation("com.kitfox.svg:svg-salamander:1.1.3")
implementation 'com.formdev:svgSalamander:1.1.4'
include modImplementation("dev.kosmx.player-anim:player-animation-lib-fabric:${project.player_anim}")
//You might want bendy-lib. playerAnimator will wrap it.
@@ -32,11 +32,13 @@ dependencies {
repositories {
maven { url 'https://maven.fabricmc.net/' } // Fabric's official repo
maven { url 'https://maven.fabricmc.net/' }
maven { url 'https://jitpack.io' }
maven { url "https://maven.parchmentmc.org" }
maven { name = "FelNull Maven"; url = "https://maven.felnull.dev" }
maven { name = "KosmX maven"; url = 'https://maven.kosmx.dev/' }
mavenCentral()
}
processResources {
@@ -1,10 +1,13 @@
package org.saturnclient.ui2.resources;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.image.ImageTranscoder;
import com.kitfox.svg.SVGDiagram;
import com.kitfox.svg.SVGUniverse;
import org.jetbrains.annotations.Nullable;
import org.saturnclient.saturnclient.SaturnClient;
import org.saturnclient.saturnclient.cosmetics.cloaks.utils.IdentifierUtils;
@@ -13,30 +16,26 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Identifier;
public class SvgTexture {
private static BufferedImage renderSvg(InputStream svgStream, float width, float height) throws Exception {
TranscoderInput input = new TranscoderInput(svgStream);
final BufferedImage[] imagePointer = new BufferedImage[1];
private static BufferedImage renderSvg(InputStream svgStream, int width, int height) throws Exception {
// Create SVGUniverse and load the SVG
SVGUniverse universe = new SVGUniverse();
java.net.URI uri = universe.loadSVG(svgStream, "tempSvg");
SVGDiagram diagram = universe.getDiagram(uri);
ImageTranscoder transcoder = new ImageTranscoder() {
// Create a BufferedImage to render the SVG
BufferedImage image = new BufferedImage((int) width, (int) height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
@Override
public BufferedImage createImage(int w, int h) {
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
}
// Set the diagram's viewport to match the desired size
diagram.setIgnoringClipHeuristic(true);
diagram.setDeviceViewport(new Rectangle(0, 0, width, height));
@Override
public void writeImage(BufferedImage img, org.apache.batik.transcoder.TranscoderOutput out) {
imagePointer[0] = img;
}
};
// Render the SVG onto the BufferedImage
diagram.render(g);
transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, width);
transcoder.addTranscodingHint(ImageTranscoder.KEY_HEIGHT, height);
transcoder.transcode(input, null);
return imagePointer[0];
g.dispose();
return image;
}
@Nullable
@@ -58,8 +57,7 @@ public class SvgTexture {
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
}
@@ -14,10 +14,12 @@ import org.saturnclient.ui2.elements.Button;
import org.saturnclient.ui2.elements.ImageTexture;
import org.saturnclient.ui2.elements.TextureButton;
import org.saturnclient.ui2.resources.Fonts;
import org.saturnclient.ui2.resources.SvgTexture;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
import net.minecraft.util.Identifier;
public class TitleMenu extends SaturnScreen {
public TitleMenu() {
@@ -70,5 +72,9 @@ public class TitleMenu extends SaturnScreen {
}).dimensions(s, s).position((s + 2) * 2, 0).animation(new SlideFade(1000, s + 8)));
draw(saturnStagger.dimensions(((s + 2) * 2) + s, s).centerHorizontal(width, height, 0, 8));
draw(new ImageTexture(
SvgTexture.getSvg(client, Identifier.of("saturnclient", "textures/gui/test.svg"), 98, 98, 1.0f))
.dimensions(98, 98));
}
}