⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlwriter.java

📁 java itext java itext java itext
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                }
                if (listItem.font().style() != Font.UNDEFINED && listItem.font().style() != Font.NORMAL) {
                    addTabs(indent);
                    writeFontStyleEnd(listItem.font().style());
                    os.write(NEWLINE);
                }
                if (!listItem.font().isStandardFont()) {
                    addTabs(indent);
                    writeEnd(HtmlTags.PHRASE);
                }
                addTabs(indent);
                writeEnd(HtmlTags.LISTITEM);
                return;
            }
            case Element.CELL:
            {
                Cell cell = (Cell) element;
                
                addTabs(indent);
                if (cell.header()) {
                    writeStart(HtmlTags.HEADERCELL);
                }
                else {
                    writeStart(HtmlTags.CELL);
                }
                if (cell.borderWidth() != Rectangle.UNDEFINED) {
                    write(HtmlTags.BORDERWIDTH, String.valueOf(cell.borderWidth()));
                }
                if (cell.borderColor() != null) {
                    write(HtmlTags.BORDERCOLOR, HtmlEncoder.encode(cell.borderColor()));
                }
                if (cell.backgroundColor() != null) {
                    write(HtmlTags.BACKGROUNDCOLOR, HtmlEncoder.encode(cell.backgroundColor()));
                }
                String alignment = HtmlEncoder.getAlignment(cell.horizontalAlignment());
                if (!"".equals(alignment)) {
                    write(HtmlTags.HORIZONTALALIGN, alignment);
                }
                alignment = HtmlEncoder.getAlignment(cell.verticalAlignment());
                if (!"".equals(alignment)) {
                    write(HtmlTags.VERTICALALIGN, alignment);
                }
                if (cell.cellWidth() != null) {
                    write(HtmlTags.WIDTH, cell.cellWidth());
                }
                if (cell.colspan() != 1) {
                    write(HtmlTags.COLSPAN, String.valueOf(cell.colspan()));
                }
                if (cell.rowspan() != 1) {
                    write(HtmlTags.ROWSPAN, String.valueOf(cell.rowspan()));
                }
                if (cell.noWrap()) {
                    write(HtmlTags.NOWRAP, String.valueOf(true));
                }
                os.write(GT);
                os.write(NEWLINE);
                for (Iterator i = cell.getElements(); i.hasNext(); ) {
                    write((Element) i.next(), indent + 1);
                }
                if (cell.isEmpty()) {
                    write(NBSP);
                }
                addTabs(indent);
                if (cell.header()) {
                    writeEnd(HtmlTags.HEADERCELL);
                }
                else {
                    writeEnd(HtmlTags.CELL);
                }
                return;
            }
            case Element.ROW:
            {
                Row row = (Row) element;
                
                addTabs(indent);
                writeStart(HtmlTags.ROW);
                os.write(GT);
                os.write(NEWLINE);
                Element cell;
                for (int i = 0; i < row.columns(); i++) {
                    if ((cell = (Element)row.getCell(i)) != null) {
                        write(cell, indent + 1);
                    }
                }
                addTabs(indent);
                writeEnd(HtmlTags.ROW);
                return;
            }
            case Element.TABLE:
            {
                Table table = (Table) element;
                
                addTabs(indent);
                writeStart(HtmlTags.TABLE);
                //write(HtmlTags.COLUMNS, String.valueOf(table.columns()));
                os.write(SPACE);
                write(HtmlTags.WIDTH);
                os.write(EQUALS);
                os.write(QUOTE);
                if (! "".equals(table.absWidth())){
                    write(table.absWidth());
                }
                else{
                    write(String.valueOf(table.widthPercentage()));
                    write("%");
                }
                os.write(QUOTE);
                String alignment = HtmlEncoder.getAlignment(table.alignment());
                if (!"".equals(alignment)) {
                    write(HtmlTags.ALIGN, alignment);
                }
                write(HtmlTags.CELLPADDING, String.valueOf(table.cellpadding()));
                write(HtmlTags.CELLSPACING, String.valueOf(table.cellspacing()));
                if (table.borderWidth() != Rectangle.UNDEFINED) {
                    write(HtmlTags.BORDERWIDTH, String.valueOf(table.borderWidth()));
                }
                if (table.borderColor() != null) {
                    write(HtmlTags.BORDERCOLOR, HtmlEncoder.encode(table.borderColor()));
                }
                if (table.backgroundColor() != null) {
                    write(HtmlTags.BACKGROUNDCOLOR, HtmlEncoder.encode(table.backgroundColor()));
                }
                os.write(GT);
                os.write(NEWLINE);
                Row row;
                for (Iterator iterator = table.iterator(); iterator.hasNext(); ) {
                    row = (Row) iterator.next();
                    write(row, indent + 1);
                }
                addTabs(indent);
                writeEnd(HtmlTags.TABLE);
                return;
            }
            case Element.ANNOTATION:
            {
                Annotation annotation = (Annotation) element;
                writeComment(annotation.title() + ": " + annotation.content());
                return;
            }
            case Element.GIF:
            case Element.JPEG:
            case Element.PNG:
            {
                Image image = (Image) element;
                if (image.url() == null) {
                    return;
                }
                
                addTabs(indent);
                writeStart(HtmlTags.IMAGE);
                String path = image.url().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.alignment() & Image.LEFT) > 0) {
                    write(HtmlTags.ALIGN, HtmlTags.ALIGN_LEFT);
                }
                else if ((image.alignment() & Image.RIGHT) > 0) {
                    write(HtmlTags.ALIGN, HtmlTags.ALIGN_RIGHT);
                }
                else if ((image.alignment() & Image.MIDDLE) > 0) {
                    write(HtmlTags.ALIGN, HtmlTags.ALIGN_MIDDLE);
                }
                if (image.alt() != null) {
                    write(HtmlTags.ALT, image.alt());
                }
                write(HtmlTags.PLAINWIDTH, String.valueOf(image.scaledWidth()));
                write(HtmlTags.PLAINHEIGHT, String.valueOf(image.scaledHeight()));
                writeEnd();
                return;
            }
            default:
                return;
        }
    }
    
/**
 * Writes the HTML representation of a section.
 *
 * @param   section     the section to write
 * @param   indent      the indentation
 */
    
    protected void writeSection(Section section, int indent) throws IOException {
        os.write(GT);
        os.write(NEWLINE);
        
        if (section.title() != null) {
            int depth = section.depth() - 1;
            if (depth > 5) {
                depth = 5;
            }
            addTabs(indent + 1);
            writeStart(HtmlTags.H[depth]);
            String alignment = HtmlEncoder.getAlignment(section.title().alignment());
            if (!"".equals(alignment)) {
                write(HtmlTags.ALIGN, alignment);
            }
            os.write(GT);
            os.write(NEWLINE);
            for (Iterator i = section.title().iterator(); i.hasNext(); ) {
                write((Element)i.next(), indent + 2);
            }
            addTabs(indent + 1);
            writeEnd(HtmlTags.H[depth]);
        }
        for (Iterator i = section.iterator(); i.hasNext(); ) {
            write((Element) i.next(), indent + 1);
        }
        addTabs(indent);
    }
    
/**
 * Writes the HTML representation of a <CODE>Font</CODE>.
 *
 * @param	a <CODE>Font</CODE>
 */
    
    protected void write(Font font) throws IOException {
        switch(font.family()) {
            case Font.COURIER:
                write(HtmlTags.FONT, "Courier");
                break;
            case Font.HELVETICA:
                write(HtmlTags.FONT, "Helvetica");
                break;
            case Font.TIMES_NEW_ROMAN:
                write(HtmlTags.FONT, "Times New Roman");
                break;
            case Font.SYMBOL:
                write(HtmlTags.FONT, "Symbol");
                break;
            case Font.ZAPFDINGBATS:
                write(HtmlTags.FONT, "ZapfDingbats");
                break;
                default:
        }
        if (font.size() != Font.UNDEFINED) {
            write(HtmlTags.SIZE, String.valueOf(font.size()));
        }
        if (font.color() != null) {
            write(HtmlTags.COLOR, HtmlEncoder.encode(font.color()));
        }
    }
    
/**
 * Writes the HTML representation of a <CODE>Font</CODE>.
 *
 * @param	a <CODE>Font</CODE>
 */
    
    protected void writeFontStyleStart(int fontstyle) throws IOException {
        if (fontstyle == Font.UNDEFINED || fontstyle == Font.NORMAL) {
            return;
        }
        os.write(LT);
        switch(fontstyle & Font.BOLDITALIC) {
            case Font.BOLD:
                write(HtmlTags.B);
                break;
            case Font.ITALIC:
                write(HtmlTags.I);
                break;
            case Font.BOLDITALIC:
                write(HtmlTags.B);
                os.write(GT);
                os.write(LT);
                write(HtmlTags.I);
                break;
        }
        if ((fontstyle & Font.UNDERLINE) > 0) {
            if ((fontstyle & Font.BOLDITALIC) > 0) {
                os.write(GT);
                os.write(LT);
                write(HtmlTags.U);
            }
            else {
                write(HtmlTags.U);
            }
        }
        if ((fontstyle & Font.STRIKETHRU) > 0) {
            if ((fontstyle & Font.BOLDITALIC) > 0 || (fontstyle & Font.UNDERLINE) > 0) {
                os.write(GT);
                os.write(LT);
                write(HtmlTags.S);
            }
            else {
                write(HtmlTags.S);
            }
        }
        os.write(GT);
    }
    
/**
 * Writes the HTML representation of a <CODE>Font</CODE>.
 *
 * @param	a <CODE>Font</CODE>
 */
    
    protected void writeFontStyleEnd(int fontstyle) throws IOException {
        if (fontstyle == Font.UNDEFINED || fontstyle == Font.NORMAL) {
            return;
        }
        os.write(LT);
        os.write(FORWARD);
        if ((fontstyle & Font.STRIKETHRU) > 0) {
            write(HtmlTags.S);
        }
        if ((fontstyle& Font.UNDERLINE) > 0) {
            if ((fontstyle & Font.STRIKETHRU) > 0) {
                os.write(GT);
                os.write(LT);
                os.write(FORWARD);
                write(HtmlTags.U);
            }
            else {
                write(HtmlTags.U);
            }
        }
        if ((fontstyle & Font.BOLDITALIC) > 0) {
            if((fontstyle & Font.STRIKETHRU) > 0 || (fontstyle & Font.UNDERLINE) > 0) {
                os.write(GT);
                os.write(LT);
                os.write(FORWARD);
            }
            switch(fontstyle & Font.BOLDITALIC) {
                case Font.BOLD:
                    write(HtmlTags.B);
                    break;
                case Font.ITALIC:
                    write(HtmlTags.I);
                    break;
                case Font.BOLDITALIC:
                    write(HtmlTags.I);
                    os.write(GT);
                    os.write(LT);
                    os.write(FORWARD);
                    write(HtmlTags.B);
                    break;
            }
        }
        os.write(GT);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -