public static void ApplyAttrs(Node node, FractionAttributes fractionAttributes)
 {
     if (((node != null) && (node.type_ != null)) && ((node.type_.type == ElementType.Mfrac) && (fractionAttributes != null)))
     {
         if (fractionAttributes.isBevelled)
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             node.attrs.Add("bevelled", "true");
         }
         else if (node.attrs != null)
         {
             Nodes.Attribute attribute = node.attrs.Get("bevelled");
             if (attribute != null)
             {
                 node.attrs.Remove(attribute);
             }
         }
         if (fractionAttributes.lineThickness != 1)
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             node.attrs.Add("linethickness", fractionAttributes.lineThickness.ToString());
         }
         else if (node.attrs != null)
         {
             Nodes.Attribute attribute = node.attrs.Get("linethickness");
             if (attribute != null)
             {
                 node.attrs.Remove(attribute);
             }
         }
         if (fractionAttributes.denomAlign != FractionAlign.CENTER)
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             if (fractionAttributes.denomAlign == FractionAlign.LEFT)
             {
                 node.attrs.Add("denomalign", "left");
             }
             else if (fractionAttributes.denomAlign == FractionAlign.RIGHT)
             {
                 node.attrs.Add("denomalign", "right");
             }
             else
             {
                 node.attrs.Add("denomalign", "center");
             }
         }
         else if (node.attrs != null)
         {
             Nodes.Attribute attribute = node.attrs.Get("denomalign");
             if (attribute != null)
             {
                 node.attrs.Remove(attribute);
             }
         }
         if (fractionAttributes.numAlign != FractionAlign.CENTER)
         {
             if (node.attrs == null)
             {
                 node.attrs = new AttributeList();
             }
             if (fractionAttributes.numAlign == FractionAlign.LEFT)
             {
                 node.attrs.Add("numalign", "left");
             }
             else if (fractionAttributes.numAlign == FractionAlign.RIGHT)
             {
                 node.attrs.Add("numalign", "right");
             }
             else
             {
                 node.attrs.Add("numalign", "center");
             }
         }
         else if (node.attrs != null)
         {
             Nodes.Attribute attribute = node.attrs.Get("numalign");
             if (attribute != null)
             {
                 node.attrs.Remove(attribute);
             }
         }
     }
 }
 public static FractionAttributes FractionAttrsFromNode(Node node)
 {
     Nodes.Attribute attribute = null;
     FractionAttributes fractionAttributes = null;
     try
     {
         if (node.attrs == null)
         {
             return fractionAttributes;
         }
         node.attrs.Reset();
         for (attribute = node.attrs.Next(); attribute != null; attribute = node.attrs.Next())
         {
             string s = attribute.val.Trim();
             if (attribute.name == "linethickness")
             {
                 if (s.Length > 0)
                 {
                     int lineThickness = 1;
                     if (s.ToUpper() == "THIN")
                     {
                         lineThickness = 1;
                     }
                     else if (s.ToUpper() == "MEDIUM")
                     {
                         lineThickness = 2;
                     }
                     else if (s.ToUpper() == "THICK")
                     {
                         lineThickness = 3;
                     }
                     else
                     {
                         bool isInteger = true;
                         for (int i = 0; i < s.Length; i++)
                         {
                             if (s[i] == '.')
                             {
                                 isInteger = false;
                             }
                         }
                         if (isInteger)
                         {
                             try
                             {
                                 lineThickness = Convert.ToInt32(s);
                             }
                             catch
                             {
                                 lineThickness = 1;
                             }
                         }
                         else
                         {
                             lineThickness = 1;
                         }
                     }
                     if (fractionAttributes == null)
                     {
                         fractionAttributes = new FractionAttributes();
                     }
                     fractionAttributes.lineThickness = lineThickness;
                 }
             }
             else if (attribute.name == "numalign")
             {
                 if (s.Length > 0)
                 {
                     if (fractionAttributes == null)
                     {
                         fractionAttributes = new FractionAttributes();
                     }
                     if (s.ToUpper() == "LEFT")
                     {
                         fractionAttributes.numAlign = FractionAlign.LEFT;
                     }
                     else if (s.ToUpper() == "CENTER")
                     {
                         fractionAttributes.numAlign = FractionAlign.CENTER;
                     }
                     else if (s.ToUpper() == "RIGHT")
                     {
                         fractionAttributes.numAlign = FractionAlign.RIGHT;
                     }
                 }
             }
             else if (attribute.name == "denomalign")
             {
                 if (s.Length > 0)
                 {
                     if (fractionAttributes == null)
                     {
                         fractionAttributes = new FractionAttributes();
                     }
                     if (s.ToUpper() == "LEFT")
                     {
                         fractionAttributes.denomAlign = FractionAlign.LEFT;
                     }
                     else if (s.ToUpper() == "CENTER")
                     {
                         fractionAttributes.denomAlign = FractionAlign.CENTER;
                     }
                     else if (s.ToUpper() == "RIGHT")
                     {
                         fractionAttributes.denomAlign = FractionAlign.RIGHT;
                     }
                 }
             }
             else if ((attribute.name == "bevelled") && (s.Length > 0))
             {
                 if (fractionAttributes == null)
                 {
                     fractionAttributes = new FractionAttributes();
                 }
                 if (s.ToUpper() == "TRUE")
                 {
                     fractionAttributes.isBevelled = true;
                 }
                 else
                 {
                     fractionAttributes.isBevelled = false;
                 }
             }
         }
         node.attrs.Reset();
     }
     catch
     {
     }
     return fractionAttributes;
 }
 public static FractionAttributes FractionAttrsFromNode(float emHeight, float DPI, Node node)
 {
     Nodes.Attribute attribute = null;
     FractionAttributes attributes = null;
     try
     {
         if (node.attrs == null)
         {
             return attributes;
         }
         node.attrs.Reset();
         for (attribute = node.attrs.Next(); attribute != null; attribute = node.attrs.Next())
         {
             string s = attribute.val.Trim();
             if (attribute.name == "linethickness")
             {
                 if (s.Length > 0)
                 {
                     int lineThickness = 1;
                     if (s.ToUpper() == "THIN")
                     {
                         lineThickness = 1;
                     }
                     else if (s.ToUpper() == "MEDIUM")
                     {
                         lineThickness = 2;
                     }
                     else if (s.ToUpper() == "THICK")
                     {
                         lineThickness = 3;
                     }
                     else
                     {
                         bool isInteger = true;
                         for (int i = 0; i < s.Length; i++)
                         {
                             if (s[i] == '.')
                             {
                                 isInteger = false;
                             }
                         }
                         if (isInteger)
                         {
                             try
                             {
                                 lineThickness = Convert.ToInt32(s);
                             }
                             catch
                             {
                                 try
                                 {
                                     if (!char.IsLetter(s[s.Length - 1]))
                                     {
                                         s = s + "ex";
                                     }
                                     lineThickness = AttributeBuilder.FontWidth(emHeight, DPI, s, 1);
                                 }
                                 catch
                                 {
                                     lineThickness = 1;
                                 }
                             }
                         }
                         else
                         {
                             try
                             {
                                 if (!char.IsLetter(s[s.Length - 1]))
                                 {
                                     s = s + "ex";
                                 }
                                 lineThickness = AttributeBuilder.FontWidth(emHeight, DPI, s, 1);
                             }
                             catch
                             {
                                 lineThickness = 1;
                             }
                         }
                     }
                     if (attributes == null)
                     {
                         attributes = new FractionAttributes();
                     }
                     attributes.lineThickness = lineThickness;
                 }
             }
             else if (attribute.name == "numalign")
             {
                 if (s.Length > 0)
                 {
                     if (attributes == null)
                     {
                         attributes = new FractionAttributes();
                     }
                     if (s.ToUpper() == "LEFT")
                     {
                         attributes.numAlign = FractionAlign.LEFT;
                     }
                     else if (s.ToUpper() == "CENTER")
                     {
                         attributes.numAlign = FractionAlign.CENTER;
                     }
                     else if (s.ToUpper() == "RIGHT")
                     {
                         attributes.numAlign = FractionAlign.RIGHT;
                     }
                 }
             }
             else if (attribute.name == "denomalign")
             {
                 if (s.Length > 0)
                 {
                     if (attributes == null)
                     {
                         attributes = new FractionAttributes();
                     }
                     if (s.ToUpper() == "LEFT")
                     {
                         attributes.denomAlign = FractionAlign.LEFT;
                     }
                     else if (s.ToUpper() == "CENTER")
                     {
                         attributes.denomAlign = FractionAlign.CENTER;
                     }
                     else if (s.ToUpper() == "RIGHT")
                     {
                         attributes.denomAlign = FractionAlign.RIGHT;
                     }
                 }
             }
             else if ((attribute.name == "bevelled") && (s.Length > 0))
             {
                 if (attributes == null)
                 {
                     attributes = new FractionAttributes();
                 }
                 if (s.ToUpper() == "TRUE")
                 {
                     attributes.isBevelled = true;
                 }
                 else
                 {
                     attributes.isBevelled = false;
                 }
             }
         }
         node.attrs.Reset();
     }
     catch
     {
     }
     return attributes;
 }
示例#4
0
 //
 public bool ApplyFractionAttrs (Node node, FractionAttributes FractionAttributes)
 {
     try
     {
         this.OnInsert (false);
         AttributeBuilder.ApplyAttrs (node, FractionAttributes);
     }
     catch
     {
     }
     return true;
 }