List of usage examples for java.awt.font TextAttribute STRIKETHROUGH_ON
Boolean STRIKETHROUGH_ON
To view the source code for java.awt.font TextAttribute STRIKETHROUGH_ON.
Click Source Link
From source file:lucee.runtime.img.Image.java
public void drawString(String text, int x, int y, Struct attr) throws PageException { if (attr != null && attr.size() > 0) { // font//w w w . jav a 2 s . co m String font = StringUtil.toLowerCase(Caster.toString(attr.get("font", ""))).trim(); if (!StringUtil.isEmpty(font)) { font = FontUtil.getFont(font).getFontName(); } else font = "Serif"; // alpha //float alpha=Caster.toFloatValue(attr.get("alpha",null),1F); // size int size = Caster.toIntValue(attr.get("size", Constants.INTEGER_10)); // style int style = Font.PLAIN; String strStyle = StringUtil.toLowerCase(Caster.toString(attr.get("style", ""))); strStyle = StringUtil.removeWhiteSpace(strStyle); if (!StringUtil.isEmpty(strStyle)) { if ("plain".equals(strStyle)) style = Font.PLAIN; else if ("bold".equals(strStyle)) style = Font.BOLD; else if ("italic".equals(strStyle)) style = Font.ITALIC; else if ("bolditalic".equals(strStyle)) style = Font.BOLD + Font.ITALIC; else if ("bold,italic".equals(strStyle)) style = Font.BOLD + Font.ITALIC; else if ("italicbold".equals(strStyle)) style = Font.BOLD + Font.ITALIC; else if ("italic,bold".equals(strStyle)) style = Font.BOLD + Font.ITALIC; else throw new ExpressionException("key style of argument attributeCollection has an invalid value [" + strStyle + "], valid values are [plain,bold,italic,bolditalic]"); } // strikethrough boolean strikethrough = Caster.toBooleanValue(attr.get("strikethrough", Boolean.FALSE)); // underline boolean underline = Caster.toBooleanValue(attr.get("underline", Boolean.FALSE)); AttributedString as = new AttributedString(text); as.addAttribute(TextAttribute.FONT, new Font(font, style, size)); if (strikethrough) as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); if (underline) as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); Graphics2D g = getGraphics(); //if(alpha!=1D) setAlpha(g,alpha); g.drawString(as.getIterator(), x, y); } else getGraphics().drawString(text, x, y); }
From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java
private Font parseFont(String fontSpecs) { // split attribute value to get font name and carachteristics // bold, italic, underline, and strikeout. // Size and Unit (Point, Pixel, Millimeter, Inch) String[] fontSpecsArray = fontSpecs.split(","); int fontStyle = Font.PLAIN; boolean isUnderline = false; boolean isStrikeout = false; // TODO: manage unit String unit;//from w ww.ja v a 2 s .c o m // font name String fontName = "Droid Sans"; //fontSpecsArray[0]; int size = Integer.valueOf(fontSpecsArray[1]); // size = (int)Math.round(size * Toolkit.getDefaultToolkit().getScreenResolution() / 72.0); if (fontSpecsArray.length > 5) { // her we have a full description // bold if (Boolean.valueOf(fontSpecsArray[2])) { fontStyle += Font.BOLD; } // italic if (Boolean.valueOf(fontSpecsArray[3])) { fontStyle += Font.ITALIC; } // underline isUnderline = Boolean.valueOf(fontSpecsArray[4]); // strikeout isStrikeout = Boolean.valueOf(fontSpecsArray[5]); // unit unit = fontSpecsArray[6]; } else { // unit unit = fontSpecsArray[2]; } Font font = new Font(fontName, fontStyle, size); Map attributes = font.getAttributes(); if (isStrikeout) { attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); } if (isUnderline) { attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } return new Font(attributes); }
From source file:net.sf.jasperreports.engine.export.JRXhtmlExporter.java
/** * *///www .ja v a 2 s . c o 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);//FIXMENOW reuse this font lookup code everywhere 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:net.sf.jasperreports.engine.export.JRHtmlExporter.java
/** * *//*from ww w . j av a 2s . c om*/ 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.raddle.tools.MergeMain.java
private void setCellRenderer(JList list) { list.setCellRenderer(new DefaultListCellRenderer() { private static final long serialVersionUID = 1L; @Override/* ww w . j av a2 s.com*/ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value != null) { PropertyLine line = (PropertyLine) value; boolean isInSelected = false; for (int selectedIndex : list.getSelectedIndices()) { if (index == selectedIndex) { isInSelected = true; } } if (!isInSelected) { if (CompareResult.extra == line.getCompareResult()) { c.setBackground(new Color(0xFFC48E)); } else if (CompareResult.different == line.getCompareResult()) { c.setBackground(new Color(0xBBBBFF)); } } if (line.getState() != null) { if (LineState.added == line.getState()) { c.setForeground(new Color(0xCC0033)); } else if (LineState.updated == line.getState()) { c.setForeground(new Color(0x0066CC)); } else if (LineState.deleted == line.getState()) { if (line.getOriginalValue() == null) { c.setForeground(new Color(0xAAAAAA)); } else { c.setForeground(new Color(0x666666)); } Map<Attribute, Object> map = new HashMap<Attribute, Object>(); map.put(TextAttribute.FONT, c.getFont()); map.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); c.setFont(Font.getFont(map)); } } } return c; } }); }
From source file:com.dlya.facturews.DlyaPdfExporter2.java
protected boolean hasStrikethrough(Map<Attribute, Object> textAttributes) { Boolean strike = (Boolean) textAttributes.get(TextAttribute.STRIKETHROUGH); return TextAttribute.STRIKETHROUGH_ON.equals(strike); }
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 w w.ja v a2s . co 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--;/*from w w w . j ava 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; }