Java Code Examples for com.lowagie.text.Font#STRIKETHRU

The following examples show how to use com.lowagie.text.Font#STRIKETHRU . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RTFTextExtractor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void add( final String text ) {
  int style = Font.NORMAL;
  if ( bold ) {
    style |= Font.BOLD;
  }
  if ( italic ) {
    style |= Font.ITALIC;
  }
  if ( strikethrough ) {
    style |= Font.STRIKETHRU;
  }
  if ( underline ) {
    style |= Font.UNDERLINE;
  }

  final BaseFontFontMetrics fontMetrics =
      metaData.getBaseFontFontMetrics( fontName, fontSize, bold, italic, "utf-8", false, false );
  final BaseFont baseFont = fontMetrics.getBaseFont();
  final Font font = new Font( baseFont, (float) fontSize, style, textColor );
  final Chunk c = new Chunk( text, font );
  if ( backgroundColor != null ) {
    c.setBackground( backgroundColor );
  }
  target.add( c );
}
 
Example 2
Source File: PdfLogicalPageDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
  }
  if ( nativeContext.isNativeItalics() == false && italics >= TextAttribute.POSTURE_OBLIQUE ) {
    style |= Font.ITALIC;
  }
  if ( underlined ) {
    style |= Font.UNDERLINE;
  }
  if ( strikethrough ) {
    style |= Font.STRIKETHRU;
  }
  return style;
}
 
Example 3
Source File: FactoryProperties.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Font getFont(ChainedProperties props) {
	String face = props.getProperty(ElementTags.FACE);
	if (face != null) {
		StringTokenizer tok = new StringTokenizer(face, ",");
		while (tok.hasMoreTokens()) {
			face = tok.nextToken().trim();
			if (face.startsWith("\""))
				face = face.substring(1);
			if (face.endsWith("\""))
				face = face.substring(0, face.length() - 1);
			if (fontImp.isRegistered(face))
				break;
		}
	}
	int style = 0;
	if (props.hasProperty(HtmlTags.I))
		style |= Font.ITALIC;
	if (props.hasProperty(HtmlTags.B))
		style |= Font.BOLD;
	if (props.hasProperty(HtmlTags.U))
		style |= Font.UNDERLINE;
	if (props.hasProperty(HtmlTags.S))
		style |= Font.STRIKETHRU;
	String value = props.getProperty(ElementTags.SIZE);
	float size = 12;
	if (value != null)
		size = Float.parseFloat(value);
	Color color = Markup.decodeColor(props.getProperty("color"));
	String encoding = props.getProperty("encoding");
	if (encoding == null)
		encoding = BaseFont.WINANSI;
	return fontImp.getFont(face, encoding, true, size, style, color);
}
 
Example 4
Source File: FactoryProperties.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
public Font getFont(ChainedProperties props) {
	String face = props.getProperty(ElementTags.FACE);
	if (face != null) {
		StringTokenizer tok = new StringTokenizer(face, ",");
		while (tok.hasMoreTokens()) {
			face = tok.nextToken().trim();
			if (face.startsWith("\"")) {
				face = face.substring(1);
			}
			if (face.endsWith("\"")) {
				face = face.substring(0, face.length() - 1);
			}
			if (fontImp.isRegistered(face)) {
				break;
			}
		}
	}
	int style = 0;
	if (props.hasProperty(HtmlTags.I)) {
		style |= Font.ITALIC;
	}
	if (props.hasProperty(HtmlTags.B)) {
		style |= Font.BOLD;
	}
	if (props.hasProperty(HtmlTags.U)) {
		style |= Font.UNDERLINE;
	}
	if (props.hasProperty(HtmlTags.S)) {
		style |= Font.STRIKETHRU;
	}
	String value = props.getProperty(ElementTags.SIZE);
	float size = 12;
	if (value != null) {
		size = Float.parseFloat(value);
	}
	Color color = Markup.decodeColor(props.getProperty("color"));
	String encoding = props.getProperty("encoding");
	if (encoding == null) {
		encoding = BaseFont.WINANSI;
	}
	return fontImp.getFont(face, encoding, true, size, style, color);
}
 
Example 5
Source File: HtmlWriter.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Writes the representation of a <CODE>Font</CODE>.
 *
 * @param font a <CODE>Font</CODE>
 * @param styleAttributes the style of the font
 * @throws IOException
 */

protected void write(Font font, Properties styleAttributes) throws IOException {
	if (font == null || !isOtherFont(font) /* || styleAttributes == null*/) {
		return;
	}
	write(" ");
	write(HtmlTags.STYLE);
	write("=\"");
	if (styleAttributes != null) {
		String key;
		for (Enumeration e = styleAttributes.propertyNames(); e.hasMoreElements();) {
			key = (String) e.nextElement();
			writeCssProperty(key, styleAttributes.getProperty(key));
		}
	}
	if (isOtherFont(font)) {
		writeCssProperty(Markup.CSS_KEY_FONTFAMILY, font.getFamilyname());

		if (font.getSize() != Font.UNDEFINED) {
			writeCssProperty(Markup.CSS_KEY_FONTSIZE, font.getSize() + "pt");
		}
		if (font.getColor() != null) {
			writeCssProperty(Markup.CSS_KEY_COLOR, HtmlEncoder.encode(font.getColor()));
		}

		int fontstyle = font.getStyle();
		BaseFont bf = font.getBaseFont();
		if (bf != null) {
			String ps = bf.getPostscriptFontName().toLowerCase();
			if (ps.indexOf("bold") >= 0) {
				if (fontstyle == Font.UNDEFINED) {
					fontstyle = 0;
				}
				fontstyle |= Font.BOLD;
			}
			if (ps.indexOf("italic") >= 0 || ps.indexOf("oblique") >= 0) {
				if (fontstyle == Font.UNDEFINED) {
					fontstyle = 0;
				}
				fontstyle |= Font.ITALIC;
			}
		}
		if (fontstyle != Font.UNDEFINED && fontstyle != Font.NORMAL) {
			switch (fontstyle & Font.BOLDITALIC) {
				case Font.BOLD:
					writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD);
					break;
				case Font.ITALIC:
					writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC);
					break;
				case Font.BOLDITALIC:
					writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD);
					writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC);
					break;
			}

			// CSS only supports one decoration tag so if both are specified
			// only one of the two will display
			if ((fontstyle & Font.UNDERLINE) > 0) {
				writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_UNDERLINE);
			}
			if ((fontstyle & Font.STRIKETHRU) > 0) {
				writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_LINETHROUGH);
			}
		}
	}
	write("\"");
}
 
Example 6
Source File: HtmlWriter.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Writes the representation of a <CODE>Font</CODE>.
 *
 * @param font              a <CODE>Font</CODE>
 * @param styleAttributes   the style of the font
 * @throws IOException
 */

protected void write(Font font, Properties styleAttributes) throws IOException {
    if (font == null || !isOtherFont(font) /* || styleAttributes == null*/) return;
    write(" ");
    write(HtmlTags.STYLE);
    write("=\"");
    if (styleAttributes != null) {
        String key;
        for (Enumeration e = styleAttributes.propertyNames(); e.hasMoreElements(); ) {
            key = (String)e.nextElement();
            writeCssProperty(key, styleAttributes.getProperty(key));
        }
    }
    if (isOtherFont(font)) {
        writeCssProperty(Markup.CSS_KEY_FONTFAMILY, font.getFamilyname());
        
        if (font.getSize() != Font.UNDEFINED) {
            writeCssProperty(Markup.CSS_KEY_FONTSIZE, font.getSize() + "pt");
        }
        if (font.getColor() != null) {
            writeCssProperty(Markup.CSS_KEY_COLOR, HtmlEncoder.encode(font.getColor()));
        }
        
        int fontstyle = font.getStyle();
        BaseFont bf = font.getBaseFont();
        if (bf != null) {
            String ps = bf.getPostscriptFontName().toLowerCase();
            if (ps.indexOf("bold") >= 0) {
                if (fontstyle == Font.UNDEFINED)
                    fontstyle = 0;
                fontstyle |= Font.BOLD;
            }
            if (ps.indexOf("italic") >= 0 || ps.indexOf("oblique") >= 0) {
                if (fontstyle == Font.UNDEFINED)
                    fontstyle = 0;
                fontstyle |= Font.ITALIC;
            }
        }
        if (fontstyle != Font.UNDEFINED && fontstyle != Font.NORMAL) {
            switch (fontstyle & Font.BOLDITALIC) {
                case Font.BOLD:
                    writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD);
                    break;
                case Font.ITALIC:
                    writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC);
                    break;
                case Font.BOLDITALIC:
                    writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD);
                    writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC);
                    break;
            }
            
            // CSS only supports one decoration tag so if both are specified
            // only one of the two will display
            if ((fontstyle & Font.UNDERLINE) > 0) {
                writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_UNDERLINE);
            }
            if ((fontstyle & Font.STRIKETHRU) > 0) {
                writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_LINETHROUGH);
            }
        }
    }
    write("\"");
}