Example usage for com.lowagie.text Font setColor

List of usage examples for com.lowagie.text Font setColor

Introduction

In this page you can find the example usage for com.lowagie.text Font setColor.

Prototype


public void setColor(Color color) 

Source Link

Document

Sets the color.

Usage

From source file:org.areasy.common.doclet.document.tags.HtmlTag.java

License:Open Source License

/**
 * Returns the appropriate PDF font for this
 * HTML tag. The font is created based on the
 * type and attributes of the tag./*from ww  w.  jav  a  2  s.c  o  m*/
 *
 * @return The PDF document font.
 */
public Font getFont() {
    Font font;

    int faceId = TEXT_FONT;
    boolean parentIsFixedFont = false;

    if (isCode() || isPre())
        faceId = CODE_FONT;

    if (parent != null) {
        if (getFontSize() == DEFAULT_FONT_SIZE)
            setFontSize(parent.getFontSize());
        parentIsFixedFont = parent.isCode() || parent.isPre();
    }

    // Pre-formatted text parts tend to appear bigger, so make them 1 point smaller
    if ((isCode() || isPre()) && !parentIsFixedFont)
        setFontSize(getFontSize() - 1);

    if (type == TAG_I)
        setItalic(true);
    if (type == TAG_B)
        setBold(true);
    if (type == TAG_U)
        setUnderline(true);

    if (type == TAG_H1)
        setFontSize(26);
    if (type == TAG_H2)
        setFontSize(22);
    if (type == TAG_H3)
        setFontSize(19);
    if (type == TAG_H4)
        setFontSize(16);
    if (type == TAG_H5)
        setFontSize(13);
    if (type == TAG_H6)
        setFontSize(10);

    int style = 0;

    if (isBold() && isItalic())
        style = BOLD + ITALIC;
    else if (isBold())
        style = BOLD;
    else if (isItalic())
        style = ITALIC;

    if (isLink())
        style = style + LINK;
    if (isUnderline())
        style = style + UNDERLINE;
    if (isStrikethrough())
        style = style + STRIKETHROUGH;

    if (type == TAG_BODY && Locale.getDefault().getLanguage().equals(Locale.JAPANESE.getLanguage()))
        font = FontFactory.getFont("HeiseiMin-W3", "UniJIS-UCS2-HW-H", getFontSize(), style, getFontColor());
    else
        font = Fonts.getFont(faceId, style, getFontSize());

    if (getFontColor() == null && parent != null && parent.getFontColor() != null)
        setFontColor(parent.getFontColor());
    if (getFontFace() == null && parent != null && parent.getFontFace() != null)
        setFontFace(parent.getFontFace());

    if (getFontColor() != null)
        font.setColor(getFontColor());
    if (StringUtility.isNotEmpty(getFontFace()))
        font.setFamily(getFontFace());

    return font;
}

From source file:org.areasy.common.doclet.document.tags.TagA.java

License:Open Source License

protected Chunk createChunk(String text) {
    Chunk chunk = new Chunk(text);

    Font font = chunk.font();
    font.setStyle(Font.NORMAL);/*from  w  w w .  j  a  v  a2s.c o m*/
    font.setColor(Color.blue);

    chunk.setFont(font);

    return chunk;
}

From source file:org.mapfish.print.config.layout.FontBlock.java

License:Open Source License

protected Font getPdfFont() {
    Font result = FontFactory.getFont(font, fontEncoding, (float) getFontSize());
    result.setColor(getFontColorVal());
    return result;
}

From source file:org.odftoolkit.odfdom.converter.internal.itext.ElementVisitorForIText.java

License:Open Source License

@Override
public void visit(TextAElement ele) {
    StylableAnchor anchor = document.createAnchor(currentContainer);
    String reference = ele.getXlinkHrefAttribute();
    applyStyles(ele, anchor);/*w w  w.j  av a2  s  .c o m*/

    if (anchor.getFont().getColor() == null) {
        // if no color was applied to the link get the font of the paragraph and set blue color.
        Font linkFont = anchor.getFont();
        Style style = currentContainer.getLastStyleApplied();
        if (style != null) {
            StyleTextProperties textProperties = style.getTextProperties();
            if (textProperties != null) {
                Font font = textProperties.getFont();
                if (font != null) {
                    linkFont = new Font(font);
                    anchor.setFont(linkFont);
                }
            }
        }
        linkFont.setColor(Color.BLUE);
    }

    // set the link
    anchor.setReference(reference);
    // Add to current container.
    addITextContainer(ele, anchor);
}

From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java

License:Open Source License

/**
 * Renders a Cell for//  w  w w  .  ja v  a2 s . co  m
 *
 * @param label
 * @param header
 * @param depth
 * @param leaf
 * @param horizantalAlignment
 * @return
 * @throws BadElementException
 */
public static Cell bodyCell(String label, boolean header, int depth, boolean leaf, int horizantalAlignment)
        throws BadElementException {

    Cell cell = new Cell();
    cell.setHorizontalAlignment(horizantalAlignment);

    if (label != null) {
        Paragraph para = new Paragraph(label);
        Font font = new Font(Font.HELVETICA, 10, Font.NORMAL, Color.BLACK);
        if (depth == 0 && !leaf) {
            font.setColor(Color.WHITE);
        }
        para.setFont(font);
        para.setIndentationLeft(5.4f + (header ? 12 * depth : 0));
        cell.addElement(para);
    }

    cell.setBorderWidthLeft(0f);
    cell.setBorderWidthRight(0);
    cell.setBorderWidthTop(0);

    if (!leaf && depth == 0) {
        cell.setBackgroundColor(new Color(149, 179, 215)); // #95B3D7
        cell.setBorderWidthBottom(0.5f);
        cell.setBorderColorBottom(new Color(219, 229, 241)); // #DBE5F1
    } else if (!leaf && depth == 1) {
        cell.setBackgroundColor(new Color(219, 229, 241));
        cell.setBorderWidthBottom(0.5f);
        cell.setBorderColorBottom(new Color(79, 129, 189));
    } else {
        cell.setBorderWidthBottom(0.5f);
        cell.setBorderColorBottom(new Color(219, 229, 241));
        cell.setBorderWidthTop(0.5f);
        cell.setBorderColorTop(new Color(219, 229, 241));
    }

    return cell;
}

From source file:org.unitime.timetable.util.PdfFont.java

License:Open Source License

public static Font getFont(boolean bold, boolean italic, boolean underline, Color color) {
    Font font = getFont(bold, italic);
    if (underline)
        font.setStyle(font.getStyle() + Font.UNDERLINE);
    if (color != null)
        font.setColor(color);
    return font;/*from  ww w.ja va 2 s . c o  m*/
}

From source file:org.unitime.timetable.util.PdfFont.java

License:Open Source License

public static Font getSmallFont(boolean bold, boolean italic, boolean underline, Color color) {
    Font font = getSmallFont(bold, italic);
    if (underline)
        font.setStyle(font.getStyle() + Font.UNDERLINE);
    if (color != null)
        font.setColor(color);
    return font;/*from   w w w .j a va2  s  .  co  m*/
}

From source file:org.webguitoolkit.ui.util.export.PDFTableExport.java

License:Apache License

/**
 * @param table/*from  w  ww  . j  a  v a  2 s.  co  m*/
 * @param footer
 * @param header
 * @return
 */
public PdfPTable pdfExport(Table table) {
    TableExportOptions exportOptions = table.getExportOptions();
    boolean showOnlyDisplayed = exportOptions.isShowOnlyDisplayedColumns();
    Font headfont = new Font(Font.UNDEFINED, Font.DEFAULTSIZE, Font.BOLD);

    Font bodyfont = new Font(exportOptions.getPdfFontSize(), exportOptions.getPdfFontSize(), Font.NORMAL);
    if (exportOptions.getPdfFontColour() != null) {
        Color fontColor = exportOptions.getPdfFontColour();
        bodyfont.setColor(fontColor);
        headfont.setColor(fontColor);
    }

    List<ITableColumn> columns = getTableColumns(showOnlyDisplayed, table);
    int columnCount = 0;
    for (int i = 0; i < columns.size(); i++) {
        TableColumn c = (TableColumn) columns.get(i);
        //hide select checkbox column
        if (!c.isExporatble())
            continue;

        columnCount++;

    }
    PdfPTable resulttable = new PdfPTable(columnCount);
    resulttable.setWidthPercentage(100f);

    if (StringUtils.isNotEmpty(exportOptions.getTableHeadline())) {
        PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableHeadline()));
        cell.setColspan(columns.size());
        cell.setBackgroundColor(Color.lightGray);
        resulttable.addCell(cell);
    }

    for (int i = 0; i < columns.size(); i++) {
        TableColumn c = (TableColumn) columns.get(i);
        // hide select checkbox column
        if (!c.isExporatble())
            continue;

        String cellData = TextService.getString(c.getTitle());
        if (cellData.contains("<br/>") || cellData.contains("<br>")) {
            cellData = cellData.replaceAll("<br\\/>", "\\/");
            cellData = cellData.replaceAll("<br>", "\\/");
        }
        PdfPCell cell = new PdfPCell(new Paragraph((cellData), headfont));
        cell.setBackgroundColor(Color.lightGray);
        resulttable.addCell(cell);

    }

    List tabledata = table.getDefaultModel().getFilteredList();
    if (tabledata.isEmpty()) {
        for (int i = 0; i < columns.size(); i++) {
            resulttable.addCell(new PdfPCell((new Phrase(""))));
        }
    }

    for (Iterator it = tabledata.iterator(); it.hasNext();) {
        DataBag dbag = (DataBag) it.next();
        for (int i = 0; i < columns.size(); i++) {
            TableColumn tableColumn = (TableColumn) columns.get(i);
            if (!tableColumn.isExporatble())
                continue;
            logger.debug("property: " + tableColumn.getProperty());
            IColumnRenderer renderer = tableColumn.getRenderer();
            Converter converter = tableColumn.getConverter();

            addObjectCell(bodyfont, resulttable, dbag, tableColumn, renderer, converter);
        }
    }

    if (StringUtils.isNotEmpty(exportOptions.getTableFooter())) {
        PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableFooter()));
        cell.setColspan(columnCount);
        cell.setBackgroundColor(Color.lightGray);
        resulttable.addCell(cell);
    }

    resulttable.setHeaderRows(1);
    return resulttable;

}

From source file:questions.importpages.NameCard.java

public static void createOneCard() throws DocumentException, IOException {
    Rectangle rect = new Rectangle(Utilities.millimetersToPoints(86.5f), Utilities.millimetersToPoints(55));
    Document document = new Document(rect);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(CARD));
    writer.setViewerPreferences(PdfWriter.PrintScalingNone);
    document.open();//from   w  ww  .j  a  v a  2s  .c  o m
    PdfReader reader = new PdfReader(LOGO);
    Image img = Image.getInstance(writer.getImportedPage(reader, 1));
    img.scaleToFit(rect.getWidth() / 1.5f, rect.getHeight() / 1.5f);
    img.setAbsolutePosition((rect.getWidth() - img.getScaledWidth()) / 2,
            (rect.getHeight() - img.getScaledHeight()) / 2);
    document.add(img);
    document.newPage();
    BaseFont bf = BaseFont.createFont(FONT, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    Font font = new Font(bf, 12);
    font.setColor(new CMYKColor(1, 0.5f, 0, 0.467f));
    ColumnText column = new ColumnText(writer.getDirectContent());
    Paragraph p;
    p = new Paragraph("Bruno Lowagie\n1T3XT\nbruno@1t3xt.com", font);
    p.setAlignment(Element.ALIGN_CENTER);
    column.addElement(p);
    column.setSimpleColumn(0, 0, rect.getWidth(), rect.getHeight() * 0.75f);
    column.go();
    document.close();
}

From source file:ro.nextreports.engine.exporter.RtfExporter.java

License:Apache License

private void updateFont(Font fnt, Map<String, Object> style) {
    if (style != null) {
        if (style.containsKey(StyleFormatConstants.FONT_FAMILY_KEY)) {
            String val = (String) style.get(StyleFormatConstants.FONT_FAMILY_KEY);
            fnt.setFamily(val);
        }/*from   w w  w . j a  v a  2  s .  c  om*/
        if (style.containsKey(StyleFormatConstants.FONT_SIZE)) {
            Float val = (Float) style.get(StyleFormatConstants.FONT_SIZE);
            fnt.setSize(val);
        }
        if (style.containsKey(StyleFormatConstants.FONT_COLOR)) {
            Color val = (Color) style.get(StyleFormatConstants.FONT_COLOR);
            fnt.setColor(val);
        }
        if (style.containsKey(StyleFormatConstants.FONT_STYLE_KEY)) {
            if (StyleFormatConstants.FONT_STYLE_NORMAL.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) {
                fnt.setStyle(com.lowagie.text.Font.NORMAL);
            }
            if (StyleFormatConstants.FONT_STYLE_BOLD.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) {
                fnt.setStyle(com.lowagie.text.Font.BOLD);
            }
            if (StyleFormatConstants.FONT_STYLE_ITALIC.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) {
                fnt.setStyle(com.lowagie.text.Font.ITALIC);
            }
            if (StyleFormatConstants.FONT_STYLE_BOLDITALIC
                    .equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) {
                fnt.setStyle(com.lowagie.text.Font.BOLDITALIC);
            }
        }
    }
}