Example usage for com.lowagie.text Font ITALIC

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

Introduction

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

Prototype

int ITALIC

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

Click Source Link

Document

this is a possible style.

Usage

From source file:org.apache.maven.doxia.module.itext.ITextFont.java

License:Apache License

/**
 * Remove italic style to the current style
 *///from  w ww .jav a2  s  . c om
public void removeItalic() {
    this.currentStyle -= Font.ITALIC;
    if (this.currentStyle < 0) {
        this.currentStyle = Font.NORMAL;
    }
}

From source file:org.apache.poi.xwpf.converter.internal.itext.PDFMapper.java

License:Open Source License

@Override
protected void visitRun(XWPFRun run, IITextContainer pdfContainer) throws Exception {
    CTR ctr = run.getCTR();// ww w.ja va2 s. c om
    // Get family name
    // Get CTRPr from style+defaults
    CTString rStyle = getRStyle(run);
    CTRPr runRprStyle = getRPr(super.getXWPFStyle(rStyle != null ? rStyle.getVal() : null));
    CTRPr rprStyle = getRPr(super.getXWPFStyle(run.getParagraph().getStyleID()));
    CTRPr rprDefault = getRPr(defaults);

    // Font family
    String fontFamily = getFontFamily(run, rprStyle, rprDefault);

    // Get font size
    float fontSize = run.getFontSize();

    // Get font style
    int fontStyle = Font.NORMAL;
    if (isBold(run, runRprStyle, rprStyle, rprDefault)) {
        fontStyle |= Font.BOLD;
    }
    if (isItalic(run, runRprStyle, rprStyle, rprDefault)) {
        fontStyle |= Font.ITALIC;
    }

    // Process color
    Color fontColor = null;
    String hexColor = getFontColor(run, runRprStyle, rprStyle, rprDefault);
    if (StringUtils.isNotEmpty(hexColor)) {
        if (hexColor != null && !"auto".equals(hexColor)) {
            fontColor = ColorRegistry.getInstance().getColor("0x" + hexColor);
        }
    }
    // Get font
    Font font = XWPFFontRegistry.getRegistry().getFont(fontFamily, options.getFontEncoding(), fontSize,
            fontStyle, fontColor);

    UnderlinePatterns underlinePatterns = run.getUnderline();

    boolean singleUnderlined = false;
    switch (underlinePatterns) {
    case SINGLE:
        singleUnderlined = true;
        break;

    default:
        break;
    }

    List<CTBr> brs = ctr.getBrList();
    for (@SuppressWarnings("unused")
    CTBr br : brs) {
        pdfContainer.addElement(Chunk.NEWLINE);
    }

    List<CTText> texts = run.getCTR().getTList();
    for (CTText ctText : texts) {

        Chunk aChunk = new Chunk(ctText.getStringValue(), font);
        if (singleUnderlined)
            aChunk.setUnderline(1, -2);

        pdfContainer.addElement(aChunk);
    }

    super.visitPictures(run, pdfContainer);

    // <w:lastRenderedPageBreak />
    List<CTEmpty> lastRenderedPageBreakList = ctr.getLastRenderedPageBreakList();
    if (lastRenderedPageBreakList != null && lastRenderedPageBreakList.size() > 0) {
        // IText Document#newPage must be called to generate page break.
        // But before that, CTSectPr must be getted to compute pageSize,
        // margins...
        // The CTSectPr <w:pPr><w:sectPr w:rsidR="00AA33F7"
        // w:rsidSect="00607077"><w:pgSz w:w="16838" w:h="11906"
        // w:orient="landscape" />...
        Stack<CTSectPr> sectPrStack = getSectPrStack();
        if (sectPrStack != null && !sectPrStack.isEmpty()) {
            CTSectPr sectPr = sectPrStack.pop();
            applySectPr(sectPr);
        }
        for (CTEmpty lastRenderedPageBreak : lastRenderedPageBreakList) {
            pdfDocument.newPage();
        }
    }
}

From source file:org.apache.poi.xwpf.converter.internal.itext.StyleEngineForIText.java

License:Open Source License

private FontInfos processRPR(CTRPr ctParaRPr) {

    FontInfos fontInfos = new FontInfos();
    CTFonts fonts = ctParaRPr.getRFonts();
    if (fonts != null && fonts.getAscii() != null) {

        // font familly
        fontInfos.setFontFamily(fonts.getAscii());
    }//ww w  .  j  a  v  a2 s.c  o m

    boolean bold = ctParaRPr.getB() != null && STOnOff.TRUE.equals(ctParaRPr.getB().xgetVal());
    boolean italic = ctParaRPr.getI() != null && STOnOff.TRUE.equals(ctParaRPr.getI().xgetVal());

    if (bold && italic) {
        fontInfos.setFontStyle(Font.BOLDITALIC);
    } else if (bold) {
        fontInfos.setFontStyle(Font.BOLD);
    } else if (italic) {
        fontInfos.setFontStyle(Font.ITALIC);

    }
    // font size
    CTHpsMeasure hpsMeasure = ctParaRPr.getSz();
    if (hpsMeasure != null) {

        STHpsMeasure measure = hpsMeasure.xgetVal();
        float size = measure.getBigDecimalValue().floatValue();
        // cf. http://www.schemacentral.com/sc/ooxml/t-w_ST_HpsMeasure.html
        fontInfos.setFontSize(size / 2);
    }

    CTUnderline underline = ctParaRPr.getU();

    int style = fontInfos.getFontStyle();
    if (underline != null) {

        STUnderline uu = underline.xgetVal();

        if (STUnderline.NONE != uu.enumValue()) {
            style = style | Font.UNDERLINE;
            fontInfos.setFontStyle(style);
        }
    }

    // font color...
    CTColor ctColor = ctParaRPr.getColor();
    if (ctColor != null) {

        STHexColor hexColor = ctColor.xgetVal();
        String strText = hexColor.getStringValue();

        if (!"auto".equals(strText)) {

            Color color = ColorRegistry.getInstance().getColor("0x" + strText);
            fontInfos.setFontColor(color);
        }
    }

    // font encoding
    fontInfos.setFontEncoding(options.getFontEncoding());
    return fontInfos;
}

From source file:org.areasy.common.doclet.document.Fonts.java

License:Open Source License

public static Font getFont(int faceType, int style, int size) {
    Font font = null;// w  w  w.ja v a 2 s. c o  m
    String lookup = String.valueOf(faceType);
    String fontFile = fontTable.getProperty(lookup);

    int fontStyle = Font.NORMAL;
    Color color = COLOR_BLACK;

    if ((style & LINK) != 0) {
        fontStyle += Font.UNDERLINE;
        color = COLOR_LINK;
    } else if ((style & UNDERLINE) != 0)
        fontStyle += Font.UNDERLINE;

    if ((style & STRIKETHROUGH) != 0)
        fontStyle += Font.STRIKETHRU;

    if (fontFile != null) {

        File file = new File(DefaultConfiguration.getWorkDir(), fontFile);
        if (file.exists() && file.isFile()) {

            try {
                String encoding = encTable.getProperty(lookup, BaseFont.CP1252);
                BaseFont bfComic = BaseFont.createFont(file.getAbsolutePath(), encoding, BaseFont.EMBEDDED);

                if ((style & AbstractConfiguration.ITALIC) > 0) {
                    if ((style & AbstractConfiguration.BOLD) > 0)
                        fontStyle += Font.BOLDITALIC;
                    else
                        fontStyle += Font.ITALIC;
                } else if ((style & AbstractConfiguration.BOLD) > 0)
                    fontStyle += Font.BOLD;

                if (fontStyle != Font.NORMAL)
                    font = new Font(bfComic, size, fontStyle, color);
                else
                    font = new Font(bfComic, size);

                if (font == null)
                    throw new IllegalArgumentException("Font null: " + fontFile);
            } catch (Exception e) {
                e.printStackTrace();
                throw new IllegalArgumentException("Font unusable");
            }
        } else
            DocletUtility.error("Font file not found: " + fontFile);
    } else {
        // Use predefined font
        String face = "";

        if (faceType == TEXT_FONT) {
            face = FontFactory.HELVETICA;

            if ((style & AbstractConfiguration.ITALIC) > 0) {
                if ((style & AbstractConfiguration.BOLD) > 0)
                    face = FontFactory.HELVETICA_BOLDOBLIQUE;
                else
                    face = FontFactory.HELVETICA_OBLIQUE;
            } else if ((style & AbstractConfiguration.BOLD) > 0)
                face = FontFactory.HELVETICA_BOLD;
        } else {
            face = FontFactory.COURIER;
            if ((style & ITALIC) > 0) {
                if ((style & BOLD) > 0)
                    face = FontFactory.COURIER_BOLDOBLIQUE;
                else
                    face = FontFactory.COURIER_OBLIQUE;
            } else if ((style & BOLD) > 0)
                face = FontFactory.COURIER_BOLD;
        }

        if (fontStyle != Font.NORMAL)
            font = FontFactory.getFont(face, size, fontStyle, color);
        else
            font = FontFactory.getFont(face, size);
    }

    return font;
}

From source file:org.eclipse.birt.report.engine.emitter.odp.device.OdpPage.java

License:Open Source License

protected void drawText(String text, float textX, float textY, float baseline, float width, float height,
        TextStyle textStyle) {//from   www .jav  a 2  s  .  c  om
    // width of text is enlarged by 1 point because the text will be
    // automatically wrapped if the width of textbox equals to the width of
    // text exactly.
    FontInfo fontInfo = textStyle.getFontInfo();
    float descend = fontInfo.getBaseFont().getFontDescriptor(BaseFont.DESCENT, fontInfo.getFontSize());

    StyleEntry style = StyleBuilder.createEmptyStyleEntry(StyleConstant.TYPE_TEXT);
    style.setProperty(StyleConstant.DIRECTION_PROP, textStyle.getDirection());
    style.setProperty(StyleConstant.COLOR_PROP, OdpUtil.getColorString(textStyle.getColor()));
    style.setProperty(StyleConstant.LETTER_SPACING,
            new FloatValue(FloatValue.CSS_PT, textStyle.getLetterSpacing() / PDFConstants.LAYOUT_TO_PDF_RATIO));

    if (fontInfo != null) {
        BaseFont baseFont = fontInfo.getBaseFont();
        String fontName = OdpUtil.getFontName(baseFont);

        style.setProperty(StyleConstant.FONT_FAMILY_PROP, fontName);
        style.setProperty(StyleConstant.FONT_SIZE_PROP, Double.valueOf(fontInfo.getFontSize()));

        if ((fontInfo.getFontStyle() & Font.BOLD) != 0) {
            style.setProperty(StyleConstant.FONT_WEIGHT_PROP, "bold");
        }

        if ((fontInfo.getFontStyle() & Font.ITALIC) != 0) {
            style.setProperty(StyleConstant.FONT_STYLE_PROP, "italic");
        }

        if (textStyle.isLinethrough()) {
            style.setProperty(StyleConstant.TEXT_LINE_THROUGH_PROP, true);
        }

        if (textStyle.isOverline()) {
            style.setProperty(StyleConstant.TEXT_OVERLINE_PROP, true);
        }

        if (textStyle.isUnderline()) {
            style.setProperty(StyleConstant.TEXT_UNDERLINE_PROP, true);
        }
    }

    // TODO: hyperlink

    context.addStyle(style);
    writer.drawText(text, textX, textY, width, height + descend * 0.6f, textFrameStyle, style, link);
}

From source file:org.eclipse.birt.report.engine.emitter.pdf.PDFPage.java

License:Open Source License

private void setTextMatrix(PdfContentByte cb, FontInfo fi, float x, float y) {
    cb.concatCTM(1, 0, 0, 1, x, y);/* ww  w . ja v  a 2 s  . c o  m*/
    if (!fi.getSimulation()) {
        cb.setTextMatrix(0, 0);
        return;
    }
    switch (fi.getFontStyle()) {
    case Font.ITALIC: {
        simulateItalic(cb);
        break;
    }
    case Font.BOLD: {
        simulateBold(cb, fi.getFontWeight());
        break;
    }
    case Font.BOLDITALIC: {
        simulateBold(cb, fi.getFontWeight());
        simulateItalic(cb);
        break;
    }
    }
}

From source file:org.eclipse.birt.report.engine.emitter.postscript.PostscriptWriter.java

License:Open Source License

public void drawString(String str, float x, float y, FontInfo fontInfo, float letterSpacing, float wordSpacing,
        Color color, boolean linethrough, boolean overline, boolean underline, CSSValue align) {
    y = transformY(y);//from w  ww  .  ja va2  s  .  com
    String text = str;
    boolean needSimulateItalic = false;
    boolean needSimulateBold = false;
    boolean hasSpace = wordSpacing != 0 || letterSpacing != 0;
    float offset = 0;
    if (fontInfo != null) {
        float fontSize = fontInfo.getFontSize();
        int fontStyle = fontInfo.getFontStyle();
        if (fontInfo.getSimulation()) {
            if (fontStyle == Font.BOLD || fontStyle == Font.BOLDITALIC) {
                offset = (float) (fontSize * Math.log10(fontSize) / 100);
                needSimulateBold = true;
            }
            if (fontStyle == Font.ITALIC || fontStyle == Font.BOLDITALIC) {
                needSimulateItalic = true;
            }
        }
        BaseFont baseFont = fontInfo.getBaseFont();
        String fontName = baseFont.getPostscriptFontName();
        text = applyFont(fontName, fontStyle, fontSize, text);
    }
    outputColor(color);
    out.print(x + " " + y + " ");
    if (hasSpace)
        out.print(wordSpacing + " " + letterSpacing + " ");
    out.print(text + " ");
    if (needSimulateBold)
        out.print(offset + " ");
    String command = getCommand(hasSpace, needSimulateBold, needSimulateItalic);
    out.println(command);
}

From source file:org.eclipse.birt.report.engine.emitter.ppt.PPTWriter.java

License:Open Source License

/**
 * Draws a chunk of text on the PPT./*from w ww .  j a  v a2  s . c o m*/
 * 
 * @param text
 *            the textArea to be drawn.
 * @param textX
 *            the X position of the textArea relative to current page.
 * @param textY
 *            the Y position of the textArea relative to current page.
 * @param width
 *            the Width of the textArea
 * @param height
 *              the height of the textArea
 * @param textStyle
 *            the style of the textArea
 * @param link
 *            the hyperlink of the textArea
 */
public void drawText(String text, float textX, float textY, float width, float height, TextStyle textStyle,
        HyperlinkDef link) {
    FontInfo fontInfo = textStyle.getFontInfo();
    Color color = textStyle.getColor();
    boolean rtl = textStyle.isRtl();

    if (fontInfo == null) {
        return;
    }

    float descend = fontInfo.getBaseFont().getFontDescriptor(BaseFont.DESCENT, fontInfo.getFontSize());
    height = height + descend * 0.6f;

    BaseFont baseFont = fontInfo.getBaseFont();
    String fontName = getFontName(baseFont);

    println("<v:shape id=3D\"_x0000_s" + (++shapeCount) + "\" type=3D\"#_x0000_t202\""); //$NON-NLS-1$ //$NON-NLS-2$
    println(" style=3D'position:absolute;left:" + textX + "pt;top:" + textY + "pt;width:" + width + "pt;height:" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
            + height + "pt;v-text-anchor:bottom-baseline;mso-wrap-style:none;'"); //$NON-NLS-1$
    println(" filled=3D'f' stroked=3D'f'>"); //$NON-NLS-1$
    println("<v:textbox style=3D'mso-fit-shape-to-text:f;' inset=3D'0.00pt 0.00pt 0.00pt 0.00pt'/>"); //$NON-NLS-1$
    println("</v:shape>"); //$NON-NLS-1$
    println("<div v:shape=3D\"_x0000_s" + shapeCount + "\">"); //$NON-NLS-1$ //$NON-NLS-2$

    println("<div style=3D'mso-text-indent-alt:" //$NON-NLS-1$
            + 0 + ";text-align:left;'>" //$NON-NLS-1$
            + "<span style=3D'font-family:" //$NON-NLS-1$
            + fontName + ";font-size:" //$NON-NLS-1$
            + fontInfo.getFontSize() + "pt;color:#" //$NON-NLS-1$
            + getColorString(color) + ";'" + buildI18nAttributes(text, rtl) + ">"); //$NON-NLS-2$

    boolean isItalic = fontInfo != null && (fontInfo.getFontStyle() & Font.ITALIC) != 0;
    boolean isBold = fontInfo != null && (fontInfo.getFontStyle() & Font.BOLD) != 0;

    boolean isUnderline = textStyle.isUnderline();

    if (isItalic) {
        print("<i>");
    }
    if (isBold) {
        print("<b>");
    }
    if (isUnderline) {
        print("<u>");
    }
    if (link != null) {
        String hyperlink = link.getLink();
        String tooltip = link.getTooltip();
        if (hyperlink != null) {
            hyperlink = codeLink(hyperlink);
            print("<p:onmouseclick  hyperlinktype=3D\"url\" href=3D\"" + hyperlink + "\"");
            if (tooltip != null) {
                tooltip = codeLink(tooltip);
                print(" tips=3D\"" + tooltip + "\"");
            }
            println("/><a href=3D\"" + hyperlink
                    + "/\" target=3D\"_parent\" onclick=3D\"window.event.cancelBubble=3Dtrue;\">");
        }
    }
    print(getEscapedStr(text));
    if (link != null) {
        print("</a>");
    }
    if (isUnderline) {
        print("</u>");
    }
    if (isBold) {
        print("</b>");
    }
    if (isItalic) {
        print("</i>");
    }
    println("</span></div>"); //$NON-NLS-1$
    println("</div>"); //$NON-NLS-1$
}

From source file:org.eclipse.birt.report.engine.emitter.pptx.PPTXCanvas.java

License:Open Source License

private void setTextProperty(String fontName, float fontSize, int fontStyle, Color color, boolean isUnderline,
        boolean isLineThrough, HyperlinkDef link) {
    writer.openTag("a:rPr");
    writer.attribute("lang", "en-US");
    writer.attribute("altLang", "zh-CN");
    writer.attribute("dirty", "0");
    writer.attribute("smtClean", "0");
    if (isLineThrough) {
        writer.attribute("strike", "sngStrike");
    }//from   w  w  w .  j a va 2 s  .com
    if (isUnderline) {
        writer.attribute("u", "sng");
    }
    writer.attribute("sz", (int) (fontSize * 100));
    boolean isItalic = (fontStyle & Font.ITALIC) != 0;
    boolean isBold = (fontStyle & Font.BOLD) != 0;
    if (isItalic) {
        writer.attribute("i", 1);
    }
    if (isBold) {
        writer.attribute("b", 1);
    }
    setBackgroundColor(color);
    setTextFont(fontName);
    setHyperlink(link);
    writer.closeTag("a:rPr");
}

From source file:org.eclipse.birt.report.engine.emitter.pptx.writer.Slide.java

License:Open Source License

private void setTextProperty(String fontName, float fontSize, int fontStyle, Color color, boolean isUnderline,
        boolean isLineThrough, HyperlinkDef link) {
    writer.openTag("a:rPr");
    writer.attribute("lang", "en-US");
    writer.attribute("altLang", "zh-CN");
    writer.attribute("dirty", "0");
    writer.attribute("smtClean", "0");
    if (isLineThrough) {
        writer.attribute("strike", "sngStrike");
    }/*  w  ww .  j  a va  2  s.  c  o m*/
    if (isUnderline) {
        writer.attribute("u", "sng");
    }
    writer.attribute("sz", (int) (fontSize * 100));
    boolean isItalic = (fontStyle & Font.ITALIC) != 0;
    boolean isBold = (fontStyle & Font.BOLD) != 0;
    if (isItalic) {
        writer.attribute("i", 1);
    }
    if (isBold) {
        writer.attribute("b", 1);
    }
    setColor(color);
    setTextFont(fontName);
    setHyperlink(link);
    writer.closeTag("a:rPr");
}