diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/context/ContentFunctionFactory.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/context/ContentFunctionFactory.java index 3697c91cd..d18edecb8 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/context/ContentFunctionFactory.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/context/ContentFunctionFactory.java @@ -19,7 +19,8 @@ */ package org.xhtmlrenderer.context; -import org.w3c.dom.css.CSSPrimitiveValue; +import com.google.errorprone.annotations.CheckReturnValue; +import org.jspecify.annotations.Nullable; import org.xhtmlrenderer.css.constants.IdentValue; import org.xhtmlrenderer.css.extend.ContentFunction; import org.xhtmlrenderer.css.parser.FSFunction; @@ -35,6 +36,10 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; + +import static org.w3c.dom.css.CSSPrimitiveValue.CSS_IDENT; +import static org.w3c.dom.css.CSSPrimitiveValue.CSS_STRING; public class ContentFunctionFactory { private final List _functions = new ArrayList<>(); @@ -46,6 +51,7 @@ public ContentFunctionFactory() { _functions.add(new LeaderFunction()); } + @Nullable public ContentFunction lookupFunction(LayoutContext c, FSFunction function) { for (ContentFunction f : _functions) { if (f.canHandle(c, function)) { @@ -65,6 +71,7 @@ public boolean isStatic() { return false; } + @Nullable @Override public String calculate(LayoutContext c, FSFunction function) { return null; @@ -95,14 +102,14 @@ protected boolean isCounter(FSFunction function, String counterName) { List parameters = function.getParameters(); if (parameters.size() == 1 || parameters.size() == 2) { PropertyValue param = parameters.get(0); - if (param.getPrimitiveType() != CSSPrimitiveValue.CSS_IDENT || - ! param.getStringValue().equals(counterName)) { + if (param.getPrimitiveType() != CSS_IDENT || + !Objects.equals(param.getStringValue(), counterName)) { return false; } if (parameters.size() == 2) { param = parameters.get(1); - return param.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT; + return param.getPrimitiveType() == CSS_IDENT; } return true; @@ -163,6 +170,7 @@ public String calculate(RenderingContext c, FSFunction function, InlineText text return ""; } + @Nullable @Override public String calculate(LayoutContext c, FSFunction function) { return null; @@ -181,14 +189,14 @@ public boolean canHandle(LayoutContext c, FSFunction function) { FSFunction f = parameters.get(0).getFunction(); if (f == null || f.getParameters().size() != 1 || - f.getParameters().get(0).getPrimitiveType() != CSSPrimitiveValue.CSS_IDENT || - ! f.getParameters().get(0).getStringValue().equals("href")) { + f.getParameters().get(0).getPrimitiveType() != CSS_IDENT || + ! "href".equals(f.getParameters().get(0).getStringValue())) { return false; } PropertyValue param = parameters.get(1); - return param.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT && - param.getStringValue().equals("page"); + return param.getPrimitiveType() == CSS_IDENT && + Objects.equals(param.getStringValue(), "page"); } } @@ -253,10 +261,12 @@ public String calculate(RenderingContext c, FSFunction function, InlineText text return leaderString; } + @Nullable + @CheckReturnValue private String getLeaderValue(FSFunction function) { final PropertyValue param = function.getParameters().get(0); final String value = param.getStringValue(); - if (param.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { + if (param.getPrimitiveType() == CSS_IDENT) { return switch (value) { case "dotted" -> ". "; case "solid" -> "_"; @@ -267,27 +277,30 @@ private String getLeaderValue(FSFunction function) { return value; } + @Nullable @Override public String calculate(LayoutContext c, FSFunction function) { return null; } @Override + @CheckReturnValue public String getLayoutReplacementText() { return " . "; } @Override + @CheckReturnValue public boolean canHandle(LayoutContext c, FSFunction function) { if (c.isPrint() && function.is("leader")) { List parameters = function.getParameters(); if (parameters.size() == 1) { PropertyValue param = parameters.get(0); - return param.getPrimitiveType() == CSSPrimitiveValue.CSS_STRING || - (param.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT && - (param.getStringValue().equals("dotted") || - param.getStringValue().equals("solid") || - param.getStringValue().equals("space"))); + return param.getPrimitiveType() == CSS_STRING || + (param.getPrimitiveType() == CSS_IDENT && + ("dotted".equals(param.getStringValue()) || + "solid".equals(param.getStringValue()) || + "space".equals(param.getStringValue()))); } } diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/newmatch/Selector.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/newmatch/Selector.java index 119cde61a..74ef3eb3d 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/newmatch/Selector.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/newmatch/Selector.java @@ -480,5 +480,10 @@ public void setSiblingSelector(Selector selector) { public void setNamespaceURI(String namespaceURI) { _namespaceURI = namespaceURI; } + + @Override + public String toString() { + return "%s{%s}".formatted(getClass().getSimpleName(), _name); + } } diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java index e8ce21c3d..a93bd8107 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java @@ -79,7 +79,7 @@ public CSSParser(CSSErrorHandler errorHandler) { } @CheckReturnValue - public Stylesheet parseStylesheet(String uri, Origin origin, Reader reader) throws IOException { + public Stylesheet parseStylesheet(@Nullable String uri, Origin origin, Reader reader) throws IOException { _uri = uri; reset(reader); diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/sheet/Ruleset.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/sheet/Ruleset.java index c47af92f2..a6077acf8 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/sheet/Ruleset.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/sheet/Ruleset.java @@ -70,4 +70,8 @@ public Origin getOrigin() { return _origin; } + @Override + public String toString() { + return "%s{%s %s %s}".formatted(getClass().getSimpleName(), _origin, _props, _fsSelectors); + } } diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/extend/OutputDevice.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/extend/OutputDevice.java index 2a6391463..49c8ee938 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/extend/OutputDevice.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/extend/OutputDevice.java @@ -76,6 +76,7 @@ void paintBackground( void fillOval(int x, int y, int width, int height); void clip(Shape s); + @Nullable Shape getClip(); void setClip(Shape s); diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/LayoutContext.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/LayoutContext.java index 74dd992d3..4a05ca09e 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/LayoutContext.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/LayoutContext.java @@ -77,16 +77,21 @@ public class LayoutContext implements CssContext { private final Map _counterContextMap = new HashMap<>(); + @Nullable private String _pendingPageName; + @Nullable private String _pageName; private int _noPageBreak; + @Nullable private Layer _rootDocumentLayer; + @Nullable private PageBox _page; private boolean _mayCheckKeepTogether = true; + @Nullable private BreakAtLineContext _breakAtLineContext; public TextRenderer getTextRenderer() { @@ -510,14 +515,18 @@ public boolean isPageBreaksAllowed() { return _noPageBreak == 0; } + @Nullable + @CheckReturnValue public String getPendingPageName() { return _pendingPageName; } - public void setPendingPageName(String pendingPageName) { + public void setPendingPageName(@Nullable String pendingPageName) { _pendingPageName = pendingPageName; } + @Nullable + @CheckReturnValue public Layer getRootDocumentLayer() { return _rootDocumentLayer; } @@ -542,11 +551,13 @@ public void setMayCheckKeepTogether(boolean mayKeepTogether) { _mayCheckKeepTogether = mayKeepTogether; } + @Nullable + @CheckReturnValue public BreakAtLineContext getBreakAtLineContext() { return _breakAtLineContext; } - public void setBreakAtLineContext(BreakAtLineContext breakAtLineContext) { + public void setBreakAtLineContext(@Nullable BreakAtLineContext breakAtLineContext) { _breakAtLineContext = breakAtLineContext; } } diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/LayoutState.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/LayoutState.java index c162152d3..04f62166b 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/LayoutState.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/LayoutState.java @@ -19,6 +19,7 @@ */ package org.xhtmlrenderer.layout; +import org.jspecify.annotations.Nullable; import org.xhtmlrenderer.render.MarkerData; import java.util.LinkedList; @@ -50,6 +51,7 @@ public void setBFCs(LinkedList s) { _BFCs = s; } + @Nullable public MarkerData getCurrentMarkerData() { return _currentMarkerData; } diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/VerticalAlignContext.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/VerticalAlignContext.java index 8e2f61925..7a3ce5c77 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/VerticalAlignContext.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/layout/VerticalAlignContext.java @@ -197,10 +197,6 @@ public ChildContextData(Box root, VerticalAlignContext vaContext) { _verticalAlignContext = vaContext; } - public Box getRoot() { - return _root; - } - public VerticalAlignContext getVerticalAlignContext() { return _verticalAlignContext; } diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/newtable/TableBox.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/newtable/TableBox.java index b5519b04f..804f6fa9f 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/newtable/TableBox.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/newtable/TableBox.java @@ -55,9 +55,11 @@ // to the KHTML developers for making such an amazing piece of software! public class TableBox extends BlockBox { private final List _columns = new ArrayList<>(); - private int[] _columnPos; + private int @Nullable [] _columnPos; + @Nullable private TableLayout _tableLayout; + @Nullable private List _styleColumns; private int _pageClearance; @@ -1182,7 +1184,9 @@ public void layout(LayoutContext c) { private static class AutoTableLayout implements TableLayout { private final TableBox _table; + @Nullable private Layout[] _layoutStruct; + @Nullable private List _spanCells; private AutoTableLayout(TableBox table) { @@ -1195,6 +1199,7 @@ public void reset() { _spanCells = null; } + @Nullable protected Layout[] getLayoutStruct() { return _layoutStruct; } @@ -1515,10 +1520,6 @@ private long calcEffectiveWidth(LayoutContext c) { return tMaxWidth; } - private boolean shouldScaleColumns(TableBox table) { - return true; - } - @Override public void calcMinMaxWidth(LayoutContext c) { TableBox table = _table; @@ -1547,12 +1548,9 @@ public void calcMinMaxWidth(LayoutContext c) { } } - if (shouldScaleColumns(table)) { - maxNonPercent = (maxNonPercent * 100 + 50) / Math.max(remainingPercent, 1); - maxWidth = Math.max(maxNonPercent, maxWidth); - maxWidth = Math.max(maxWidth, maxPercent); - } - + maxNonPercent = (maxNonPercent * 100 + 50) / Math.max(remainingPercent, 1); + maxWidth = Math.max(maxNonPercent, maxWidth); + maxWidth = Math.max(maxWidth, maxPercent); maxWidth = Math.max(maxWidth, spanMaxWidth); int bs = table.marginsBordersPaddingAndSpacing(c, true); diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/render/BorderPainter.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/render/BorderPainter.java index 2235941c6..c5d2a8648 100755 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/render/BorderPainter.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/render/BorderPainter.java @@ -72,7 +72,7 @@ public static Path2D generateBorderShape(Rectangle bounds, int side, BorderPrope * @param side what side you want * @param border border props * @param drawInterior if you want it to be 2d or not, if false it will be just a line - * @param scaledOffset insets the border by multipling border widths by this variable, best use would be 1 or .5, cant see it for much other than that + * @param scaledOffset insets the border by multiplying border widths by this variable, best use would be 1 or .5, cant see it for much other than that * @return a path for the side chosen! */ public static Path2D generateBorderShape(Rectangle bounds, int side, BorderPropertySet border, boolean drawInterior, float scaledOffset) { @@ -85,7 +85,7 @@ public static Path2D generateBorderShape(Rectangle bounds, int side, BorderPrope * @param side what side you want * @param border border props * @param drawInterior if you want it to be 2d or not, if false it will be just a line - * @param scaledOffset insets the border by multipling border widths by this variable, best use would be 1 or .5, cant see it for much other than that + * @param scaledOffset insets the border by multiplying border widths by this variable, best use would be 1 or .5, cant see it for much other than that * @param widthScale scales the border widths by this factor, useful for drawing half borders for border types like groove or double * @return a path for the side chosen! */ diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/Java2DOutputDevice.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/Java2DOutputDevice.java index 7376e5609..0754df137 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/Java2DOutputDevice.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/Java2DOutputDevice.java @@ -219,6 +219,8 @@ public void setClip(Shape s) { _graphics.setClip(s); } + @Nullable + @CheckReturnValue @Override public Shape getClip() { return _graphics.getClip(); diff --git a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java index fdb7bbc48..06dd80e6a 100644 --- a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java +++ b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java @@ -798,6 +798,8 @@ public void clip(Shape s) { } } + @Nullable + @CheckReturnValue @Override public Shape getClip() { try { diff --git a/flying-saucer-swt/src/main/java/org/xhtmlrenderer/swt/SWTOutputDevice.java b/flying-saucer-swt/src/main/java/org/xhtmlrenderer/swt/SWTOutputDevice.java index 5fbd1568d..9e38164ce 100644 --- a/flying-saucer-swt/src/main/java/org/xhtmlrenderer/swt/SWTOutputDevice.java +++ b/flying-saucer-swt/src/main/java/org/xhtmlrenderer/swt/SWTOutputDevice.java @@ -124,6 +124,8 @@ public void setClip(Shape s) { _clippingArea = (s == null ? null : new Area(s)); } + @Nullable + @CheckReturnValue @Override public Shape getClip() { return _clippingArea;