📄 rtfcell.java
字号:
os.write(cellVMergePrev);
break;
case MERGE_BOTH_PREV:
os.write(RtfWriter.escape);
os.write(cellMergeFirst);
break;
}
switch (store.getVerticalAlignment()) {
case Element.ALIGN_BOTTOM:
os.write(RtfWriter.escape);
os.write(cellVerticalAlignBottom);
break;
case Element.ALIGN_CENTER:
case Element.ALIGN_MIDDLE:
os.write(RtfWriter.escape);
os.write(cellVerticalAlignCenter);
break;
case Element.ALIGN_TOP:
os.write(RtfWriter.escape);
os.write(cellVerticalAlignTop);
break;
}
if (((store.getBorder() & Rectangle.LEFT) == Rectangle.LEFT) &&
(lWidth > 0)) {
os.write(RtfWriter.escape);
os.write(cellBorderLeft);
os.write(RtfWriter.escape);
os.write(lStyle);
os.write(RtfWriter.escape);
os.write(RtfRow.tableBorderWidth);
writeInt(os, (int) (lWidth * RtfWriter.TWIPSFACTOR));
os.write(RtfWriter.escape);
os.write(RtfRow.tableBorderColor);
if (store.getBorderColor() == null)
writeInt(os, writer.addColor(new
Color(0, 0, 0)));
else
writeInt(os, writer.addColor(store.getBorderColor()));
os.write((byte) '\n');
}
if (((store.getBorder() & Rectangle.TOP) == Rectangle.TOP) && (tWidth > 0)) {
os.write(RtfWriter.escape);
os.write(cellBorderTop);
os.write(RtfWriter.escape);
os.write(tStyle);
os.write(RtfWriter.escape);
os.write(RtfRow.tableBorderWidth);
writeInt(os, (int) (tWidth * RtfWriter.TWIPSFACTOR));
os.write(RtfWriter.escape);
os.write(RtfRow.tableBorderColor);
if (store.getBorderColor() == null)
writeInt(os, writer.addColor(new
Color(0, 0, 0)));
else
writeInt(os, writer.addColor(store.getBorderColor()));
os.write((byte) '\n');
}
if (((store.getBorder() & Rectangle.BOTTOM) == Rectangle.BOTTOM) &&
(bWidth > 0)) {
os.write(RtfWriter.escape);
os.write(cellBorderBottom);
os.write(RtfWriter.escape);
os.write(bStyle);
os.write(RtfWriter.escape);
os.write(RtfRow.tableBorderWidth);
writeInt(os, (int) (bWidth * RtfWriter.TWIPSFACTOR));
os.write(RtfWriter.escape);
os.write(RtfRow.tableBorderColor);
if (store.getBorderColor() == null)
writeInt(os, writer.addColor(new
Color(0, 0, 0)));
else
writeInt(os, writer.addColor(store.getBorderColor()));
os.write((byte) '\n');
}
if (((store.getBorder() & Rectangle.RIGHT) == Rectangle.RIGHT) &&
(rWidth > 0)) {
os.write(RtfWriter.escape);
os.write(cellBorderRight);
os.write(RtfWriter.escape);
os.write(rStyle);
os.write(RtfWriter.escape);
os.write(RtfRow.tableBorderWidth);
writeInt(os, (int) (rWidth * RtfWriter.TWIPSFACTOR));
os.write(RtfWriter.escape);
os.write(RtfRow.tableBorderColor);
if (store.getBorderColor() == null)
writeInt(os, writer.addColor(new
Color(0, 0, 0)));
else
writeInt(os, writer.addColor(store.getBorderColor()));
os.write((byte) '\n');
}
os.write(RtfWriter.escape);
os.write(cellBackgroundColor);
if (store.getBackgroundColor() == null) {
writeInt(os, writer.addColor(new Color(255, 255, 255)));
} else {
writeInt(os, writer.addColor(store.getBackgroundColor()));
}
os.write((byte) '\n');
os.write(RtfWriter.escape);
os.write(cellWidthStyle);
os.write((byte) '\n');
os.write(RtfWriter.escape);
os.write(cellWidthTag);
writeInt(os, cellWidth);
os.write((byte) '\n');
if (cellpadding > 0) {
// values
os.write(RtfWriter.escape);
os.write(cellPaddingLeft);
writeInt(os, cellpadding / 2);
os.write(RtfWriter.escape);
os.write(cellPaddingTop);
writeInt(os, cellpadding / 2);
os.write(RtfWriter.escape);
os.write(cellPaddingRight);
writeInt(os, cellpadding / 2);
os.write(RtfWriter.escape);
os.write(cellPaddingBottom);
writeInt(os, cellpadding / 2);
// unit
os.write(RtfWriter.escape);
os.write(cellPaddingLeftUnit);
os.write(RtfWriter.escape);
os.write(cellPaddingTopUnit);
os.write(RtfWriter.escape);
os.write(cellPaddingRightUnit);
os.write(RtfWriter.escape);
os.write(cellPaddingBottomUnit);
}
os.write(RtfWriter.escape);
os.write(cellRightBorder);
writeInt(os, cellRight);
} catch (IOException e) {
return false;
}
return true;
}
/**
* Write the content of the <code>RtfCell</code>.
*
* @param os The <code>OutputStream</code> to which to write the content of
* the <code>RtfCell</code> to.
* @return true if writing the cell content succeeded
* @throws DocumentException
*/
public boolean writeCellContent(ByteArrayOutputStream os) throws DocumentException {
try {
if (mergeType == MERGE_HORIZ_PREV || mergeType == MERGE_BOTH_PREV) {
return true;
}
if (!emptyCell) {
Iterator cellIterator = store.getElements();
Paragraph container = null;
while (cellIterator.hasNext()) {
Element element = (Element) cellIterator.next();
// should we wrap it in a paragraph
if(!(element instanceof Paragraph)) {
if(container != null) {
container.add(element);
} else {
container = new Paragraph();
container.setAlignment(store.getHorizontalAlignment());
container.add(element);
}
} else {
if(container != null) {
writer.addElement(container, os);
container = null;
}
// if horizontal alignment is undefined overwrite
// with that of enclosing cell
if (element instanceof Paragraph && ((Paragraph) element).getAlignment() == Element.ALIGN_UNDEFINED) {
((Paragraph) element).setAlignment(store.getHorizontalAlignment());
}
writer.addElement(element, os);
if (element.type() == Element.PARAGRAPH && cellIterator.hasNext()) {
os.write(RtfWriter.escape);
os.write(RtfWriter.paragraph);
}
}
}
if(container != null) {
writer.addElement(container, os);
container =null;
}
} else {
os.write(RtfWriter.escape);
os.write(RtfWriter.paragraphDefaults);
os.write(RtfWriter.escape);
os.write(cellInTable);
}
os.write(RtfWriter.escape);
os.write(cellEnd);
} catch (IOException e) {
return false;
}
return true;
}
/**
* Sets the merge type and the <code>RtfCell</code> with which this
* <code>RtfCell</code> is to be merged.
*
* @param mergeType The merge type specifies the kind of merge to be applied
* (MERGE_HORIZ_PREV, MERGE_VERT_PREV, MERGE_BOTH_PREV)
* @param mergeCell The <code>RtfCell</code> that the cell at x and y is to
* be merged with
*/
public void setMerge(int mergeType, RtfCell mergeCell) {
this.mergeType = mergeType;
store = mergeCell.getStore();
}
/**
* Get the <code>Cell</code> with the actual content.
*
* @return <code>Cell</code> which is contained in the <code>RtfCell</code>
*/
public Cell getStore() {
return store;
}
/**
* Get the with of this <code>RtfCell</code>
*
* @return Width of the current <code>RtfCell</code>
*/
public int getCellWidth() {
return cellWidth;
}
/**
* sets the width of the cell
* @param value a width
*/
public void setCellWidth(int value) {
cellWidth = value;
}
/**
* Get the position of the right border of this <code>RtfCell</code>.
* @return position of the right border
*/
public int getCellRight() {
return cellRight;
}
/**
* Sets the right position of the cell
* @param value a cell position
*/
public void setCellRight(int value) {
cellRight = value;
}
/**
* Write an Integer to the Outputstream.
*
* @param out The <code>OutputStream</code> to be written to.
* @param i The int to be written.
* @throws IOException
*/
private void writeInt(ByteArrayOutputStream out, int i) throws IOException {
out.write(Integer.toString(i).getBytes());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -