Example usage for java.awt.font TextAttribute STRIKETHROUGH

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

Introduction

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

Prototype

TextAttribute STRIKETHROUGH

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

Click Source Link

Document

Attribute key for strikethrough.

Usage

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

protected Element createText(String text) {
    // #232718 to support bidi
    boolean bRtl = false;

    if (text.length() > 0) {
        int iEnd = text.length();
        if (chPDF == text.charAt(text.length() - 1)) {
            iEnd--;/*from   w ww  .  j a v a 2  s . c  o m*/
        }

        if (chRLE == text.charAt(0)) {
            bRtl = true;
            text = text.substring(1, iEnd);
        }
    }

    Element elem = dom.createElement("text"); //$NON-NLS-1$
    elem.appendChild(dom.createTextNode(text));
    switch (getFont().getStyle()) {
    case Font.BOLD:
        elem.setAttribute("font-weight", "bold"); //$NON-NLS-1$ //$NON-NLS-2$
        break;
    case Font.ITALIC:
        elem.setAttribute("font-style", "italic"); //$NON-NLS-1$ //$NON-NLS-2$
        break;
    case (Font.BOLD + Font.ITALIC):
        elem.setAttribute("font-style", "italic"); //$NON-NLS-1$ //$NON-NLS-2$
        elem.setAttribute("font-weight", "bold"); //$NON-NLS-1$ //$NON-NLS-2$
        break;
    }
    String textDecorator = null;
    Map<TextAttribute, ?> attributes = getFont().getAttributes();
    if (attributes.get(TextAttribute.UNDERLINE) == TextAttribute.UNDERLINE_ON) {
        textDecorator = "underline"; //$NON-NLS-1$ 
    }
    if (attributes.get(TextAttribute.STRIKETHROUGH) == TextAttribute.STRIKETHROUGH_ON) {
        if (textDecorator == null)
            textDecorator = "line-through"; //$NON-NLS-1$
        else
            textDecorator += ",line-through"; //$NON-NLS-1$
    }
    if (textDecorator != null)
        elem.setAttribute("text-decoration", textDecorator); //$NON-NLS-1$

    // for now just preserve space for text elements Bug 182159
    elem.setAttribute("xml:space", "preserve"); //$NON-NLS-1$ //$NON-NLS-2$
    elem.setAttribute("stroke", "none"); //$NON-NLS-1$ //$NON-NLS-2$

    // Here we still use Font.getName() as font-family for SVG instead of
    // Font.getFaimly(), since if current code is running on linux and there
    // isn't a valid font family to fit the font setting in chart model,
    // the call of Font.getFamily() will get a default 'Dialog' font family,
    // it will caused that the svg in client system can't correct display
    // mulitple-characters text(Chinese, Jpanese and so on).
    // We just need to set the original font family setting of chart model
    // into svg document, if the font family is valid in client system
    // and can support current text character, it will correct display.
    elem.setAttribute("font-family", getFont().getName()); //$NON-NLS-1$
    elem.setAttribute("font-size", Integer.toString(getFont().getSize())); //$NON-NLS-1$
    String style = getRenderingStyle(RenderingHints.KEY_TEXT_ANTIALIASING);
    if (color != null) {
        String alpha = alphaToString(color);
        if (alpha != null)
            style += "fill-opacity:" + alpha + ";"; //$NON-NLS-1$ //$NON-NLS-2$
        style += "fill:" + serializeToString(color) + ";"; //$NON-NLS-1$ //$NON-NLS-2$ 
    }
    if (bRtl) {
        style += sStyleBidi;

    }
    elem.setAttribute("style", style); //$NON-NLS-1$
    if (transforms.getType() != AffineTransform.TYPE_IDENTITY) {
        double[] matrix = new double[6];
        transforms.getMatrix(matrix);
        elem.setAttribute("transform", "matrix(" + toString(matrix, ',') + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }

    return elem;
}

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

private int computeStyle(final TypedMapWrapper<Attribute, Object> attributes, final PdfTextSpec pdfTextSpec) {
    final Float weight = attributes.get(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR, Float.class);
    final Float italics = attributes.get(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, Float.class);
    final boolean underlined = attributes.exists(TextAttribute.UNDERLINE);
    final boolean strikethrough = attributes.exists(TextAttribute.STRIKETHROUGH);

    FontNativeContext nativeContext = pdfTextSpec.getFontMetrics().getNativeContext();

    int style = 0;
    if (nativeContext.isNativeBold() == false && weight >= TextAttribute.WEIGHT_DEMIBOLD) {
        style |= Font.BOLD;//from   w ww.java 2 s  . c  om
    }
    if (nativeContext.isNativeItalics() == false && italics >= TextAttribute.POSTURE_OBLIQUE) {
        style |= Font.ITALIC;
    }
    if (underlined) {
        style |= Font.UNDERLINE;
    }
    if (strikethrough) {
        style |= Font.STRIKETHRU;
    }
    return style;
}