Skip to content

Commit

Permalink
#429 [refactor] make class PaintingInfo immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Oct 30, 2024
1 parent f4e656c commit b8aa47a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
*/
package org.xhtmlrenderer.layout;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.*;

/**
* A bean which every box uses to provide its aggregate bounds (which may be
Expand All @@ -30,34 +29,26 @@
* overflow property into account.
*/
public class PaintingInfo {
private Dimension _outerMarginCorner;
private Rectangle _aggregateBounds;
private final Dimension _outerMarginCorner;
private final Rectangle _aggregateBounds;

public PaintingInfo() {
public PaintingInfo(Dimension outerMarginCorner, Rectangle aggregateBounds) {
_outerMarginCorner = outerMarginCorner;
_aggregateBounds = aggregateBounds;
}

public Rectangle getAggregateBounds() {
return _aggregateBounds;
}

public void setAggregateBounds(Rectangle aggregateBounds) {
_aggregateBounds = aggregateBounds;
}

public Dimension getOuterMarginCorner() {
return _outerMarginCorner;
}

public void setOuterMarginCorner(Dimension outerMarginCorner) {
_outerMarginCorner = outerMarginCorner;
}

public PaintingInfo copyOf() {
PaintingInfo result = new PaintingInfo();
result.setOuterMarginCorner(new Dimension(_outerMarginCorner));
result.setAggregateBounds(new Rectangle(_aggregateBounds));

return result;
return new PaintingInfo(
new Dimension(_outerMarginCorner), new Rectangle(_aggregateBounds)
);
}

public void translate(int tx, int ty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,13 +804,12 @@ public PaintingInfo calcPaintingInfo(CssContext c, boolean useCache) {
return cached;
}

final PaintingInfo result = new PaintingInfo();

Rectangle bounds = getMarginEdge(getAbsX(), getAbsY(), c, 0, 0);
result.setOuterMarginCorner(
new Dimension(bounds.x + bounds.width, bounds.y + bounds.height));

result.setAggregateBounds(getPaintingClipEdge(c));
PaintingInfo result = new PaintingInfo(
new Dimension(bounds.x + bounds.width, bounds.y + bounds.height),
getPaintingClipEdge(c)
);

if (!getStyle().isOverflowApplies() || getStyle().isOverflowVisible()) {
calcChildPaintingInfo(c, result, useCache);
Expand Down

0 comments on commit b8aa47a

Please sign in to comment.