List of usage examples for java.awt.font TextAttribute SIZE
TextAttribute SIZE
To view the source code for java.awt.font TextAttribute SIZE.
Click Source Link
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 ww w . j a v a 2s .c om 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 . jav a2 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
/** * Tries to find matching fonts in FOP's {@link FontInfo} instance for fonts used by * Apache Batik. The method inspects the various GVT attributes found in the ACI. * @param aci the ACI to find matching fonts for * @param fontInfo the font info instance with FOP's fonts * @return an array of matching fonts//from ww w . jav a 2 s.c o m */ public static Font[] findFontsForBatikACI(AttributedCharacterIterator aci, FontInfo fontInfo) { List<Font> fonts = new java.util.ArrayList<Font>(); @SuppressWarnings("unchecked") List<GVTFontFamily> gvtFonts = (List<GVTFontFamily>) aci .getAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES); Float posture = (Float) aci.getAttribute(TextAttribute.POSTURE); Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT); Float fontSize = (Float) aci.getAttribute(TextAttribute.SIZE); String style = toStyle(posture); int weight = toCSSWeight(taWeight); int fsize = (int) (fontSize.floatValue() * 1000); String firstFontFamily = null; //GVT_FONT can sometimes be different from the fonts in GVT_FONT_FAMILIES //or GVT_FONT_FAMILIES can even be empty and only GVT_FONT is set /* The following code section is not available until Batik 1.7 is released. */ GVTFont gvtFont = (GVTFont) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT); if (gvtFont != null) { String gvtFontFamily = gvtFont.getFamilyName(); if (fontInfo.hasFont(gvtFontFamily, style, weight)) { FontTriplet triplet = fontInfo.fontLookup(gvtFontFamily, style, weight); Font f = fontInfo.getFontInstance(triplet, fsize); if (LOG.isDebugEnabled()) { LOG.debug("Found a font that matches the GVT font: " + gvtFontFamily + ", " + weight + ", " + style + " -> " + f); } fonts.add(f); } firstFontFamily = gvtFontFamily; } if (gvtFonts != null) { boolean haveInstanceOfSVGFontFamily = false; for (GVTFontFamily fam : gvtFonts) { if (fam instanceof SVGFontFamily) { haveInstanceOfSVGFontFamily = true; } String fontFamily = fam.getFamilyName(); if (fontInfo.hasFont(fontFamily, style, weight)) { FontTriplet triplet = fontInfo.fontLookup(fontFamily, style, weight); Font f = fontInfo.getFontInstance(triplet, fsize); if (LOG.isDebugEnabled()) { LOG.debug("Found a font that matches the GVT font family: " + fontFamily + ", " + weight + ", " + style + " -> " + f); } fonts.add(f); } if (firstFontFamily == null) { firstFontFamily = fontFamily; } } // SVG fonts are embedded fonts in the SVG document and are rarely used; however if they // are used but the fonts also exists in the system and are known to FOP then FOP should // use them; then the decision whether Batik should stroke the text should be made after // no matching fonts are found if (fonts.isEmpty() && haveInstanceOfSVGFontFamily) { fontInfo.notifyStrokingSVGTextAsShapes(firstFontFamily); return null; // Let Batik paint this text! } } if (fonts.isEmpty()) { if (firstFontFamily == null) { //This will probably never happen. Just to be on the safe side. firstFontFamily = "any"; } //lookup with fallback possibility (incl. substitution notification) FontTriplet triplet = fontInfo.fontLookup(firstFontFamily, style, weight); Font f = fontInfo.getFontInstance(triplet, fsize); if (LOG.isDebugEnabled()) { LOG.debug("Falling back to adjustable font lookup up for: " + firstFontFamily + ", " + weight + ", " + style + " -> " + f); } fonts.add(f); } return fonts.toArray(new Font[fonts.size()]); }
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 va 2 s . c o m */ 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 Phrase createPhrase(final RenderableComplexText node) { Phrase p = new Phrase(); RichTextSpec text = node.getRichText(); for (RichTextSpec.StyledChunk c : text.getStyleChunks()) { TypedMapWrapper<Attribute, Object> attributes = new TypedMapWrapper<Attribute, Object>( c.getAttributes());//from w w w.j ava 2 s .co m final Number size = attributes.get(TextAttribute.SIZE, 10f, Number.class); final PdfTextSpec pdfTextSpec = computeFont(c); final int style = computeStyle(attributes, pdfTextSpec); final Color paint = (Color) c.getStyleSheet().getStyleProperty(ElementStyleKeys.PAINT); // add chunks BaseFont baseFont = pdfTextSpec.getFontMetrics().getBaseFont(); Font font = new Font(baseFont, size.floatValue(), style, paint); if (c.getOriginatingTextNode() instanceof RenderableReplacedContentBox) { RenderableReplacedContentBox content = (RenderableReplacedContentBox) c.getOriginatingTextNode(); com.lowagie.text.Image image = imageHandler.createImage(content); if (image != null) { Chunk chunk = new Chunk(image, 0, 0); // chunk.setFont(font); p.add(chunk); } } else { String textToPrint = c.getText(); Chunk chunk = new Chunk(textToPrint, font); p.add(chunk); } } return p; }
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());/*from www. j a va 2s.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.zkoss.poi.ss.util.SheetUtil.java
/** * Copy text attributes from the supplied Font to Java2D AttributedString *//*ww w . j a v a2 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); }