use of org.loboevolution.html.style.HtmlLength in project LoboEvolution by LoboEvolution.
the class TableMatrixSizes method determineRowSizes.
void determineRowSizes(int hasBorder, int cellSpacing, int availHeight, boolean sizeOnly) {
final HtmlLength tableHeightLength = TableMatrixSizes.getHeightLength(matrix.tableElement, availHeight);
int tableHeight;
final SizeInfo[] rowSizes = matrix.rowSizes;
final int heightsOfExtras = matrix.heightsOfExtras;
if (tableHeightLength != null) {
tableHeight = tableHeightLength.getLength(availHeight);
determineRowSizesFixedTH(hasBorder, cellSpacing, availHeight, tableHeight, sizeOnly);
} else {
tableHeight = heightsOfExtras;
for (SizeInfo rowSize : rowSizes) {
tableHeight += rowSize.getMinSize();
}
determineRowSizesFlexibleTH(hasBorder, cellSpacing, availHeight, sizeOnly);
}
}
use of org.loboevolution.html.style.HtmlLength in project LoboEvolution by LoboEvolution.
the class TableMatrixSizes method columnSizes.
private SizeInfo[] columnSizes(List<ArrayList<VirtualCell>> rows, int numCols) {
final SizeInfo[] columnSizes = new SizeInfo[numCols];
for (int i = 0; i < numCols; i++) {
HtmlLength bestWidthLength = null;
// Cells with colspan==1 first.
for (final List<VirtualCell> row : rows) {
VirtualCell vc = row.size() > i ? row.get(i) : null;
if (vc != null) {
final RTableCell ac = vc.getActualCell();
if (ac.getColSpan() == 1) {
final HtmlLength vcWidthLength = vc.getWidthLength();
if (vcWidthLength != null && vcWidthLength.isPreferredOver(bestWidthLength)) {
bestWidthLength = vcWidthLength;
}
}
}
}
// Now cells with colspan>1.
if (bestWidthLength == null) {
for (final List<VirtualCell> row : rows) {
VirtualCell vc = row.size() > i ? row.get(i) : null;
if (vc != null) {
final RTableCell ac = vc.getActualCell();
if (ac.getColSpan() > 1) {
final HtmlLength vcWidthLength = vc.getWidthLength();
if (vcWidthLength != null && vcWidthLength.isPreferredOver(bestWidthLength)) {
bestWidthLength = vcWidthLength;
}
}
}
}
}
final SizeInfo colSizeInfo = new SizeInfo();
colSizeInfo.setHtmlLength(bestWidthLength);
columnSizes[i] = colSizeInfo;
}
return columnSizes;
}
use of org.loboevolution.html.style.HtmlLength in project LoboEvolution by LoboEvolution.
the class TableMatrixSizes method expandColumns.
private int expandColumns(SizeInfo[] columnSizes, int cellAvailWidth, boolean expand, int hasBorder, int cellSpacingX, int currentTotal, int numCols, int difference) {
int noWidthTotal = 0;
int numNoWidth = 0;
for (int i = 0; i < numCols; i++) {
if (columnSizes[i].getHtmlLength() == null) {
numNoWidth++;
noWidthTotal += columnSizes[i].getActualSize();
}
}
if (noWidthTotal > 0) {
currentTotal = adjustCurrentTotal2(columnSizes, matrix.rowSizes, matrix.rows, cellSpacingX, numCols, noWidthTotal, difference, cellSpacingX, hasBorder, numNoWidth, cellAvailWidth, currentTotal);
difference = currentTotal - cellAvailWidth;
}
// See if absolutes need to be contracted
if (difference > 0 || difference < 0 && expand) {
int absoluteWidthTotal = 0;
for (int i = 0; i < numCols; i++) {
HtmlLength widthLength = (HtmlLength) columnSizes[i].getHtmlLength();
if (widthLength != null && widthLength.getLengthType() != HtmlLength.LENGTH) {
absoluteWidthTotal += columnSizes[i].getActualSize();
}
}
if (absoluteWidthTotal > 0) {
currentTotal = adjustCurrentTotal(columnSizes, matrix.rowSizes, matrix.rows, matrix.cellSpacingY, numCols, absoluteWidthTotal, difference, cellSpacingX, hasBorder, currentTotal);
difference = currentTotal - cellAvailWidth;
}
// See if percentages need to be contracted
if (difference > 0 || difference < 0 && expand) {
int percentWidthTotal = 0;
for (int i = 0; i < numCols; i++) {
HtmlLength widthLength = (HtmlLength) columnSizes[i].getHtmlLength();
if (widthLength != null && widthLength.getLengthType() == HtmlLength.LENGTH) {
percentWidthTotal += columnSizes[i].getActualSize();
}
}
if (percentWidthTotal > 0) {
currentTotal = adjustCurrentTotal(columnSizes, matrix.rowSizes, matrix.rows, matrix.cellSpacingY, numCols, percentWidthTotal, difference, cellSpacingX, hasBorder, currentTotal);
}
}
}
return currentTotal;
}
use of org.loboevolution.html.style.HtmlLength in project LoboEvolution by LoboEvolution.
the class TableMatrixSizes method determineColumnSizes.
/**
* Determines the size of each column, and the table width. Does the following:
* <ol>
* <li>Determine tentative widths. This is done by looking at declared column
* widths, any table width, and filling in the blanks. No rendering is done. The
* tentative width of columns with no declared width is zero.
*
* <li>Render all cell blocks. It uses the tentative widths from the previous
* step as a desired width. The resulting width is considered a sort of minimum.
* If the column width is not defined, use a NOWRAP override flag to render.
*
* <li>Check if cell widths are too narrow for the rendered width. In the case
* of columns without a declared width, check if they are too wide.
*
* <li>Finally, adjust widths considering the expected max table size. Columns
* are layed out again if necessary to determine if they can really be shrunk.
* </ol>
*
* @param hasBorder
* @param cellSpacingX
* @param cellSpacingY
* @param availWidth
*/
void determineColumnSizes(int hasBorder, int cellSpacingX, int cellSpacingY, int availWidth) {
final HtmlLength tableWidthLength = matrix.tableWidthLength;
int tableWidth;
boolean widthKnown;
if (tableWidthLength != null) {
tableWidth = tableWidthLength.getLength(availWidth);
widthKnown = true;
} else {
tableWidth = availWidth;
widthKnown = false;
}
final SizeInfo[] columnSizes = matrix.columnSizes;
final int widthsOfExtras = matrix.widthsOfExtras;
int cellAvailWidth = tableWidth - widthsOfExtras;
if (cellAvailWidth < 0) {
tableWidth += -cellAvailWidth;
cellAvailWidth = 0;
}
// Determine tentative column widths based on specified cell widths
determineTentativeSizes(columnSizes, widthsOfExtras, cellAvailWidth, widthKnown);
// Pre-render cells. This will give the minimum width of each cell,
// in addition to the minimum height.
preLayout(hasBorder, cellSpacingX, cellSpacingY, widthKnown);
// Increases column widths if they are less than minimums of each cell.
adjustForRenderWidths(columnSizes, hasBorder, cellSpacingX, widthKnown);
// Adjust for expected total width
adjustWidthsForExpectedMax(columnSizes, cellAvailWidth, widthKnown, matrix.captionSize != null ? matrix.captionSize.getWidth() : 0, widthsOfExtras);
}
use of org.loboevolution.html.style.HtmlLength in project LoboEvolution by LoboEvolution.
the class TableMatrixSizes method determineRowSizesFlexibleTH.
private void determineRowSizesFlexibleTH(int hasBorder, int cellSpacing, int availHeight, boolean sizeOnly) {
final SizeInfo[] rowSizes = matrix.rowSizes;
final int heightsOfExtras = matrix.heightsOfExtras;
// Look at rows with absolute sizes
int heightUsedByAbsolute = 0;
int percentSum = 0;
for (final SizeInfo rowSizeInfo : rowSizes) {
final HtmlLength heightLength = (HtmlLength) rowSizeInfo.getHtmlLength();
if (heightLength != null && heightLength.getLengthType() == HtmlLength.PIXELS) {
int actualSizeInt = heightLength.getRawValue();
if (actualSizeInt < rowSizeInfo.getMinSize()) {
actualSizeInt = rowSizeInfo.getMinSize();
}
heightUsedByAbsolute += actualSizeInt;
rowSizeInfo.setActualSize(actualSizeInt);
} else if (heightLength != null && heightLength.getLengthType() == HtmlLength.LENGTH) {
percentSum += heightLength.getRawValue();
}
}
// Look at rows with no specified heights
int heightUsedByNoSize = 0;
// Set sizes to in row height
for (final SizeInfo rowSizeInfo : rowSizes) {
final HtmlLength widthLength = (HtmlLength) rowSizeInfo.getHtmlLength();
if (widthLength == null) {
final int actualSizeInt = rowSizeInfo.getMinSize();
heightUsedByNoSize += actualSizeInt;
rowSizeInfo.setActualSize(actualSizeInt);
}
}
// Calculate actual total cell width
final int expectedTotalCellHeight = (int) Math.round((heightUsedByAbsolute + heightUsedByNoSize) / (1 - percentSum / 100.0));
// Set widths of columns with percentages
int heightUsedByPercent = 0;
for (final SizeInfo rowSizeInfo : rowSizes) {
final HtmlLength heightLength = (HtmlLength) rowSizeInfo.getHtmlLength();
if (heightLength != null && heightLength.getLengthType() == HtmlLength.LENGTH) {
int actualSizeInt = heightLength.getLength(expectedTotalCellHeight);
if (actualSizeInt < rowSizeInfo.getMinSize()) {
actualSizeInt = rowSizeInfo.getMinSize();
}
heightUsedByPercent += actualSizeInt;
rowSizeInfo.setActualSize(actualSizeInt);
}
}
// Set width of table
matrix.tableHeight = heightUsedByAbsolute + heightUsedByNoSize + heightUsedByPercent + heightsOfExtras;
// Do a final render to set actual cell sizes
finalRender(hasBorder, cellSpacing, sizeOnly);
}
Aggregations