List of usage examples for java.awt.font TextAttribute WEIGHT_REGULAR
Float WEIGHT_REGULAR
To view the source code for java.awt.font TextAttribute WEIGHT_REGULAR.
Click Source Link
From source file:net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.java
@Override public boolean start(JRStyledText styledText) { if (!measureSimpleTexts) { return false; }//from w w w .j ava 2s. c o m List<Run> runs = styledText.getRuns(); if (runs.size() != 1) { // multiple styles return false; } wholeText = styledText.getText(); if (wholeText.indexOf('\t') >= 0) { // supporting tabs is more difficult because we'd need // measureParagraphFragment to include the white space advance. return false; } Run run = styledText.getRuns().get(0); if (run.attributes.get(TextAttribute.SUPERSCRIPT) != null) { // not handling this case, see JRStyledText.getAwtAttributedString return false; } AwtFontAttribute fontAttribute = AwtFontAttribute.fromAttributes(run.attributes); Number size = (Number) run.attributes.get(TextAttribute.SIZE); if (!fontAttribute.hasAttribute() || size == null) { // this should not happen, but still checking return false; } int style = 0; Number posture = (Number) run.attributes.get(TextAttribute.POSTURE); if (posture != null && !TextAttribute.POSTURE_REGULAR.equals(posture)) { if (TextAttribute.POSTURE_OBLIQUE.equals(posture)) { style |= Font.ITALIC; } else { // non standard posture return false; } } Number weight = (Number) run.attributes.get(TextAttribute.WEIGHT); if (weight != null && !TextAttribute.WEIGHT_REGULAR.equals(weight)) { if (TextAttribute.WEIGHT_BOLD.equals(weight)) { style |= Font.BOLD; } else { // non standard weight return false; } } fontKey = new FontKey(fontAttribute, size.floatValue(), style, styledText.getLocale()); createFontInfo(run.attributes); return true; }
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)); }//from w ww. j av a 2 s .c o m 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.ja v a 2 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:org.apache.fop.svg.ACIUtils.java
private static int toCSSWeight(Float weight) { if (weight == null) { return 400; } else if (weight <= TextAttribute.WEIGHT_EXTRA_LIGHT.floatValue()) { return 100; } else if (weight <= TextAttribute.WEIGHT_LIGHT.floatValue()) { return 200; } else if (weight <= TextAttribute.WEIGHT_DEMILIGHT.floatValue()) { return 300; } else if (weight <= TextAttribute.WEIGHT_REGULAR.floatValue()) { return 400; } else if (weight <= TextAttribute.WEIGHT_SEMIBOLD.floatValue()) { return 500; } else if (weight < TextAttribute.WEIGHT_BOLD.floatValue()) { return 600; } else if (weight == TextAttribute.WEIGHT_BOLD.floatValue()) { return 700; } else if (weight <= TextAttribute.WEIGHT_HEAVY.floatValue()) { return 800; } else if (weight <= TextAttribute.WEIGHT_EXTRABOLD.floatValue()) { return 900; } else {/* ww w .j a v a 2 s . c o m*/ return 900; } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java
private PdfTextSpec computeFont(final RichTextSpec.StyledChunk c) { final StyleSheet layoutContext = c.getStyleSheet(); final PdfGraphics2D g2 = (PdfGraphics2D) getGraphics(); final PdfContentByte cb = g2.getRawContentByte(); final TypedMapWrapper<Attribute, Object> attributes = new TypedMapWrapper<Attribute, Object>( c.getAttributes());/*ww w .java2 s .co m*/ final String fontName = attributes.get(TextAttribute.FAMILY, String.class); final Number fontSize = attributes.get(TextAttribute.SIZE, 10f, Number.class); final String encoding = (String) layoutContext.getStyleProperty(TextStyleKeys.FONTENCODING); final boolean embed = globalEmbed || layoutContext.getBooleanStyleProperty(TextStyleKeys.EMBEDDED_FONT); final Float weightRaw = attributes.get(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR, Float.class); final Float italicsRaw = attributes.get(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, Float.class); final BaseFontFontMetrics fontMetrics = getMetaData().getBaseFontFontMetrics(fontName, fontSize.doubleValue(), weightRaw >= TextAttribute.WEIGHT_DEMIBOLD, italicsRaw >= TextAttribute.POSTURE_OBLIQUE, encoding, embed, false); return new PdfTextSpec(layoutContext, getMetaData(), g2, fontMetrics, cb); }
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 av 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; }