public Font GetFont(ChainedProperties props) { String face = props["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("i")) { style |= Font.ITALIC; } if (props.HasProperty("b")) { style |= Font.BOLD; } if (props.HasProperty("u")) { style |= Font.UNDERLINE; } String value = props["size"]; float size = 12; if (value != null) { size = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } Color color = MarkupParser.DecodeColor(props["color"]); String encoding = props["encoding"]; if (encoding == null) { encoding = BaseFont.WINANSI; } return(fontImp.GetFont(face, encoding, true, size, style, color)); }
/// <summary> /// Returns a Chunk that has been constructed taking in account /// the value of some attributes. /// </summary> /// <param name="attributes">some attributes</param> public Chunk(Properties attributes) : this("", FontFactory.GetFont(attributes)) { string value; if ((value = attributes.Remove(ElementTags.ITEXT)) != null) { Append(value); } if ((value = attributes.Remove(ElementTags.LOCALGOTO)) != null) { SetLocalGoto(value); } if ((value = attributes.Remove(ElementTags.REMOTEGOTO)) != null) { String destination = attributes.Remove(ElementTags.DESTINATION); String page = attributes.Remove(ElementTags.PAGE); if (page != null) { SetRemoteGoto(value, int.Parse(page)); } else if (destination != null) { SetRemoteGoto(value, destination); } } if ((value = attributes.Remove(ElementTags.LOCALDESTINATION)) != null) { SetLocalDestination(value); } if ((value = attributes.Remove(ElementTags.SUBSUPSCRIPT)) != null) { SetTextRise(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo)); } if ((value = attributes.Remove(MarkupTags.CSS_KEY_VERTICALALIGN)) != null && value.EndsWith("%")) { float p = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo) / 100f; SetTextRise(p * font.Size); } if ((value = attributes.Remove(ElementTags.GENERICTAG)) != null) { SetGenericTag(value); } if ((value = attributes.Remove(ElementTags.BACKGROUNDCOLOR)) != null) { SetBackground(MarkupParser.DecodeColor(value)); } if (attributes.Count > 0) { this.MarkupAttributes = attributes; } }
/// <summary> /// Constructs a Font-object. /// </summary> /// <param name="attributes">the attributes of a Font object</param> /// <returns>a Font object</returns> public virtual Font GetFont(Properties attributes) { string fontname = null; string encoding = defaultEncoding; bool embedded = defaultEmbedding; float size = Font.UNDEFINED; int style = Font.NORMAL; Color color = null; string value = attributes.Remove(MarkupTags.HTML_ATTR_STYLE); if (value != null && value.Length > 0) { Properties styleAttributes = MarkupParser.ParseAttributes(value); if (styleAttributes.Count == 0) { attributes.Add(MarkupTags.HTML_ATTR_STYLE, value); } else { fontname = (string)styleAttributes.Remove(MarkupTags.CSS_KEY_FONTFAMILY); if (fontname != null) { string tmp; while (fontname.IndexOf(",") != -1) { tmp = fontname.Substring(0, fontname.IndexOf(",")); if (IsRegistered(tmp)) { fontname = tmp; } else { fontname = fontname.Substring(fontname.IndexOf(",") + 1); } } } if ((value = (string)styleAttributes.Remove(MarkupTags.CSS_KEY_FONTSIZE)) != null) { size = MarkupParser.ParseLength(value); } if ((value = (string)styleAttributes.Remove(MarkupTags.CSS_KEY_FONTWEIGHT)) != null) { style |= Font.GetStyleValue(value); } if ((value = (string)styleAttributes.Remove(MarkupTags.CSS_KEY_FONTSTYLE)) != null) { style |= Font.GetStyleValue(value); } if ((value = (string)styleAttributes.Remove(MarkupTags.CSS_KEY_COLOR)) != null) { color = MarkupParser.DecodeColor(value); } attributes.AddAll(styleAttributes); } } if ((value = attributes.Remove(ElementTags.ENCODING)) != null) { encoding = value; } if ("true".Equals(attributes.Remove(ElementTags.EMBEDDED))) { embedded = true; } if ((value = attributes.Remove(ElementTags.FONT)) != null) { fontname = value; } if ((value = attributes.Remove(ElementTags.SIZE)) != null) { size = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(MarkupTags.HTML_ATTR_STYLE)) != null) { style |= Font.GetStyleValue(value); } if ((value = attributes.Remove(ElementTags.STYLE)) != null) { style |= Font.GetStyleValue(value); } string r = attributes.Remove(ElementTags.RED); string g = attributes.Remove(ElementTags.GREEN); string b = attributes.Remove(ElementTags.BLUE); if (r != null || g != null || b != null) { int red = 0; int green = 0; int blue = 0; if (r != null) { red = int.Parse(r); } if (g != null) { green = int.Parse(g); } if (b != null) { blue = int.Parse(b); } color = new Color(red, green, blue); } else if ((value = attributes.Remove(ElementTags.COLOR)) != null) { color = MarkupParser.DecodeColor(value); } if (fontname == null) { return(GetFont(null, encoding, embedded, size, style, color)); } return(GetFont(fontname, encoding, embedded, size, style, color)); }
public static void InsertStyle(Hashtable h) { String style = (String)h["style"]; if (style == null) { return; } Properties prop = MarkupParser.ParseAttributes(style); foreach (String key in prop.Keys) { if (key.Equals(MarkupTags.CSS_KEY_FONTFAMILY)) { h["face"] = prop[key]; } else if (key.Equals(MarkupTags.CSS_KEY_FONTSIZE)) { h["size"] = MarkupParser.ParseLength(prop[key]).ToString(NumberFormatInfo.InvariantInfo) + "px"; } else if (key.Equals(MarkupTags.CSS_KEY_FONTSTYLE)) { String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture); if (ss.Equals("italic") || ss.Equals("oblique")) { h["i"] = null; } } else if (key.Equals(MarkupTags.CSS_KEY_FONTWEIGHT)) { String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture); if (ss.Equals("bold") || ss.Equals("700") || ss.Equals("800") || ss.Equals("900")) { h["b"] = null; } } else if (key.Equals(MarkupTags.CSS_KEY_FONTWEIGHT)) { String ss = prop[key].Trim().ToLower(CultureInfo.InvariantCulture); if (ss.Equals("underline")) { h["u"] = null; } } else if (key.Equals(MarkupTags.CSS_KEY_COLOR)) { Color c = MarkupParser.DecodeColor(prop[key]); if (c != null) { int hh = c.ToArgb() & 0xffffff; String hs = "#" + hh.ToString("X06", NumberFormatInfo.InvariantInfo); h["color"] = hs; } } else if (key.Equals(MarkupTags.CSS_KEY_LINEHEIGHT)) { String ss = prop[key].Trim(); float v = MarkupParser.ParseLength(prop[key]); if (ss.EndsWith("%")) { v /= 100; h["leading"] = "0," + v.ToString(NumberFormatInfo.InvariantInfo); } else { h["leading"] = v.ToString(NumberFormatInfo.InvariantInfo) + ",0"; } } else if (key.Equals(MarkupTags.CSS_KEY_TEXTALIGN)) { String ss = prop[key].Trim().ToLower(); h["align"] = ss; } } }
/// <summary> /// Returns a Cell that has been constructed taking in account /// the value of some attributes. /// </summary> /// <param name="attributes">some attributes</param> public Cell(Properties attributes) : this() { string value; if ((value = attributes.Remove(ElementTags.HORIZONTALALIGN)) != null) { SetHorizontalAlignment(value); } if ((value = attributes.Remove(ElementTags.VERTICALALIGN)) != null) { SetVerticalAlignment(value); } if ((value = attributes.Remove(ElementTags.WIDTH)) != null) { this.Width = value; } if ((value = attributes.Remove(ElementTags.COLSPAN)) != null) { this.Colspan = int.Parse(value); } if ((value = attributes.Remove(ElementTags.ROWSPAN)) != null) { this.Rowspan = int.Parse(value); } if ((value = attributes.Remove(ElementTags.LEADING)) != null) { this.Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.HEADER)) != null) { this.Header = Boolean.Parse(value); } if ((value = attributes.Remove(ElementTags.NOWRAP)) != null) { this.NoWrap = Boolean.Parse(value); } if ((value = attributes.Remove(ElementTags.BORDERWIDTH)) != null) { this.BorderWidth = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } int border = 0; if ((value = attributes.Remove(ElementTags.LEFT)) != null) { if (Boolean.Parse(value)) { border |= Rectangle.LEFT_BORDER; } } if ((value = attributes.Remove(ElementTags.RIGHT)) != null) { if (Boolean.Parse(value)) { border |= Rectangle.RIGHT_BORDER; } } if ((value = attributes.Remove(ElementTags.TOP)) != null) { if (Boolean.Parse(value)) { border |= Rectangle.TOP_BORDER; } } if ((value = attributes.Remove(ElementTags.BOTTOM)) != null) { if (Boolean.Parse(value)) { border |= Rectangle.BOTTOM_BORDER; } } this.Border = border; string r = attributes.Remove(ElementTags.RED); string g = attributes.Remove(ElementTags.GREEN); string b = attributes.Remove(ElementTags.BLUE); if (r != null || g != null || b != null) { int red = 0; int green = 0; int blue = 0; if (r != null) { red = int.Parse(r); } if (g != null) { green = int.Parse(g); } if (b != null) { blue = int.Parse(b); } this.BorderColor = new Color(red, green, blue); } else if ((value = attributes.Remove(ElementTags.BORDERCOLOR)) != null) { this.BorderColor = MarkupParser.DecodeColor(value); } r = attributes.Remove(ElementTags.BGRED); g = attributes.Remove(ElementTags.BGGREEN); b = attributes.Remove(ElementTags.BGBLUE); if (r != null || g != null || b != null) { int red = 0; int green = 0; int blue = 0; if (r != null) { red = int.Parse(r); } if (g != null) { green = int.Parse(g); } if (b != null) { blue = int.Parse(b); } this.BackgroundColor = new Color(red, green, blue); } else if ((value = attributes.Remove(ElementTags.BACKGROUNDCOLOR)) != null) { this.BackgroundColor = MarkupParser.DecodeColor(value); } if ((value = attributes.Remove(ElementTags.GRAYFILL)) != null) { this.GrayFill = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if (attributes.Count > 0) { this.MarkupAttributes = attributes; } }
/** Creates a new instance of IncCell */ public IncCell(String tag, ChainedProperties props) { cell = new PdfPCell(); String value = props["colspan"]; if (value != null) { cell.Colspan = int.Parse(value); } value = props["align"]; if (tag.Equals("th")) { cell.HorizontalAlignment = Element.ALIGN_CENTER; } if (value != null) { if (Util.EqualsIgnoreCase(value, "center")) { cell.HorizontalAlignment = Element.ALIGN_CENTER; } else if (Util.EqualsIgnoreCase(value, "right")) { cell.HorizontalAlignment = Element.ALIGN_RIGHT; } else if (Util.EqualsIgnoreCase(value, "left")) { cell.HorizontalAlignment = Element.ALIGN_LEFT; } else if (Util.EqualsIgnoreCase(value, "justify")) { cell.HorizontalAlignment = Element.ALIGN_JUSTIFIED; } } value = props["valign"]; cell.VerticalAlignment = Element.ALIGN_MIDDLE; if (value != null) { if (Util.EqualsIgnoreCase(value, "top")) { cell.VerticalAlignment = Element.ALIGN_TOP; } else if (Util.EqualsIgnoreCase(value, "bottom")) { cell.VerticalAlignment = Element.ALIGN_BOTTOM; } } value = props["border"]; float border = 0; if (value != null) { border = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } cell.BorderWidth = border; value = props["cellpadding"]; if (value != null) { cell.Padding = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } cell.UseDescender = true; value = props["bgcolor"]; cell.BackgroundColor = MarkupParser.DecodeColor(value); }