Example usage for java.awt.font TextAttribute UNDERLINE_ON

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

Introduction

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

Prototype

Integer UNDERLINE_ON

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

Click Source Link

Document

Standard underline.

Usage

From source file:com.dlya.facturews.DlyaPdfExporter2.java

protected boolean hasUnderline(Map<Attribute, Object> textAttributes) {
    Integer underline = (Integer) textAttributes.get(TextAttribute.UNDERLINE);
    return TextAttribute.UNDERLINE_ON.equals(underline);
}

From source file:net.sf.jasperreports.engine.export.HtmlExporter.java

protected void exportStyledTextRun(Map<Attribute, Object> attributes, String text, String tooltip,
        Locale locale, LineSpacingEnum lineSpacing, Float lineSpacingSize, float lineSpacingFactor,
        Color backcolor, boolean hyperlinkStarted) throws IOException {
    boolean localHyperlink = false;
    JRPrintHyperlink hyperlink = (JRPrintHyperlink) attributes.get(JRTextAttribute.HYPERLINK);
    if (!hyperlinkStarted && hyperlink != null) {
        localHyperlink = startHyperlink(hyperlink);
    }/*from  w  ww.  j a v a2  s.c o  m*/

    boolean isBold = TextAttribute.WEIGHT_BOLD.equals(attributes.get(TextAttribute.WEIGHT));
    boolean isItalic = TextAttribute.POSTURE_OBLIQUE.equals(attributes.get(TextAttribute.POSTURE));

    String fontFamily = resolveFontFamily(attributes, locale);

    // do not put single quotes around family name here because the value might already contain quotes, 
    // especially if it is coming from font extension export configuration
    writer.write("<span style=\"font-family: ");
    // don't encode single quotes as the output would be too verbose and too much of a chance compared to previous releases
    writer.write(JRStringUtil.encodeXmlAttribute(fontFamily, true));
    writer.write("; ");

    Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND);
    if (!hyperlinkStarted || !Color.black.equals(forecolor)) {
        writer.write("color: ");
        writer.write(JRColorUtil.getCssColor(forecolor));
        writer.write("; ");
    }

    Color runBackcolor = (Color) attributes.get(TextAttribute.BACKGROUND);
    if (runBackcolor != null && !runBackcolor.equals(backcolor)) {
        writer.write("background-color: ");
        writer.write(JRColorUtil.getCssColor(runBackcolor));
        writer.write("; ");
    }

    writer.write("font-size: ");
    writer.write(toSizeUnit((Float) attributes.get(TextAttribute.SIZE)));
    writer.write(";");

    switch (lineSpacing) {
    case SINGLE:
    default: {
        if (lineSpacingFactor == 0) {
            writer.write(" line-height: 1; *line-height: normal;");
        } else {
            writer.write(" line-height: " + lineSpacingFactor + ";");
        }
        break;
    }
    case ONE_AND_HALF: {
        if (lineSpacingFactor == 0) {
            writer.write(" line-height: 1.5;");
        } else {
            writer.write(" line-height: " + lineSpacingFactor + ";");
        }
        break;
    }
    case DOUBLE: {
        if (lineSpacingFactor == 0) {
            writer.write(" line-height: 2.0;");
        } else {
            writer.write(" line-height: " + lineSpacingFactor + ";");
        }
        break;
    }
    case PROPORTIONAL: {
        if (lineSpacingSize != null) {
            writer.write(" line-height: " + lineSpacingSize + ";");
        }
        break;
    }
    case AT_LEAST:
    case FIXED: {
        if (lineSpacingSize != null) {
            writer.write(" line-height: " + lineSpacingSize + "px;");
        }
        break;
    }
    }

    /*
    if (!horizontalAlignment.equals(CSS_TEXT_ALIGN_LEFT))
    {
       writer.write(" text-align: ");
       writer.write(horizontalAlignment);
       writer.write(";");
    }
    */

    if (isBold) {
        writer.write(" font-weight: bold;");
    }
    if (isItalic) {
        writer.write(" font-style: italic;");
    }
    if (TextAttribute.UNDERLINE_ON.equals(attributes.get(TextAttribute.UNDERLINE))) {
        writer.write(" text-decoration: underline;");
    }
    if (TextAttribute.STRIKETHROUGH_ON.equals(attributes.get(TextAttribute.STRIKETHROUGH))) {
        writer.write(" text-decoration: line-through;");
    }

    if (TextAttribute.SUPERSCRIPT_SUPER.equals(attributes.get(TextAttribute.SUPERSCRIPT))) {
        writer.write(" vertical-align: super;");
    } else if (TextAttribute.SUPERSCRIPT_SUB.equals(attributes.get(TextAttribute.SUPERSCRIPT))) {
        writer.write(" vertical-align: sub;");
    }

    writer.write("\"");

    if (tooltip != null) {
        writer.write(" title=\"");
        writer.write(JRStringUtil.encodeXmlAttribute(tooltip));
        writer.write("\"");
    }

    writer.write(">");

    writer.write(JRStringUtil.htmlEncode(text));

    writer.write("</span>");

    if (localHyperlink) {
        endHyperlink();
    }
}

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--;// ww  w. 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.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  a  2  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));
        }
    }
}

From source file:org.zkoss.poi.ss.util.SheetUtil.java

/**
 * Copy text attributes from the supplied Font to Java2D AttributedString
 *//*  w  ww  .  j  ava  2s.co  m*/
private static void copyAttributes(Font font, AttributedString str, int startIdx, int endIdx) {
    str.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx);
    str.addAttribute(TextAttribute.SIZE, (float) font.getFontHeightInPoints());
    if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD)
        str.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx);
    if (font.getItalic())
        str.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIdx, endIdx);
    if (font.getUnderline() == Font.U_SINGLE)
        str.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, startIdx, endIdx);
}

From source file:processing.app.Theme.java

public static Map<String, Object> getStyledFont(String what, Font font) {
    String split[] = get("editor." + what + ".style").split(",");

    Color color = PreferencesHelper.parseColor(split[0]);

    String style = split[1];//from w w w.  ja v  a  2 s.  c  o  m
    boolean bold = style.contains("bold");
    boolean italic = style.contains("italic");
    boolean underlined = style.contains("underlined");

    Font styledFont = new Font(font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0),
            font.getSize());
    if (underlined) {
        Map<TextAttribute, Object> attr = new Hashtable<>();
        attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        styledFont = styledFont.deriveFont(attr);
    }

    Map<String, Object> result = new HashMap<>();
    result.put("color", color);
    result.put("font", styledFont);

    return result;
}

From source file:utybo.branchingstorytree.swing.visuals.AboutDialog.java

@SuppressWarnings("unchecked")
public AboutDialog(OpenBSTGUI parent) {
    super(parent);
    setTitle(Lang.get("about.title"));
    setModalityType(ModalityType.APPLICATION_MODAL);

    JPanel banner = new JPanel(new FlowLayout(FlowLayout.CENTER));
    banner.setBackground(OpenBSTGUI.OPENBST_BLUE);
    JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogoWhite", 48)));
    lblOpenbst.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    banner.add(lblOpenbst, "flowx,cell 0 0,alignx center");
    getContentPane().add(banner, BorderLayout.NORTH);

    JPanel pan = new JPanel();
    pan.setLayout(new MigLayout("insets 10, gap 10px", "[grow]", "[][][grow]"));
    getContentPane().add(pan, BorderLayout.CENTER);

    JLabel lblWebsite = new JLabel("https://utybo.github.io/BST/");
    Font f = lblWebsite.getFont();
    @SuppressWarnings("rawtypes")
    Map attrs = f.getAttributes();
    attrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    lblWebsite.setFont(f.deriveFont(attrs));
    lblWebsite.setForeground(OpenBSTGUI.OPENBST_BLUE);
    lblWebsite.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    lblWebsite.addMouseListener(new MouseAdapter() {
        @Override//www.  j a v  a  2  s.c om
        public void mouseClicked(MouseEvent e) {
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new URL("https://utybo.github.io/BST/").toURI());
                } catch (IOException | URISyntaxException e1) {
                    OpenBST.LOG.warn("Exception when trying to open website", e1);
                }
            }
        }
    });
    pan.add(lblWebsite, "cell 0 0,alignx center");

    JLabel lblVersion = new JLabel(Lang.get("about.version").replace("$v", OpenBST.VERSION));
    pan.add(lblVersion, "flowy,cell 0 1");

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBorder(new LineBorder(pan.getBackground().darker(), 1, false));
    pan.add(scrollPane, "cell 0 2,grow");

    JTextArea textArea = new JTextArea();
    textArea.setMargin(new Insets(5, 5, 5, 5));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setFont(new Font(textArea.getFont().getFontName(), Font.PLAIN, (int) (Icons.getScale() * 11)));

    try (InputStream in = getClass().getResourceAsStream("/utybo/branchingstorytree/swing/about.txt");) {
        textArea.setText(IOUtils.toString(in, StandardCharsets.UTF_8));
    } catch (IOException ex) {
        OpenBST.LOG.warn("Loading about information failed", ex);
    }
    textArea.setEditable(false);
    textArea.setCaretPosition(0);
    scrollPane.setViewportView(textArea);

    JLabel lblTranslatedBy = new JLabel(Lang.get("author"));
    pan.add(lblTranslatedBy, "cell 0 1");

    setSize((int) (Icons.getScale() * 450), (int) (Icons.getScale() * 400));
    setLocationRelativeTo(parent);
}

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Get a font based on size and font index. If this font has not already been created, then it will be generated.
 * Can be reused later if the same font was already created.
 *
 * @param size Font size./* w  ww. j  ava 2  s .c  o m*/
 * @param font Font index. See MapBoard.java for format.
 */

/* Binary format for fonts:
 *
 *             00000000
 *                 ||||_ Font name index (between 1 and 9).
 *                |_____ Bold flag.
 *               |______ Italics flag.
 *              |_______ Underline flag.
 */
protected static Font getDefaultFont(int size, int font) {
    final Integer key = Integer.valueOf((size << 8) + font);
    Font f = defaultFonts.get(key);
    if (f == null) {
        int fontIndex = font & 0xf;
        assert (fontIndex >= 1 && fontIndex <= 9);
        boolean isBold = (font & 0x0010) > 0;
        boolean isItalic = (font & 0x0020) > 0;
        boolean isUnderline = (font & 0x0040) > 0;
        String fontName = defaultFontNames[fontIndex - 1];
        int fontStyle = Font.PLAIN;
        if (isItalic)
            fontStyle |= Font.ITALIC;
        if (isBold)
            fontStyle |= Font.BOLD;
        f = new Font(fontName, fontStyle, size);
        if (isUnderline) {
            // TODO: why doesn't underlining doesn't work? Why why why?
            Hashtable<TextAttribute, Object> hash = new Hashtable<TextAttribute, Object>();
            hash.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
            f = f.deriveFont(hash);
        }
        defaultFonts.put(key, f);
    }
    return f;
}