Skip to content

Commit

Permalink
ph-commons 11.1.5; Java 21 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Mar 27, 2024
1 parent 4860adc commit a06401b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Between v4.0.0 and v5.2.2 the `artifactId` was called `ph-pdf-layout4`
# News and Noteworthy

* v7.3.2 - work in progress
* Updated to ph-commons 11.1.5
* Created Java 21 compatibility
* Extracted a parent POM and prepared a submodule structure
* Using https://github.com/red6/pdfcompare to test created PDFs against the stored ones. See [issue #35](https://github.com/phax/ph-pdf-layout/issues/35) - thx @Lolf1010
* v7.3.1 - 2024-01-24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
* @param <IMPLTYPE>
* Implementation type
*/
public abstract class AbstractPLHBox <IMPLTYPE extends AbstractPLHBox <IMPLTYPE>> extends AbstractPLRenderableObject <IMPLTYPE> implements
public abstract class AbstractPLHBox <IMPLTYPE extends AbstractPLHBox <IMPLTYPE>> extends
AbstractPLRenderableObject <IMPLTYPE> implements
IPLSplittableObject <IMPLTYPE, IMPLTYPE>
{
private final ICommonsList <PLHBoxColumn> m_aColumns = new CommonsArrayList <> ();
Expand Down Expand Up @@ -137,13 +138,13 @@ public PLHBoxColumn getColumnAtIndex (@Nonnegative final int nIndex)
@Nullable
public PLHBoxColumn getFirstColumn ()
{
return m_aColumns.getFirst ();
return m_aColumns.getFirstOrNull ();
}

@Nullable
public PLHBoxColumn getLastColumn ()
{
return m_aColumns.getLast ();
return m_aColumns.getLastOrNull ();
}

@Nullable
Expand Down Expand Up @@ -177,7 +178,8 @@ private void _addAndReturnColumn (@CheckForSigned final int nIndex, @Nonnull fin
}

@Nonnull
public PLHBoxColumn addAndReturnColumn (@Nonnull final IPLRenderableObject <?> aElement, @Nonnull final WidthSpec aWidth)
public PLHBoxColumn addAndReturnColumn (@Nonnull final IPLRenderableObject <?> aElement,
@Nonnull final WidthSpec aWidth)
{
return addAndReturnColumn (-1, aElement, aWidth);
}
Expand Down Expand Up @@ -314,7 +316,8 @@ protected SizeSpec onPrepare (@Nonnull final PreparationContext aCtx)
float fUsedWidthAutoTooWide = 0;

// Full width of this element
final float fAvailableAutoColumnWidth = nAutoColumns + nStarColumns == 0 ? 0 : fRestWidth / (nAutoColumns + nStarColumns);
final float fAvailableAutoColumnWidth = nAutoColumns + nStarColumns == 0 ? 0 : fRestWidth /
(nAutoColumns + nStarColumns);
final float fAvailableAutoColumnWidthAll = fAvailableAutoColumnWidth * nAutoColumns;

final SizeSpec [] aTooWideAutoCols = new SizeSpec [m_aColumns.size ()];
Expand Down Expand Up @@ -381,7 +384,8 @@ protected SizeSpec onPrepare (@Nonnull final PreparationContext aCtx)

// Percentage of used width compared to total used width of all too
// wide columns (0-1)
final float fAvailableColumnWidthPerc = fUsedWidthAutoTooWide == 0 ? 0 : fTooWideColumnWidth / fUsedWidthAutoTooWide;
final float fAvailableColumnWidthPerc = fUsedWidthAutoTooWide == 0 ? 0 : fTooWideColumnWidth /
fUsedWidthAutoTooWide;

// Use x% of remaining width
final float fNewAvailableColumnWidth = fRemainingWidthAutoFull * fAvailableColumnWidthPerc;
Expand Down Expand Up @@ -461,7 +465,8 @@ protected SizeSpec onPrepare (@Nonnull final PreparationContext aCtx)
{
final AbstractPLElement <?> aRealElement = (AbstractPLElement <?>) aElement;
// Set minimum column width and height as prepared width
aRealElement.setMinSize (m_aPreparedColumnSizes[nIndex].getWidth () - aRealElement.getOutlineXSum (), fMaxContentHeightNet);
aRealElement.setMinSize (m_aPreparedColumnSizes[nIndex].getWidth () - aRealElement.getOutlineXSum (),
fMaxContentHeightNet);
}
++nIndex;
}
Expand All @@ -471,9 +476,15 @@ protected SizeSpec onPrepare (@Nonnull final PreparationContext aCtx)
if (PLDebugLog.isDebugPrepare ())
{
if (fUsedWidthFull - fElementWidth > 0.01)
PLDebugLog.debugPrepare (this, "uses more width (" + fUsedWidthFull + ") than available (" + fElementWidth + ")!");
PLDebugLog.debugPrepare (this,
"uses more width (" + fUsedWidthFull + ") than available (" + fElementWidth + ")!");
if (fMaxColumnHeightFull - fElementHeight > 0.01 && !isVertSplittable ())
PLDebugLog.debugPrepare (this, "uses more height (" + fMaxColumnHeightFull + ") than available (" + fElementHeight + ")!");
PLDebugLog.debugPrepare (this,
"uses more height (" +
fMaxColumnHeightFull +
") than available (" +
fElementHeight +
")!");
}

return new SizeSpec (fUsedWidthFull, fMaxColumnHeightFull);
Expand Down Expand Up @@ -555,8 +566,10 @@ public PLSplitResult splitElementVert (final float fAvailableWidth, final float
}
}

final AbstractPLHBox <?> aHBox1 = internalCreateNewVertSplitObject (thisAsT ()).setID (getID () + "-1").setVertSplittable (false);
final AbstractPLHBox <?> aHBox2 = internalCreateNewVertSplitObject (thisAsT ()).setID (getID () + "-2").setVertSplittable (true);
final AbstractPLHBox <?> aHBox1 = internalCreateNewVertSplitObject (thisAsT ()).setID (getID () + "-1")
.setVertSplittable (false);
final AbstractPLHBox <?> aHBox2 = internalCreateNewVertSplitObject (thisAsT ()).setID (getID () + "-2")
.setVertSplittable (true);

// Fill all columns with empty content
for (int i = 0; i < nCols; ++i)
Expand All @@ -568,9 +581,13 @@ public PLSplitResult splitElementVert (final float fAvailableWidth, final float

// Create empty element with the same width as the original element
final IPLRenderableObject <?> aSrcElement = aColumn.getElement ();
aHBox1.addColumn (internalCreateVertSplitEmptyElement (aSrcElement, fColumnWidth, fColumnHeight).setID (aSrcElement.getID () + "-1"),
aHBox1.addColumn (internalCreateVertSplitEmptyElement (aSrcElement,
fColumnWidth,
fColumnHeight).setID (aSrcElement.getID () + "-1"),
aColumnWidth);
aHBox2.addColumn (internalCreateVertSplitEmptyElement (aSrcElement, fColumnWidth, fColumnHeight).setID (aSrcElement.getID () + "-2"),
aHBox2.addColumn (internalCreateVertSplitEmptyElement (aSrcElement,
fColumnWidth,
fColumnHeight).setID (aSrcElement.getID () + "-2"),
aColumnWidth);
}

Expand Down Expand Up @@ -608,7 +625,8 @@ public PLSplitResult splitElementVert (final float fAvailableWidth, final float
PLDebugLog.getWH (fSplitWidth, fSplitHeight));

// Use width and height without padding and margin!
final PLSplitResult aSplitResult = aColumnElement.getAsSplittable ().splitElementVert (fSplitWidth, fSplitHeight);
final PLSplitResult aSplitResult = aColumnElement.getAsSplittable ()
.splitElementVert (fSplitWidth, fSplitHeight);
if (aSplitResult != null)
{
final IPLRenderableObject <?> aHBox1Element = aSplitResult.getFirstElement ().getElement ();
Expand Down Expand Up @@ -676,7 +694,8 @@ public PLSplitResult splitElementVert (final float fAvailableWidth, final float
aHBox1.getColumnAtIndex (nCol).internalSetElement (aColumnElement);

// Use "as-is sizes" and not render sizes
aHBox1ColumnSizes[nCol] = new SizeSpec (fColumnWidth, aColumnElement.getPreparedHeight () + aColumnElement.getOutlineYSum ());
aHBox1ColumnSizes[nCol] = new SizeSpec (fColumnWidth,
aColumnElement.getPreparedHeight () + aColumnElement.getOutlineYSum ());
aHBox2ColumnSizes[nCol] = new SizeSpec (fColumnWidth, 0);
aHBox1ElementSizes[nCol] = new SizeSpec (fElementWidthNet, aColumnElement.getPreparedHeight ());
aHBox2ElementSizes[nCol] = new SizeSpec (fElementWidthNet, 0);
Expand Down Expand Up @@ -706,15 +725,17 @@ public PLSplitResult splitElementVert (final float fAvailableWidth, final float
{
// Set minimum column width and height as prepared width
final AbstractPLElement <?> aRealElement1 = (AbstractPLElement <?>) aElement1;
aRealElement1.setMinSize (m_aPreparedColumnSizes[nIndex].getWidth () - aRealElement1.getOutlineXSum (), fHBox1MaxHeightNet);
aRealElement1.setMinSize (m_aPreparedColumnSizes[nIndex].getWidth () - aRealElement1.getOutlineXSum (),
fHBox1MaxHeightNet);
}

final IPLRenderableObject <?> aElement2 = aHBox2.getColumnElementAtIndex (nIndex);
if (aElement2 instanceof AbstractPLElement <?>)
{
// Set minimum column width and height as prepared width
final AbstractPLElement <?> aRealElement2 = (AbstractPLElement <?>) aElement2;
aRealElement2.setMinSize (m_aPreparedColumnSizes[nIndex].getWidth () - aRealElement2.getOutlineXSum (), fHBox2MaxHeightNet);
aRealElement2.setMinSize (m_aPreparedColumnSizes[nIndex].getWidth () - aRealElement2.getOutlineXSum (),
fHBox2MaxHeightNet);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public PLVBoxRow getRowAtIndex (@Nonnegative final int nIndex)
@Nullable
public PLVBoxRow getFirstRow ()
{
return m_aRows.getFirst ();
return m_aRows.getFirstOrNull ();
}

/**
Expand All @@ -175,7 +175,7 @@ public PLVBoxRow getFirstRow ()
@Nullable
public PLVBoxRow getLastRow ()
{
return m_aRows.getLast ();
return m_aRows.getLastOrNull ();
}

/**
Expand Down Expand Up @@ -652,7 +652,8 @@ protected SizeSpec onPrepare (@Nonnull final PreparationContext aCtx)
// Update used height
// If no height is left, use the net size of the element
final float fRowHeightFull = bTooSmallRestHeight ? aElementPreparedSize.getHeight () +
aElement.getOutlineYSum () : fRowHeight;
aElement.getOutlineYSum ()
: fRowHeight;
fUsedHeightFull += fRowHeightFull;
// Don't change rest-height!

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<dependency>
<groupId>com.helger.commons</groupId>
<artifactId>ph-commons-parent-pom</artifactId>
<version>11.1.4</version>
<version>11.1.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down

0 comments on commit a06401b

Please sign in to comment.