List of usage examples for java.awt.font TextAttribute BACKGROUND
TextAttribute BACKGROUND
To view the source code for java.awt.font TextAttribute BACKGROUND.
Click Source Link
From source file:net.sf.jasperreports.engine.util.JRStyledTextParser.java
/** * *//*w w w . ja va2 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:com.dlya.facturews.DlyaPdfExporter2.java
/** * *///from ww w.j a v a 2 s.c o m protected Chunk getChunk(Map<Attribute, Object> attributes, String text, Locale locale) { // underline and strikethrough are set on the chunk below Font font = getFont(attributes, locale, false); Chunk chunk = new Chunk(text, font); if (hasUnderline(attributes)) { // using the same values as sun.font.Fond2D chunk.setUnderline(null, 0, 1f / 18, 0, -1f / 12, 0); } if (hasStrikethrough(attributes)) { // using the same thickness as sun.font.Fond2D. // the position is calculated in Fond2D based on the ascent, defaulting // to iText default position which depends on the font size chunk.setUnderline(null, 0, 1f / 18, 0, 1f / 3, 0); } Color backcolor = (Color) attributes.get(TextAttribute.BACKGROUND); if (backcolor != null) { chunk.setBackground(backcolor); } Object script = attributes.get(TextAttribute.SUPERSCRIPT); if (script != null) { if (TextAttribute.SUPERSCRIPT_SUPER.equals(script)) { chunk.setTextRise(font.getCalculatedSize() / 2); } else if (TextAttribute.SUPERSCRIPT_SUB.equals(script)) { chunk.setTextRise(-font.getCalculatedSize() / 2); } } if (splitCharacter != null) { //TODO use line break offsets if available? chunk.setSplitCharacter(splitCharacter); } return chunk; }
From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java
/** * *///from w ww.ja v a2 s . c o m protected Chunk getChunk(Map<Attribute, Object> attributes, String text, Locale locale) { // underline and strikethrough are set on the chunk below Font font = getFont(attributes, locale, false); Chunk chunk = new Chunk(text, font); if (hasUnderline(attributes)) { // using the same values as sun.font.Fond2D chunk.setUnderline(null, 0, 1f / 18, 0, -1f / 12, 0); } if (hasStrikethrough(attributes)) { // using the same thickness as sun.font.Fond2D. // the position is calculated in Fond2D based on the ascent, defaulting // to iText default position which depends on the font size chunk.setUnderline(null, 0, 1f / 18, 0, 1f / 3, 0); } Color backcolor = (Color) attributes.get(TextAttribute.BACKGROUND); if (backcolor != null) { chunk.setBackground(backcolor); } Object script = attributes.get(TextAttribute.SUPERSCRIPT); if (script != null) { if (TextAttribute.SUPERSCRIPT_SUPER.equals(script)) { chunk.setTextRise(font.getCalculatedLeading(1f) / 2); } else if (TextAttribute.SUPERSCRIPT_SUB.equals(script)) { chunk.setTextRise(-font.getCalculatedLeading(1f) / 2); } } if (splitCharacter != null) { //TODO use line break offsets if available? chunk.setSplitCharacter(splitCharacter); } return chunk; }
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. ja va2 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(); } }