}
case LwgElement.CHUNK:
{
Chunk chunk = (Chunk) element;
// if the chunk contains an image, return the image representation
LwgImage image = chunk.getImage();
if (image != null) {
write(image, indent);
return;
}
if (chunk.isEmpty()) return;
HashMap attributes = chunk.getAttributes();
if (attributes != null && attributes.get(Chunk.NEWPAGE) != null) {
return;
}
boolean tag = isOtherFont(chunk.getFont()) || markup.size() > 0;
if (tag) {
// start span tag
addTabs(indent);
writeStart(HtmlTags.SPAN);
if (isOtherFont(chunk.getFont())) {
write(chunk.getFont(), null);
}
writeMarkupAttributes(markup);
os.write(GT);
}
if (attributes != null && attributes.get(Chunk.SUBSUPSCRIPT) != null) {
// start sup or sub tag
if (((Float)attributes.get(Chunk.SUBSUPSCRIPT)).floatValue() > 0) {
writeStart(HtmlTags.SUP);
}
else {
writeStart(HtmlTags.SUB);
}
os.write(GT);
}
// contents
write(HtmlEncoder.encode(chunk.getContent()));
if (attributes != null && attributes.get(Chunk.SUBSUPSCRIPT) != null) {
// end sup or sub tag
os.write(LT);
os.write(FORWARD);
if (((Float)attributes.get(Chunk.SUBSUPSCRIPT)).floatValue() > 0) {
write(HtmlTags.SUP);
}
else {
write(HtmlTags.SUB);
}
os.write(GT);
}
if (tag) {
// end tag
writeEnd(Markup.HTML_TAG_SPAN);
}
return;
}
case LwgElement.PHRASE:
{
LwgPhrase phrase = (LwgPhrase) element;
styleAttributes = new Properties();
if (phrase.hasLeading()) styleAttributes.setProperty(Markup.CSS_KEY_LINEHEIGHT, phrase.getLeading() + "pt");
// start tag
addTabs(indent);
writeStart(Markup.HTML_TAG_SPAN);
writeMarkupAttributes(markup);
write(phrase.getFont(), styleAttributes);
os.write(GT);
currentfont.push(phrase.getFont());
// contents
for (Iterator i = phrase.iterator(); i.hasNext(); ) {
write((LwgElement) i.next(), indent + 1);
}
// end tag
addTabs(indent);
writeEnd(Markup.HTML_TAG_SPAN);
currentfont.pop();
return;
}
case LwgElement.ANCHOR:
{
Anchor anchor = (Anchor) element;
styleAttributes = new Properties();
if (anchor.hasLeading()) styleAttributes.setProperty(Markup.CSS_KEY_LINEHEIGHT, anchor.getLeading() + "pt");
// start tag
addTabs(indent);
writeStart(HtmlTags.ANCHOR);
if (anchor.getName() != null) {
write(HtmlTags.NAME, anchor.getName());
}
if (anchor.getReference() != null) {
write(HtmlTags.REFERENCE, anchor.getReference());
}
writeMarkupAttributes(markup);
write(anchor.getFont(), styleAttributes);
os.write(GT);
currentfont.push(anchor.getFont());
// contents
for (Iterator i = anchor.iterator(); i.hasNext(); ) {
write((LwgElement) i.next(), indent + 1);
}
// end tag
addTabs(indent);
writeEnd(HtmlTags.ANCHOR);
currentfont.pop();
return;
}
case LwgElement.PARAGRAPH:
{
Paragraph paragraph = (Paragraph) element;
styleAttributes = new Properties();
if (paragraph.hasLeading()) styleAttributes.setProperty(Markup.CSS_KEY_LINEHEIGHT, paragraph.getTotalLeading() + "pt");
// start tag
addTabs(indent);
writeStart(HtmlTags.DIV);
writeMarkupAttributes(markup);
String alignment = HtmlEncoder.getAlignment(paragraph.getAlignment());
if (!"".equals(alignment)) {
write(HtmlTags.ALIGN, alignment);
}
write(paragraph.getFont(), styleAttributes);
os.write(GT);
currentfont.push(paragraph.getFont());
// contents
for (Iterator i = paragraph.iterator(); i.hasNext(); ) {
write((LwgElement)i.next(), indent + 1);
}
// end tag
addTabs(indent);
writeEnd(HtmlTags.DIV);
currentfont.pop();
return;
}
case LwgElement.SECTION:
case LwgElement.CHAPTER:
{
// part of the start tag + contents
writeSection((Section) element, indent);
return;
}
case LwgElement.LIST:
{
List list = (List) element;
// start tag
addTabs(indent);
if (list.isNumbered()) {
writeStart(HtmlTags.ORDEREDLIST);
}
else {
writeStart(HtmlTags.UNORDEREDLIST);
}
writeMarkupAttributes(markup);
os.write(GT);
// contents
for (Iterator i = list.getItems().iterator(); i.hasNext(); ) {
write((LwgElement) i.next(), indent + 1);
}
// end tag
addTabs(indent);
if (list.isNumbered()) {
writeEnd(HtmlTags.ORDEREDLIST);
}
else {
writeEnd(HtmlTags.UNORDEREDLIST);
}
return;
}
case LwgElement.LISTITEM:
{
ListItem listItem = (ListItem) element;
styleAttributes = new Properties();
if (listItem.hasLeading()) styleAttributes.setProperty(Markup.CSS_KEY_LINEHEIGHT, listItem.getTotalLeading() + "pt");
// start tag
addTabs(indent);
writeStart(HtmlTags.LISTITEM);
writeMarkupAttributes(markup);
write(listItem.getFont(), styleAttributes);
os.write(GT);
currentfont.push(listItem.getFont());
// contents
for (Iterator i = listItem.iterator(); i.hasNext(); ) {
write((LwgElement) i.next(), indent + 1);
}
// end tag
addTabs(indent);
writeEnd(HtmlTags.LISTITEM);
currentfont.pop();
return;
}
case LwgElement.CELL:
{
LwgCell cell = (LwgCell) element;
// start tag
addTabs(indent);
if (cell.isHeader()) {
writeStart(HtmlTags.HEADERCELL);
}
else {
writeStart(HtmlTags.CELL);
}
writeMarkupAttributes(markup);
if (cell.getBorderWidth() != LwgRectangle.UNDEFINED) {
write(HtmlTags.BORDERWIDTH, String.valueOf(cell.getBorderWidth()));
}
if (cell.getBorderColor() != null) {
write(HtmlTags.BORDERCOLOR, HtmlEncoder.encode(cell.getBorderColor()));
}
if (cell.getBackgroundColor() != null) {
write(HtmlTags.BACKGROUNDCOLOR, HtmlEncoder.encode(cell.getBackgroundColor()));
}
String alignment = HtmlEncoder.getAlignment(cell.getHorizontalAlignment());
if (!"".equals(alignment)) {
write(HtmlTags.HORIZONTALALIGN, alignment);
}
alignment = HtmlEncoder.getAlignment(cell.getVerticalAlignment());
if (!"".equals(alignment)) {
write(HtmlTags.VERTICALALIGN, alignment);
}
if (cell.getWidthAsString() != null) {
write(HtmlTags.WIDTH, cell.getWidthAsString());
}
if (cell.getColspan() != 1) {
write(HtmlTags.COLSPAN, String.valueOf(cell.getColspan()));
}
if (cell.getRowspan() != 1) {
write(HtmlTags.ROWSPAN, String.valueOf(cell.getRowspan()));
}
if (cell.getMaxLines() == 1) {
write(HtmlTags.STYLE, "white-space: nowrap;");
}
os.write(GT);
// contents
if (cell.isEmpty()) {
write(NBSP);
} else {
for (Iterator i = cell.getElements(); i.hasNext(); ) {
write((LwgElement) i.next(), indent + 1);
}
}
// end tag
addTabs(indent);
if (cell.isHeader()) {
writeEnd(HtmlTags.HEADERCELL);
}
else {
writeEnd(HtmlTags.CELL);
}
return;
}
case LwgElement.ROW:
{
LwgRow row = (LwgRow) element;
// start tag
addTabs(indent);
writeStart(HtmlTags.ROW);
writeMarkupAttributes(markup);
os.write(GT);
// contents
LwgElement cell;
for (int i = 0; i < row.getColumns(); i++) {
if ((cell = (LwgElement)row.getCell(i)) != null) {
write(cell, indent + 1);
}
}
// end tag
addTabs(indent);
writeEnd(HtmlTags.ROW);
return;
}
case LwgElement.TABLE:
{
Table table;
try {
table = (Table) element;
}
catch(ClassCastException cce) {
try {
table = ((SimpleTable)element).createTable();
} catch (BadElementException e) {
throw new ExceptionConverter(e);
}
}
table.complete();
// start tag
addTabs(indent);
writeStart(HtmlTags.TABLE);
writeMarkupAttributes(markup);
os.write(SPACE);
write(HtmlTags.WIDTH);
os.write(EQUALS);
os.write(QUOTE);
write(String.valueOf(table.getWidth()));
if (!table.isLocked()){
write("%");
}
os.write(QUOTE);
String alignment = HtmlEncoder.getAlignment(table.getAlignment());
if (!"".equals(alignment)) {
write(HtmlTags.ALIGN, alignment);
}
write(HtmlTags.CELLPADDING, String.valueOf(table.getPadding()));
write(HtmlTags.CELLSPACING, String.valueOf(table.getSpacing()));
if (table.getBorderWidth() != LwgRectangle.UNDEFINED) {
write(HtmlTags.BORDERWIDTH, String.valueOf(table.getBorderWidth()));
}
if (table.getBorderColor() != null) {
write(HtmlTags.BORDERCOLOR, HtmlEncoder.encode(table.getBorderColor()));
}
if (table.getBackgroundColor() != null) {
write(HtmlTags.BACKGROUNDCOLOR, HtmlEncoder.encode(table.getBackgroundColor()));
}
os.write(GT);
// contents
LwgRow row;
for (Iterator iterator = table.iterator(); iterator.hasNext(); ) {
row = (LwgRow) iterator.next();
write(row, indent + 1);
}
// end tag
addTabs(indent);
writeEnd(HtmlTags.TABLE);
return;
}
case LwgElement.ANNOTATION:
{
Annotation annotation = (Annotation) element;
writeComment(annotation.title() + ": " + annotation.content());
return;
}
case LwgElement.IMGRAW:
case LwgElement.JPEG:
case LwgElement.JPEG2000:
case LwgElement.IMGTEMPLATE:
{
LwgImage image = (LwgImage) element;
if (image.getUrl() == null) {
return;
}
// start tag
addTabs(indent);
writeStart(HtmlTags.IMAGE);
String path = image.getUrl().toString();
if (imagepath != null) {
if (path.indexOf('/') > 0) {
path = imagepath + path.substring(path.lastIndexOf('/') + 1);
}
else {
path = imagepath + path;
}
}
write(HtmlTags.URL, path);
if ((image.getAlignment() & LwgImage.RIGHT) > 0) {
write(HtmlTags.ALIGN, HtmlTags.ALIGN_RIGHT);
}
else if ((image.getAlignment() & LwgImage.MIDDLE) > 0) {
write(HtmlTags.ALIGN, HtmlTags.ALIGN_MIDDLE);
}
else {
write(HtmlTags.ALIGN, HtmlTags.ALIGN_LEFT);
}
if (image.getAlt() != null) {
write(HtmlTags.ALT, image.getAlt());
}
write(HtmlTags.PLAINWIDTH, String.valueOf(image.getScaledWidth()));
write(HtmlTags.PLAINHEIGHT, String.valueOf(image.getScaledHeight()));
writeMarkupAttributes(markup);
writeEnd();
return;
}