Java Code Examples for com.lowagie.text.Font#getColor()

The following examples show how to use com.lowagie.text.Font#getColor() . 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: EntitiesToSymbol.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Gets a chunk with a symbol character.
 *
 * @param e a symbol value (see Entities class: alfa is greek alfa,...)
 * @param font the font if the symbol isn't found (otherwise Font.SYMBOL)
 * @return a Chunk
 */
public static Chunk get(String e, Font font) {
	char s = getCorrespondingSymbol(e);
	if (s == (char) 0) {
		try {
			return new Chunk(String.valueOf((char) Integer.parseInt(e)), font);
		} catch (Exception exception) {
			return new Chunk(e, font);
		}
	}
	Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
	return new Chunk(String.valueOf(s), symbol);
}
 
Example 2
Source File: FontSelector.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Adds a <CODE>Font</CODE> to be searched for valid characters.
 * 
 * @param font the <CODE>Font</CODE>
 */
public void addFont(Font font) {
	if (font.getBaseFont() != null) {
		fonts.add(font);
		return;
	}
	BaseFont bf = font.getCalculatedBaseFont(true);
	Font f2 = new Font(bf, font.getSize(), font.getCalculatedStyle(), font.getColor());
	fonts.add(f2);
}
 
Example 3
Source File: EntitiesToSymbol.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets a chunk with a symbol character.
 * @param e a symbol value (see Entities class: alfa is greek alfa,...)
 * @param font the font if the symbol isn't found (otherwise Font.SYMBOL)
 * @return a Chunk
 */
public static Chunk get(String e, Font font) {
    char s = getCorrespondingSymbol(e);
    if (s == (char)0) {
        try {
            return new Chunk(String.valueOf((char)Integer.parseInt(e)), font);
        }
        catch(Exception exception) {
            return new Chunk(e, font);
        }
    }
    Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
    return new Chunk(String.valueOf(s), symbol);
}
 
Example 4
Source File: FontSelector.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adds a <CODE>Font</CODE> to be searched for valid characters.
 * @param font the <CODE>Font</CODE>
 */    
public void addFont(Font font) {
    if (font.getBaseFont() != null) {
        fonts.add(font);
        return;
    }
    BaseFont bf = font.getCalculatedBaseFont(true);
    Font f2 = new Font(bf, font.getSize(), font.getCalculatedStyle(), font.getColor());
    fonts.add(f2);
}
 
Example 5
Source File: RtfFont.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Replaces the attributes that are equal to <VAR>null</VAR> with
 * the attributes of a given font.
 *
 * @param font The surrounding font
 * @return A RtfFont
 */
public Font difference(Font font) {
    String dFamilyname = font.getFamilyname();
    if(dFamilyname == null || dFamilyname.trim().equals("") || dFamilyname.trim().equalsIgnoreCase("unknown")) {
        dFamilyname = this.fontName;
    }

    float dSize = font.getSize();
    if(dSize == Font.UNDEFINED) {
        dSize = this.getSize();
    }

    int dStyle = Font.UNDEFINED;
    if(this.getStyle() != Font.UNDEFINED && font.getStyle() != Font.UNDEFINED) {
        dStyle = this.getStyle() | font.getStyle();
    } else if(this.getStyle() != Font.UNDEFINED) {
        dStyle = this.getStyle();
    } else if(font.getStyle() != Font.UNDEFINED) {
        dStyle = font.getStyle();
    }

    Color dColor = font.getColor();
    if(dColor == null) {
        dColor = this.getColor();
    }
    
    int dCharset = this.charset;
    if(font instanceof RtfFont) {
        dCharset = ((RtfFont) font).getCharset();
    }
    
    return new RtfFont(dFamilyname, dSize, dStyle, dColor, dCharset);
}
 
Example 6
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 7
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("\"");
}