Example usage for java.awt Font getFamily

List of usage examples for java.awt Font getFamily

Introduction

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

Prototype

public String getFamily(Locale l) 

Source Link

Document

Returns the family name of this Font , localized for the specified locale.

Usage

From source file:org.kalypsodeegree_impl.graphics.displayelements.LabelFactory.java

/**
 * Generates <tt>Label</tt> -representations for a given <tt>LabelDisplayElement</tt>.
 *//*  ww  w .  ja  v a 2  s.  c o m*/
public Label[] createLabels() throws GM_Exception {
    try {
        final Feature feature = m_element.getFeature();

        final String caption = m_element.getLabel().evaluate(feature);
        // sanity check: empty labels are ignored
        if (StringUtils.isBlank(caption))
            return EMPTY_LABELS;

        // gather font information
        final org.kalypsodeegree.graphics.sld.Font sldFont = m_symbolizer.getFont();
        final java.awt.Font font = new java.awt.Font(sldFont.getFamily(feature),
                sldFont.getStyle(feature) | sldFont.getWeight(feature), sldFont.getSize(feature));
        m_graphics.setFont(font);

        final Color color = sldFont.getColor(feature);

        final FontRenderContext frc = m_graphics.getFontRenderContext();

        // bugstories...
        // I got the following error in the next line:
        // # An unexpected error has been detected by HotSpot Virtual Machine:
        // # [...]
        // # Problematic frame:
        // # C [libfontmanager.so+0x2ecd5]
        //
        // while running kalypso on linux, kubuntu-Dapper.
        // The error was caused by some buggy fonts in Dapper (Rekha-normal and aakar-MagNet ).
        // Work-around is to remove the toxic fonts by removing the package ttf-gujarati-fonts from the distribution.
        // this error was not easy to locate, so do not remove this notice !
        // ( v.doemming@tuhh.de )

        final Rectangle2D bounds = font.getStringBounds(caption, frc);
        final Dimension size = bounds.getBounds().getSize();
        final LineMetrics metrics = font.getLineMetrics(caption, frc);

        final GM_Object[] geometries = m_element.getGeometry();
        final List<Label> allLabels = new ArrayList<>();
        for (final GM_Object geometry : geometries) {
            final Label[] labels = createLabels(feature, caption, geometry, font, color, metrics, size);
            allLabels.addAll(Arrays.asList(labels));
        }

        return allLabels.toArray(new Label[allLabels.size()]);
    } catch (final FilterEvaluationException e) {
        // if properties are unknown to features, this should be ignored!
        return EMPTY_LABELS;
    }
}