Search in sources :

Example 6 with Font

use of com.lowagie.text.Font in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method generateElementHtml.

private Object generateElementHtml(Element element, int depth, Font font) {
    String tag = element.getName();
    Object myself;
    Object av;
    Font vFont = font;
    if (element instanceof HTMLDocument.RunElement) {
        HTMLDocument.RunElement re = (HTMLDocument.RunElement) element;
        int start = re.getStartOffset();
        int end = re.getEndOffset();
        try {
            String content = re.getDocument().getText(start, end - start);
            HtmlAttr htmlattr = printAttributesHtml(re);
            av = re.getAttribute(CSS.Attribute.FONT_SIZE);
            String fontsize = av == null ? null : av.toString();
            av = re.getAttribute(CSS.Attribute.FONT_FAMILY);
            String fontfamily = av == null ? null : av.toString();
            av = re.getAttribute(CSS.Attribute.COLOR);
            String fontcolor = av == null ? null : av.toString();
            if (fontcolor != null || fontsize != null || fontfamily != null) {
                if (fontfamily == null)
                    fontfamily = font.getFamilyname();
                if (fontsize != null && fontsize.endsWith("pt"))
                    fontsize = fontsize.substring(0, fontsize.indexOf("pt"));
                float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 8);
                int style = font.getStyle();
                Color color;
                if (fontcolor != null) {
                    color = Color.decode(fontcolor);
                } else
                    color = font.getColor();
                vFont = FontFactory.getFont(fontfamily, size, style, color);
            } else if (htmlattr.bold || htmlattr.italic) {
                String family = font.getFamilyname();
                float size = font.getSize();
                Color color = font.getColor();
                if (htmlattr.bold && htmlattr.italic)
                    vFont = FontFactory.getFont(family, size, Font.BOLDITALIC, color);
                else if (htmlattr.italic)
                    vFont = FontFactory.getFont(family, size, Font.ITALIC, color);
                else if (htmlattr.bold)
                    vFont = FontFactory.getFont(family, size, Font.BOLD);
            }
            myself = new Chunk(content, vFont);
        } catch (BadLocationException e) {
            e.printStackTrace();
            myself = null;
        }
    } else if (element instanceof HTMLDocument.BlockElement) {
        HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element;
        HtmlAttr htmlattr = printAttributesHtml(be);
        av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN);
        String align = av == null ? null : av.toString();
        if (htmlattr.bold || htmlattr.italic) {
            String family = font.getFamilyname();
            float size = font.getSize();
            Color color = font.getColor();
            if (htmlattr.bold && htmlattr.italic)
                vFont = FontFactory.getFont(family, size, Font.BOLDITALIC, color);
            else if (htmlattr.italic)
                vFont = FontFactory.getFont(family, size, Font.ITALIC, color);
            else if (htmlattr.bold)
                vFont = FontFactory.getFont(family, size, Font.BOLD, Color.blue);
        }
        if ("html".equalsIgnoreCase(tag)) {
            myself = generateElementChildrenHtml(element, depth + 1, vFont);
        } else if ("head".equalsIgnoreCase(tag)) {
            myself = null;
        } else if ("body".equalsIgnoreCase(tag)) {
            myself = generateElementChildrenHtml(element, depth + 1, vFont);
        } else if ("p".equalsIgnoreCase(tag) || "p-implied".equalsIgnoreCase(tag)) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            Paragraph paragraph = new Paragraph();
            paragraph.setFirstLineIndent(0F);
            for (Object child : children) {
                if (!(child instanceof Chunk))
                    paragraph.add(child);
            }
            if (align != null)
                paragraph.setAlignment(align);
            myself = paragraph;
        } else if ("h1".equalsIgnoreCase(tag) || "h2".equalsIgnoreCase(tag) || "h3".equalsIgnoreCase(tag)) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, subSectionFont);
            Paragraph title = new Paragraph();
            for (Object child : children) {
                title.add(child);
            }
            myself = new TempSectionPdf(title);
        } else if ("ul".equalsIgnoreCase(tag)) {
            com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f);
            list.setIndentationLeft(25.0f);
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                list.add(child);
            }
            myself = list;
        } else if ("ol".equalsIgnoreCase(tag)) {
            com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f);
            list.setIndentationLeft(25.0f);
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                list.add(child);
            }
            myself = list;
        } else if ("li".equalsIgnoreCase(tag)) {
            ListItem li = new ListItem();
            li.setSpacingAfter(0.0f);
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                li.add(child);
            }
            myself = li;
        } else if ("table".equalsIgnoreCase(tag)) {
            List<Object> rows = generateElementChildrenHtml(element, depth + 1, normalFont);
            try {
                int ncols = 0;
                for (Object row : rows) {
                    if (row instanceof List<?>) {
                        int n = ((List<?>) row).size();
                        if (n > ncols)
                            ncols = n;
                    }
                }
                Table table = new Table(2);
                table.setBorderWidth(1);
                table.setBorderColor(new Color(0, 128, 128));
                table.setPadding(1.0f);
                table.setSpacing(0.5f);
                Cell c = new Cell("header");
                c.setHeader(true);
                c.setColspan(ncols);
                table.addCell(c);
                table.endHeaders();
                for (Object row : rows) {
                    if (row instanceof List<?>) {
                        for (Object cell : (List<?>) row) {
                            if (cell instanceof Cell)
                                table.addCell((Cell) cell);
                        }
                    }
                }
                myself = table;
            } catch (BadElementException e) {
                e.printStackTrace();
                myself = null;
            }
        } else if ("tr".equalsIgnoreCase(tag)) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            myself = children;
        } else if ("td".equalsIgnoreCase(tag)) {
            Cell cell = new Cell();
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                cell.add(child);
            }
            myself = cell;
        } else if ("div".equalsIgnoreCase(tag)) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            Paragraph paragraph = new Paragraph();
            paragraph.setFirstLineIndent(0F);
            for (Object child : children) {
                paragraph.add(child);
            }
            if (align != null)
                paragraph.setAlignment(align);
            myself = paragraph;
        } else {
            System.err.println("Unknown element " + element.getName());
            myself = null;
        }
    } else {
        // could be BidiElement - not sure what it is
        myself = null;
    }
    return myself;
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Font(com.lowagie.text.Font) List(java.util.List) ArrayList(java.util.ArrayList) Cell(com.lowagie.text.Cell) DocxTable(com.centurylink.mdw.designer.utils.DocxBuilder.DocxTable) Table(com.lowagie.text.Table) BadElementException(com.lowagie.text.BadElementException) Color(java.awt.Color) Chunk(com.lowagie.text.Chunk) Paragraph(com.lowagie.text.Paragraph) ListItem(com.lowagie.text.ListItem) BadLocationException(javax.swing.text.BadLocationException)

Example 7 with Font

use of com.lowagie.text.Font in project OpenClinica by OpenClinica.

the class DownloadDiscrepancyNote method createCell.

private Cell createCell(String propertyName, String propertyValue) throws BadElementException {
    StringBuilder content = new StringBuilder(propertyName + ": ");
    content.append(propertyValue);
    Paragraph para = new Paragraph(content.toString(), new Font(Font.HELVETICA, 14, Font.BOLD, new Color(0, 0, 0)));
    return new Cell(para);
}
Also used : Color(java.awt.Color) Cell(com.lowagie.text.Cell) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph)

Example 8 with Font

use of com.lowagie.text.Font in project Openfire by igniterealtime.

the class ConversationUtils method getConversationPDF.

public ByteArrayOutputStream getConversationPDF(Conversation conversation) {
    Font red = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD, new Color(0xFF, 0x00, 0x00));
    Font blue = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.ITALIC, new Color(0x00, 0x00, 0xFF));
    Font black = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD, Color.BLACK);
    Map<String, Font> colorMap = new HashMap<String, Font>();
    if (conversation != null) {
        Collection<JID> set = conversation.getParticipants();
        int count = 0;
        for (JID jid : set) {
            if (conversation.getRoom() == null) {
                if (count == 0) {
                    colorMap.put(jid.toString(), blue);
                } else {
                    colorMap.put(jid.toString(), red);
                }
                count++;
            } else {
                colorMap.put(jid.toString(), black);
            }
        }
    }
    return buildPDFContent(conversation, colorMap);
}
Also used : JID(org.xmpp.packet.JID) HashMap(java.util.HashMap) Color(java.awt.Color) Font(com.lowagie.text.Font)

Example 9 with Font

use of com.lowagie.text.Font in project vcell by virtualcell.

the class ITextWriter method writeStructure.

protected void writeStructure(Model model, Structure struct, Table structTable) throws DocumentException {
    // If this structure has any reactions in it, add its name as a hyperlink to the reactions' list.
    if (hasReactions(model, struct)) {
        Paragraph linkParagraph = new Paragraph();
        Font linkFont;
        try {
            BaseFont fontBaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            linkFont = new Font(fontBaseFont, DEF_FONT_SIZE, Font.NORMAL, new java.awt.Color(0, 0, 255));
        } catch (Exception e) {
            linkFont = getFont();
            e.printStackTrace();
        }
        linkParagraph.add(new Chunk(struct.getName(), linkFont).setLocalGoto(struct.getName()));
        Cell structLinkCell = new Cell(linkParagraph);
        structLinkCell.setBorderWidth(1);
        structLinkCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        structTable.addCell(structLinkCell);
    } else {
        structTable.addCell(createCell(struct.getName(), getFont()));
    }
    StructureTopology structTopology = model.getStructureTopology();
    if (struct instanceof Membrane) {
        structTable.addCell(createCell("Membrane", getFont()));
        Feature outsideFeature = structTopology.getOutsideFeature((Membrane) struct);
        Feature insideFeature = structTopology.getInsideFeature((Membrane) struct);
        structTable.addCell(createCell((insideFeature != null ? insideFeature.getName() : "N/A"), getFont()));
        structTable.addCell(createCell((outsideFeature != null ? outsideFeature.getName() : "N/A"), getFont()));
    } else {
        structTable.addCell(createCell("Feature", getFont()));
        String outsideStr = "N/A", insideStr = "N/A";
        Membrane enclosingMem = (Membrane) structTopology.getParentStructure(struct);
        if (enclosingMem != null) {
            outsideStr = enclosingMem.getName();
        }
        // To do:  retrieve the 'child' membrane here...
        structTable.addCell(createCell(insideStr, getFont()));
        structTable.addCell(createCell(outsideStr, getFont()));
    }
}
Also used : StructureTopology(cbit.vcell.model.Model.StructureTopology) Color(java.awt.Color) BaseFont(com.lowagie.text.pdf.BaseFont) Membrane(cbit.vcell.model.Membrane) Chunk(com.lowagie.text.Chunk) Cell(com.lowagie.text.Cell) Feature(cbit.vcell.model.Feature) BaseFont(com.lowagie.text.pdf.BaseFont) Font(com.lowagie.text.Font) DocumentException(com.lowagie.text.DocumentException) ExpressionException(cbit.vcell.parser.ExpressionException) Paragraph(com.lowagie.text.Paragraph)

Example 10 with Font

use of com.lowagie.text.Font in project activityinfo by bedatadriven.

the class ThemeHelper method columnHeaderCell.

public static Cell columnHeaderCell(String label, boolean leaf, int hAlign) throws BadElementException {
    Paragraph para = new Paragraph(label);
    para.setFont(new Font(Font.HELVETICA, BODY_FONT_SIZE, Font.NORMAL, Color.WHITE));
    Cell cell = new Cell();
    cell.addElement(para);
    cell.setHorizontalAlignment(hAlign);
    cell.setHeader(true);
    cell.setVerticalAlignment(Cell.ALIGN_BOTTOM);
    cell.setBackgroundColor(BLUE3);
    cell.setBorderWidth(0);
    return cell;
}
Also used : Cell(com.lowagie.text.Cell) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph)

Aggregations

Font (com.lowagie.text.Font)18 Paragraph (com.lowagie.text.Paragraph)14 Color (java.awt.Color)9 Cell (com.lowagie.text.Cell)6 DocumentException (com.lowagie.text.DocumentException)6 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)4 ExpressionException (cbit.vcell.parser.ExpressionException)3 Chunk (com.lowagie.text.Chunk)3 Document (com.lowagie.text.Document)3 BaseFont (com.lowagie.text.pdf.BaseFont)3 HeaderFooter (com.lowagie.text.HeaderFooter)2 Phrase (com.lowagie.text.Phrase)2 Table (com.lowagie.text.Table)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 Feature (cbit.vcell.model.Feature)1 Membrane (cbit.vcell.model.Membrane)1 StructureTopology (cbit.vcell.model.Model.StructureTopology)1 DocxTable (com.centurylink.mdw.designer.utils.DocxBuilder.DocxTable)1 BadElementException (com.lowagie.text.BadElementException)1 ListItem (com.lowagie.text.ListItem)1