Skip to content

Commit

Permalink
make field RenderingContext.rootLayer final
Browse files Browse the repository at this point in the history
users needs to pass it right to constructor instead of calling setRootLayer().
  • Loading branch information
asolntsev committed Sep 29, 2024
1 parent 03f389d commit cb0ed80
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ public LayoutContext newLayoutContextInstance() {
}

public RenderingContext newRenderingContextInstance(OutputDevice outputDevice, FontContext fontContext) {
return newRenderingContextInstance(outputDevice, fontContext, 0);
return newRenderingContextInstance(outputDevice, fontContext, null, 0);
}

public RenderingContext newRenderingContextInstance(OutputDevice outputDevice, FontContext fontContext, int initialPageNo) {
return new RenderingContext(this, outputDevice, fontContext, initialPageNo);
public RenderingContext newRenderingContextInstance(OutputDevice outputDevice, FontContext fontContext, @Nullable Layer rootLayer, int initialPageNo) {
return new RenderingContext(this, outputDevice, fontContext, rootLayer, initialPageNo);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.xhtmlrenderer.layout.Layer;
import org.xhtmlrenderer.layout.SharedContext;

import javax.annotation.Nullable;
import java.awt.*;

/**
Expand All @@ -49,17 +50,20 @@ public class RenderingContext implements CssContext {
private int pageNo;
private PageBox page;

private Layer rootLayer;
private final Layer rootLayer;

private final int initialPageNo;

/**
* needs a new instance every run
*/
public RenderingContext(SharedContext sharedContext, OutputDevice outputDevice, FontContext fontContext, int initialPageNo) {
public RenderingContext(SharedContext sharedContext, OutputDevice outputDevice, FontContext fontContext,
@Nullable Layer rootLayer,
int initialPageNo) {
this.sharedContext = sharedContext;
this.outputDevice = outputDevice;
this.fontContext = fontContext;
this.rootLayer = rootLayer;
this.initialPageNo = initialPageNo;
}

Expand Down Expand Up @@ -205,10 +209,6 @@ public Layer getRootLayer() {
return rootLayer;
}

public void setRootLayer(Layer rootLayer) {
this.rootLayer = rootLayer;
}

public int getInitialPageNo() {
return initialPageNo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,11 @@ public RenderingContext newRenderingContext(Graphics2D g) {

XRLog.layout(Level.FINEST, "new context end");

RenderingContext result = getSharedContext().newRenderingContextInstance(
new Java2DOutputDevice(g), new Java2DFontContext(g));

getSharedContext().getTextRenderer().setup(result.getFontContext());

Java2DFontContext fontContext = new Java2DFontContext(g);
getSharedContext().getTextRenderer().setup(fontContext);
final Box rb = getRootBox();
if (rb != null) {
result.setRootLayer(rb.getLayer());
}

return result;
Layer rootLayer = rb == null ? null : rb.getLayer();
return getSharedContext().newRenderingContextInstance(new Java2DOutputDevice(g), fontContext, rootLayer, 0);
}

protected LayoutContext newLayoutContext(Graphics2D g) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,9 @@ private Rectangle getInitialExtents(LayoutContext c) {
}

private RenderingContext newRenderingContext(int initialPageNo) {
RenderingContext result = _sharedContext.newRenderingContextInstance(_outputDevice, new ITextFontContext(), initialPageNo);
_sharedContext.getTextRenderer().setup(result.getFontContext());
result.setRootLayer(_root.getLayer());
return result;
ITextFontContext fontContext = new ITextFontContext();
_sharedContext.getTextRenderer().setup(fontContext);
return _sharedContext.newRenderingContextInstance(_outputDevice, fontContext, _root.getLayer(), initialPageNo);
}

private LayoutContext newLayoutContext() {
Expand Down

0 comments on commit cb0ed80

Please sign in to comment.