| Method from com.lowagie.text.rtf.RtfWriter Detail: |
public boolean add(Element element) throws DocumentException {
if (pause) {
return false;
}
return addElement(element, content);
}
Signals that an Element was added to the Document. |
protected int addColor(Color newColor) {
int cn = 0;
if (newColor == null) {
return cn;
}
cn = colorList.indexOf(newColor);
if (cn == -1) {
colorList.add(newColor);
return colorList.size() - 1;
}
return cn;
}
Add a new Color to the list of colours. If the Color
already exists in the list of colours, then it is not added again. |
protected boolean addElement(Element element,
ByteArrayOutputStream out) throws DocumentException {
try {
switch (element.type()) {
case Element.CHUNK:
writeChunk((Chunk) element, out);
break;
case Element.PARAGRAPH:
writeParagraph((Paragraph) element, out);
break;
case Element.ANCHOR:
writeAnchor((Anchor) element, out);
break;
case Element.PHRASE:
writePhrase((Phrase) element, out);
break;
case Element.CHAPTER:
case Element.SECTION:
writeSection((Section) element, out);
break;
case Element.LIST:
writeList((com.lowagie.text.List) element, out);
break;
case Element.TABLE:
try {
writeTable((Table) element, out);
}
catch(ClassCastException cce) {
writeTable(((SimpleTable)element).createTable(), out);
}
break;
case Element.ANNOTATION:
writeAnnotation((Annotation) element, out);
break;
case Element.IMGRAW:
case Element.IMGTEMPLATE:
case Element.JPEG:
Image img = (Image)element;
writeImage(img, out);
break;
case Element.AUTHOR:
writeMeta(metaAuthor, (Meta) element);
break;
case Element.SUBJECT:
writeMeta(metaSubject, (Meta) element);
break;
case Element.KEYWORDS:
writeMeta(metaKeywords, (Meta) element);
break;
case Element.TITLE:
writeMeta(metaTitle, (Meta) element);
break;
case Element.PRODUCER:
writeMeta(metaProducer, (Meta) element);
break;
case Element.CREATIONDATE:
writeMeta(metaCreationDate, (Meta) element);
break;
}
} catch (IOException e) {
return false;
}
return true;
}
Adds an Element to the Document. |
protected int addFont(Font newFont) {
int fn = -1;
for (int i = 0; i < fontList.size(); i++) {
if (newFont.getFamilyname().equals(((Font) fontList.get(i)).getFamilyname())) {
fn = i;
}
}
if (fn == -1) {
fontList.add(newFont);
return fontList.size() - 1;
}
return fn;
}
Add a new Font to the list of fonts. If the Font
already exists in the list of fonts, then it is not added again. |
public void close() {
writeDocument();
super.close();
}
Signals that the Document was closed and that no other
Elements will be added.
The content of the font table, color table, information group, content, header, footer are merged into the final
OutputStream |
public static final String filterSpecialChar(String str,
boolean useHex) {
int length = str.length();
int z = (int) 'z";
StringBuffer ret = new StringBuffer(length);
for (int i = 0; i < length; i++) {
char ch = str.charAt(i);
if (ch == '\\") {
ret.append("\\\\");
} else if (ch == '\n") {
ret.append("\\par ");
} else if (((int) ch) > z) {
if(useHex) {
ret.append("\\\'").append(Long.toHexString((long) ch));
} else {
ret.append("\\u").append((long) ch).append('?");
}
} else {
ret.append(ch);
}
}
String s = ret.toString();
if(s.indexOf("$newpage$") >= 0) {
String before = s.substring(0, s.indexOf("$newpage$"));
String after = s.substring(s.indexOf("$newpage$") + 9);
ret = new StringBuffer(before);
ret.append("\\page\\par ");
ret.append(after);
return ret.toString();
}
return s;
}
Replaces special characters with their unicode values |
public boolean getGeneratingTOCEntries() {
return writeTOC;
}
Gets the current setting of writeTOC |
public boolean getHasTitlePage() {
return hasTitlePage;
}
Gets the current setting of hasTitlePage |
public static RtfWriter getInstance(Document document,
OutputStream os) {
return (new RtfWriter(document, os));
}
Gets an instance of the RtfWriter. |
public boolean getLandscape() {
return landscape;
}
Returns the current landscape setting |
public boolean newPage() throws DocumentException {
try {
content.write(escape);
content.write(newPage);
content.write(escape);
content.write(paragraph);
} catch (IOException e) {
return false;
}
return true;
}
Tells the RtfWriter that a new page is to be begun. |
public void open() {
super.open();
}
Signals that the Document has been opened and that
Elements can be added. |
public void resetFooter() {
setFooter(null);
}
|
public void resetHeader() {
setHeader(null);
}
|
public void setFooter(HeaderFooter footer) {
this.footer = footer;
processHeaderFooter(this.footer);
}
Adds the footer to the bottom of the Document. |
public void setGenerateTOCEntries(boolean writeTOC) {
this.writeTOC = writeTOC;
}
This method controls whether TOC entries are automatically generated |
public void setHasTitlePage(boolean hasTitlePage) {
this.hasTitlePage = hasTitlePage;
}
This method controls whether the first page is a title page |
public void setHeader(HeaderFooter header) {
this.header = header;
processHeaderFooter(this.header);
}
Adds the header to the top of the Document. |
public void setLandscape(boolean landscape) {
this.landscape = landscape;
}
Explicitly sets the page format to use.
Otherwise the RtfWriter will try to guess the format by comparing pagewidth and pageheight |
public boolean setMarginMirroring(boolean MarginMirroring) {
return false;
}
|
public boolean setMargins(float marginLeft,
float marginRight,
float marginTop,
float marginBottom) {
this.marginLeft = (int) (marginLeft * TWIPSFACTOR);
this.marginRight = (int) (marginRight * TWIPSFACTOR);
this.marginTop = (int) (marginTop * TWIPSFACTOR);
this.marginBottom = (int) (marginBottom * TWIPSFACTOR);
return true;
}
|
public boolean setPageSize(Rectangle pageSize) {
if (!parseFormat(pageSize, false)) {
pageWidth = (int) (pageSize.width() * TWIPSFACTOR);
pageHeight = (int) (pageSize.height() * TWIPSFACTOR);
landscape = pageWidth > pageHeight;
}
return true;
}
|
protected void writeFinishingFontSignature(OutputStream out,
Chunk chunk) throws IOException {
Font font = chunk.font();
if (font.isBold()) {
out.write(escape);
out.write(bold);
writeInt(out, 0);
}
if (font.isItalic()) {
out.write(escape);
out.write(italic);
writeInt(out, 0);
}
if (font.isUnderlined()) {
out.write(escape);
out.write(underline);
writeInt(out, 0);
}
if (font.isStrikethru()) {
out.write(escape);
out.write(strikethrough);
writeInt(out, 0);
}
/*
* Superscript / Subscript added by Scott Dietrich (sdietrich@emlab.com)
*/
if (chunk.getAttributes() != null) {
Float f = (Float) chunk.getAttributes().get(Chunk.SUBSUPSCRIPT);
if (f != null)
if (f.floatValue() != 0) {
out.write(escape);
out.write(endSuperSub);
}
}
}
|
public void writeHeadersFooters(ByteArrayOutputStream os) throws IOException {
if (this.footer instanceof RtfHeaderFooters) {
RtfHeaderFooters rtfHf = (RtfHeaderFooters) this.footer;
HeaderFooter hf = rtfHf.get(RtfHeaderFooters.ALL_PAGES);
if (hf != null) {
writeHeaderFooter(hf, footerBegin, os);
}
hf = rtfHf.get(RtfHeaderFooters.LEFT_PAGES);
if (hf != null) {
writeHeaderFooter(hf, footerlBegin, os);
}
hf = rtfHf.get(RtfHeaderFooters.RIGHT_PAGES);
if (hf != null) {
writeHeaderFooter(hf, footerrBegin, os);
}
hf = rtfHf.get(RtfHeaderFooters.FIRST_PAGE);
if (hf != null) {
writeHeaderFooter(hf, footerfBegin, os);
}
} else {
writeHeaderFooter(this.footer, footerBegin, os);
}
if (this.header instanceof RtfHeaderFooters) {
RtfHeaderFooters rtfHf = (RtfHeaderFooters) this.header;
HeaderFooter hf = rtfHf.get(RtfHeaderFooters.ALL_PAGES);
if (hf != null) {
writeHeaderFooter(hf, headerBegin, os);
}
hf = rtfHf.get(RtfHeaderFooters.LEFT_PAGES);
if (hf != null) {
writeHeaderFooter(hf, headerlBegin, os);
}
hf = rtfHf.get(RtfHeaderFooters.RIGHT_PAGES);
if (hf != null) {
writeHeaderFooter(hf, headerrBegin, os);
}
hf = rtfHf.get(RtfHeaderFooters.FIRST_PAGE);
if (hf != null) {
writeHeaderFooter(hf, headerfBegin, os);
}
} else {
writeHeaderFooter(this.header, headerBegin, os);
}
}
Write the current header and footer to a ByteArrayOutputStream |
protected void writeInitialFontSignature(OutputStream out,
Chunk chunk) throws IOException {
Font font = chunk.font();
out.write(escape);
out.write(fontNumber);
if (!font.getFamilyname().equalsIgnoreCase("unknown")) {
writeInt(out, addFont(font));
} else {
writeInt(out, 0);
}
out.write(escape);
out.write(fontSize);
if (font.size() > 0) {
writeInt(out, (int) (font.size() * 2));
} else {
writeInt(out, 20);
}
out.write(escape);
out.write(fontColor);
writeInt(out, addColor(font.color()));
if (font.isBold()) {
out.write(escape);
out.write(bold);
}
if (font.isItalic()) {
out.write(escape);
out.write(italic);
}
if (font.isUnderlined()) {
out.write(escape);
out.write(underline);
}
if (font.isStrikethru()) {
out.write(escape);
out.write(strikethrough);
}
/*
* Superscript / Subscript added by Scott Dietrich (sdietrich@emlab.com)
*/
if (chunk.getAttributes() != null) {
Float f = (Float) chunk.getAttributes().get(Chunk.SUBSUPSCRIPT);
if (f != null)
if (f.floatValue() > 0) {
out.write(escape);
out.write(startSuper);
} else if (f.floatValue() < 0) {
out.write(escape);
out.write(startSub);
}
}
out.write(delimiter);
}
|
public static final void writeInt(OutputStream out,
int i) throws IOException {
out.write(Integer.toString(i).getBytes());
}
|
public boolean writeTOC(String tocTitle,
Font titleFont,
boolean showTOCasEntry,
Font showTOCEntryFont) {
try {
RtfTOC toc = new RtfTOC(tocTitle, titleFont);
if (showTOCasEntry) {
toc.addTOCAsTOCEntry(tocTitle, showTOCEntryFont);
}
add(new Paragraph(toc));
} catch (DocumentException de) {
return false;
}
return true;
}
Write the table of contents. |
public boolean writingHeaderFooter() {
return inHeaderFooter;
}
Returns whether we are currently writing a header or footer |