Skip to content

Commit

Permalink
make few fields in Java2DRenderer final
Browse files Browse the repository at this point in the history
converted "init" method (that was used only in constructor) to a constructor
  • Loading branch information
asolntsev committed Sep 30, 2024
1 parent 0a995db commit 17ec2cf
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class Java2DRenderer {
private static final int DEFAULT_DOTS_PER_PIXEL = 1;
private static final int DEFAULT_IMAGE_TYPE = BufferedImage.TYPE_INT_RGB;

private SharedContext sharedContext;
private final SharedContext sharedContext;
private Java2DOutputDevice outputDevice;

private Document doc;
Expand All @@ -96,7 +96,7 @@ public class Java2DRenderer {
private String sourceDocument;
private String sourceDocumentBase;
private final int width;
private int height;
private final int height;
private static final int NO_HEIGHT = -1;

public Java2DRenderer(String url, String baseUrl, int width, int height) {
Expand All @@ -116,13 +116,10 @@ public Java2DRenderer(String url, String baseUrl, int width, int height, int buf
// bypass scaling routines based on DPI -- see PDFRenderer and compare--dotsPerPoint is not implemented
// in all subordinate classes and interfaces for Java2D, so leaving it out
// leaving this constructor call here as a TODO
init();
this(width, height, bufferedImageType);

this.sourceDocument = url;
this.sourceDocumentBase = baseUrl;
this.width = width;
this.height = height;
this.bufferedImageType = bufferedImageType;
}

/**
Expand All @@ -146,11 +143,8 @@ public Java2DRenderer(File file, int width, int height) throws IOException {
* @param height Target height, in pixels, for the image.
*/
public Java2DRenderer(Document doc, int width, int height) {
init();
this(width, height, DEFAULT_IMAGE_TYPE);
this.doc = doc;
this.width = width;
this.height = height;
this.bufferedImageType = DEFAULT_IMAGE_TYPE;
}

public Java2DRenderer(Document doc, int width) {
Expand Down Expand Up @@ -247,7 +241,7 @@ public BufferedImage getImage() {

layout(this.width);

height = this.height == -1 ? root.getHeight() : this.height;
int height = this.height == -1 ? root.getHeight() : this.height;
outputImage = createBufferedImage(this.width, height);
outputDevice = new Java2DOutputDevice(outputImage);
withGraphics(outputImage, newG -> {
Expand Down Expand Up @@ -319,7 +313,11 @@ private LayoutContext newLayoutContext() {
return result;
}

private void init() {
private Java2DRenderer(int width, int height, int bufferedImageType) {
this.width = width;
this.height = height;
this.bufferedImageType = bufferedImageType;

outputImage = ImageUtil.createCompatibleBufferedImage(DEFAULT_DOTS_PER_POINT, DEFAULT_DOTS_PER_POINT);
outputDevice = new Java2DOutputDevice(outputImage);

Expand Down

0 comments on commit 17ec2cf

Please sign in to comment.