List of usage examples for java.awt.font TextAttribute FAMILY
TextAttribute FAMILY
To view the source code for java.awt.font TextAttribute FAMILY.
Click Source Link
From source file:image.writer.ImageWriterExample1.java
/** * Paints a few things on a Graphics2D instance. * @param g2d the Graphics2D instance/* w w w . j a v a2s . com*/ * @param pageNum a page number */ protected void paintSome(Graphics2D g2d, int pageNum) { //Paint a bounding box g2d.drawRect(0, 0, 400, 200); //A few rectangles rotated and with different color Graphics2D copy = (Graphics2D) g2d.create(); int c = 12; for (int i = 0; i < c; i++) { float f = ((i + 1) / (float) c); Color col = new Color(0.0f, 1 - f, 0.0f); copy.setColor(col); copy.fillRect(70, 90, 50, 50); copy.rotate(-2 * Math.PI / (double) c, 70, 90); } copy.dispose(); //Some text copy = (Graphics2D) g2d.create(); copy.rotate(-0.25); copy.setColor(Color.RED); copy.setFont(new Font("sans-serif", Font.PLAIN, 36)); copy.drawString("Hello world!", 140, 140); copy.setColor(Color.RED.darker()); copy.setFont(new Font("serif", Font.PLAIN, 36)); copy.drawString("Hello world!", 140, 180); copy.dispose(); //Try attributed text AttributedString aString = new AttributedString("This is attributed text."); aString.addAttribute(TextAttribute.FAMILY, "SansSerif"); aString.addAttribute(TextAttribute.FAMILY, "Serif", 8, 18); aString.addAttribute(TextAttribute.FOREGROUND, Color.orange, 8, 18); g2d.drawString(aString.getIterator(), 250, 170); g2d.drawString("Page: " + pageNum, 250, 190); }
From source file:net.sf.jasperreports.engine.util.JRFontUtil.java
/** * *//*from w w w. j av a2 s . c o m*/ public static Map<Attribute, Object> getAttributesWithoutAwtFont(Map<Attribute, Object> attributes, JRFont font) { attributes.put(TextAttribute.FAMILY, font.getFontName()); attributes.put(TextAttribute.SIZE, new Float(font.getFontSize())); if (font.isBold()) { attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); } if (font.isItalic()) { attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); } if (font.isUnderline()) { attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } if (font.isStrikeThrough()) { attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); } attributes.put(JRTextAttribute.PDF_FONT_NAME, font.getPdfFontName()); attributes.put(JRTextAttribute.PDF_ENCODING, font.getPdfEncoding()); if (font.isPdfEmbedded()) { attributes.put(JRTextAttribute.IS_PDF_EMBEDDED, Boolean.TRUE); } return attributes; }
From source file:net.sf.jasperreports.engine.fonts.FontUtil.java
/** * *///from w w w .j a va 2 s . com public Map<Attribute, Object> getAttributesWithoutAwtFont(Map<Attribute, Object> attributes, JRFont font) { attributes.put(TextAttribute.FAMILY, font.getFontName()); attributes.put(TextAttribute.SIZE, font.getFontsize()); if (font.isBold()) { attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); } if (font.isItalic()) { attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); } if (font.isUnderline()) { attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } if (font.isStrikeThrough()) { attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); } attributes.put(JRTextAttribute.PDF_FONT_NAME, font.getPdfFontName()); attributes.put(JRTextAttribute.PDF_ENCODING, font.getPdfEncoding()); if (font.isPdfEmbedded()) { attributes.put(JRTextAttribute.IS_PDF_EMBEDDED, Boolean.TRUE); } return attributes; }
From source file:net.sf.jasperreports.engine.util.JEditorPaneHtmlMarkupProcessor.java
@Override protected Map<Attribute, Object> getAttributes(AttributeSet attrSet) { Map<Attribute, Object> attrMap = new HashMap<Attribute, Object>(); if (attrSet.isDefined(StyleConstants.FontFamily)) { attrMap.put(TextAttribute.FAMILY, StyleConstants.getFontFamily(attrSet)); }/* w w w . ja v a 2s . c om*/ if (attrSet.isDefined(StyleConstants.Bold)) { attrMap.put(TextAttribute.WEIGHT, StyleConstants.isBold(attrSet) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); } if (attrSet.isDefined(StyleConstants.Italic)) { attrMap.put(TextAttribute.POSTURE, StyleConstants.isItalic(attrSet) ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); } if (attrSet.isDefined(StyleConstants.Underline)) { attrMap.put(TextAttribute.UNDERLINE, StyleConstants.isUnderline(attrSet) ? TextAttribute.UNDERLINE_ON : null); } if (attrSet.isDefined(StyleConstants.StrikeThrough)) { attrMap.put(TextAttribute.STRIKETHROUGH, StyleConstants.isStrikeThrough(attrSet) ? TextAttribute.STRIKETHROUGH_ON : null); } if (attrSet.isDefined(StyleConstants.FontSize)) { attrMap.put(TextAttribute.SIZE, StyleConstants.getFontSize(attrSet)); } if (attrSet.isDefined(StyleConstants.Foreground)) { attrMap.put(TextAttribute.FOREGROUND, StyleConstants.getForeground(attrSet)); } if (attrSet.isDefined(StyleConstants.Background)) { attrMap.put(TextAttribute.BACKGROUND, StyleConstants.getBackground(attrSet)); } //FIXME: why StyleConstants.isSuperscript(attrSet) does return false if (attrSet.isDefined(StyleConstants.Superscript) && !StyleConstants.isSubscript(attrSet)) { attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER); } if (attrSet.isDefined(StyleConstants.Subscript) && StyleConstants.isSubscript(attrSet)) { attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB); } return attrMap; }
From source file:net.sf.jasperreports.engine.util.JRStyledTextParser.java
/** * *//*from w w w . j a va2 s.c o m*/ private void parseStyle(JRStyledText styledText, Node parentNode) throws SAXException { NodeList nodeList = parentNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.TEXT_NODE) { styledText.append(node.getNodeValue()); } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_style.equals(node.getNodeName())) { NamedNodeMap nodeAttrs = node.getAttributes(); Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>(); if (nodeAttrs.getNamedItem(ATTRIBUTE_fontName) != null) { styleAttrs.put(TextAttribute.FAMILY, nodeAttrs.getNamedItem(ATTRIBUTE_fontName).getNodeValue()); } if (nodeAttrs.getNamedItem(ATTRIBUTE_isBold) != null) { styleAttrs.put(TextAttribute.WEIGHT, Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isBold).getNodeValue()) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); } if (nodeAttrs.getNamedItem(ATTRIBUTE_isItalic) != null) { styleAttrs.put(TextAttribute.POSTURE, Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isItalic).getNodeValue()) ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); } if (nodeAttrs.getNamedItem(ATTRIBUTE_isUnderline) != null) { styleAttrs.put(TextAttribute.UNDERLINE, Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isUnderline).getNodeValue()) ? TextAttribute.UNDERLINE_ON : null); } if (nodeAttrs.getNamedItem(ATTRIBUTE_isStrikeThrough) != null) { styleAttrs.put(TextAttribute.STRIKETHROUGH, Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isStrikeThrough).getNodeValue()) ? TextAttribute.STRIKETHROUGH_ON : null); } if (nodeAttrs.getNamedItem(ATTRIBUTE_size) != null) { styleAttrs.put(TextAttribute.SIZE, Float.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_size).getNodeValue())); } if (nodeAttrs.getNamedItem(ATTRIBUTE_pdfFontName) != null) { styleAttrs.put(JRTextAttribute.PDF_FONT_NAME, nodeAttrs.getNamedItem(ATTRIBUTE_pdfFontName).getNodeValue()); } if (nodeAttrs.getNamedItem(ATTRIBUTE_pdfEncoding) != null) { styleAttrs.put(JRTextAttribute.PDF_ENCODING, nodeAttrs.getNamedItem(ATTRIBUTE_pdfEncoding).getNodeValue()); } if (nodeAttrs.getNamedItem(ATTRIBUTE_isPdfEmbedded) != null) { styleAttrs.put(JRTextAttribute.IS_PDF_EMBEDDED, Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isPdfEmbedded).getNodeValue())); } if (nodeAttrs.getNamedItem(ATTRIBUTE_forecolor) != null) { Color color = JRColorUtil.getColor(nodeAttrs.getNamedItem(ATTRIBUTE_forecolor).getNodeValue(), Color.black); styleAttrs.put(TextAttribute.FOREGROUND, color); } if (nodeAttrs.getNamedItem(ATTRIBUTE_backcolor) != null) { Color color = JRColorUtil.getColor(nodeAttrs.getNamedItem(ATTRIBUTE_backcolor).getNodeValue(), Color.black); styleAttrs.put(TextAttribute.BACKGROUND, color); } int startIndex = styledText.length(); parseStyle(styledText, node); styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length())); } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_bold.equalsIgnoreCase(node.getNodeName())) { Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>(); styleAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); int startIndex = styledText.length(); parseStyle(styledText, node); styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length())); } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_italic.equalsIgnoreCase(node.getNodeName())) { Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>(); styleAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); int startIndex = styledText.length(); parseStyle(styledText, node); styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length())); } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_underline.equalsIgnoreCase(node.getNodeName())) { Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>(); styleAttrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); int startIndex = styledText.length(); parseStyle(styledText, node); styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length())); } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_sup.equalsIgnoreCase(node.getNodeName())) { Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>(); styleAttrs.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER); int startIndex = styledText.length(); parseStyle(styledText, node); styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length())); } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_sub.equalsIgnoreCase(node.getNodeName())) { Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>(); styleAttrs.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB); int startIndex = styledText.length(); parseStyle(styledText, node); styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length())); } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_font.equalsIgnoreCase(node.getNodeName())) { NamedNodeMap nodeAttrs = node.getAttributes(); Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>(); if (nodeAttrs.getNamedItem(ATTRIBUTE_size) != null) { styleAttrs.put(TextAttribute.SIZE, Float.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_size).getNodeValue())); } if (nodeAttrs.getNamedItem(ATTRIBUTE_color) != null) { Color color = JRColorUtil.getColor(nodeAttrs.getNamedItem(ATTRIBUTE_color).getNodeValue(), Color.black); styleAttrs.put(TextAttribute.FOREGROUND, color); } if (nodeAttrs.getNamedItem(ATTRIBUTE_fontFace) != null) { String fontFaces = nodeAttrs.getNamedItem(ATTRIBUTE_fontFace).getNodeValue(); StringTokenizer t = new StringTokenizer(fontFaces, ","); while (t.hasMoreTokens()) { String face = t.nextToken().trim(); if (AVAILABLE_FONT_FACE_NAMES.contains(face)) { styleAttrs.put(TextAttribute.FAMILY, face); break; } } } int startIndex = styledText.length(); parseStyle(styledText, node); styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length())); } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_br.equalsIgnoreCase(node.getNodeName())) { styledText.append("\n"); int startIndex = styledText.length(); resizeRuns(styledText.getRuns(), startIndex, 1); parseStyle(styledText, node); styledText.addRun( new JRStyledText.Run(new HashMap<Attribute, Object>(), startIndex, styledText.length())); if (startIndex < styledText.length()) { styledText.append("\n"); resizeRuns(styledText.getRuns(), startIndex, 1); } } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_li.equalsIgnoreCase(node.getNodeName())) { String tmpText = styledText.getText(); if (tmpText.length() > 0 && !tmpText.endsWith("\n")) { styledText.append("\n"); } styledText.append(" \u2022 "); int startIndex = styledText.length(); resizeRuns(styledText.getRuns(), startIndex, 1); parseStyle(styledText, node); styledText.addRun( new JRStyledText.Run(new HashMap<Attribute, Object>(), startIndex, styledText.length())); // if the text in the next node does not start with a '\n', or // if the next node is not a <li /> one, we have to append a new line Node nextNode = node.getNextSibling(); String textContent = getFirstTextOccurence(nextNode); if (nextNode != null && !((nextNode.getNodeType() == Node.ELEMENT_NODE && NODE_li.equalsIgnoreCase(nextNode.getNodeName()) || (textContent != null && textContent.startsWith("\n"))))) { styledText.append("\n"); resizeRuns(styledText.getRuns(), startIndex, 1); } } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_a.equalsIgnoreCase(node.getNodeName())) { if (hyperlink == null) { NamedNodeMap nodeAttrs = node.getAttributes(); Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>(); hyperlink = new JRBasePrintHyperlink(); hyperlink.setHyperlinkType(HyperlinkTypeEnum.REFERENCE); styleAttrs.put(JRTextAttribute.HYPERLINK, hyperlink); if (nodeAttrs.getNamedItem(ATTRIBUTE_href) != null) { hyperlink.setHyperlinkReference(nodeAttrs.getNamedItem(ATTRIBUTE_href).getNodeValue()); } if (nodeAttrs.getNamedItem(ATTRIBUTE_type) != null) { hyperlink.setLinkType(nodeAttrs.getNamedItem(ATTRIBUTE_type).getNodeValue()); } if (nodeAttrs.getNamedItem(ATTRIBUTE_target) != null) { hyperlink.setLinkTarget(nodeAttrs.getNamedItem(ATTRIBUTE_target).getNodeValue()); } int startIndex = styledText.length(); parseStyle(styledText, node); styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length())); hyperlink = null; } else { throw new SAXException("Hyperlink <a> tags cannot be nested."); } } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_param.equalsIgnoreCase(node.getNodeName())) { if (hyperlink == null) { throw new SAXException("Hyperlink <param> tags must appear inside an <a> tag only."); } else { NamedNodeMap nodeAttrs = node.getAttributes(); JRPrintHyperlinkParameter parameter = new JRPrintHyperlinkParameter(); if (nodeAttrs.getNamedItem(ATTRIBUTE_name) != null) { parameter.setName(nodeAttrs.getNamedItem(ATTRIBUTE_name).getNodeValue()); } if (nodeAttrs.getNamedItem(ATTRIBUTE_valueClass) != null) { parameter.setValueClass(nodeAttrs.getNamedItem(ATTRIBUTE_valueClass).getNodeValue()); } String strValue = node.getTextContent(); if (strValue != null) { Object value = JRValueStringUtils.deserialize(parameter.getValueClass(), strValue); parameter.setValue(value); } hyperlink.addHyperlinkParameter(parameter); } } else if (node.getNodeType() == Node.ELEMENT_NODE) { String nodeName = "<" + node.getNodeName() + ">"; throw new SAXException("Tag " + nodeName + " is not a valid styled text tag."); } } }
From source file:net.sf.jasperreports.engine.export.JRXhtmlExporter.java
/** * *//*from w w w .jav 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.util.JRStyledTextParser.java
/** * *//*from w w w . j a v a 2 s . c om*/ private StringBuilder writeStyleAttributes(Map<Attribute, Object> parentAttrs, Map<Attribute, Object> attrs) { StringBuilder sb = new StringBuilder(); Object value = attrs.get(TextAttribute.FAMILY); Object oldValue = parentAttrs.get(TextAttribute.FAMILY); if (value != null && !value.equals(oldValue)) { sb.append(SPACE); sb.append(ATTRIBUTE_fontName); sb.append(EQUAL_QUOTE); sb.append(value); sb.append(QUOTE); } value = attrs.get(TextAttribute.WEIGHT); oldValue = parentAttrs.get(TextAttribute.WEIGHT); if (value != null && !value.equals(oldValue)) { sb.append(SPACE); sb.append(ATTRIBUTE_isBold); sb.append(EQUAL_QUOTE); sb.append(value.equals(TextAttribute.WEIGHT_BOLD)); sb.append(QUOTE); } value = attrs.get(TextAttribute.POSTURE); oldValue = parentAttrs.get(TextAttribute.POSTURE); if (value != null && !value.equals(oldValue)) { sb.append(SPACE); sb.append(ATTRIBUTE_isItalic); sb.append(EQUAL_QUOTE); sb.append(value.equals(TextAttribute.POSTURE_OBLIQUE)); sb.append(QUOTE); } value = attrs.get(TextAttribute.UNDERLINE); oldValue = parentAttrs.get(TextAttribute.UNDERLINE); if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) { sb.append(SPACE); sb.append(ATTRIBUTE_isUnderline); sb.append(EQUAL_QUOTE); sb.append(value != null); sb.append(QUOTE); } value = attrs.get(TextAttribute.STRIKETHROUGH); oldValue = parentAttrs.get(TextAttribute.STRIKETHROUGH); if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) { sb.append(SPACE); sb.append(ATTRIBUTE_isStrikeThrough); sb.append(EQUAL_QUOTE); sb.append(value != null); sb.append(QUOTE); } value = attrs.get(TextAttribute.SIZE); oldValue = parentAttrs.get(TextAttribute.SIZE); if (value != null && !value.equals(oldValue)) { sb.append(SPACE); sb.append(ATTRIBUTE_size); sb.append(EQUAL_QUOTE); sb.append(value); sb.append(QUOTE); } value = attrs.get(JRTextAttribute.PDF_FONT_NAME); oldValue = parentAttrs.get(JRTextAttribute.PDF_FONT_NAME); if (value != null && !value.equals(oldValue)) { sb.append(SPACE); sb.append(ATTRIBUTE_pdfFontName); sb.append(EQUAL_QUOTE); sb.append(value); sb.append(QUOTE); } value = attrs.get(JRTextAttribute.PDF_ENCODING); oldValue = parentAttrs.get(JRTextAttribute.PDF_ENCODING); if (value != null && !value.equals(oldValue)) { sb.append(SPACE); sb.append(ATTRIBUTE_pdfEncoding); sb.append(EQUAL_QUOTE); sb.append(value); sb.append(QUOTE); } value = attrs.get(JRTextAttribute.IS_PDF_EMBEDDED); oldValue = parentAttrs.get(JRTextAttribute.IS_PDF_EMBEDDED); if (value != null && !value.equals(oldValue)) { sb.append(SPACE); sb.append(ATTRIBUTE_isPdfEmbedded); sb.append(EQUAL_QUOTE); sb.append(value); sb.append(QUOTE); } value = attrs.get(TextAttribute.FOREGROUND); oldValue = parentAttrs.get(TextAttribute.FOREGROUND); if (value != null && !value.equals(oldValue)) { sb.append(SPACE); sb.append(ATTRIBUTE_forecolor); sb.append(EQUAL_QUOTE); sb.append(JRColorUtil.getCssColor((Color) value)); sb.append(QUOTE); } value = attrs.get(TextAttribute.BACKGROUND); oldValue = parentAttrs.get(TextAttribute.BACKGROUND); if (value != null && !value.equals(oldValue)) { sb.append(SPACE); sb.append(ATTRIBUTE_backcolor); sb.append(EQUAL_QUOTE); sb.append(JRColorUtil.getCssColor((Color) value)); sb.append(QUOTE); } return sb; }
From source file:net.sf.jasperreports.engine.export.JRHtmlExporter.java
/** * */// w w w .j a 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); 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:de.kiwiwings.jasperreports.exporter.PptxShapeExporter.java
public java.awt.Font loadFont(Map<Attribute, Object> attr, Locale locale) { String family = (String) attr.get(TextAttribute.FAMILY); FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(family, locale); if (fontInfo == null || fontInfo.getFontFamily() == null) { return java.awt.Font.getFont(attr); }//from w w w. j av a 2 s. c om FontFamily ffamily = fontInfo.getFontFamily(); FontFace fface = null; if (fface == null && TextAttribute.WEIGHT_BOLD.equals(attr.get(TextAttribute.WEIGHT)) && TextAttribute.POSTURE_OBLIQUE.equals(attr.get(TextAttribute.POSTURE))) { fface = ffamily.getBoldItalicFace(); } if (fface == null && TextAttribute.WEIGHT_BOLD.equals(attr.get(TextAttribute.WEIGHT))) { fface = ffamily.getBoldFace(); } if (fface == null && TextAttribute.POSTURE_OBLIQUE.equals(attr.get(TextAttribute.POSTURE))) { fface = ffamily.getItalicFace(); } if (fface == null) { fface = ffamily.getNormalFace(); } if (fface == null) { return java.awt.Font.getFont(attr); } attr.remove(TextAttribute.FAMILY); return fface.getFont().deriveFont(attr); }
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 om*/ */ 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)); } } }