Пример #1
0
 public static TableRowAttributes MRowAttributes(Node node)
 {
     Nodes.Attribute attribute = null;
     TableRowAttributes tableRowAttributes = null;
     try
     {
         if (node.attrs != null)
         {
             node.attrs.Reset();
             for (attribute = node.attrs.Next(); attribute != null; attribute = node.attrs.Next())
             {
                 string s = attribute.val.Trim();
                 if (attribute.name == "rowalign")
                 {
                     if (s.Length > 0)
                     {
                         if (tableRowAttributes == null)
                         {
                             tableRowAttributes = new TableRowAttributes();
                         }
                         if (s.ToUpper() == "TOP")
                         {
                             tableRowAttributes.align = RowAlign.TOP;
                         }
                         else if (s.ToUpper() == "BOTTOM")
                         {
                             tableRowAttributes.align = RowAlign.BOTTOM;
                         }
                         else if (s.ToUpper() == "CENTER")
                         {
                             tableRowAttributes.align = RowAlign.CENTER;
                         }
                         else if (s.ToUpper() == "BASELINE")
                         {
                             tableRowAttributes.align = RowAlign.BASELINE;
                         }
                         else if (s.ToUpper() == "AXIS")
                         {
                             tableRowAttributes.align = RowAlign.AXIS;
                         }
                         else
                         {
                             tableRowAttributes.align = RowAlign.UNKNOWN;
                         }
                     }
                 }
                 else if ((attribute.name == "columnalign") && (s.Length > 0))
                 {
                     if (tableRowAttributes == null)
                     {
                         tableRowAttributes = new TableRowAttributes();
                     }
                     s = s.Trim();
                     string[] strings = s.Split(new char[] { ' ' }, 100);
                     int numAligns = 0;
                     for (int i = 0; i < strings.Length; i++)
                     {
                         if (((strings[i].ToUpper() == "LEFT") || (strings[i].ToUpper() == "CENTER")) || (strings[i].ToUpper() == "RIGHT"))
                         {
                             numAligns++;
                         }
                     }
                     tableRowAttributes.colAligns = new HAlign[numAligns];
                     if (numAligns > 0)
                     {
                         for (int i = 0; i < strings.Length; i++)
                         {
                             if (strings[i].ToUpper() == "LEFT")
                             {
                                 tableRowAttributes.colAligns[i] = HAlign.LEFT;
                             }
                             else if (strings[i].ToUpper() == "CENTER")
                             {
                                 tableRowAttributes.colAligns[i] = HAlign.CENTER;
                             }
                             else if (strings[i].ToUpper() == "RIGHT")
                             {
                                 tableRowAttributes.colAligns[i] = HAlign.RIGHT;
                             }
                         }
                     }
                     else
                     {
                         tableRowAttributes.colAligns = new HAlign[] { HAlign.CENTER };
                     }
                 }
             }
         }
         node.attrs.Reset();
     }
     catch
     {
     }
     return tableRowAttributes;
 }
Пример #2
0
 public static void ApplyAttributes(Node node, TableRowAttributes tableRowAttributes)
 {
     if ((((node != null) && (node.type_ != null)) && 
         ((node.type_.type == ElementType.Mtr) || (node.type_.type == ElementType.Mlabeledtr))) && (tableRowAttributes != null))
     {
         if (tableRowAttributes.align == RowAlign.TOP)
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             node.attrs.Add("rowalign", "top");
         }
         else if (tableRowAttributes.align == RowAlign.BOTTOM)
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             node.attrs.Add("rowalign", "bottom");
         }
         else if (tableRowAttributes.align == RowAlign.CENTER)
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             node.attrs.Add("rowalign", "center");
         }
         else if (tableRowAttributes.align == RowAlign.BASELINE)
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             node.attrs.Add("rowalign", "baseline");
         }
         else if (tableRowAttributes.align == RowAlign.AXIS)
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             node.attrs.Add("rowalign", "axis");
         }
         else if ((tableRowAttributes.align == RowAlign.UNKNOWN) && (node.attrs != null))
         {
             Nodes.Attribute attribute = node.attrs.Get("rowalign");
             if (attribute != null)
             {
                 node.attrs.Remove(attribute);
             }
         }
         string s = "";
         for (int i = 0; i < tableRowAttributes.colAligns.Length; i++)
         {
             if (tableRowAttributes.colAligns[i] == HAlign.LEFT)
             {
                 if (i > 0)
                 {
                     s = s + " ";
                 }
                 s = s + "left";
             }
             else if (tableRowAttributes.colAligns[i] == HAlign.CENTER)
             {
                 if (i > 0)
                 {
                     s = s + " ";
                 }
                 s = s + "center";
             }
             else if (tableRowAttributes.colAligns[i] == HAlign.RIGHT)
             {
                 if (i > 0)
                 {
                     s = s + " ";
                 }
                 s = s + "right";
             }
             else if (tableRowAttributes.colAligns[i] == HAlign.UNKNOWN)
             {
                 if (i > 0)
                 {
                     s = s + " ";
                 }
                 s = s + "center";
             }
         }
         if ((tableRowAttributes.colAligns.Length == 1) && (s.Trim() == "center"))
         {
             if (node.attrs == null)
             {
                 return;
             }
             Nodes.Attribute attribute = node.attrs.Get("columnalign");
             if (attribute == null)
             {
                 return;
             }
             node.attrs.Remove(attribute);
         }
         else
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             if (s.Length > 0)
             {
                 node.attrs.Add("columnalign", s);
             }
         }
     }
 }
Пример #3
0
 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
     {
     }
 }