Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static java.awt.RenderingHints.VALUE_STROKE_PURE;
import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints.Key;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -139,6 +140,7 @@ private int calculateTargetHeight(float scalingFactor, FloatSize sourceImageSize
private Graphics2D configureRenderingOptions(float widthScalingFactor, float heightScalingFactor,
BufferedImage image) {
Graphics2D g = image.createGraphics();
g.setColor(Color.BLACK);
g.setRenderingHints(RENDERING_HINTS);
g.scale(widthScalingFactor, heightScalingFactor);
return g;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.RGB;
import org.junit.jupiter.api.Test;

class JSVGRasterizerTest {

private final JSVGRasterizer rasterizer = new JSVGRasterizer();
private String svgString = """
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%"/>
<rect width="100%" height="100%" fill="currentColor"/>
</svg>
""";

Expand Down Expand Up @@ -89,4 +90,10 @@ void testRasterizeWithTargetSizeWithInvalidSVG() {
assertEquals(SWT.ERROR_INVALID_IMAGE, exception.code);
}

@Test
void testDefaultCurrentColorIsBlack() {
ImageData data = rasterizer.rasterizeSVG(svgStream(svgString), 100);
RGB rgb = data.palette.getRGB(data.getPixel(0, 0));
assertEquals(new RGB(0, 0, 0), rgb);
}
}
Loading