Example usage for java.awt Font isBold

List of usage examples for java.awt Font isBold

Introduction

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

Prototype

public boolean isBold() 

Source Link

Document

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

Usage

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.PersonalSettings.java

public void setStandardFont(final Font value) {
    fontName = value.getFontName();// w w w.  ja  v  a2 s.  c o m
    fontSize = value.getSize();
    fontBold = value.isBold();
    fontItalic = value.isItalic();
    fontPlain = value.isPlain();
    saveData();
}

From source file:org.docx4j.fonts.fop.fonts.FontInfo.java

/**
 * Returns a suitable internal font given an AWT Font instance.
 *
 * @param awtFont the AWT font/*from   www .j a  va  2s  . co m*/
 * @return a best matching internal Font
 */
public Font getFontInstanceForAWTFont(java.awt.Font awtFont) {
    String awtFontName = awtFont.getName();
    String awtFontFamily = awtFont.getFamily();
    String awtFontStyle = awtFont.isItalic() ? Font.STYLE_ITALIC : Font.STYLE_NORMAL;
    int awtFontWeight = awtFont.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL;

    FontTriplet matchedTriplet = null;
    List/*<FontTriplet>*/ triplets = getTripletsForName(awtFontName);
    if (!triplets.isEmpty()) {
        Iterator it = triplets.iterator();
        while (it.hasNext()) {
            FontTriplet triplet = (FontTriplet) it.next();
            boolean styleMatched = triplet.getStyle().equals(awtFontStyle);
            boolean weightMatched = triplet.getWeight() == awtFontWeight;
            if (styleMatched && weightMatched) {
                matchedTriplet = triplet;
                break;
            }
        }
    }

    // not matched on font name so do a lookup using family
    if (matchedTriplet == null) {
        if (awtFontFamily.equals("sanserif")) {
            awtFontFamily = "sans-serif";
        }
        matchedTriplet = fontLookup(awtFontFamily, awtFontStyle, awtFontWeight);
    }
    int fontSize = Math.round(awtFont.getSize2D() * 1000);
    return getFontInstance(matchedTriplet, fontSize);
}

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;/*w w w .  j  a va  2s .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//  w  ww  .  j a  va2 s.c  o 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

/**
 * Returns a BaseFont which can be used to represent the given AWT Font
 *
 * @param font the font to be converted//  w ww  .j  a va 2  s  .co m
 *
 * @return a BaseFont which has similar properties to the provided Font
 */
public PdfFont awtToPdf(Font font) {
    if (font.isBold())
        return BOLD;
    return REGULAR;
    //      try {
    //         // fontName - either a font alias, if the font file has been registered with an alias, or just a font name otherwise
    //         // encoding - the encoding of the font to be created. See PdfEncodings
    //         // embedded - indicates whether the font is to be embedded into the target document
    //         // style - the style of the font to look for. Possible values are listed in FontStyles. See FontStyles.BOLD, FontStyles.ITALIC, FontStyles.NORMAL, FontStyles.BOLDITALIC, FontStyles.UNDEFINED
    //         // cached - whether to try to get the font program from cache
    //         FontProgramFactory.createRegisteredFont(font.getPSName(), extractItextStyle(font));
    ////         return PdfFontFactory.createRegisteredFont(font.getPSName(), PdfEncodings.UTF8, false, extractItextStyle(font), true);
    //      } catch (IOException e) {
    //         LoggerFactory.getLogger(DefaultFontMapper.class).error("Font " + font.getName() + " is not registered");
    //      }
    //      return null;
}

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());
}