Skip to content

Commit

Permalink
make field RenderingContext.fontContext final
Browse files Browse the repository at this point in the history
users needs to pass it right to constructor instead of calling setOutputDevice().
  • Loading branch information
asolntsev committed Sep 29, 2024
1 parent 634ba3c commit bdf3215
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public LayoutContext newLayoutContextInstance() {
return new LayoutContext(this);
}

public RenderingContext newRenderingContextInstance(OutputDevice outputDevice) {
return new RenderingContext(this, outputDevice);
public RenderingContext newRenderingContextInstance(OutputDevice outputDevice, FontContext fontContext) {
return new RenderingContext(this, outputDevice, fontContext);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class RenderingContext implements CssContext {
protected SharedContext sharedContext;
private final OutputDevice outputDevice;
private FontContext fontContext;
private final FontContext fontContext;

private int pageCount;

Expand All @@ -56,9 +56,10 @@ public class RenderingContext implements CssContext {
/**
* needs a new instance every run
*/
public RenderingContext(SharedContext sharedContext, OutputDevice outputDevice) {
public RenderingContext(SharedContext sharedContext, OutputDevice outputDevice, FontContext fontContext) {
this.sharedContext = sharedContext;
this.outputDevice = outputDevice;
this.fontContext = fontContext;
}

public void setContext(SharedContext sharedContext) {
Expand Down Expand Up @@ -178,10 +179,6 @@ public FontContext getFontContext() {
return fontContext;
}

public void setFontContext(FontContext fontContext) {
this.fontContext = fontContext;
}

public void setPage(int pageNo, PageBox page) {
this.pageNo = pageNo;
this.page = page;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ public Box render() {
newG.getRenderingHints().putAll(renderingHints);
}

RenderingContext rc = sharedContext.newRenderingContextInstance(outputDevice);
rc.setFontContext(new Java2DFontContext(newG));
RenderingContext rc = sharedContext.newRenderingContextInstance(outputDevice, new Java2DFontContext(newG));
sharedContext.getTextRenderer().setup(rc.getFontContext());

root.getLayer().paint(rc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ public BufferedImage getImage() {
outputImage = createBufferedImage(this.width, height);
outputDevice = new Java2DOutputDevice(outputImage);
withGraphics(outputImage, newG -> {
RenderingContext rc = sharedContext.newRenderingContextInstance(outputDevice);
rc.setFontContext(new Java2DFontContext(newG));
RenderingContext rc = sharedContext.newRenderingContextInstance(outputDevice, new Java2DFontContext(newG));
sharedContext.getTextRenderer().setup(rc.getFontContext());
root.getLayer().paint(rc);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public RenderingContext newRenderingContext(Graphics2D g) {

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ private Rectangle getInitialExtents(LayoutContext c) {
}

private RenderingContext newRenderingContext() {
RenderingContext result = _sharedContext.newRenderingContextInstance(_outputDevice);
result.setFontContext(new ITextFontContext());
RenderingContext result = _sharedContext.newRenderingContextInstance(_outputDevice, new ITextFontContext());
_sharedContext.getTextRenderer().setup(result.getFontContext());
result.setRootLayer(_root.getLayer());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ protected LayoutContext newLayoutcontext() {
* @return a new {@link RenderingContext}
*/
protected RenderingContext newRenderingContext(GC gc) {
RenderingContext result = _sharedContext.newRenderingContextInstance(new SWTOutputDevice(gc));
result.setFontContext(new SWTFontContext(gc));
RenderingContext result = _sharedContext.newRenderingContextInstance(new SWTOutputDevice(gc), new SWTFontContext(gc));
_sharedContext.getTextRenderer().setup(result.getFontContext());
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ protected LayoutContext newLayoutcontext(GC gc) {
}

protected RenderingContext newRenderingContext(GC gc) {
RenderingContext result = _sharedContext.newRenderingContextInstance(new SWTOutputDevice(gc));
result.setFontContext(new SWTFontContext(gc));
RenderingContext result = _sharedContext.newRenderingContextInstance(new SWTOutputDevice(gc), new SWTFontContext(gc));
_sharedContext.getTextRenderer().setup(result.getFontContext());
return result;
}
Expand Down

0 comments on commit bdf3215

Please sign in to comment.