Example usage for com.lowagie.text Font STRIKETHRU

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

Introduction

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

Prototype

int STRIKETHRU

To view the source code for com.lowagie.text Font STRIKETHRU.

Click Source Link

Document

this is a possible style.

Usage

From source file:com.bibisco.export.ITextExporter.java

License:GNU General Public License

@Override
public void addText(String pStrText, TextFormatting pTextFormatting) {

    mLog.debug("Start addText(): " + pStrText);

    Font lFont = new Font();
    lFont.setFamily(mFont.getFamilyname());
    lFont.setSize(mFont.getSize());//from  www . java 2 s  .com

    int lIntStyle = 0;
    if (pTextFormatting.bold) {
        lIntStyle = lIntStyle | Font.BOLD;
    }
    if (pTextFormatting.italic) {
        lIntStyle = lIntStyle | Font.ITALIC;
    }
    if (pTextFormatting.underline) {
        lIntStyle = lIntStyle | Font.UNDERLINE;
    }
    if (pTextFormatting.strike) {
        lIntStyle = lIntStyle | Font.STRIKETHRU;
    }
    lFont.setStyle(lIntStyle);

    Chunk lChunk = new Chunk(pStrText, lFont);

    if (mListItem != null) {
        mListItem.add(lChunk);
    } else if (mParagraph != null) {
        mParagraph.add(lChunk);
    }

    mLog.debug("End addText()");
}

From source file:com.develog.utils.report.engine.export.JRPdfExporter.java

License:Open Source License

/**
 *
 *///from ww  w.j  av a2 s  .c o  m
protected Chunk getChunk(Map attributes, String text) throws JRException, DocumentException, IOException {
    JRFont jrFont = new JRBaseFont(attributes);

    BaseFont baseFont = null;
    Exception initialException = null;

    try {
        baseFont = BaseFont.createFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded(),
                true, null, null);
    } catch (Exception e) {
        initialException = e;
    }

    if (baseFont == null) {
        byte[] bytes = null;

        try {
            bytes = JRLoader.loadBytesFromLocation(jrFont.getPdfFontName());
        } catch (JRException e) {
            throw new JRException("Could not load the following font : " + "\npdfFontName   : "
                    + jrFont.getPdfFontName() + "\npdfEncoding   : " + jrFont.getPdfEncoding()
                    + "\nisPdfEmbedded : " + jrFont.isPdfEmbedded(), initialException);
        }

        baseFont = BaseFont.createFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded(),
                true, bytes, null);
    }

    Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND);
    Color backcolor = (Color) attributes.get(TextAttribute.BACKGROUND);
    /*
    if (forecolor == null)
    {
       forecolor = Color.black;
    }
    */

    Font font = new Font(baseFont, (float) jrFont.getSize(),
            //((jrFont.isBold())?Font.BOLD:0) +
            //((jrFont.isItalic())?Font.ITALIC:0) +
            (jrFont.isUnderline() ? Font.UNDERLINE : 0) | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0),
            forecolor);

    Chunk chunk = new Chunk(text, font);

    if (backcolor != null) {
        chunk.setBackground(backcolor);
    }

    return chunk;
}

From source file:com.dlya.facturews.DlyaPdfExporter2.java

License:Open Source License

/**
 * Creates a PDF font.//from  w w w .  ja v a  2  s.c om
 * 
 * @param attributes the text attributes of the font
 * @param locale the locale for which to create the font
 * @param setFontLines whether to set underline and strikethrough as font style
 * @return the PDF font for the specified attributes
 */
@SuppressWarnings("deprecation")
protected Font getFont(Map<Attribute, Object> attributes, Locale locale, boolean setFontLines) {
    JRFont jrFont = new JRBaseFont(attributes);

    Exception initialException = null;

    Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND);

    // use the same font scale ratio as in JRStyledText.getAwtAttributedString
    float fontSizeScale = 1f;
    Integer scriptStyle = (Integer) attributes.get(TextAttribute.SUPERSCRIPT);
    if (scriptStyle != null && (TextAttribute.SUPERSCRIPT_SUB.equals(scriptStyle)
            || TextAttribute.SUPERSCRIPT_SUPER.equals(scriptStyle))) {
        fontSizeScale = 2f / 3;
    }

    Font font = null;
    PdfFont pdfFont = null;
    FontKey key = new FontKey(jrFont.getFontName(), jrFont.isBold(), jrFont.isItalic());

    if (fontMap != null && fontMap.containsKey(key)) {
        pdfFont = pdfFontMap.get(key);
    } else {
        FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(jrFont.getFontName(),
                locale);
        if (fontInfo == null) {
            //fontName NOT found in font extensions
            pdfFont = new PdfFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded());
        } else {
            //fontName found in font extensions
            FontFamily family = fontInfo.getFontFamily();
            FontFace face = fontInfo.getFontFace();
            int faceStyle = java.awt.Font.PLAIN;

            if (face == null) {
                //fontName matches family name in font extension
                if (jrFont.isBold() && jrFont.isItalic()) {
                    face = family.getBoldItalicFace();
                    faceStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC;
                }

                if (face == null && jrFont.isBold()) {
                    face = family.getBoldFace();
                    faceStyle = java.awt.Font.BOLD;
                }

                if (face == null && jrFont.isItalic()) {
                    face = family.getItalicFace();
                    faceStyle = java.awt.Font.ITALIC;
                }

                if (face == null) {
                    face = family.getNormalFace();
                    faceStyle = java.awt.Font.PLAIN;
                }

                //               if (face == null)
                //               {
                //                  throw new JRRuntimeException("Font family '" + family.getName() + "' does not have the normal font face.");
                //               }
            } else {
                //fontName matches face name in font extension; not family name
                faceStyle = fontInfo.getStyle();
            }

            String pdfFontName = null;
            int pdfFontStyle = java.awt.Font.PLAIN;
            if (jrFont.isBold() && jrFont.isItalic()) {
                pdfFontName = family.getBoldItalicPdfFont();
                pdfFontStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC;
            }

            if (pdfFontName == null && jrFont.isBold()) {
                pdfFontName = family.getBoldPdfFont();
                pdfFontStyle = java.awt.Font.BOLD;
            }

            if (pdfFontName == null && jrFont.isItalic()) {
                pdfFontName = family.getItalicPdfFont();
                pdfFontStyle = java.awt.Font.ITALIC;
            }

            if (pdfFontName == null) {
                pdfFontName = family.getNormalPdfFont();
                pdfFontStyle = java.awt.Font.PLAIN;
            }

            if (pdfFontName == null) {
                //in theory, face file cannot be null here
                pdfFontName = (face == null || face.getFile() == null ? jrFont.getPdfFontName()
                        : face.getFile());
                pdfFontStyle = faceStyle;//FIXMEFONT not sure this is correct, in case we inherit pdfFontName from default properties
            }

            //            String ttf = face.getFile();
            //            if (ttf == null)
            //            {
            //               throw new JRRuntimeException("The '" + face.getName() + "' font face in family '" + family.getName() + "' returns a null file.");
            //            }

            pdfFont = new PdfFont(pdfFontName,
                    family.getPdfEncoding() == null ? jrFont.getPdfEncoding() : family.getPdfEncoding(),
                    family.isPdfEmbedded() == null ? jrFont.isPdfEmbedded()
                            : family.isPdfEmbedded().booleanValue(),
                    jrFont.isBold() && ((pdfFontStyle & java.awt.Font.BOLD) == 0),
                    jrFont.isItalic() && ((pdfFontStyle & java.awt.Font.ITALIC) == 0));
        }
    }

    int pdfFontStyle = (pdfFont.isPdfSimulatedBold() ? Font.BOLD : 0)
            | (pdfFont.isPdfSimulatedItalic() ? Font.ITALIC : 0);
    if (setFontLines) {
        pdfFontStyle |= (jrFont.isUnderline() ? Font.UNDERLINE : 0)
                | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0);
    }

    try {
        font = FontFactory.getFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(),
                jrFont.getFontSize() * fontSizeScale, pdfFontStyle, forecolor);

        // check if FontFactory didn't find the font
        if (font.getBaseFont() == null && font.family() == Font.UNDEFINED) {
            font = null;
        }
    } catch (Exception e) {
        initialException = e;
    }

    if (font == null) {
        byte[] bytes = null;

        try {
            bytes = RepositoryUtil.getInstance(jasperReportsContext)
                    .getBytesFromLocation(pdfFont.getPdfFontName());
        } catch (JRException e) {
            throw //NOPMD
            new JRRuntimeException("Could not load the following font : " + "\npdfFontName   : "
                    + pdfFont.getPdfFontName() + "\npdfEncoding   : " + pdfFont.getPdfEncoding()
                    + "\nisPdfEmbedded : " + pdfFont.isPdfEmbedded(), initialException);
        }

        BaseFont baseFont = null;

        try {
            baseFont = BaseFont.createFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(),
                    pdfFont.isPdfEmbedded(), true, bytes, null);
        } catch (DocumentException e) {
            throw new JRRuntimeException(e);
        } catch (IOException e) {
            throw new JRRuntimeException(e);
        }

        font = new Font(baseFont, jrFont.getFontSize() * fontSizeScale, pdfFontStyle, forecolor);
    }

    return font;
}

From source file:corner.orm.tapestry.jasper.exporter.CornerPdfExporter.java

License:Apache License

/**
 * ?,,./*from  w  w  w. j a v  a 2  s. c  o  m*/
 * @see net.sf.jasperreports.engine.export.JRPdfExporter#getFont(java.util.Map)
 */
protected Font getFont(Map attributes) {
    JRFont jrFont = new JRBaseFont(attributes);

    Exception initialException = null;

    Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND);
    /*
    if (forecolor == null)
    {
       forecolor = Color.black;
    }
    */

    Font font = null;
    PdfFont pdfFont = null;
    FontKey key = new FontKey(jrFont.getFontName(), jrFont.isBold(), jrFont.isItalic());

    if (fontMap != null && fontMap.containsKey(key)) {
        pdfFont = (PdfFont) fontMap.get(key);
    } else {
        pdfFont = new PdfFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded(),
                jrFont.isBold(), jrFont.isItalic());
    }

    try {
        font = FontFactory.getFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(),
                jrFont.getFontSize(),
                (pdfFont.isPdfSimulatedBold() ? Font.BOLD : 0)
                        | (pdfFont.isPdfSimulatedItalic() ? Font.ITALIC : 0)
                        | (jrFont.isUnderline() ? Font.UNDERLINE : 0)
                        | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0),
                forecolor);

        // check if FontFactory didn't find the font
        if (font.getBaseFont() == null && font.family() == Font.UNDEFINED) {
            font = null;
        }
    } catch (Exception e) {
        initialException = e;
    }

    if (font == null) {
        byte[] bytes = null;

        try {
            bytes = JRLoader.loadBytesFromLocation(pdfFont.getPdfFontName(), classLoader, urlHandlerFactory);
        } catch (JRException e) {
            throw new JRRuntimeException("Could not load the following font : " + "\npdfFontName   : "
                    + pdfFont.getPdfFontName() + "\npdfEncoding   : " + pdfFont.getPdfEncoding()
                    + "\nisPdfEmbedded : " + pdfFont.isPdfEmbedded(), initialException);
        }

        BaseFont baseFont = null;

        try {
            baseFont = BaseFont.createFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(),
                    pdfFont.isPdfEmbedded(), true, bytes, null);
        } catch (DocumentException e) {
            throw new JRRuntimeException(e);
        } catch (IOException e) {
            throw new JRRuntimeException(e);
        }

        font = new Font(baseFont, jrFont.getFontSize(),
                ((pdfFont.isPdfSimulatedBold()) ? Font.BOLD : 0)
                        | ((pdfFont.isPdfSimulatedItalic()) ? Font.ITALIC : 0)
                        | (jrFont.isUnderline() ? Font.UNDERLINE : 0)
                        | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0),
                forecolor);
    }

    return font;
}

From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFTitlePage.java

License:Apache License

/************************************************************************************
 * render paragraph into title page/*  w  w  w  .  j  a  va 2s. c  o m*/
 * 
 * @param pdftpp given {@link PDFTitlePageParagraph} to render
 * @param pdfdoc given {@link com.lowagie.text.Document} where to render
 * @throws DocumentException
 ************************************************************************************/
private void renderParagraph(PDFTitlePageParagraph pdftpp, com.lowagie.text.Document pdfdoc)
        throws DocumentException {
    String text = pdftpp.getContent();
    if (text == null) {
        text = "";
    }
    int fontstyle = Font.NORMAL;
    if (pdftpp.getFonttype().equals("bold")) {
        fontstyle = Font.BOLD;
    }
    if (pdftpp.getFonttype().equals("italic")) {
        fontstyle = Font.ITALIC;
    }
    if (pdftpp.getFonttype().equals("bolditalic")) {
        fontstyle = Font.BOLDITALIC;
    }
    if (pdftpp.getFonttype().equals("underline")) {
        fontstyle = Font.UNDERLINE;
    }
    if (pdftpp.getFonttype().equals("strikethru")) {
        fontstyle = Font.STRIKETHRU;
    }
    // create BaseFont for embedding
    try {
        Font font = FontFactory.getFont("Arial", BaseFont.CP1252, BaseFont.EMBEDDED, pdftpp.getFontsize(),
                fontstyle);
        Paragraph p2 = new Paragraph(new Chunk(text, font));
        // Paragraph p2=new Paragraph(text,
        // FontFactory.getFont(FontFactory.TIMES_ROMAN, 12));
        pdfdoc.add(p2);
    } catch (Exception e) {
        LOGGER.error("error occured while generating paragraph for titlepage", e);
    }
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableParagraph.java

License:Open Source License

@SuppressWarnings("unchecked")
private void postProcessLineHeightAndBaseline() {
    // adjust line height and baseline
    Font font = getMostOftenUsedFont();
    if (font == null || font.getBaseFont() == null) {
        font = this.font;
    }/*from  w  ww  .j  a  v a 2s . c  o  m*/
    if (font != null && font.getBaseFont() != null) {
        // iText and open office computes proportional line height differently
        // [iText] line height = coefficient * font size
        // [open office] line height = coefficient * (font ascender + font descender + font extra margin)
        // we have to increase paragraph line height to generate pdf similar to open office document
        // this algorithm may be inaccurate if fonts with different multipliers are used in this paragraph
        float size = font.getSize();
        float ascender = font.getBaseFont().getFontDescriptor(BaseFont.AWT_ASCENT, size);
        float descender = -font.getBaseFont().getFontDescriptor(BaseFont.AWT_DESCENT, size); // negative value
        float margin = font.getBaseFont().getFontDescriptor(BaseFont.AWT_LEADING, size);
        float multiplier = (ascender + descender + margin) / size;
        if (multipliedLeading > 0.0f) {
            setMultipliedLeading(getMultipliedLeading() * multiplier);
        }

        // iText seems to output text with baseline lower than open office
        // we raise all paragraph text by some amount
        // again this may be inaccurate if fonts with different size are used in this paragraph
        float itextdescender = -font.getBaseFont().getFontDescriptor(BaseFont.DESCENT, size); // negative
        float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier;
        ArrayList<Chunk> chunks = getChunks();
        for (Chunk chunk : chunks) {
            Font f = chunk.getFont();
            if (f != null) {
                // have to raise underline and strikethru as well
                float s = f.getSize();
                if (f.isUnderlined()) {
                    f.setStyle(f.getStyle() & ~Font.UNDERLINE);
                    chunk.setUnderline(s * 1 / 17, s * -1 / 7 + textRise);
                }
                if (f.isStrikethru()) {
                    f.setStyle(f.getStyle() & ~Font.STRIKETHRU);
                    chunk.setUnderline(s * 1 / 17, s * 1 / 4 + textRise);
                }
            }
            chunk.setTextRise(chunk.getTextRise() + textRise);
        }
    }
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java

License:Open Source License

public int getStyleFlag() {
    int style = Font.NORMAL;
    if (Boolean.TRUE.equals(fontItalic)) {
        style |= Font.ITALIC;// w ww .j  av a 2 s . c  o  m
    }
    if (Boolean.TRUE.equals(fontBold)) {
        style |= Font.BOLD;
    }
    if (Boolean.TRUE.equals(fontUnderline)) {
        style |= Font.UNDERLINE;
    }
    if (Boolean.TRUE.equals(fontStrikeThru)) {
        style |= Font.STRIKETHRU;
    }
    return style;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java

License:Open Source License

public int getStyleFlagAsian() {
    int style = Font.NORMAL;
    if (Boolean.TRUE.equals(fontItalicAsian)) {
        style |= Font.ITALIC;/*from   w ww.  j  av  a  2  s .c o  m*/
    }
    if (Boolean.TRUE.equals(fontBoldAsian)) {
        style |= Font.BOLD;
    }
    if (Boolean.TRUE.equals(fontUnderline)) {
        style |= Font.UNDERLINE;
    }
    if (Boolean.TRUE.equals(fontStrikeThru)) {
        style |= Font.STRIKETHRU;
    }
    return style;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java

License:Open Source License

public int getStyleFlagComplex() {
    int style = Font.NORMAL;
    if (Boolean.TRUE.equals(fontItalicComplex)) {
        style |= Font.ITALIC;/*from  w  ww  .  j av a2s .c  o  m*/
    }
    if (Boolean.TRUE.equals(fontBoldComplex)) {
        style |= Font.BOLD;
    }
    if (Boolean.TRUE.equals(fontUnderline)) {
        style |= Font.UNDERLINE;
    }
    if (Boolean.TRUE.equals(fontStrikeThru)) {
        style |= Font.STRIKETHRU;
    }
    return style;
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java

License:Open Source License

@Override
protected void visitRun(CTR run, CTP paragraph, boolean pageNumber, String url,
        IITextContainer pdfParagraphContainer) throws Exception {
    // Font family
    String fontFamilyAscii = stylesDocument.getFontFamilyAscii(run, paragraph);
    String fontFamilyEastAsia = stylesDocument.getFontFamilyEastAsia(run, paragraph);
    String fontFamilyHAnsi = stylesDocument.getFontFamilyHAnsi(run, paragraph);

    // Get font size
    Float fontSize = stylesDocument.getFontSize(run, paragraph);
    if (fontSize == null) {
        fontSize = -1f;//from   www.  java 2  s. c  o m
    }

    // Get font style
    int fontStyle = Font.NORMAL;
    Boolean bold = stylesDocument.getFontStyleBold(run, paragraph);
    if (bold != null && bold) {
        fontStyle |= Font.BOLD;
    }
    Boolean italic = stylesDocument.getFontStyleItalic(run, paragraph);
    if (italic != null && italic) {
        fontStyle |= Font.ITALIC;
    }
    Boolean strike = stylesDocument.getFontStyleStrike(run, paragraph);
    if (strike != null && strike) {
        fontStyle |= Font.STRIKETHRU;
    }

    // Font color
    Color fontColor = stylesDocument.getFontColor(run, paragraph);

    // Font
    this.currentRunFontAscii = getFont(fontFamilyAscii, fontSize, fontStyle, fontColor);
    this.currentRunFontEastAsia = getFont(fontFamilyEastAsia, fontSize, fontStyle, fontColor);
    this.currentRunFontHAnsi = getFont(fontFamilyHAnsi, fontSize, fontStyle, fontColor);

    // Underline patterns
    this.currentRunUnderlinePatterns = stylesDocument.getUnderline(run, paragraph);

    // background color
    this.currentRunBackgroundColor = stylesDocument.getBackgroundColor(run, paragraph);

    // highlight
    if (currentRunBackgroundColor == null) {
        this.currentRunBackgroundColor = stylesDocument.getTextHighlighting(run, paragraph);
    }

    StylableParagraph pdfParagraph = (StylableParagraph) pdfParagraphContainer;
    pdfParagraph.adjustMultipliedLeading(currentRunFontAscii);

    // addd symbol list item chunk if needed.
    String listItemText = pdfParagraph.getListItemText();
    if (StringUtils.isNotEmpty(listItemText)) {
        // FIXME: add some space after the list item
        listItemText += "    ";

        String listItemFontFamily = pdfParagraph.getListItemFontFamily();
        Float listItemFontSize = pdfParagraph.getListItemFontSize();
        int listItemFontStyle = pdfParagraph.getListItemFontStyle();
        java.awt.Color listItemFontColor = pdfParagraph.getListItemFontColor();
        Font listItemFont = options.getFontProvider().getFont(
                listItemFontFamily != null ? listItemFontFamily : fontFamilyAscii, options.getFontEncoding(),
                listItemFontSize != null ? listItemFontSize : fontSize,
                listItemFontStyle != Font.NORMAL ? listItemFontStyle : fontStyle,
                listItemFontColor != null ? listItemFontColor : Converter.toAwtColor(fontColor));
        Chunk symbol = createTextChunk(listItemText, false, listItemFont, currentRunUnderlinePatterns,
                currentRunBackgroundColor);
        pdfParagraph.add(symbol);
        pdfParagraph.setListItemText(null);
    }

    IITextContainer container = pdfParagraphContainer;
    if (url != null) {
        // URL is not null, generate a PDF hyperlink.
        StylableAnchor pdfAnchor = new StylableAnchor();
        pdfAnchor.setReference(url);
        pdfAnchor.setITextContainer(container);
        container = pdfAnchor;
    }
    super.visitRun(run, paragraph, pageNumber, url, pdfParagraphContainer);

    if (url != null) {
        // URL is not null, add the PDF hyperlink in the PDF paragraph
        pdfParagraphContainer.addElement((StylableAnchor) container);
    }

    this.currentRunFontAscii = null;
    this.currentRunFontEastAsia = null;
    this.currentRunFontHAnsi = null;
    this.currentRunUnderlinePatterns = null;
    this.currentRunBackgroundColor = null;
}