Skip to content

Commit

Permalink
#431 [bugfix] don't use "hidden" as a "border is undefined"
Browse files Browse the repository at this point in the history
hidden means "border is hidden", and it hides the border :)
  • Loading branch information
asolntsev committed Oct 28, 2024
1 parent 221b161 commit 6e72d1e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.xhtmlrenderer.css.style.derived;

import com.google.errorprone.annotations.CheckReturnValue;
import com.google.errorprone.annotations.InlineMe;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.css.constants.CSSName;
Expand Down Expand Up @@ -38,11 +39,11 @@
*/
public class BorderPropertySet extends RectPropertySet {
private static final Corners NO_CORNERS = new Corners(BorderRadiusCorner.UNDEFINED, BorderRadiusCorner.UNDEFINED, BorderRadiusCorner.UNDEFINED, BorderRadiusCorner.UNDEFINED);
private static final Styles NO_STYLES = new Styles(HIDDEN, HIDDEN, HIDDEN, HIDDEN);
private static final Styles NO_STYLES = new Styles(null, null, null, null);
private static final Colors NO_COLORS = new Colors(TRANSPARENT, TRANSPARENT, TRANSPARENT, TRANSPARENT);
public static final BorderPropertySet EMPTY_BORDER = new BorderPropertySet(0.0f, 0.0f, 0.0f, 0.0f, NO_STYLES, NO_CORNERS, NO_COLORS);

private record Styles(IdentValue top, IdentValue right, IdentValue bottom, IdentValue left) {
private record Styles(@Nullable IdentValue top, @Nullable IdentValue right, @Nullable IdentValue bottom, @Nullable IdentValue left) {
private boolean hasHidden() {
return top == HIDDEN || right == HIDDEN || bottom == HIDDEN || left == HIDDEN;
}
Expand Down Expand Up @@ -211,18 +212,26 @@ public boolean noLeft() {
return styles.left() == NONE || (int) left() == 0;
}

@Nullable
@CheckReturnValue
public IdentValue topStyle() {
return styles.top();
}

@Nullable
@CheckReturnValue
public IdentValue rightStyle() {
return styles.right();
}

@Nullable
@CheckReturnValue
public IdentValue bottomStyle() {
return styles.bottom();
}

@Nullable
@CheckReturnValue
public IdentValue leftStyle() {
return styles.left();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@
*/
package org.xhtmlrenderer.newtable;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.css.constants.IdentValue;
import org.xhtmlrenderer.css.parser.FSColor;
import org.xhtmlrenderer.css.style.derived.BorderPropertySet;

/**
* This class encapsulates all information related to a particular border side
* along with an overall precedence (e.g. cell borders take precendence over
* along with an overall precedence (e.g. cell borders take precedence over
* row borders). It is used when comparing overlapping borders when calculating
* collapsed borders.
*/
public class CollapsedBorderValue {
@Nullable
private final IdentValue _style;
private final int _width;
private final FSColor _color;
private final int _precedence;

public CollapsedBorderValue(IdentValue style, int width, FSColor color, int precedence) {
public CollapsedBorderValue(@Nullable IdentValue style, int width, FSColor color, int precedence) {
_style = style;
_width = width;
_color = color;
Expand All @@ -46,49 +49,61 @@ public FSColor color() {
return _color;
}

@Nullable
@CheckReturnValue
public IdentValue style() {
return _style;
}

@CheckReturnValue
public int width() {
return _width;
}

@CheckReturnValue
public CollapsedBorderValue withWidth(int width) {
return new CollapsedBorderValue(_style, width, _color, _precedence);
}

@CheckReturnValue
public int precedence() {
return _precedence;
}

@CheckReturnValue
public boolean defined() {
return _style != null;
}

@CheckReturnValue
public boolean exists() {
return _style != null && _style != IdentValue.NONE && _style != IdentValue.HIDDEN;
}

@CheckReturnValue
public boolean hidden() {
return _style == IdentValue.HIDDEN;
}

@CheckReturnValue
public static CollapsedBorderValue borderLeft(BorderPropertySet border, int precedence) {
return new CollapsedBorderValue(
border.leftStyle(), (int)border.left(), border.leftColor(), precedence);
}

@CheckReturnValue
public static CollapsedBorderValue borderRight(BorderPropertySet border, int precedence) {
return new CollapsedBorderValue(
border.rightStyle(), (int)border.right(), border.rightColor(), precedence);
}

@CheckReturnValue
public static CollapsedBorderValue borderTop(BorderPropertySet border, int precedence) {
return new CollapsedBorderValue(
border.topStyle(), (int)border.top(), border.topColor(), precedence);
}

@CheckReturnValue
public static CollapsedBorderValue borderBottom(BorderPropertySet border, int precedence) {
return new CollapsedBorderValue(
border.bottomStyle(), (int)border.bottom(), border.bottomColor(), precedence);
Expand Down

0 comments on commit 6e72d1e

Please sign in to comment.