List of usage examples for java.awt.font TextAttribute UNDERLINE
TextAttribute UNDERLINE
To view the source code for java.awt.font TextAttribute UNDERLINE.
Click Source Link
From source file:net.sf.jasperreports.engine.export.JRHtmlExporter.java
/** * */// www. j a v a2 s . co m protected void exportStyledTextRun(Map<Attribute, Object> attributes, String text, String tooltip, Locale locale, LineSpacingEnum lineSpacing, Float lineSpacingSize, float lineSpacingFactor, Color backcolor) throws IOException { boolean isBold = TextAttribute.WEIGHT_BOLD.equals(attributes.get(TextAttribute.WEIGHT)); boolean isItalic = TextAttribute.POSTURE_OBLIQUE.equals(attributes.get(TextAttribute.POSTURE)); String fontFamilyAttr = (String) attributes.get(TextAttribute.FAMILY); String fontFamily = fontFamilyAttr; FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(fontFamilyAttr, locale); if (fontInfo != null) { //fontName found in font extensions FontFamily family = fontInfo.getFontFamily(); String exportFont = family.getExportFont(getExporterKey()); if (exportFont == null) { HtmlResourceHandler fontHandler = getExporterOutput().getFontHandler() == null ? getFontHandler() : getExporterOutput().getFontHandler(); HtmlResourceHandler resourceHandler = getExporterOutput().getResourceHandler() == null ? getResourceHandler() : getExporterOutput().getResourceHandler(); if (fontHandler != null && resourceHandler != null) { HtmlFont htmlFont = HtmlFont.getInstance(locale, fontInfo, isBold, isItalic); if (htmlFont != null) { if (!fontsToProcess.containsKey(htmlFont.getId())) { fontsToProcess.put(htmlFont.getId(), htmlFont); HtmlFontUtil.handleFont(resourceHandler, htmlFont); } fontFamily = htmlFont.getId(); } } } else { fontFamily = exportFont; } } boolean localHyperlink = false; JRPrintHyperlink hyperlink = (JRPrintHyperlink) attributes.get(JRTextAttribute.HYPERLINK); if (!hyperlinkStarted && hyperlink != null) { startHyperlink(hyperlink); localHyperlink = true; } writer.write("<span style=\"font-family: "); writer.write(fontFamily); 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.floatValue() + ";"); } break; } case AT_LEAST: case FIXED: { if (lineSpacingSize != null) { writer.write(" line-height: " + lineSpacingSize.floatValue() + "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.xmlEncode(tooltip)); writer.write("\""); } writer.write(">"); writer.write(JRStringUtil.htmlEncode(text)); writer.write("</span>"); if (localHyperlink) { endHyperlink(); } }
From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java
/** * Updates the charts./*from w ww. j ava2 s . c o m*/ */ @SuppressWarnings({ "unchecked", "rawtypes" }) private void updateCharts() { for (int i = 0; i < listOfChartPanels.size(); i++) { JPanel panel = listOfChartPanels.get(i); panel.removeAll(); final ChartPanel chartPanel = new ChartPanel(getModel().getChartOrNull(i)) { private static final long serialVersionUID = -6953213567063104487L; @Override public Dimension getPreferredSize() { return DIMENSION_CHART_PANEL_ENLARGED; } }; chartPanel.setPopupMenu(null); chartPanel.setBackground(COLOR_TRANSPARENT); chartPanel.setOpaque(false); chartPanel.addMouseListener(enlargeAndHoverAndPopupMouseAdapter); panel.add(chartPanel, BorderLayout.CENTER); JPanel openChartPanel = new JPanel(new GridBagLayout()); openChartPanel.setOpaque(false); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 1.0; gbc.weighty = 1.0; JButton openChartButton = new JButton(OPEN_CHART_ACTION); openChartButton.setOpaque(false); openChartButton.setContentAreaFilled(false); openChartButton.setBorderPainted(false); openChartButton.addMouseListener(enlargeAndHoverAndPopupMouseAdapter); openChartButton.setHorizontalAlignment(SwingConstants.LEFT); openChartButton.setHorizontalTextPosition(SwingConstants.LEFT); openChartButton.setIcon(null); Font font = openChartButton.getFont(); Map attributes = font.getAttributes(); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); openChartButton.setFont(font.deriveFont(attributes).deriveFont(10.0f)); openChartPanel.add(openChartButton, gbc); panel.add(openChartPanel, BorderLayout.SOUTH); panel.revalidate(); panel.repaint(); } }
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); }/*w w w . ja v a2 s . com*/ 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 av a2 s . c om } 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 www . j a v a2 s. com*/ */ 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.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;/*w w w . j a v a 2s . co m*/ } if (nativeContext.isNativeItalics() == false && italics >= TextAttribute.POSTURE_OBLIQUE) { style |= Font.ITALIC; } if (underlined) { style |= Font.UNDERLINE; } if (strikethrough) { style |= Font.STRIKETHRU; } return style; }
From source file:org.zkoss.poi.ss.util.SheetUtil.java
/** * Copy text attributes from the supplied Font to Java2D AttributedString */// w w w . java2 s . c om 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 www . j a v a 2 s .co 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/* ww w . j a va 2 s . c o m*/ 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); }