Example usage for java.awt Font isItalic

List of usage examples for java.awt Font isItalic

Introduction

In this page you can find the example usage for java.awt Font isItalic.

Prototype

public boolean isItalic() 

Source Link

Document

Indicates whether or not this Font object's style is ITALIC.

Usage

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

@Override
public void drawString(final String s, final float x, float y) {
    if (s.length() == 0) {
        return;//from  www .j a v  a 2  s  . c o  m
    }
    setFillPaint();
    setStrokePaint();

    final AffineTransform at = getTransform();
    final AffineTransform at2 = getTransform();
    at2.translate(x, y);
    at2.concatenate(font.getTransform());
    setTransform(at2);
    final AffineTransform inverse = this.normalizeMatrix();
    final AffineTransform flipper = FLIP_TRANSFORM;
    inverse.concatenate(flipper);
    final double[] mx = new double[6];
    inverse.getMatrix(mx);
    cb.beginText();

    final float fontSize = font.getSize2D();
    if (lastBaseFont == null) {
        final String fontName = font.getName();
        final boolean bold = font.isBold();
        final boolean italic = font.isItalic();

        final BaseFontFontMetrics fontMetrics = metaData.getBaseFontFontMetrics(fontName, fontSize, bold,
                italic, null, metaData.isFeatureSupported(OutputProcessorFeature.EMBED_ALL_FONTS), false);
        final FontNativeContext nativeContext = fontMetrics.getNativeContext();
        lastBaseFont = fontMetrics.getBaseFont();

        cb.setFontAndSize(lastBaseFont, fontSize);
        if (fontMetrics.isTrueTypeFont() && bold && nativeContext.isNativeBold() == false) {
            final float strokeWidth = font.getSize2D() / 30.0f; // right from iText ...
            if (strokeWidth == 1) {
                cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
            } else {
                cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
                cb.setLineWidth(strokeWidth);
            }
        } else {
            cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
        }
    } else {
        cb.setFontAndSize(lastBaseFont, fontSize);
    }

    cb.setTextMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]);
    double width = 0;
    if (fontSize > 0) {
        final float scale = 1000 / fontSize;
        final Font font = this.font.deriveFont(AffineTransform.getScaleInstance(scale, scale));
        final Rectangle2D stringBounds = font.getStringBounds(s, getFontRenderContext());
        width = stringBounds.getWidth() / scale;
    }
    if (s.length() > 1) {
        final float adv = ((float) width - lastBaseFont.getWidthPoint(s, fontSize)) / (s.length() - 1);
        cb.setCharacterSpacing(adv);
    }
    cb.showText(s);
    if (s.length() > 1) {
        cb.setCharacterSpacing(0);
    }
    cb.endText();
    setTransform(at);
    if (underline) {
        // These two are supposed to be taken from the .AFM file
        // int UnderlinePosition = -100;
        final int UnderlineThickness = 50;
        //
        final double d = PdfGraphics2D.asPoints(UnderlineThickness, (int) fontSize);
        setStroke(new BasicStroke((float) d));
        y = (float) ((y) + PdfGraphics2D.asPoints((UnderlineThickness), (int) fontSize));
        final Line2D line = new Line2D.Double(x, y, (width + x), y);
        draw(line);
    }
}

From source file:org.pentaho.reporting.libraries.fonts.itext.BaseFontSupport.java

/**
 * Returns a BaseFont which can be used to represent the given AWT Font
 *
 * @param font the font to be converted//from  w  ww .  j  a  va 2  s  .  co  m
 * @return a BaseFont which has similar properties to the provided Font
 */

public BaseFont awtToPdf(final Font font) {
    // this has to be defined in the element, an has to set as a default...
    final boolean embed = isEmbedFonts();
    final String encoding = getDefaultEncoding();
    try {
        return createBaseFont(font.getName(), font.isBold(), font.isItalic(), encoding, embed);
    } catch (Exception e) {
        // unable to handle font creation exceptions properly, all we can
        // do is throw a runtime exception and hope the best ..
        throw new BaseFontCreateException("Unable to create font: " + font, e);
    }
}

From source file:org.reactome.server.tools.diagram.exporter.raster.itext.awt.DefaultFontMapper.java

private int extractItextStyle(Font font) {
    if (font.isItalic() && font.isBold())
        return FontStyles.BOLDITALIC;
    if (font.isBold())
        return FontStyles.BOLD;
    if (font.isItalic())
        return FontStyles.ITALIC;
    if (font.isPlain())
        return FontStyles.NORMAL;
    return FontStyles.UNDEFINED;
}

From source file:org.zephyrsoft.sdb2.presenter.SongView.java

private Style addStyleFromFont(String styleName, Font font) {
    return addStyle(styleName, font.isItalic(), font.isBold(), font.getFamily(), font.getSize());
}