Skip to content

Commit

Permalink
#429 [refactor] replace few setters in InlineBoxMeasurements by con…
Browse files Browse the repository at this point in the history
…structor parameters
  • Loading branch information
asolntsev committed Oct 30, 2024
1 parent b8aa47a commit 99761e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,8 @@ private static void positionVertically(
current.setHeight(0);
} else {
FSFontMetrics strutM = container.getStyle().getFSFontMetrics(c);
VerticalAlignContext vaContext = new VerticalAlignContext();
InlineBoxMeasurements measurements = getInitialMeasurements(c, container, strutM);
vaContext.setInitialMeasurements(measurements);
VerticalAlignContext vaContext = new VerticalAlignContext(measurements);

List<TextDecoration> lBDecorations = calculateTextDecorations(container, measurements.getBaseline(), strutM);
current.setTextDecorations(lBDecorations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.xhtmlrenderer.layout;

import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.css.constants.CSSName;
import org.xhtmlrenderer.css.constants.IdentValue;
import org.xhtmlrenderer.render.Box;
Expand All @@ -27,6 +28,8 @@
import java.util.ArrayList;
import java.util.List;

import static java.util.Objects.requireNonNullElse;

/**
* This class performs the real work of vertically positioning inline boxes
* within a line (i.e. implementing the vertical-align property). Because
Expand All @@ -51,7 +54,17 @@ public class VerticalAlignContext {

private final List<ChildContextData> _children = new ArrayList<>();

private VerticalAlignContext _parent = null;
@Nullable
private final VerticalAlignContext _parent;

public VerticalAlignContext(VerticalAlignContext parent) {
_parent = parent;
}

public VerticalAlignContext(InlineBoxMeasurements initialMeasurements) {
_parent = null;
_measurements.add(initialMeasurements);
}

private void moveTrackedValues(int ty) {
if (_inlineTopSet) {
Expand Down Expand Up @@ -138,13 +151,10 @@ public int getPaintingTop() {
}

public VerticalAlignContext createChild(Box root) {
VerticalAlignContext result = new VerticalAlignContext();

VerticalAlignContext vaRoot = getRoot();

result.setParent(vaRoot);

InlineBoxMeasurements initial = vaRoot._measurements.get(0);

VerticalAlignContext result = new VerticalAlignContext(vaRoot);
result.pushMeasurements(initial);

vaRoot._children.add(new ChildContextData(root, result));
Expand All @@ -155,17 +165,13 @@ private List<ChildContextData> getChildren() {
return _children;
}

@Nullable
public VerticalAlignContext getParent() {
return _parent;
}

public void setParent(VerticalAlignContext parent) {
_parent = parent;
}

private VerticalAlignContext getRoot() {
VerticalAlignContext result = this;
return result.getParent() != null ? result.getParent() : this;
return requireNonNullElse(_parent, this);
}

private void merge(VerticalAlignContext context) {
Expand All @@ -184,10 +190,6 @@ public void alignChildren() {
}
}

public void setInitialMeasurements(InlineBoxMeasurements measurements) {
_measurements.add(measurements);
}

private static final class ChildContextData {
private final Box _root;
private final VerticalAlignContext _verticalAlignContext;
Expand Down

0 comments on commit 99761e0

Please sign in to comment.