Prepare for new Batik version

This commit is contained in:
Harald Kuhr 2023-08-23 12:41:54 +02:00
parent 608b37232d
commit aab2d36e92
3 changed files with 50 additions and 49 deletions

View File

@ -91,10 +91,10 @@ public class SVGImageReader extends ImageReaderBase {
/**
* Creates an {@code SVGImageReader}.
*
* @param pProvider the provider
* @param provider the provider
*/
public SVGImageReader(final ImageReaderSpi pProvider) {
super(pProvider);
public SVGImageReader(final ImageReaderSpi provider) {
super(provider);
}
protected void resetMembers() {
@ -108,20 +108,20 @@ public class SVGImageReader extends ImageReaderBase {
}
@Override
public void setInput(Object pInput, boolean seekForwardOnly, boolean ignoreMetadata) {
super.setInput(pInput, seekForwardOnly, ignoreMetadata);
public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) {
super.setInput(input, seekForwardOnly, ignoreMetadata);
if (imageInput != null) {
TranscoderInput input = new TranscoderInput(IIOUtil.createStreamAdapter(imageInput));
rasterizer.setInput(input);
TranscoderInput transcoderInput = new TranscoderInput(IIOUtil.createStreamAdapter(imageInput));
rasterizer.setInput(transcoderInput);
}
}
public BufferedImage read(int pIndex, ImageReadParam pParam) throws IOException {
checkBounds(pIndex);
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException {
checkBounds(imageIndex);
if (pParam instanceof SVGReadParam) {
SVGReadParam svgParam = (SVGReadParam) pParam;
if (param instanceof SVGReadParam) {
SVGReadParam svgParam = (SVGReadParam) param;
// set the external-resource-resolution preference
allowExternalResources = svgParam.isAllowExternalResources();
@ -139,17 +139,17 @@ public class SVGImageReader extends ImageReaderBase {
}
Dimension size = null;
if (pParam != null) {
size = pParam.getSourceRenderSize();
if (param != null) {
size = param.getSourceRenderSize();
}
if (size == null) {
size = new Dimension(getWidth(pIndex), getHeight(pIndex));
size = new Dimension(getWidth(imageIndex), getHeight(imageIndex));
}
BufferedImage destination = getDestination(pParam, getImageTypes(pIndex), size.width, size.height);
BufferedImage destination = getDestination(param, getImageTypes(imageIndex), size.width, size.height);
// Read in the image, using the Batik Transcoder
processImageStarted(pIndex);
processImageStarted(imageIndex);
BufferedImage image = rasterizer.getImage();
@ -173,18 +173,18 @@ public class SVGImageReader extends ImageReaderBase {
return ex.getException() != null ? ex.getException() : ex;
}
private TranscodingHints paramsToHints(SVGReadParam pParam) throws IOException {
private TranscodingHints paramsToHints(SVGReadParam param) throws IOException {
TranscodingHints hints = new TranscodingHints();
// Note: We must allow generic ImageReadParams, so converting to
// TanscodingHints should be done outside the SVGReadParam class.
// Set dimensions
Dimension size = pParam.getSourceRenderSize();
Dimension size = param.getSourceRenderSize();
Rectangle viewBox = rasterizer.getViewBox();
if (size == null) {
// SVG is not a pixel based format, but we'll scale it, according to
// the subsampling for compatibility
size = getSourceRenderSizeFromSubsamping(pParam, viewBox.getSize());
size = getSourceRenderSizeFromSubsamping(param, viewBox.getSize());
}
if (size != null) {
@ -193,7 +193,7 @@ public class SVGImageReader extends ImageReaderBase {
}
// Set area of interest
Rectangle region = pParam.getSourceRegion();
Rectangle region = param.getSourceRegion();
if (region != null) {
hints.put(ImageTranscoder.KEY_AOI, region);
@ -217,7 +217,7 @@ public class SVGImageReader extends ImageReaderBase {
}
// Background color
Paint bg = pParam.getBackgroundColor();
Paint bg = param.getBackgroundColor();
if (bg != null) {
hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, bg);
}
@ -225,10 +225,10 @@ public class SVGImageReader extends ImageReaderBase {
return hints;
}
private Dimension getSourceRenderSizeFromSubsamping(ImageReadParam pParam, Dimension pOrigSize) {
if (pParam.getSourceXSubsampling() > 1 || pParam.getSourceYSubsampling() > 1) {
return new Dimension((int) (pOrigSize.width / (float) pParam.getSourceXSubsampling()),
(int) (pOrigSize.height / (float) pParam.getSourceYSubsampling()));
private Dimension getSourceRenderSizeFromSubsamping(ImageReadParam param, Dimension origSize) {
if (param.getSourceXSubsampling() > 1 || param.getSourceYSubsampling() > 1) {
return new Dimension((int) (origSize.width / (float) param.getSourceXSubsampling()),
(int) (origSize.height / (float) param.getSourceYSubsampling()));
}
return null;
}
@ -237,14 +237,14 @@ public class SVGImageReader extends ImageReaderBase {
return new SVGReadParam();
}
public int getWidth(int pIndex) throws IOException {
checkBounds(pIndex);
public int getWidth(int imageIndex) throws IOException {
checkBounds(imageIndex);
return rasterizer.getDefaultWidth();
}
public int getHeight(int pIndex) throws IOException {
checkBounds(pIndex);
public int getHeight(int imageIndex) throws IOException {
checkBounds(imageIndex);
return rasterizer.getDefaultHeight();
}
@ -601,6 +601,7 @@ public class SVGImageReader extends ImageReaderBase {
initialized = true;
try {
super.addTranscodingHint(SVGAbstractTranscoder.KEY_ALLOW_EXTERNAL_RESOURCES, allowExternalResources);
super.transcode(transcoderInput, null);
}
catch (TranscoderException e) {
@ -633,8 +634,8 @@ public class SVGImageReader extends ImageReaderBase {
return viewBox.getBounds();
}
void setInput(final TranscoderInput pInput) {
transcoderInput = pInput;
void setInput(final TranscoderInput input) {
transcoderInput = input;
}
@Override

View File

@ -60,22 +60,22 @@ public final class SVGImageReaderSpi extends ImageReaderSpiBase {
super(new SVGProviderInfo());
}
public boolean canDecodeInput(final Object pSource) throws IOException {
return pSource instanceof ImageInputStream && canDecode((ImageInputStream) pSource);
public boolean canDecodeInput(final Object source) throws IOException {
return source instanceof ImageInputStream && canDecode((ImageInputStream) source);
}
@SuppressWarnings("StatementWithEmptyBody")
private static boolean canDecode(final ImageInputStream pInput) throws IOException {
private static boolean canDecode(final ImageInputStream input) throws IOException {
// NOTE: This test is quite quick as it does not involve any parsing,
// however it may not recognize all kinds of SVG documents.
try {
pInput.mark();
input.mark();
// TODO: This is not ok for UTF-16 and other wide encodings
// TODO: Use an XML (encoding) aware Reader instance instead
// Need to figure out pretty fast if this is XML or not
int b;
while (Character.isWhitespace((char) (b = pInput.read()))) {
while (Character.isWhitespace((char) (b = input.read()))) {
// Skip over leading WS
}
@ -95,30 +95,30 @@ public final class SVGImageReaderSpi extends ImageReaderSpiBase {
byte[] buffer = new byte[4];
while (true) {
pInput.readFully(buffer);
input.readFully(buffer);
if (buffer[0] == '?') {
// This is the XML declaration or a processing instruction
while (!((pInput.readByte() & 0xFF) == '?' && pInput.read() == '>')) {
while (!((input.readByte() & 0xFF) == '?' && input.read() == '>')) {
// Skip until end of XML declaration or processing instruction or EOF
}
}
else if (buffer[0] == '!') {
if (buffer[1] == '-' && buffer[2] == '-') {
// This is a comment
while (!((pInput.readByte() & 0xFF) == '-' && pInput.read() == '-' && pInput.read() == '>')) {
while (!((input.readByte() & 0xFF) == '-' && input.read() == '-' && input.read() == '>')) {
// Skip until end of comment or EOF
}
}
else if (buffer[1] == 'D' && buffer[2] == 'O' && buffer[3] == 'C'
&& pInput.read() == 'T' && pInput.read() == 'Y'
&& pInput.read() == 'P' && pInput.read() == 'E') {
&& input.read() == 'T' && input.read() == 'Y'
&& input.read() == 'P' && input.read() == 'E') {
// This is the DOCTYPE declaration
while (Character.isWhitespace((char) (b = pInput.read()))) {
while (Character.isWhitespace((char) (b = input.read()))) {
// Skip over WS
}
if (b == 's' && pInput.read() == 'v' && pInput.read() == 'g') {
if (b == 's' && input.read() == 'v' && input.read() == 'g') {
// It's SVG, identified by DOCTYPE
return true;
}
@ -142,7 +142,7 @@ public final class SVGImageReaderSpi extends ImageReaderSpiBase {
return false;
}
while ((pInput.readByte() & 0xFF) != '<') {
while ((input.readByte() & 0xFF) != '<') {
// Skip over, until next begin tag or EOF
}
}
@ -153,7 +153,7 @@ public final class SVGImageReaderSpi extends ImageReaderSpiBase {
}
finally {
//noinspection ThrowFromFinallyBlock
pInput.reset();
input.reset();
}
}

View File

@ -51,16 +51,16 @@ public class SVGReadParam extends ImageReadParam {
return background;
}
public void setBackgroundColor(Paint pColor) {
background = pColor;
public void setBackgroundColor(Paint color) {
background = color;
}
public String getBaseURI() {
return baseURI;
}
public void setBaseURI(String pBaseURI) {
baseURI = pBaseURI;
public void setBaseURI(String baseURI) {
this.baseURI = baseURI;
}
public void setAllowExternalResources(boolean allow) {