List of usage examples for java.awt.font TextAttribute WEIGHT_BOLD
Float WEIGHT_BOLD
To view the source code for java.awt.font TextAttribute WEIGHT_BOLD.
Click Source Link
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 ww . j a va 2 s . c o m*/ 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:net.sf.jasperreports.engine.export.JRPdfExporter.java
protected FontKey extractFontKey(Map<Attribute, Object> attributes, Locale locale) { AwtFontAttribute fontAttribute = AwtFontAttribute.fromAttributes(attributes); Number posture = (Number) attributes.get(TextAttribute.POSTURE); boolean italic = TextAttribute.POSTURE_OBLIQUE.equals(posture);//FIXME check for non standard posture Number weight = (Number) attributes.get(TextAttribute.WEIGHT); boolean bold = TextAttribute.WEIGHT_BOLD.equals(weight); return new FontKey(fontAttribute, italic, bold, locale); }
From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java
protected boolean canUseGlyphRendering(FontKey fontKey) { Map<Attribute, Object> fontAttributes = new HashMap<Attribute, Object>(); fontKey.fontAttribute.putAttributes(fontAttributes); fontAttributes.put(TextAttribute.SIZE, 10f); int style = 0; if (fontKey.italic) { style |= java.awt.Font.ITALIC; fontAttributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); }//from w ww . j a v a 2s.com if (fontKey.bold) { style |= java.awt.Font.BOLD; fontAttributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); } Font pdfFont = getFont(fontAttributes, fontKey.locale, false); BaseFont baseFont = pdfFont.getBaseFont(); if (baseFont.getFontType() != BaseFont.FONT_TYPE_TTUNI || baseFont.isFontSpecific()) { if (log.isDebugEnabled()) { log.debug("pdf font for " + fontKey + " has type " + baseFont.getFontType() + ", symbol " + baseFont.isFontSpecific() + ", cannot use glyph rendering"); } return false; } java.awt.Font awtFont = fontUtil.getAwtFontFromBundles(fontKey.fontAttribute, style, 10f, fontKey.locale, awtIgnoreMissingFont); if (awtFont == null) { awtFont = new java.awt.Font(fontAttributes); } String awtFontName = awtFont.getFontName(); if (log.isDebugEnabled()) { log.debug(fontKey + " resolved to awt font " + awtFontName); } // we need the fonts to be identical. // it would be safer to only allow fonts from extensions, // but for now we are just checking the font names. // we need to compare full names because we can't get the base name from awt. String[][] pdfFontNames = baseFont.getFullFontName(); boolean nameMatch = false; for (String[] nameArray : pdfFontNames) { if (nameArray.length >= 4) { if (log.isDebugEnabled()) { log.debug(fontKey + " resolved to pdf font " + nameArray[3]); } if (awtFontName.equals(nameArray[3])) { nameMatch = true; break; } } } return nameMatch; }
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 . j a v a 2 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.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 {//from ww w.ja v a 2s . c om return 900; } }
From source file:org.zkoss.poi.ss.util.SheetUtil.java
/** * Copy text attributes from the supplied Font to Java2D AttributedString *//*from w w w . ja v a2 s .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); }