Example usage for java.awt.font TextAttribute FOREGROUND

List of usage examples for java.awt.font TextAttribute FOREGROUND

Introduction

In this page you can find the example usage for java.awt.font TextAttribute FOREGROUND.

Prototype

TextAttribute FOREGROUND

To view the source code for java.awt.font TextAttribute FOREGROUND.

Click Source Link

Document

Attribute key for the paint used to render the text.

Usage

From source file:org.apache.fop.svg.AbstractFOPTextPainter.java

private boolean hasUnsupportedAttributes(AttributedCharacterIterator aci) {
    boolean hasUnsupported = false;

    Font font = getFont(aci);// w  w w .j a  v  a 2 s  .  c o  m
    String text = getText(aci);
    if (hasUnsupportedGlyphs(text, font)) {
        log.trace("-> Unsupported glyphs found");
        hasUnsupported = true;
    }

    TextPaintInfo tpi = (TextPaintInfo) aci
            .getAttribute(GVTAttributedCharacterIterator.TextAttribute.PAINT_INFO);
    if ((tpi != null)
            && ((tpi.strokeStroke != null && tpi.strokePaint != null) || (tpi.strikethroughStroke != null)
                    || (tpi.underlineStroke != null) || (tpi.overlineStroke != null))) {
        log.trace("-> under/overlines etc. found");
        hasUnsupported = true;
    }

    //Alpha is not supported
    Paint foreground = (Paint) aci.getAttribute(TextAttribute.FOREGROUND);
    if (foreground instanceof Color) {
        Color col = (Color) foreground;
        if (col.getAlpha() != 255) {
            log.trace("-> transparency found");
            hasUnsupported = true;
        }
    }

    Object letSpace = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.LETTER_SPACING);
    if (letSpace != null) {
        log.trace("-> letter spacing found");
        hasUnsupported = true;
    }

    Object wordSpace = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.WORD_SPACING);
    if (wordSpace != null) {
        log.trace("-> word spacing found");
        hasUnsupported = true;
    }

    Object lengthAdjust = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.LENGTH_ADJUST);
    if (lengthAdjust != null) {
        log.trace("-> length adjustments found");
        hasUnsupported = true;
    }

    Object writeMod = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE);
    if (writeMod != null && !GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE_LTR.equals(writeMod)) {
        log.trace("-> Unsupported writing modes found");
        hasUnsupported = true;
    }

    Object vertOr = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION);
    if (GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE.equals(vertOr)) {
        log.trace("-> vertical orientation found");
        hasUnsupported = true;
    }

    Object rcDel = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_DELIMITER);
    //Batik 1.6 returns null here which makes it impossible to determine whether this can
    //be painted or not, i.e. fall back to stroking. :-(
    if (rcDel != null && !(rcDel instanceof SVGOMTextElement)) {
        log.trace("-> spans found");
        hasUnsupported = true; //Filter spans
    }

    if (hasUnsupported) {
        log.trace("Unsupported attributes found in ACI, using StrokingTextPainter");
    }
    return hasUnsupported;
}

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

/**
 * This routine goes through the attributes and sets the font before calling the actual string drawing routine
 *
 * @param iter/*from  w  w w.  j  a v a2 s. c o  m*/
 */
private void doAttributes(final AttributedCharacterIterator iter) {
    underline = false;
    final Set set = iter.getAttributes().keySet();
    for (Iterator iterator = set.iterator(); iterator.hasNext();) {
        final AttributedCharacterIterator.Attribute attribute = (AttributedCharacterIterator.Attribute) iterator
                .next();
        if (!(attribute instanceof TextAttribute)) {
            continue;
        }
        final TextAttribute textattribute = (TextAttribute) attribute;
        if (textattribute.equals(TextAttribute.FONT)) {
            final Font font = (Font) iter.getAttributes().get(textattribute);
            setFont(font);
        } else if (textattribute.equals(TextAttribute.UNDERLINE)) {
            if (iter.getAttributes().get(textattribute) == TextAttribute.UNDERLINE_ON) {
                underline = true;
            }
        } else if (textattribute.equals(TextAttribute.SIZE)) {
            final Object obj = iter.getAttributes().get(textattribute);
            if (obj instanceof Integer) {
                final int i = ((Integer) obj).intValue();
                setFont(getFont().deriveFont(getFont().getStyle(), i));
            } else if (obj instanceof Float) {
                final float f = ((Float) obj).floatValue();
                setFont(getFont().deriveFont(getFont().getStyle(), f));
            }
        } else if (textattribute.equals(TextAttribute.FOREGROUND)) {
            setColor((Color) iter.getAttributes().get(textattribute));
        } else if (textattribute.equals(TextAttribute.FAMILY)) {
            final Font font = getFont();
            final Map fontAttributes = font.getAttributes();
            fontAttributes.put(TextAttribute.FAMILY, iter.getAttributes().get(textattribute));
            setFont(font.deriveFont(fontAttributes));
        } else if (textattribute.equals(TextAttribute.POSTURE)) {
            final Font font = getFont();
            final Map fontAttributes = font.getAttributes();
            fontAttributes.put(TextAttribute.POSTURE, iter.getAttributes().get(textattribute));
            setFont(font.deriveFont(fontAttributes));
        } else if (textattribute.equals(TextAttribute.WEIGHT)) {
            final Font font = getFont();
            final Map fontAttributes = font.getAttributes();
            fontAttributes.put(TextAttribute.WEIGHT, iter.getAttributes().get(textattribute));
            setFont(font.deriveFont(fontAttributes));
        }
    }
}