use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedCharacterIteratorTest method test_getRunStart.
public void test_getRunStart() {
assertEquals(0, it.getRunStart());
AttributedString as = new AttributedString("");
assertEquals(0, as.getIterator().getRunStart());
as = new AttributedString(new AttributedString("test text").getIterator(), 2, 7);
AttributedCharacterIterator it = as.getIterator();
assertEquals(0, it.getRunStart());
as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "GERMAN", 1, 2);
as.addAttribute(AttributedCharacterIterator.Attribute.READING, "READ", 1, 3);
assertEquals(0, as.getIterator().getRunStart());
}
use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedCharacterIteratorTest method test_getAttributes.
public void test_getAttributes() {
Map<AttributedCharacterIterator.Attribute, Object> attributes = it.getAttributes();
assertEquals(2, attributes.size());
assertEquals("ENGLISH", attributes.get(AttributedCharacterIterator.Attribute.LANGUAGE));
assertEquals("READ", attributes.get(AttributedCharacterIterator.Attribute.READING));
AttributedString as = new AttributedString("test");
assertTrue(as.getIterator().getAttributes().isEmpty());
}
use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedCharacterIteratorTest method test_getRunLimitLAttribute.
public void test_getRunLimitLAttribute() {
AttributedString as = new AttributedString("");
assertEquals(0, as.getIterator().getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
as = new AttributedString("text");
as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "ENGLISH");
as.addAttribute(AttributedCharacterIterator.Attribute.READING, "READ", 1, 3);
assertEquals(4, as.getIterator().getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
assertEquals(1, as.getIterator().getRunLimit(AttributedCharacterIterator.Attribute.READING));
}
use of java.text.AttributedString in project adempiere by adempiere.
the class TableElement method printColumn.
// paint
/**
* Print non zero width Column
* @param g2D graphics
* @param col column index
* @param origX start X
* @param origY start Y
* @param leftVline if true print left vertical line (for first column)
* @param firstRow first row index
* @param nextPageRow row index of next page
* @param isView true if online view (IDs are links)
*/
private void printColumn(Graphics2D g2D, int col, final int origX, final int origY, boolean leftVline, final int firstRow, final int nextPageRow, boolean isView) {
int curX = origX;
// start from top
int curY = origY;
//
// includes 2*Gaps+Line
float colWidth = ((Float) m_columnWidths.get(col)).floatValue();
float netWidth = colWidth - (2 * H_GAP) - m_tFormat.getVLineStroke().floatValue();
if (leftVline)
netWidth -= m_tFormat.getVLineStroke().floatValue();
int rowHeight = m_headerHeight;
float netHeight = rowHeight - (4 * m_tFormat.getLineStroke().floatValue()) + (2 * V_GAP);
if (DEBUG_PRINT)
log.finer("#" + col + " - x=" + curX + ", y=" + curY + ", width=" + colWidth + "/" + netWidth + ", HeaderHeight=" + rowHeight + "/" + netHeight);
String alignment = m_columnJustification[col];
// paint header ***************************************************
if (// draw left | line
leftVline) {
g2D.setPaint(m_tFormat.getVLine_Color());
g2D.setStroke(m_tFormat.getVLine_Stroke());
if (// -> | (left)
m_tFormat.isPaintBoundaryLines())
g2D.drawLine(origX, (int) (origY + m_tFormat.getLineStroke().floatValue()), origX, (int) (origY + rowHeight - (4 * m_tFormat.getLineStroke().floatValue())));
curX += m_tFormat.getVLineStroke().floatValue();
}
// X - start line
if (m_tFormat.isPaintHeaderLines()) {
g2D.setPaint(m_tFormat.getHeaderLine_Color());
g2D.setStroke(m_tFormat.getHeader_Stroke());
// -> - (top)
g2D.drawLine(// -> - (top)
origX, // -> - (top)
origY, (int) (origX + colWidth - m_tFormat.getVLineStroke().floatValue()), origY);
}
// thick
curY += (2 * m_tFormat.getLineStroke().floatValue());
// Background
Color bg = getBackground(HEADER_ROW, col);
if (!bg.equals(Color.white)) {
g2D.setPaint(bg);
g2D.fillRect(curX, (int) (curY - m_tFormat.getLineStroke().floatValue()), (int) (colWidth - m_tFormat.getVLineStroke().floatValue()), (int) (rowHeight - (4 * m_tFormat.getLineStroke().floatValue())));
}
int tempCurY = curY;
// upper left gap
curX += H_GAP;
curY += V_GAP;
// Header
AttributedString aString = null;
AttributedCharacterIterator iter = null;
LineBreakMeasurer measurer = null;
float usedHeight = 0;
// Calculate column header height - teo_sarca [ 1673429 ]
String headerString = m_columnHeader[col].toString();
if (headerString.length() == 0)
headerString = " ";
//if (m_columnHeader[col].toString().length() > 0)
{
aString = new AttributedString(headerString);
aString.addAttribute(TextAttribute.FONT, getFont(HEADER_ROW, col));
aString.addAttribute(TextAttribute.FOREGROUND, getColor(HEADER_ROW, col));
//
boolean fastDraw = LayoutEngine.s_FASTDRAW;
if (fastDraw && !isView && !Util.is8Bit(headerString))
fastDraw = false;
iter = aString.getIterator();
measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
while (// print header
measurer.getPosition() < iter.getEndIndex()) {
TextLayout layout = measurer.nextLayout(netWidth + 2);
if (iter.getEndIndex() != measurer.getPosition())
fastDraw = false;
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Block)) {
layout = layout.getJustifiedLayout(netWidth + 2);
fastDraw = false;
}
curY += layout.getAscent();
float penX = curX;
if (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Center))
penX += (netWidth - layout.getAdvance()) / 2;
else if ((alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight) && layout.isLeftToRight()) || (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft) && !layout.isLeftToRight()))
penX += netWidth - layout.getAdvance();
//
if (fastDraw) {
// Bug - set Font/Color explicitly
g2D.setFont(getFont(HEADER_ROW, col));
g2D.setColor(getColor(HEADER_ROW, col));
g2D.drawString(iter, penX, curY);
} else
// -> text
layout.draw(g2D, penX, curY);
curY += layout.getDescent() + layout.getLeading();
usedHeight += layout.getAscent() + layout.getDescent();
if (// one line only
!m_multiLineHeader)
break;
}
}
curX += netWidth + H_GAP;
curY = tempCurY + (int) (rowHeight - (4 * m_tFormat.getLineStroke().floatValue()));
// Y end line
g2D.setPaint(m_tFormat.getVLine_Color());
g2D.setStroke(m_tFormat.getVLine_Stroke());
if (// -> | (right)
m_tFormat.isPaintVLines())
g2D.drawLine(curX, (int) (origY + m_tFormat.getLineStroke().floatValue()), curX, (int) (origY + rowHeight - (4 * m_tFormat.getLineStroke().floatValue())));
curX += m_tFormat.getVLineStroke().floatValue();
// X end line
if (m_tFormat.isPaintHeaderLines()) {
g2D.setPaint(m_tFormat.getHeaderLine_Color());
g2D.setStroke(m_tFormat.getHeader_Stroke());
// -> - (button)
g2D.drawLine(// -> - (button)
origX, // -> - (button)
curY, (int) (origX + colWidth - m_tFormat.getVLineStroke().floatValue()), curY);
}
// thick
curY += (2 * m_tFormat.getLineStroke().floatValue());
// paint Data ***************************************************
for (int row = firstRow; row < nextPageRow; row++) {
// includes 2*Gaps+Line
rowHeight = ((Float) m_rowHeights.get(row)).intValue();
netHeight = rowHeight - (2 * V_GAP) - m_tFormat.getLineStroke().floatValue();
int rowYstart = curY;
curX = origX;
if (// draw left | line
leftVline) {
g2D.setPaint(m_tFormat.getVLine_Color());
g2D.setStroke(m_tFormat.getVLine_Stroke());
if (m_tFormat.isPaintBoundaryLines())
// -> | (left)
g2D.drawLine(// -> | (left)
curX, // -> | (left)
rowYstart, curX, (int) (rowYstart + rowHeight - m_tFormat.getLineStroke().floatValue()));
curX += m_tFormat.getVLineStroke().floatValue();
}
// Background
bg = getBackground(row, col);
if (!bg.equals(Color.white)) {
g2D.setPaint(bg);
g2D.fillRect(curX, curY, (int) (colWidth - m_tFormat.getVLineStroke().floatValue()), (int) (rowHeight - m_tFormat.getLineStroke().floatValue()));
}
// upper left gap
curX += H_GAP;
curY += V_GAP;
// actual data
Object[] printItems = getPrintItems(row, col);
float penY = curY;
// suppress repeated values
boolean suppress = false;
if (m_colSuppressRepeats[col] && row > 0 && row != firstRow) {
Object[] lastItems = {};
lastItems = getPrintItems(row - 1, col);
if (Arrays.equals(lastItems, printItems))
suppress = true;
}
if (!suppress) {
for (int index = 0; index < printItems.length; index++) {
if (printItems[index] == null)
;
else if (printItems[index] instanceof ImageElement) {
Image imageToDraw = ((ImageElement) printItems[index]).getImage();
if (// teo_sarca [ 1674706 ]
imageToDraw != null) {
// Draw image using the scale factor - teo_sarca, [ 1673548 ] Image is not scaled in a report table cell
double scale = ((ImageElement) printItems[index]).getScaleFactor();
if (scale != 1.0) {
AffineTransform transform = new AffineTransform();
transform.translate(curX, penY);
transform.scale(scale, scale);
g2D.drawImage(imageToDraw, transform, this);
} else {
g2D.drawImage(imageToDraw, curX, (int) penY, this);
}
}
} else if (printItems[index] instanceof BarcodeElement) {
try {
Barcode barcode = ((BarcodeElement) printItems[index]).getBarcode();
if (barcode != null) {
double scale = ((BarcodeElement) printItems[index]).getScaleFactor();
if (scale != 1.0) {
int w = barcode.getWidth();
int h = barcode.getHeight();
// draw barcode to buffer
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D temp = (Graphics2D) image.getGraphics();
barcode.draw(temp, 0, 0);
// scale barcode and paint
AffineTransform transform = new AffineTransform();
transform.translate(curX, penY);
transform.scale(scale, scale);
g2D.drawImage(image, transform, this);
} else {
barcode.draw(g2D, curX, (int) penY);
}
}
} catch (OutputException e) {
}
} else if (printItems[index] instanceof Boolean) {
// center
int penX = curX + (int) ((netWidth - LayoutEngine.IMAGE_SIZE.width) / 2);
if (((Boolean) printItems[index]).booleanValue())
g2D.drawImage(LayoutEngine.IMAGE_TRUE, penX, (int) penY, this);
else
g2D.drawImage(LayoutEngine.IMAGE_FALSE, penX, (int) penY, this);
penY += LayoutEngine.IMAGE_SIZE.height;
} else if (printItems[index] instanceof HTMLRenderer) {
HTMLRenderer renderer = (HTMLRenderer) printItems[index];
Rectangle allocation = new Rectangle((int) colWidth, (int) netHeight);
// log.finest( "printColumn HTML - " + allocation);
g2D.translate(curX, penY);
renderer.paint(g2D, allocation);
g2D.translate(-curX, -penY);
penY += allocation.getHeight();
} else {
String str = printItems[index].toString();
if (DEBUG_PRINT)
log.fine("row=" + row + ",col=" + col + " - " + str + " 8Bit=" + Util.is8Bit(str));
if (str.length() > 0) {
usedHeight = 0;
String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(str);
for (int lineNo = 0; lineNo < lines.length; lineNo++) {
aString = new AttributedString(lines[lineNo]);
aString.addAttribute(TextAttribute.FONT, getFont(row, col));
if (// ID
isView && printItems[index] instanceof NamePair) {
aString.addAttribute(TextAttribute.FOREGROUND, LINK_COLOR);
aString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL, 0, str.length());
} else
aString.addAttribute(TextAttribute.FOREGROUND, getColor(row, col));
//
iter = aString.getIterator();
boolean fastDraw = LayoutEngine.s_FASTDRAW;
if (fastDraw && !isView && !Util.is8Bit(lines[lineNo]))
fastDraw = false;
measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
while (// print element
measurer.getPosition() < iter.getEndIndex()) {
TextLayout layout = measurer.nextLayout(netWidth + 2);
if (iter.getEndIndex() != measurer.getPosition())
fastDraw = false;
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
if ((m_columnMaxHeight[col] <= 0 || (usedHeight + lineHeight) <= m_columnMaxHeight[col]) && (usedHeight + lineHeight) <= netHeight) {
if (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Block) && measurer.getPosition() < iter.getEndIndex()) {
layout = layout.getJustifiedLayout(netWidth + 2);
fastDraw = false;
}
penY += layout.getAscent();
float penX = curX;
if (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Center))
penX += (netWidth - layout.getAdvance()) / 2;
else if ((alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight) && layout.isLeftToRight()) || (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft) && !layout.isLeftToRight()))
penX += netWidth - layout.getAdvance();
//
if (fastDraw) {
// Bug - set Font/Color explicitly
g2D.setFont(getFont(row, col));
if (// ID
isView && printItems[index] instanceof NamePair) {
g2D.setColor(LINK_COLOR);
// TextAttribute.UNDERLINE
} else
g2D.setColor(getColor(row, col));
g2D.drawString(iter, penX, penY);
} else
// -> text
layout.draw(g2D, penX, penY);
if (DEBUG_PRINT)
log.fine("row=" + row + ",col=" + col + " - " + str + " - x=" + penX + ",y=" + penY);
penY += layout.getDescent() + layout.getLeading();
usedHeight += lineHeight;
//
if (// FirstLineOny
m_columnMaxHeight[col] == -1)
break;
}
}
// print element
}
// for all lines
}
// length > 0
}
// non boolean
}
// for all print items
}
// not suppressed
curY += netHeight + V_GAP;
curX += netWidth + H_GAP;
// Y end line
g2D.setPaint(m_tFormat.getVLine_Color());
g2D.setStroke(m_tFormat.getVLine_Stroke());
if (m_tFormat.isPaintVLines())
// -> | (right)
g2D.drawLine(// -> | (right)
curX, // -> | (right)
rowYstart, curX, (int) (rowYstart + rowHeight - m_tFormat.getLineStroke().floatValue()));
curX += m_tFormat.getVLineStroke().floatValue();
// X end line
if (// last Line
row == m_data.length - 1) {
/**
* Bug fix - Bottom line was always displayed whether or not header lines was set to be visible
* @author ashley
*/
if (m_tFormat.isPaintHeaderLines()) {
g2D.setPaint(m_tFormat.getHeaderLine_Color());
g2D.setStroke(m_tFormat.getHeader_Stroke());
// -> - (last line)
g2D.drawLine(// -> - (last line)
origX, // -> - (last line)
curY, (int) (origX + colWidth - m_tFormat.getVLineStroke().floatValue()), curY);
// thick
curY += (2 * m_tFormat.getLineStroke().floatValue());
} else {
curY += m_tFormat.getLineStroke().floatValue();
}
} else {
// next line is a funcion column -> underline this
boolean nextIsFunction = m_functionRows.contains(new Integer(row + 1));
if (nextIsFunction && m_functionRows.contains(new Integer(row)))
// this is a function line too
nextIsFunction = false;
if (nextIsFunction) {
g2D.setPaint(m_tFormat.getFunctFG_Color());
g2D.setStroke(m_tFormat.getHLine_Stroke());
// -> - (bottom)
g2D.drawLine(// -> - (bottom)
origX, // -> - (bottom)
curY, (int) (origX + colWidth - m_tFormat.getVLineStroke().floatValue()), curY);
} else if (m_tFormat.isPaintHLines()) {
g2D.setPaint(m_tFormat.getHLine_Color());
g2D.setStroke(m_tFormat.getHLine_Stroke());
// -> - (bottom)
g2D.drawLine(// -> - (bottom)
origX, // -> - (bottom)
curY, (int) (origX + colWidth - m_tFormat.getVLineStroke().floatValue()), curY);
}
curY += m_tFormat.getLineStroke().floatValue();
}
}
// for all rows
}
use of java.text.AttributedString in project adempiere by adempiere.
the class TableElement method calculateSize.
/**************************************************************************
* Layout and Calculate Size.
* Set p_width & p_height
* @return true if calculated
*/
protected boolean calculateSize() {
if (p_sizeCalculated)
return true;
p_width = 0;
// reset
m_printRows = new ArrayList<ArrayList<ArrayList<Object>>>(m_data.length);
// Max Column Width = 50% of available width (used if maxWidth not set)
float dynMxColumnWidth = m_firstPage.width / 2;
// Width caolculation
int rows = m_data.length;
int cols = m_columnHeader.length;
// Data Sizes and Header Sizes
Dimension2DImpl[][] dataSizes = new Dimension2DImpl[rows][cols];
Dimension2DImpl[] headerSizes = new Dimension2DImpl[cols];
FontRenderContext frc = new FontRenderContext(null, true, true);
// data columns - rows
for (int dataCol = 0; dataCol < cols; dataCol++) {
int col = dataCol;
// Print below existing column
if (m_additionalLines.containsKey(new Integer(dataCol))) {
col = ((Integer) m_additionalLines.get(new Integer(dataCol))).intValue();
log.finest("DataColumn=" + dataCol + ", BelowColumn=" + col);
}
float colWidth = 0;
for (int row = 0; row < rows; row++) {
Object dataItem = m_data[row][dataCol];
if (dataItem == null) {
dataSizes[row][dataCol] = new Dimension2DImpl();
continue;
}
String string = dataItem.toString();
if (string.length() == 0) {
dataSizes[row][dataCol] = new Dimension2DImpl();
continue;
}
Font font = getFont(row, dataCol);
// Print below existing column = (col != dataCol)
addPrintLines(row, col, dataItem);
// don't print
dataSizes[row][dataCol] = new Dimension2DImpl();
if (dataItem instanceof Boolean) {
dataSizes[row][col].addBelow(LayoutEngine.IMAGE_SIZE);
continue;
} else if (dataItem instanceof ImageElement) {
dataSizes[row][col].addBelow(new Dimension((int) ((ImageElement) dataItem).getWidth(), (int) ((ImageElement) dataItem).getHeight()));
// Adjust the column width - teo_sarca, [ 1673620 ]
float width = (float) Math.ceil(dataSizes[row][col].getWidth());
if (colWidth < width)
colWidth = width;
continue;
} else if (dataItem instanceof BarcodeElement) {
dataSizes[row][col].addBelow(new Dimension((int) ((BarcodeElement) dataItem).getWidth(), (int) ((BarcodeElement) dataItem).getHeight()));
// Check if the overflow is allowed - teo_sarca, [ 1673590 ]
if (!((BarcodeElement) dataItem).isAllowOverflow()) {
float width = (float) Math.ceil(dataSizes[row][col].getWidth());
if (colWidth < width)
colWidth = width;
}
continue;
}
// No Width Limitations
if (m_columnMaxWidth[col] == 0 || m_columnMaxWidth[col] == -1) {
// if (HTMLElement.isHTML(string))
// log.finest( "HTML (no) r=" + row + ",c=" + dataCol);
TextLayout layout = new TextLayout(string, font, frc);
// buffer
float width = layout.getAdvance() + 2;
float height = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (width > dynMxColumnWidth)
m_columnMaxWidth[col] = (int) Math.ceil(dynMxColumnWidth);
else if (colWidth < width)
colWidth = width;
if (dataSizes[row][col] == null) {
dataSizes[row][col] = new Dimension2DImpl();
log.log(Level.WARNING, "No Size for r=" + row + ",c=" + col);
}
dataSizes[row][col].addBelow(width, height);
}
// Width limitations
if (m_columnMaxWidth[col] != 0 && m_columnMaxWidth[col] != -1) {
float height = 0;
//
if (HTMLElement.isHTML(string)) {
// log.finest( "HTML (limit) r=" + row + ",c=" + dataCol);
HTMLRenderer renderer = HTMLRenderer.get(string);
colWidth = renderer.getWidth();
if (// one line only
m_columnMaxHeight[col] == -1)
height = renderer.getHeightOneLine();
else
height = renderer.getHeight();
renderer.setAllocation((int) colWidth, (int) height);
// log.finest( "calculateSize HTML - " + renderer.getAllocation());
// replace for printing
m_data[row][dataCol] = renderer;
} else {
String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(string);
for (int lineNo = 0; lineNo < lines.length; lineNo++) {
AttributedString aString = new AttributedString(lines[lineNo]);
aString.addAttribute(TextAttribute.FONT, font);
AttributedCharacterIterator iter = aString.getIterator();
LineBreakMeasurer measurer = new LineBreakMeasurer(iter, frc);
while (measurer.getPosition() < iter.getEndIndex()) {
TextLayout layout = measurer.nextLayout(Math.abs(m_columnMaxWidth[col]));
float width = layout.getAdvance();
if (colWidth < width)
colWidth = width;
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (// one line only
m_columnMaxHeight[col] == -1) {
height = lineHeight;
break;
} else if (m_columnMaxHeight[col] == 0 || (height + lineHeight) <= m_columnMaxHeight[col])
height += lineHeight;
}
}
// for all lines
}
if (m_fixedWidth[col])
colWidth = Math.abs(m_columnMaxWidth[col]);
dataSizes[row][col].addBelow(colWidth, height);
}
dataSizes[row][col].roundUp();
if (dataItem instanceof NamePair)
m_rowColDrillDown.put(new Point(row, col), (NamePair) dataItem);
//
log.finest("Col=" + col + ", row=" + row + " => " + dataSizes[row][col] + " - ColWidth=" + colWidth);
}
// for all data rows
// Column Width for Header
String string = "";
if (m_columnHeader[dataCol] != null)
string = m_columnHeader[dataCol].toString();
// Print below existing column
if (col != dataCol)
headerSizes[dataCol] = new Dimension2DImpl();
else if (// suppress Null
colWidth == 0 && m_columnMaxWidth[dataCol] < 0 || string.length() == 0)
headerSizes[dataCol] = new Dimension2DImpl();
else {
Font font = getFont(HEADER_ROW, dataCol);
if (!font.isBold())
font = new Font(font.getName(), Font.BOLD, font.getSize());
// No Width Limitations
if (m_columnMaxWidth[dataCol] == 0 || m_columnMaxWidth[dataCol] == -1 || !m_multiLineHeader) {
TextLayout layout = new TextLayout(string, font, frc);
// buffer
float width = layout.getAdvance() + 3;
float height = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (width > dynMxColumnWidth)
m_columnMaxWidth[dataCol] = (int) Math.ceil(dynMxColumnWidth);
else if (colWidth < width)
colWidth = width;
headerSizes[dataCol] = new Dimension2DImpl(width, height);
}
// Width limitations
if (m_columnMaxWidth[dataCol] != 0 && m_columnMaxWidth[dataCol] != -1) {
float height = 0;
//
String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(string);
for (int lineNo = 0; lineNo < lines.length; lineNo++) {
AttributedString aString = new AttributedString(lines[lineNo]);
aString.addAttribute(TextAttribute.FONT, font);
AttributedCharacterIterator iter = aString.getIterator();
LineBreakMeasurer measurer = new LineBreakMeasurer(iter, frc);
colWidth = Math.abs(m_columnMaxWidth[dataCol]);
while (measurer.getPosition() < iter.getEndIndex()) {
TextLayout layout = measurer.nextLayout(colWidth);
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (// one line only
!m_multiLineHeader) {
height = lineHeight;
break;
} else
/*if (m_columnMaxHeight[dataCol] == 0
|| (height + lineHeight) <= m_columnMaxHeight[dataCol])*/
height += lineHeight;
}
}
// for all header lines
headerSizes[dataCol] = new Dimension2DImpl(colWidth, height);
}
}
// headerSize
headerSizes[dataCol].roundUp();
colWidth = (float) Math.ceil(colWidth);
// Round Column Width
if (dataCol == 0)
colWidth += m_tFormat.getVLineStroke().floatValue();
if (colWidth != 0)
colWidth += (2 * H_GAP) + m_tFormat.getVLineStroke().floatValue();
// Print below existing column
if (col != dataCol) {
// for the data column
m_columnWidths.add(new Float(0.0));
Float origWidth = (Float) m_columnWidths.get(col);
if (origWidth == null)
log.log(Level.SEVERE, "Column " + dataCol + " below " + col + " - no value for orig width");
else {
if (origWidth.compareTo(new Float(colWidth)) >= 0) {
log.finest("Same Width - Col=" + col + " - OrigWidth=" + origWidth + " - Width=" + colWidth + " - Total=" + p_width);
} else {
m_columnWidths.set(col, new Float(colWidth));
p_width += (colWidth - origWidth.floatValue());
log.finest("New Width - Col=" + col + " - OrigWidth=" + origWidth + " - Width=" + colWidth + " - Total=" + p_width);
}
}
} else // Add new Column
{
m_columnWidths.add(new Float(colWidth));
p_width += colWidth;
log.finest("Width - Col=" + dataCol + " - Width=" + colWidth + " - Total=" + p_width);
}
}
// for all columns
// Height **********
p_height = 0;
for (int row = 0; row < rows; row++) {
float rowHeight = 0f;
for (int col = 0; col < cols; col++) {
if (// max
dataSizes[row][col].height > rowHeight)
rowHeight = (float) dataSizes[row][col].height;
}
// for all columns
rowHeight += m_tFormat.getLineStroke().floatValue() + (2 * V_GAP);
m_rowHeights.add(new Float(rowHeight));
p_height += rowHeight;
}
// for all rows
// HeaderRow
m_headerHeight = 0;
for (int col = 0; col < cols; col++) {
if (headerSizes[col].height > m_headerHeight)
m_headerHeight = (int) headerSizes[col].height;
}
// for all columns
// Thick lines
m_headerHeight += (4 * m_tFormat.getLineStroke().floatValue()) + (2 * V_GAP);
p_height += m_headerHeight;
// Last row Lines
// last fat line
p_height += m_tFormat.getLineStroke().floatValue();
// Page Layout *******************************************************
log.fine("FirstPage=" + m_firstPage + ", NextPages=" + m_nextPages);
// One Page on Y | Axis
if (m_firstPage.height >= p_height && m_pageBreak.size() == 0) {
log.finest("Page Y=1 - PageHeight=" + m_firstPage.height + " - TableHeight=" + p_height);
// Y
m_firstRowOnPage.add(new Integer(0));
// Y index only
m_pageHeight.add(new Float(p_height));
} else // multiple pages on Y | Axis
{
float availableHeight = 0f;
float usedHeight = 0f;
boolean firstPage = true;
int addlRows = 0;
// for all rows
for (int dataRow = 0; dataRow < m_rowHeights.size(); dataRow++) {
float rowHeight = ((Float) m_rowHeights.get(dataRow)).floatValue();
// Y page break before
boolean pageBreak = isPageBreak(dataRow);
//adjust for lastrow
if (dataRow + 1 == m_rowHeights.size()) {
availableHeight -= m_tFormat.getLineStroke().floatValue();
}
if (!pageBreak && availableHeight < rowHeight) {
if (availableHeight > 40 && rowHeight > 40) {
log.finest("- Split (leave on current) Row=" + dataRow + " - Available=" + availableHeight + ", RowHeight=" + rowHeight);
// if (splitRow (dataRow))
// addlRows += 1;
}
// else
pageBreak = true;
}
if (pageBreak) {
availableHeight = firstPage ? m_firstPage.height : m_nextPages.height;
// Y
m_firstRowOnPage.add(new Integer(dataRow + addlRows));
if (!firstPage) {
// Y index only
m_pageHeight.add(new Float(usedHeight));
log.finest("Page Y=" + m_pageHeight.size() + " - PageHeight=" + usedHeight);
}
log.finest("Page Y=" + m_firstRowOnPage.size() + " - Row=" + dataRow + " - force=" + isPageBreak(dataRow));
firstPage = false;
//
availableHeight -= m_headerHeight;
usedHeight += m_headerHeight;
}
availableHeight -= rowHeight;
usedHeight += rowHeight;
if (availableHeight < 0) {
log.finest("- Split (move to next) Row=" + dataRow + " - Available=" + availableHeight + ", RowHeight=" + rowHeight);
}
log.finest("Page Y=" + m_pageHeight.size() + ", Row=" + dataRow + ",AddlRows=" + addlRows + ", Height=" + rowHeight + " - Available=" + availableHeight + ", Used=" + usedHeight);
}
// for all rows
// Y index only
m_pageHeight.add(new Float(usedHeight));
log.finest("Page Y=" + m_pageHeight.size() + " - PageHeight=" + usedHeight);
}
// One page on - X Axis
if (m_firstPage.width >= p_width) {
log.finest("Page X=1 - PageWidth=" + m_firstPage.width + " - TableWidth=" + p_width);
// X
m_firstColumnOnPage.add(new Integer(0));
//
distributeColumns(m_firstPage.width - (int) p_width, 0, m_columnWidths.size());
} else // multiple pages on - X Axis
{
int availableWidth = 0;
int lastStart = 0;
for (int col = 0; col < m_columnWidths.size(); col++) {
int columnWidth = ((Float) m_columnWidths.get(col)).intValue();
// X page preak
if (availableWidth < columnWidth) {
if (col != 0)
distributeColumns(availableWidth, lastStart, col);
//
// X
m_firstColumnOnPage.add(new Integer(col));
log.finest("Page X=" + m_firstColumnOnPage.size() + " - Col=" + col);
lastStart = col;
// Width is the same on all pages
availableWidth = m_firstPage.width;
//
for (int repCol = 0; repCol < m_repeatedColumns && col > repCol; repCol++) {
float repColumnWidth = ((Float) m_columnWidths.get(repCol)).floatValue();
// leave 50% of space available for non repeated columns
if (availableWidth < m_firstPage.width * 0.5)
break;
availableWidth -= repColumnWidth;
}
}
// pageBreak
availableWidth -= columnWidth;
}
// for acc columns
}
// multiple - X pages
log.fine("Pages=" + getPageCount() + " X=" + m_firstColumnOnPage.size() + "/Y=" + m_firstRowOnPage.size() + " - Width=" + p_width + ", Height=" + p_height);
return true;
}
Aggregations