Esempio n. 1
0
 public override void getSize(Node containerNode)
 {
     this.totalSpacing = 0;
     this.lspace = 0;
     this.rspace = 0;
     Form form = Form.UNKNOWN;
     int lspace = 0;
     int rspace = 0;
     bool hasLspace = false;
     bool hasRspace = false;
     bool hasForm = false;
     if (containerNode.attrs != null)
     {
         if ((containerNode.attrs.Get("lspace") != null) || (containerNode.attrs.Get("rspace") != null))
         {
             float emHeight = base.painter_.FontSize(containerNode, containerNode.style_);
             if (containerNode.attrs.Get("lspace") != null)
             {
                 lspace = AttributeBuilder.SizeByAttr(emHeight, base.painter_.DpiX(), containerNode, "lspace", 0);
                 hasLspace = true;
             }
             if (containerNode.attrs.Get("rspace") != null)
             {
                 rspace = AttributeBuilder.SizeByAttr(emHeight, base.painter_.DpiX(), containerNode, "rspace", 0);
                 hasRspace = true;
             }
         }
         switch (containerNode.attrs.GetValue("form"))
         {
             case "prefix":
             {
                 form = Form.PREFIX;
                 hasForm = true;
                 break;
             }
             case "infix":
             {
                 form = Form.INFIX;
                 hasForm = true;
                 break;
             }
             case "postfix":
             {
                 form = Form.POSTFIX;
                 hasForm = true;
                 break;
             }
         }
     }
     if (containerNode.numChildren > 0)
     {
         Node firstChild = null;
         firstChild = containerNode.firstChild;
         if ((firstChild.type_.type == ElementType.Entity) && (firstChild.glyph != null))
         {
             if (((firstChild.glyph.Code == "02062") || (firstChild.glyph.Name == "0200B")) || (firstChild.glyph.Name == "02061"))
             {
                 int w = 0;
                 int h = 0;
                 int b = 0;
                 try
                 {
                     double d = base.painter_.FontSize(containerNode, containerNode.style_);
                     w = Convert.ToInt32(Math.Round((double) (d * 0.0555556)));
                     h = Convert.ToInt32(Math.Round((double) (d * 0.8)));
                     b = Convert.ToInt32(Math.Round((double) (d * 0.6)));
                 }
                 catch
                 {
                 }
                 base.rect.width = Math.Max(w, 1);
                 base.rect.height = Math.Max(h, 5);
                 base.rect.baseline = Math.Max(b, 3);
             }
             else if (base.painter_.IsStretchy(containerNode))
             {
                 base.rect.width = base.painter_.FencedWidth(false, containerNode, containerNode.firstChild.glyph.Code);
             }
             else if (!this.IsChildOfUnderOver(containerNode) && (!hasLspace || !hasRspace))
             {
                 try
                 {
                     Operator op = null;
                     if ((containerNode.prevSibling != null) || (containerNode.nextSibling != null))
                     {
                         try
                         {
                             if (!hasForm)
                             {
                                 if ((containerNode.prevSibling != null) && (containerNode.nextSibling != null))
                                 {
                                     form = Form.INFIX;
                                 }
                                 else if ((containerNode.prevSibling == null) && (containerNode.nextSibling != null))
                                 {
                                     form = Form.PREFIX;
                                 }
                                 else if ((containerNode.prevSibling != null) && (containerNode.nextSibling == null))
                                 {
                                     form = Form.POSTFIX;
                                 }
                             }
                             op = base.painter_.operators.Indexer(firstChild.glyph.Code, "", form);
                         }
                         catch
                         {
                         }
                         if (op == null)
                         {
                             op = new Operator();
                         }
                         if (op != null)
                         {
                             double d = base.painter_.FontSize(containerNode, containerNode.style_);
                             if (!hasLspace)
                             {
                                 this.lspace = Convert.ToInt32(Math.Round(d * op.LSpace));
                             }
                             if (!hasRspace)
                             {
                                 this.rspace = Convert.ToInt32(Math.Round(d * op.RSpace));
                             }
                         }
                     }
                 }
                 catch
                 {
                 }
             }
             if (hasLspace)
             {
                 this.lspace = lspace;
             }
             if (hasRspace)
             {
                 this.rspace = rspace;
             }
             this.totalSpacing = this.lspace + this.rspace;
             base.rect.width += this.totalSpacing;
         }
     }
     else if ((containerNode.literalText != null) && (containerNode.literalText.Length > 0))
     {
         base.painter_.MeasureBox(containerNode, containerNode.style_);
         if (!hasLspace || !hasRspace)
         {
             try
             {
                 Operator op = null;
                 string ltext = containerNode.literalText.Trim();
                 if (!hasForm)
                 {
                     if ((containerNode.prevSibling != null) && (containerNode.nextSibling != null))
                     {
                         form = Form.INFIX;
                     }
                     else if ((containerNode.prevSibling == null) && (containerNode.nextSibling != null))
                     {
                         form = Form.PREFIX;
                     }
                     else if ((containerNode.prevSibling != null) && (containerNode.nextSibling == null))
                     {
                         form = Form.POSTFIX;
                     }
                 }
                 op = base.painter_.operators.Indexer("", ltext, form);
                 if (op == null)
                 {
                     op = new Operator();
                 }
                 if (op != null)
                 {
                     double d = base.painter_.FontSize(containerNode, containerNode.style_);
                     if (!hasLspace)
                     {
                         this.lspace = Convert.ToInt32(Math.Round(d * op.LSpace));
                     }
                     if (!hasRspace)
                     {
                         this.rspace = Convert.ToInt32(Math.Round(d * op.RSpace));
                     }
                 }
             }
             catch
             {
             }
         }
         if (hasLspace)
         {
             this.lspace = lspace;
         }
         if (hasRspace)
         {
             this.rspace = rspace;
         }
         this.totalSpacing = this.lspace + this.rspace;
         base.rect.width += this.totalSpacing;
     }
     else
     {
         base.painter_.MeasureBox(containerNode, containerNode.style_, "X");
         if (hasLspace)
         {
             this.lspace = lspace;
         }
         if (hasRspace)
         {
             this.rspace = rspace;
         }
         this.totalSpacing = this.lspace + this.rspace;
         base.rect.width += this.totalSpacing;
     }
 }
Esempio n. 2
0
        public void LoadDictionary(string path, bool bFromResource)
        {
            try
            {
                XmlDocument document = new XmlDocument();
                if (bFromResource)
                {
                    Stream stream = Facade.ResourceLoader.GetStream("Binary", "Operator_Dictionary.xml");
                    document.Load(stream);
                }
                else
                {
                    document.Load(path);
                }
                XmlNode root = document.DocumentElement;
                if (!root.HasChildNodes)
                {
                    return;
                }
                
                this.operators = new ArrayList(root.ChildNodes.Count);
                this.entities = new Hashtable();
                this.texts = new Hashtable();
                this.unicodes = new Hashtable();
                
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    try
                    {
                        XmlNode opNode = root.ChildNodes[i];
                        Operator op = new Operator();
                        if (opNode.HasChildNodes && (opNode.FirstChild.NodeType == XmlNodeType.Text))
                        {
                            op.text = opNode.FirstChild.Value.Trim();
                        }
                        
                        int startIndex = 0;
                        int endIndex = 0;
                        startIndex = op.text.IndexOf("@", 0, op.text.Length);
                        if ((startIndex != -1) && (op.text.Length > startIndex))
                        {
                            startIndex++;
                            endIndex = op.text.IndexOf(";", startIndex, op.text.Length - startIndex);
                            if (endIndex != -1)
                            {
                                op.entity = op.text.Substring(startIndex, endIndex - startIndex);
                            }
                        }
                        
                        for (int attrIndex = 0; attrIndex < opNode.Attributes.Count; attrIndex++)
                        {
                            string formval;
                            XmlAttribute xmlAttribute = opNode.Attributes[attrIndex];
                            
                            switch (xmlAttribute.Name)
                            {
                                case "unicode":
                                {
                                    op.unicode = xmlAttribute.Value;
                                    break;
                                }
                                case "entity":
                                {
                                    op.entity = xmlAttribute.Value;
                                    break;
                                }
                                case "lspace":
                                {
                                    op.lspace = xmlAttribute.Value;
                                    break;
                                }
                                case "rspace":
                                {
                                    op.rspace = xmlAttribute.Value;
                                    break;
                                }
                                case "form":
                                    if ((formval = xmlAttribute.Value) == null)
                                    {
                                        op.form = Form.UNKNOWN;
                                        break;
                                    }
                                    formval = string.IsInterned(formval);
                                    if (formval == "prefix")
                                    {
                                        op.form = Form.PREFIX;
                                        break;
                                    }
                                    else if (formval == "infix")
                                    {
                                        op.form = Form.INFIX;
                                        break;
                                    }
                                    else if (formval == "postfix")
                                    {
                                        op.form = Form.POSTFIX;
                                        break;
                                    }
                                    else
                                    {
                                        op.form = Form.UNKNOWN;
                                        break;
                                    }

                                case "fence":
                                {
                                    op.fence = Convert.ToBoolean(xmlAttribute.Value);
                                    break;
                                }
                                case "separator":
                                {
                                    op.separator = Convert.ToBoolean(xmlAttribute.Value);
                                    break;
                                }
                                case "stretchy":
                                {
                                    op.stretchy = Convert.ToBoolean(xmlAttribute.Value);
                                    break;
                                }
                                case "symmetric":
                                {
                                    op.symmetric = Convert.ToBoolean(xmlAttribute.Value);
                                    break;
                                }
                                case "maxsize":
                                {
                                    op.maxsize = xmlAttribute.Value;
                                    break;
                                }
                                case "minsize":
                                {
                                    op.minsize = xmlAttribute.Value;
                                    break;
                                }
                                case "largeop":
                                {
                                    op.largeop = Convert.ToBoolean(xmlAttribute.Value);
                                    break;
                                }
                                case "movablelimits":
                                {
                                    op.movablelimits = Convert.ToBoolean(xmlAttribute.Value);
                                    break;
                                }
                                case "accent":
                                {
                                    op.accent = Convert.ToBoolean(xmlAttribute.Value);
                                    break;
                                }
                                case "active":
                                {
                                    op.active = Convert.ToBoolean(xmlAttribute.Value);
                                    break;
                                }
                            }
                        }
                        string form = "";
                        try
                        {
                            switch (op.form)
                            {
                                case Form.PREFIX:
                                {
                                    form = "prefix";
                                    break;
                                }
                                case Form.INFIX:
                                {
                                    form = "infix";
                                    break;
                                }
                                case Form.POSTFIX:
                                {
                                    form = "postfix";
                                    break;
                                }
                            }
                            form = "";
                        }
                        catch
                        {
                        }
                    
                        this.operators.Add(op);
                        if (op.entity.Length > 0)
                        {
                            try
                            {
                                this.entities.Add(op.entity + "_" + form, op);
                            }
                            catch
                            {
                            }
                        }
                        if (op.text.Length > 0)
                        {
                            try
                            {
                                if (!this.texts.Contains(op.text + "_" + form))
                                {
                                    this.texts.Add(op.text + "_" + form, op);
                                }
                            }
                            catch
                            {
                            }
                        }
                        if (op.unicode.Length > 0)
                        {
                            try
                            {
                                if (!this.unicodes.Contains(op.unicode + "_" + form))
                                {
                                    this.unicodes.Add(op.unicode + "_" + form, op);
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
        }