public static Anchor GetAnchor(Properties attributes) { Anchor anchor = new Anchor(GetPhrase(attributes)); String value; value = attributes[ElementTags.NAME]; if (value != null) { anchor.Name = value; } value = (String)attributes.Remove(ElementTags.REFERENCE); if (value != null) { anchor.Reference = value; } return anchor; }
/// <summary> /// Creates a given Section following a set of attributes and adds it to this one. /// </summary> /// <param name="attributes">the attributes</param> /// <returns>the newly added Section</returns> public virtual Section AddSection(Properties attributes) { Section section = new Section(new Paragraph(""), 1); string value; if ((value = attributes.Remove(ElementTags.NUMBER)) != null) { subsections = int.Parse(value) - 1; } if ((value = attributes.Remove(ElementTags.BOOKMARKOPEN)) != null) { this.BookmarkOpen = bool.Parse(value); } section.Set(attributes); Add(section); return section; }
/// <summary> /// Returns an Image that has been constructed taking in account /// the value of some attributes. /// </summary> /// <param name="attributes">Some attributes</param> /// <returns>an Image</returns> public static Image GetInstance(Properties attributes) { string value = attributes.Remove(ElementTags.URL); if (value == null) throw new Exception("The URL of the image is missing."); Image image = Image.GetInstance(value); int align = Element.ALIGN_LEFT; if ((value = attributes.Remove(ElementTags.ALIGN)) != null) { if (ElementTags.ALIGN_LEFT.ToLower().Equals(value)) align |= Image.LEFT_ALIGN; else if (ElementTags.ALIGN_RIGHT.ToLower().Equals(value)) align |= Image.RIGHT_ALIGN; else if (ElementTags.ALIGN_MIDDLE.ToLower().Equals(value)) align |= Image.MIDDLE_ALIGN; } if ((value = attributes.Remove(ElementTags.UNDERLYING)) != null) { if (bool.Parse(value)) align |= Image.UNDERLYING; } if ((value = attributes.Remove(ElementTags.TEXTWRAP)) != null) { if (bool.Parse(value)) align |= Image.TEXTWRAP; } image.alignment = align; if ((value = attributes.Remove(ElementTags.ALT)) != null) { image.Alt = value; } string x; string y; if (((x = attributes.Remove(ElementTags.ABSOLUTEX)) != null) && ((y = attributes.Remove(ElementTags.ABSOLUTEY)) != null)) { image.SetAbsolutePosition(float.Parse(x), float.Parse(y, System.Globalization.NumberFormatInfo.InvariantInfo)); } if ((value = attributes.Remove(ElementTags.PLAINWIDTH)) != null) { image.ScaleAbsoluteWidth(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo)); } if ((value = attributes.Remove(ElementTags.PLAINHEIGHT)) != null) { image.ScaleAbsoluteHeight(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo)); } if ((value = attributes.Remove(ElementTags.ROTATION)) != null) { image.Rotation = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } return image; }
/// <summary> /// Creates a new Chapter following a set of attributes. /// </summary> /// <param name="attributes">the attributes</param> /// <param name="number">the Chapter number</param> /// <overoads> /// Has three overloads. /// </overoads> public Chapter(Properties attributes, int number) : this(new Paragraph(""), number) { string value; if ((value = attributes.Remove(ElementTags.NUMBERDEPTH)) != null) { this.NumberDepth = int.Parse(value); } if ((value = attributes.Remove(ElementTags.INDENT)) != null) { this.Indentation = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } 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.BOOKMARKOPEN)) != null) { this.BookmarkOpen = bool.Parse(value); } }
public HeaderFooter(Properties attributes) : base(0, 0, 0, 0) { string value; if ((value = attributes.Remove(ElementTags.NUMBERED)) != null) { this.numbered = bool.Parse(value); } if ((value = attributes.Remove(ElementTags.ALIGN)) != null) { this.SetAlignment(value); } if ((value = attributes.Remove("border")) != null) { this.Border = int.Parse(value); } else { this.Border = TOP_BORDER + BOTTOM_BORDER; } }
/// <summary> /// This method deals with the starting tags. /// </summary> /// <param name="name">the name of the tag</param> /// <param name="attributes">the list of attributes</param> public void HandleStartingTags(String name, Properties attributes) { //System.err.Println("Start: " + name); if (ignore || ElementTags.IGNORE.Equals(name)) { ignore = true; return; } // maybe there is some meaningful data that wasn't between tags if (currentChunk != null) { ITextElementArray current; try { current = (ITextElementArray) stack.Pop(); } catch { if (bf == null) { current = new Paragraph("", new Font()); } else { current = new Paragraph("", new Font(this.bf)); } } current.Add(currentChunk); stack.Push(current); currentChunk = null; } // registerfont if (name.Equals("registerfont")) { FontFactory.Register(attributes); } // header if (ElementTags.HEADER.Equals(name)) { stack.Push(new HeaderFooter(attributes)); return; } // footer if (ElementTags.FOOTER.Equals(name)) { stack.Push(new HeaderFooter(attributes)); return; } // before if (name.Equals("before")) { HeaderFooter tmp = (HeaderFooter)stack.Pop(); tmp.Before = new Phrase(attributes); stack.Push(tmp); return; } // after if (name.Equals("after")) { HeaderFooter tmp = (HeaderFooter)stack.Pop(); tmp.After = new Phrase(attributes); stack.Push(tmp); return; } // chunks if (Chunk.IsTag(name)) { currentChunk = new Chunk(attributes); if (bf != null) { currentChunk.Font = new Font(this.bf); } return; } // symbols if (EntitiesToSymbol.IsTag(name)) { Font f = new Font(); if (currentChunk != null) { HandleEndingTags(ElementTags.CHUNK); f = currentChunk.Font; } currentChunk = EntitiesToSymbol.Get(attributes[ElementTags.ID], f); return; } // phrases if (Phrase.IsTag(name)) { stack.Push(new Phrase(attributes)); return; } // anchors if (Anchor.IsTag(name)) { stack.Push(new Anchor(attributes)); return; } // paragraphs and titles if (Paragraph.IsTag(name) || Section.IsTitle(name)) { stack.Push(new Paragraph(attributes)); return; } // lists if (List.IsTag(name)) { stack.Push(new List(attributes)); return; } // listitems if (ListItem.IsTag(name)) { stack.Push(new ListItem(attributes)); return; } // cells if (Cell.IsTag(name)) { stack.Push(new Cell(attributes)); return; } // tables if (Table.IsTag(name)) { Table table = new Table(attributes); float[] widths = table.ProportionalWidths; for (int i = 0; i < widths.Length; i++) { if (widths[i] == 0) { widths[i] = 100.0f / (float)widths.Length; } } try { table.Widths = widths; } catch (BadElementException bee) { // this shouldn't happen throw new Exception("", bee); } stack.Push(table); return; } // sections if (Section.IsTag(name)) { IElement previous = (IElement) stack.Pop(); Section section; section = ((Section)previous).AddSection(attributes); stack.Push(previous); stack.Push(section); return; } // chapters if (Chapter.IsTag(name)) { String value; // changed after a suggestion by Serge S. Vasiljev if ((value = (String)attributes.Remove(ElementTags.NUMBER)) != null){ chapters = int.Parse(value); } else { chapters++; } Chapter chapter = new Chapter(attributes,chapters); stack.Push(chapter); return; } // images if (Image.IsTag(name)) { try { Image img = Image.GetInstance(attributes); Object current; try { // if there is an element on the stack... current = stack.Pop(); // ...and it's a Chapter or a Section, the Image can be added directly if (current is Chapter || current is Section || current is Cell) { ((ITextElementArray)current).Add(img); stack.Push(current); return; } // ...if not, the Image is wrapped in a Chunk before it's added else { Stack newStack = new Stack(); try { while (! (current is Chapter || current is Section || current is Cell)) { newStack.Push(current); if (current is Anchor) { img.Annotation = new Annotation(0, 0, 0, 0, ((Anchor)current).Reference); } current = stack.Pop(); } ((ITextElementArray)current).Add(img); stack.Push(current); } catch { document.Add(img); } while (!(newStack.Count == 0)) { stack.Push(newStack.Pop()); } return; } } catch { // if there is no element on the stack, the Image is added to the document try { document.Add(img); } catch (DocumentException de) { throw new Exception("", de); } return; } } catch (Exception e) { throw new Exception("", e); } } // annotations if (Annotation.IsTag(name)) { Annotation annotation = new Annotation(attributes); ITextElementArray current; try { try { current = (ITextElementArray) stack.Pop(); try { current.Add(annotation); } catch { document.Add(annotation); } stack.Push(current); } catch { document.Add(annotation); } return; } catch (DocumentException de) { throw new Exception("", de); } } // newlines if (IsNewline(name)) { ITextElementArray current; try { current = (ITextElementArray) stack.Pop(); current.Add(Chunk.NEWLINE); stack.Push(current); } catch { if (currentChunk == null) { try { document.Add(Chunk.NEWLINE); } catch (DocumentException de) { throw new Exception("", de); } } else { currentChunk.Append("\n"); } } return; } // newpage if (IsNewpage(name)) { ITextElementArray current; try { current = (ITextElementArray) stack.Pop(); Chunk newPage = new Chunk(""); newPage.SetNewPage(); if (bf != null) { newPage.Font = new Font(this.bf); } current.Add(newPage); stack.Push(current); } catch { document.NewPage(); } return; } // documentroot if (IsDocumentRoot(name)) { String value; // pagesize and orientation specific code suggested by Samuel Gabriel // Updated by Ricardo Coutinho. Only use if set in html! Rectangle pageSize = null; String orientation = null; foreach (string key in attributes.Keys) { value = attributes[key]; // margin specific code suggested by Reza Nasiri if (Util.EqualsIgnoreCase(ElementTags.LEFT, key)) leftMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); if (Util.EqualsIgnoreCase(ElementTags.RIGHT, key)) rightMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); if (Util.EqualsIgnoreCase(ElementTags.TOP, key)) topMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); if (Util.EqualsIgnoreCase(ElementTags.BOTTOM, key)) bottomMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); if (ElementTags.PAGE_SIZE.Equals(key)) { pageSize = (Rectangle)typeof(PageSize).GetField(value).GetValue(null); } else if (ElementTags.ORIENTATION.Equals(key)) { if ("landscape".Equals(value)) { orientation = "landscape"; } } else { document.Add(new Meta(key, value)); } } if(pageSize != null) { if ("landscape".Equals(orientation)) { pageSize = pageSize.Rotate(); } document.SetPageSize(pageSize); } document.SetMargins(leftMargin, rightMargin, topMargin, bottomMargin); if (controlOpenClose) document.Open(); } }
/** * Creates an Annotation object based on a list of properties. * @param attributes * @return an Annotation */ public static Annotation GetAnnotation(Properties attributes) { float llx = 0, lly = 0, urx = 0, ury = 0; String value; value = attributes[ElementTags.LLX]; if (value != null) { llx = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } value = attributes[ElementTags.LLY]; if (value != null) { lly = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } value = attributes[ElementTags.URX]; if (value != null) { urx = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } value = attributes[ElementTags.URY]; if (value != null) { ury = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } String title = attributes[ElementTags.TITLE]; String text = attributes[ElementTags.CONTENT]; if (title != null || text != null) { return new Annotation(title, text, llx, lly, urx, ury); } value = attributes[ElementTags.URL]; if (value != null) { return new Annotation(llx, lly, urx, ury, value); } value = attributes[ElementTags.NAMED]; if (value != null) { return new Annotation(llx, lly, urx, ury, int.Parse(value)); } String file = attributes[ElementTags.FILE]; String destination = attributes[ElementTags.DESTINATION]; String page = (String) attributes.Remove(ElementTags.PAGE); if (file != null) { if (destination != null) { return new Annotation(llx, lly, urx, ury, file, destination); } if (page != null) { return new Annotation(llx, lly, urx, ury, file, int.Parse(page)); } } if (title == null) title = ""; if (text == null) text = ""; return new Annotation(title, text, llx, lly, urx, ury); }
/** * Sets some Rectangle properties (for a Cell, Table,...). */ private static void SetRectangleProperties(Rectangle rect, Properties attributes) { String value; value = attributes[ElementTags.BORDERWIDTH]; if (value != null) { rect.BorderWidth = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } int border = 0; if (Utilities.CheckTrueOrFalse(attributes, ElementTags.LEFT)) { border |= Rectangle.LEFT_BORDER; } if (Utilities.CheckTrueOrFalse(attributes, ElementTags.RIGHT)) { border |= Rectangle.RIGHT_BORDER; } if (Utilities.CheckTrueOrFalse(attributes, ElementTags.TOP)) { border |= Rectangle.TOP_BORDER; } if (Utilities.CheckTrueOrFalse(attributes, ElementTags.BOTTOM)) { border |= Rectangle.BOTTOM_BORDER; } rect.Border = border; String r = attributes[ElementTags.RED]; String g = attributes[ElementTags.GREEN]; String b = attributes[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); rect.BorderColor = new Color(red, green, blue); } else { rect.BorderColor = Markup.DecodeColor(attributes[ElementTags.BORDERCOLOR]); } r = (String)attributes.Remove(ElementTags.BGRED); g = (String)attributes.Remove(ElementTags.BGGREEN); b = (String)attributes.Remove(ElementTags.BGBLUE); value = attributes[ElementTags.BACKGROUNDCOLOR]; 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); rect.BackgroundColor = new Color(red, green, blue); } else if (value != null) { rect.BackgroundColor = Markup.DecodeColor(value); } else { value = attributes[ElementTags.GRAYFILL]; if (value != null) { rect.GrayFill = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } } }
/// <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(Markup.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(Markup.DecodeColor(value)); } }
/// <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(Markup.HTML_ATTR_STYLE); if (value != null && value.Length > 0) { Properties styleAttributes = Markup.ParseAttributes(value); if (styleAttributes.Count == 0) { attributes.Add(Markup.HTML_ATTR_STYLE, value); } else { fontname = (string)styleAttributes.Remove(Markup.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(Markup.CSS_KEY_FONTSIZE)) != null) { size = Markup.ParseLength(value); } if ((value = (string)styleAttributes.Remove(Markup.CSS_KEY_FONTWEIGHT)) != null) { style |= Font.GetStyleValue(value); } if ((value = (string)styleAttributes.Remove(Markup.CSS_KEY_FONTSTYLE)) != null) { style |= Font.GetStyleValue(value); } if ((value = (string)styleAttributes.Remove(Markup.CSS_KEY_COLOR)) != null) { color = Markup.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(Markup.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 = Markup.DecodeColor(value); } if (fontname == null) { return GetFont(null, encoding, embedded, size, style, color); } return GetFont(fontname, encoding, embedded, size, style, color); }
/// <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 = Markup.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 = Markup.DecodeColor(value); } if ((value = attributes.Remove(ElementTags.GRAYFILL)) != null) { this.GrayFill = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } }
/// <summary> /// Constructs an Annotation taking into account /// the value of some attributes /// </summary> /// <param name="attributes">some attributes</param> public Annotation(Properties attributes) { string value = attributes.Remove(ElementTags.LLX); if (value != null) { llx = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } value = attributes.Remove(ElementTags.LLY); if (value != null) { lly = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } value = attributes.Remove(ElementTags.URX); if (value != null) { urx = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } value = attributes.Remove(ElementTags.URY); if (value != null) { ury = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } string title = attributes.Remove(ElementTags.TITLE); string text = attributes.Remove(ElementTags.CONTENT); if (title != null || text != null) { annotationtype = TEXT; } else if ((value = attributes.Remove(ElementTags.URL)) != null) { annotationtype = URL_AS_STRING; annotationAttributes[FILE] = value; } else if ((value = attributes.Remove(ElementTags.NAMED)) != null) { annotationtype = NAMED_DEST; annotationAttributes[NAMED] = int.Parse(value); } else { string file = attributes.Remove(ElementTags.FILE); string destination = attributes.Remove(ElementTags.DESTINATION); string page = attributes.Remove(ElementTags.PAGE); if (file != null) { annotationAttributes[FILE] = file; if (destination != null) { annotationtype = FILE_DEST; annotationAttributes[DESTINATION] = destination; } else if (page != null) { annotationtype = FILE_PAGE; annotationAttributes[FILE] = file; annotationAttributes[PAGE] = int.Parse(page); } } else if ((value = attributes.Remove(ElementTags.NAMED)) != null) { annotationtype = LAUNCH; annotationAttributes[APPLICATION] = value; annotationAttributes[PARAMETERS] = attributes.Remove(ElementTags.PARAMETERS); annotationAttributes[OPERATION] = attributes.Remove(ElementTags.OPERATION); annotationAttributes[DEFAULTDIR] = attributes.Remove(ElementTags.DEFAULTDIR); } } if (annotationtype == TEXT) { if (title == null) title = ""; if (text == null) text = ""; annotationAttributes[TITLE] = title; annotationAttributes[CONTENT] = text; } }
/// <summary> /// Returns an Anchor that has been constructed taking in account /// the value of some <var>attributes</var>. /// </summary> /// <param name="attributes">Some attributes</param> public Anchor(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.LEADING)) != null) { Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } else if ((value = attributes.Remove(Markup.CSS_KEY_LINEHEIGHT)) != null) { this.Leading = Markup.ParseLength(value); } if ((value = attributes.Remove(ElementTags.NAME)) != null) { this.Name = value; } if ((value = attributes.Remove(ElementTags.REFERENCE)) != null) { this.Reference = value; } }
/// <summary> /// Returns a Table that has been constructed taking in account /// the value of some <VAR>attributes</VAR>. /// </summary> /// <param name="attributes">some attributes</param> /// <overloads> /// Has three overloads /// </overloads> public Table(Properties attributes) : base(0, 0, 0, 0) { Border = BOX; BorderWidth = 1; defaultLayout.Border = BOX; string value = attributes.Remove(ElementTags.COLUMNS); if (value == null) { columns = 1; } else { columns = int.Parse(value); if (columns <= 0) { columns = 1; } } rows.Add(new Row(columns)); curPosition.X = 0; if ((value = attributes.Remove(ElementTags.OFFSET)) != null) { Offset = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.LASTHEADERROW)) != null) { LastHeaderRow = int.Parse(value); } if ((value = attributes.Remove(ElementTags.ALIGN)) != null) { SetAlignment(value); } if ((value = attributes.Remove(ElementTags.CELLSPACING)) != null) { Spacing = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.CELLPADDING)) != null) { Padding = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.OFFSET)) != null) { Offset = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.WIDTH)) != null) { if (value.EndsWith("%")) this.WidthPercentage = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo); else AbsWidth = value; } widths = new float[columns]; for (int i = 0; i < columns; i++) { widths[i] = 0; } if ((value = attributes.Remove(ElementTags.WIDTHS)) != null) { StringTokenizer widthTokens = new StringTokenizer(value, ";"); int i = 0; while (widthTokens.HasMoreTokens()) { value = widthTokens.NextToken(); widths[i] = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); i++; } columns = i; } if ((value = attributes.Remove(ElementTags.TABLEFITSPAGE)) != null) { tableFitsPage = bool.Parse(value); } if ((value = attributes.Remove(ElementTags.CELLSFITPAGE)) != null) { cellsFitPage = bool.Parse(value); } if ((value = attributes.Remove(ElementTags.CONVERT2PDFP)) != null) { convert2pdfptable = bool.Parse(value); } if ((value = attributes.Remove(ElementTags.BORDERWIDTH)) != null) { BorderWidth = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } int border = 0; if ((value = attributes.Remove(ElementTags.LEFT)) != null) { if (bool.Parse(value)) border |= Rectangle.LEFT_BORDER; } if ((value = attributes.Remove(ElementTags.RIGHT)) != null) { if (bool.Parse(value)) border |= Rectangle.RIGHT_BORDER; } if ((value = attributes.Remove(ElementTags.TOP)) != null) { if (bool.Parse(value)) border |= Rectangle.TOP_BORDER; } if ((value = attributes.Remove(ElementTags.BOTTOM)) != null) { if (bool.Parse(value)) border |= Rectangle.BOTTOM_BORDER; } 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); BorderColor = new Color(red, green, blue); } else if ((value = attributes[ElementTags.BORDERCOLOR]) != null) { BorderColor = Markup.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); BackgroundColor = new Color(red, green, blue); } else if ((value = attributes.Remove(ElementTags.BACKGROUNDCOLOR)) != null) { BackgroundColor = Markup.DecodeColor(value); } if ((value = attributes.Remove(ElementTags.GRAYFILL)) != null) { GrayFill = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } }
/// <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(Markup.CSS_KEY_LINEHEIGHT)) != null) { this.Leading = Markup.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); } }
// public methods /// <summary> /// Alters the attributes of this Section. /// </summary> /// <param name="attributes">the attributes</param> public void Set(Properties attributes) { string value; if ((value = attributes.Remove(ElementTags.NUMBERDEPTH)) != null) { NumberDepth = int.Parse(value); } if ((value = attributes.Remove(ElementTags.INDENT)) != null) { Indentation = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.INDENTATIONLEFT)) != null) { IndentationLeft = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.INDENTATIONRIGHT)) != null) { IndentationRight = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } }
internal static Dictionary<String, Object> ReadFontProperties(String name) { name += ".properties"; Stream isp = GetResourceStream(RESOURCE_PATH_CMAP + name); Properties p = new Properties(); p.Load(isp); isp.Close(); IntHashtable W = CreateMetric(p["W"]); p.Remove("W"); IntHashtable W2 = CreateMetric(p["W2"]); p.Remove("W2"); Dictionary<String, Object> map = new Dictionary<string,object>(); foreach (string key in p.Keys) { map[key] = p[key]; } map["W"] = W; map["W2"] = W2; return map; }
public virtual void Register(Properties attributes) { string path; string alias = null; path = attributes.Remove("path"); alias = attributes.Remove("alias"); Register(path, alias); }
/// <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(Markup.CSS_KEY_LINEHEIGHT)) != null) { this.Leading = Markup.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); } }
internal static Hashtable ReadFontProperties(String name) { try { name += ".properties"; Stream isp = GetResourceStream(RESOURCE_PATH + name); Properties p = new Properties(); p.Load(isp); isp.Close(); IntHashtable W = CreateMetric(p["W"]); p.Remove("W"); IntHashtable W2 = CreateMetric(p["W2"]); p.Remove("W2"); Hashtable map = new Hashtable(); foreach (string key in p.Keys) { map[key] = p[key]; } map["W"] = W; map["W2"] = W2; return map; } catch { // empty on purpose } return null; }
public static void Register(Properties attributes) { string path; string alias = null; path = attributes.Remove("path"); alias = attributes.Remove("alias"); fontImp.Register(path, alias); }
/// <summary> /// Returns a List that has been constructed taking in account /// the value of some attributes. /// </summary> /// <param name="attributes">Some attributes</param> public List(Properties attributes) { string value= attributes.Remove(ElementTags.LISTSYMBOL); if (value == null) { value = "-"; } symbol = new Chunk(value, FontFactory.GetFont(attributes)); if ((value = attributes.Remove(ElementTags.NUMBERED)) != null) { this.numbered = bool.Parse(value); } if ((value = attributes.Remove(ElementTags.LETTERED)) != null) { this.lettered = bool.Parse(value); if ( this.numbered && this.lettered ) this.numbered = false; } if ((value = attributes.Remove(ElementTags.SYMBOLINDENT)) != null) { this.symbolIndent = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes.Remove(ElementTags.FIRST)) != null) { char khar = value[0]; if ( char.IsLetter( khar ) ) { First = (int)khar; } else { First = int.Parse(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); } }