public static TableCellAttributes FromNode(Node node) { Nodes.Attribute n = null; TableCellAttributes tableCellAttributes = null; try { if (node.attrs == null) { return tableCellAttributes; } node.attrs.Reset(); for (n = node.attrs.Next(); n != null; n = node.attrs.Next()) { string s = n.val.Trim(); if (n.name == "rowalign") { if (s.Length > 0) { if (tableCellAttributes == null) { tableCellAttributes = new TableCellAttributes(); } if (s.ToUpper() == "TOP") { tableCellAttributes.rowAlign = RowAlign.TOP; } else if (s.ToUpper() == "BOTTOM") { tableCellAttributes.rowAlign = RowAlign.BOTTOM; } else if (s.ToUpper() == "CENTER") { tableCellAttributes.rowAlign = RowAlign.CENTER; } else if (s.ToUpper() == "BASELINE") { tableCellAttributes.rowAlign = RowAlign.BASELINE; } else if (s.ToUpper() == "AXIS") { tableCellAttributes.rowAlign = RowAlign.AXIS; } else { tableCellAttributes.rowAlign = RowAlign.CENTER; } } } else if (n.name == "columnalign") { if (s.Length > 0) { if (tableCellAttributes == null) { tableCellAttributes = new TableCellAttributes(); } if (s.ToUpper() == "LEFT") { tableCellAttributes.columnAlign = HAlign.LEFT; } else if (s.ToUpper() == "CENTER") { tableCellAttributes.columnAlign = HAlign.CENTER; } else if (s.ToUpper() == "RIGHT") { tableCellAttributes.columnAlign = HAlign.RIGHT; } else { tableCellAttributes.columnAlign = HAlign.LEFT; } } } else if (n.name == "rowspan") { if (s.Length > 0) { if (tableCellAttributes == null) { tableCellAttributes = new TableCellAttributes(); } tableCellAttributes.rowSpan = Convert.ToInt32(s.Trim()); } } else if ((n.name == "columnspan") && (s.Length > 0)) { if (tableCellAttributes == null) { tableCellAttributes = new TableCellAttributes(); } tableCellAttributes.columnSpan = Convert.ToInt32(s.Trim()); } } node.attrs.Reset(); } catch { } return tableCellAttributes; }
public static void ApplyAttrs(Node node, TableCellAttributes tableCellAttributes) { if (((node != null) && (node.type_ != null)) && ((node.type_.type == ElementType.Mtd) && (tableCellAttributes != null))) { if (tableCellAttributes.rowAlign == RowAlign.TOP) { if (node.attrs == null) { node.attrs = new AttributeList(); } node.attrs.Add("rowalign", "top"); } else if (tableCellAttributes.rowAlign == RowAlign.BOTTOM) { if (node.attrs == null) { node.attrs = new AttributeList(); } node.attrs.Add("rowalign", "bottom"); } else if (tableCellAttributes.rowAlign == RowAlign.CENTER) { if (node.attrs == null) { node.attrs = new AttributeList(); } node.attrs.Add("rowalign", "center"); } else if (tableCellAttributes.rowAlign == RowAlign.BASELINE) { if (node.attrs == null) { node.attrs = new AttributeList(); } node.attrs.Add("rowalign", "baseline"); } else if (tableCellAttributes.rowAlign == RowAlign.AXIS) { if (node.attrs == null) { node.attrs = new AttributeList(); } node.attrs.Add("rowalign", "axis"); } else if ((tableCellAttributes.rowAlign == RowAlign.UNKNOWN) && (node.attrs != null)) { Nodes.Attribute attribute = node.attrs.Get("rowalign"); if (attribute != null) { node.attrs.Remove(attribute); } } if (tableCellAttributes.columnAlign == HAlign.LEFT) { if (node.attrs == null) { node.attrs = new AttributeList(); } node.attrs.Add("columnalign", "left"); } else if (tableCellAttributes.columnAlign == HAlign.CENTER) { if (node.attrs == null) { node.attrs = new AttributeList(); } node.attrs.Add("columnalign", "center"); } else if (tableCellAttributes.columnAlign == HAlign.RIGHT) { if (node.attrs == null) { node.attrs = new AttributeList(); } node.attrs.Add("columnalign", "right"); } else if ((tableCellAttributes.columnAlign == HAlign.UNKNOWN) && (node.attrs != null)) { Nodes.Attribute attribute = node.attrs.Get("columnalign"); if (attribute != null) { node.attrs.Remove(attribute); } } if (tableCellAttributes.rowSpan != 1) { if (node.attrs == null) { node.attrs = new AttributeList(); } string s = tableCellAttributes.rowSpan.ToString(); if (s.Length > 0) { node.attrs.Add("rowspan", s); } } else if (node.attrs != null) { Nodes.Attribute attribute = node.attrs.Get("rowspan"); if (attribute != null) { node.attrs.Remove(attribute); } } if (tableCellAttributes.columnSpan != 1) { if (node.attrs == null) { node.attrs = new AttributeList(); } string s = tableCellAttributes.columnSpan.ToString(); if (s.Length > 0) { node.attrs.Add("columnspan", s); } } else if (node.attrs != null) { Nodes.Attribute attribute = node.attrs.Get("columnspan"); if (attribute != null) { node.attrs.Remove(attribute); } } } }
public void ApplyAttrs() { try { TableAttributes attrs; this.ColAligns(); this.RowAligns(); if (this.attrs != null) { attrs = this.attrs; } else { attrs = new TableAttributes(); } attrs.colAligns = this.colAligns; attrs.rowAligns = this.rowAligns; attrs.rowSpacing = new string[this.rows.Count]; attrs.rowLines = new TableLineStyle[this.rows.Count]; attrs.colSpacing = this.colSpacing; attrs.colLines = this.colLines; attrs.displaystyle = this.displayStyle; attrs.equalColumns = this.equalColumns; attrs.equalRows = this.equalRows; attrs.align = this.align; attrs.frame = this.frame; attrs.framespacing = this.framespacing; attrs.side = this.side; attrs.minlabelspacing = this.minlabelSpacing; bool sameStyle = true; TableLineStyle lineStyle = TableLineStyle.NONE; for (int i = 0; i < attrs.colLines.Length; i++) { if ((i > 0) && (attrs.colLines[i] != lineStyle)) { sameStyle = false; } lineStyle = attrs.colLines[i]; } if (sameStyle) { attrs.colLines = new TableLineStyle[] { lineStyle }; } bool sameColSpacing = true; string colSpacing = "0.8em"; for (int i = 0; i < attrs.colSpacing.Length; i++) { if ((i > 0) && (attrs.colSpacing[i] != colSpacing)) { sameColSpacing = false; } colSpacing = attrs.colSpacing[i]; } if (sameColSpacing) { attrs.colSpacing = new string[] { colSpacing }; } for (int i = 0; i < this.rows.Count; i++) { MRow row = this.GetRow(i); attrs.rowSpacing[i] = row.spacing; attrs.rowLines[i] = row.lines; Node node = row.node; TableRowAttributes rowAttributes = row.attrs; if (rowAttributes != null) { rowAttributes.colAligns = row.colAligns; rowAttributes.align = row.align; AttributeBuilder.ApplyAttributes(node, rowAttributes); } else { rowAttributes = new TableRowAttributes(); rowAttributes.colAligns = row.colAligns; rowAttributes.align = row.align; AttributeBuilder.ApplyAttributes(node, rowAttributes); } if ((row.isLabeled && (row.cell != null)) && (row.cell.node != null)) { TableCellAttributes cellAttributes = row.cell.tableAttrs; Node n = row.cell.node; if (cellAttributes != null) { cellAttributes.columnAlign = row.cell.columnAlign; cellAttributes.rowAlign = row.cell.rowAlign; AttributeBuilder.ApplyAttrs(n, cellAttributes); } else { cellAttributes = new TableCellAttributes(); cellAttributes.columnAlign = row.cell.columnAlign; cellAttributes.rowAlign = row.cell.rowAlign; AttributeBuilder.ApplyAttrs(n, cellAttributes); } } for (int j = 0; j < ((MRow) this.rows[i]).cells.Count; j++) { Node n = ((MCell) ((MRow) this.rows[i]).cells[j]).node; TableCellAttributes cellAttributes = ((MCell) ((MRow) this.rows[i]).cells[j]).tableAttrs; RowAlign rowAlign = ((MCell) ((MRow) this.rows[i]).cells[j]).rowAlign; if (cellAttributes != null) { cellAttributes.columnAlign = ((MCell) ((MRow) this.rows[i]).cells[j]).columnAlign; cellAttributes.rowAlign = ((MCell) ((MRow) this.rows[i]).cells[j]).rowAlign; AttributeBuilder.ApplyAttrs(n, cellAttributes); } else { cellAttributes = new TableCellAttributes(); cellAttributes.columnAlign = ((MCell) ((MRow) this.rows[i]).cells[j]).columnAlign; cellAttributes.rowAlign = ((MCell) ((MRow) this.rows[i]).cells[j]).rowAlign; AttributeBuilder.ApplyAttrs(n, cellAttributes); } } } bool sameRowL = true; TableLineStyle tableLineStyle = TableLineStyle.NONE; for (int i = 0; i < attrs.rowLines.Length; i++) { if ((i > 0) && (attrs.rowLines[i] != tableLineStyle)) { sameRowL = false; } tableLineStyle = attrs.rowLines[i]; } if (sameRowL) { attrs.rowLines = new TableLineStyle[] { tableLineStyle }; } bool sameRowS = true; string rowSpacing = "0.5ex"; for (int i = 0; i < attrs.rowSpacing.Length; i++) { if ((i > 0) && (attrs.rowSpacing[i] != rowSpacing)) { sameRowS = false; } rowSpacing = attrs.rowSpacing[i]; } if (sameRowS) { attrs.rowSpacing = new string[] { rowSpacing }; } AttributeBuilder.ApplyAttrs(this.node_, attrs); } catch { } }