List of usage examples for java.awt.font TextAttribute POSTURE_OBLIQUE
Float POSTURE_OBLIQUE
To view the source code for java.awt.font TextAttribute POSTURE_OBLIQUE.
Click Source Link
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 ww w . ja v a2 s .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); }//from w ww .j a va 2s .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.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 w ww . j av a 2s . c o 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;/*from ww w .j a v a2s. com*/ } if (nativeContext.isNativeItalics() == false && italics >= TextAttribute.POSTURE_OBLIQUE) { style |= Font.ITALIC; } if (underlined) { style |= Font.UNDERLINE; } if (strikethrough) { style |= Font.STRIKETHRU; } return style; }
From source file:org.zkoss.poi.ss.util.SheetUtil.java
/** * Copy text attributes from the supplied Font to Java2D AttributedString */// w w w .j ava 2 s .c o 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); }