/// <summary> /// Returns a Phrase that has been constructed taking in account /// the value of some attributes. /// </summary> /// <param name="attributes">some attributes</param> public Phrase(Properties attributes) : this("", FontFactory.GetFont(attributes)) { this.Clear(); string value; if ((value = attributes.Remove(ElementTags.LEADING)) != null) { Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } else if ((value = attributes.Remove(MarkupTags.CSS_KEY_LINEHEIGHT)) != null) { Leading = MarkupParser.ParseLength(value); } if ((value = attributes.Remove(ElementTags.ITEXT)) != null) { Chunk chunk = new Chunk(value); if ((value = attributes.Remove(ElementTags.GENERICTAG)) != null) { chunk.SetGenericTag(value); } Add(chunk); } if (attributes.Count > 0) { MarkupAttributes = attributes; } }
/// <summary> /// Returns a ListItem that has been constructed taking in account /// the value of some attributes. /// </summary> /// <param name="attributes">Some attributes</param> public ListItem(Properties attributes) : base("", FontFactory.GetFont(attributes)) { string value; if ((value = attributes.Remove(ElementTags.ITEXT)) != null) { Add(new Chunk(value)); } if ((value = attributes.Remove(ElementTags.LEADING)) != null) { this.Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } else if ((value = attributes.Remove(MarkupTags.CSS_KEY_LINEHEIGHT)) != null) { this.Leading = MarkupParser.ParseLength(value); } if ((value = attributes.Remove(ElementTags.INDENTATIONLEFT)) != null) { this.IndentationLeft = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.INDENTATIONRIGHT)) != null) { this.IndentationRight = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.ALIGN)) != null) { SetAlignment(value); } if (attributes.Count > 0) { this.MarkupAttributes = attributes; } }
/// <summary> /// Returns a Paragraph that has been constructed taking in account /// the value of some attributes. /// </summary> /// <param name="attributes">Some attributes</param> public Paragraph(Properties attributes) : this("", FontFactory.GetFont(attributes)) { string value; if ((value = attributes.Remove(ElementTags.ITEXT)) != null) { Chunk chunk = new Chunk(value); if ((value = attributes.Remove(ElementTags.GENERICTAG)) != null) { chunk.SetGenericTag(value); } Add(chunk); } if ((value = attributes.Remove(ElementTags.ALIGN)) != null) { SetAlignment(value); } if ((value = attributes.Remove(ElementTags.LEADING)) != null) { this.Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } else if ((value = attributes.Remove(MarkupTags.CSS_KEY_LINEHEIGHT)) != null) { this.Leading = MarkupParser.ParseLength(value); } else { this.Leading = 16; } if ((value = attributes.Remove(ElementTags.INDENTATIONLEFT)) != null) { this.IndentationLeft = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.INDENTATIONRIGHT)) != null) { IndentationRight = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.KEEPTOGETHER)) != null) { keeptogether = bool.Parse(value); } if (attributes.Count > 0) { 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; } } }