Пример #1
0
 static public int constructor(IntPtr l)
 {
     try {
         FairyGUI.Utils.XMLIterator o;
         o = new FairyGUI.Utils.XMLIterator();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #2
0
        virtual public void Parse(string aSource, TextFormat defaultFormat, List <HtmlElement> elements, HtmlParseOptions parseOptions)
        {
            if (parseOptions == null)
            {
                parseOptions = _defaultOptions;
            }

            _elements           = elements;
            _textFormatStackTop = 0;
            _ignoreWhiteSpace   = parseOptions.ignoreWhiteSpace;
            _format.CopyFrom(defaultFormat);
            _format.colorChanged = false;
            string text;

            XMLIterator.Begin(aSource, true);
            while (XMLIterator.NextTag())
            {
                if (_skipText == 0)
                {
                    text = XMLIterator.GetText(_ignoreWhiteSpace);
                    if (text.Length > 0)
                    {
                        AppendText(text);
                    }
                }

                switch (XMLIterator.tagName)
                {
                case "b":
                    if (XMLIterator.tagType == XMLTagType.Start)
                    {
                        PushTextFormat();
                        _format.bold = true;
                    }
                    else
                    {
                        PopTextFormat();
                    }
                    break;

                case "i":
                    if (XMLIterator.tagType == XMLTagType.Start)
                    {
                        PushTextFormat();
                        _format.italic = true;
                    }
                    else
                    {
                        PopTextFormat();
                    }
                    break;

                case "u":
                    if (XMLIterator.tagType == XMLTagType.Start)
                    {
                        PushTextFormat();
                        _format.underline = true;
                    }
                    else
                    {
                        PopTextFormat();
                    }
                    break;

                case "sub":
                {
                    if (XMLIterator.tagType == XMLTagType.Start)
                    {
                        PushTextFormat();
                        _format.size         = Mathf.CeilToInt(_format.size * 0.58f);
                        _format.specialStyle = TextFormat.SpecialStyle.Subscript;
                    }
                    else
                    {
                        PopTextFormat();
                    }
                }
                break;

                case "sup":
                {
                    if (XMLIterator.tagType == XMLTagType.Start)
                    {
                        PushTextFormat();
                        _format.size         = Mathf.CeilToInt(_format.size * 0.58f);
                        _format.specialStyle = TextFormat.SpecialStyle.Superscript;
                    }
                    else
                    {
                        PopTextFormat();
                    }
                }
                break;

                case "font":
                    if (XMLIterator.tagType == XMLTagType.Start)
                    {
                        PushTextFormat();

                        _format.size = XMLIterator.GetAttributeInt("size", _format.size);
                        string color = XMLIterator.GetAttribute("color");
                        if (color != null)
                        {
                            string[] parts = color.Split(',');
                            if (parts.Length == 1)
                            {
                                _format.color         = ToolSet.ConvertFromHtmlColor(color);
                                _format.gradientColor = null;
                                _format.colorChanged  = true;
                            }
                            else
                            {
                                if (_format.gradientColor == null)
                                {
                                    _format.gradientColor = new Color32[4];
                                }
                                _format.gradientColor[0] = ToolSet.ConvertFromHtmlColor(parts[0]);
                                _format.gradientColor[1] = ToolSet.ConvertFromHtmlColor(parts[1]);
                                if (parts.Length > 2)
                                {
                                    _format.gradientColor[2] = ToolSet.ConvertFromHtmlColor(parts[2]);
                                    if (parts.Length > 3)
                                    {
                                        _format.gradientColor[3] = ToolSet.ConvertFromHtmlColor(parts[3]);
                                    }
                                    else
                                    {
                                        _format.gradientColor[3] = _format.gradientColor[2];
                                    }
                                }
                                else
                                {
                                    _format.gradientColor[2] = _format.gradientColor[0];
                                    _format.gradientColor[3] = _format.gradientColor[1];
                                }
                            }
                        }
                    }
                    else if (XMLIterator.tagType == XMLTagType.End)
                    {
                        PopTextFormat();
                    }
                    break;

                case "br":
                    AppendText("\n");
                    break;

                case "img":
                    if (XMLIterator.tagType == XMLTagType.Start || XMLIterator.tagType == XMLTagType.Void)
                    {
                        HtmlElement element = HtmlElement.GetElement(HtmlElementType.Image);
                        element.FetchAttributes();
                        element.name         = element.GetString("name");
                        element.format.align = _format.align;
                        _elements.Add(element);
                    }
                    break;

                case "a":
                    if (XMLIterator.tagType == XMLTagType.Start)
                    {
                        PushTextFormat();

                        _format.underline = _format.underline | parseOptions.linkUnderline;
                        if (!_format.colorChanged && parseOptions.linkColor.a != 0)
                        {
                            _format.color = parseOptions.linkColor;
                        }

                        HtmlElement element = HtmlElement.GetElement(HtmlElementType.Link);
                        element.FetchAttributes();
                        element.name         = element.GetString("name");
                        element.format.align = _format.align;
                        _elements.Add(element);
                    }
                    else if (XMLIterator.tagType == XMLTagType.End)
                    {
                        PopTextFormat();

                        HtmlElement element = HtmlElement.GetElement(HtmlElementType.LinkEnd);
                        _elements.Add(element);
                    }
                    break;

                case "input":
                {
                    HtmlElement element = HtmlElement.GetElement(HtmlElementType.Input);
                    element.FetchAttributes();
                    element.name = element.GetString("name");
                    element.format.CopyFrom(_format);
                    _elements.Add(element);
                }
                break;

                case "select":
                {
                    if (XMLIterator.tagType == XMLTagType.Start || XMLIterator.tagType == XMLTagType.Void)
                    {
                        HtmlElement element = HtmlElement.GetElement(HtmlElementType.Select);
                        element.FetchAttributes();
                        if (XMLIterator.tagType == XMLTagType.Start)
                        {
                            sHelperList1.Clear();
                            sHelperList2.Clear();
                            while (XMLIterator.NextTag())
                            {
                                if (XMLIterator.tagName == "select")
                                {
                                    break;
                                }

                                if (XMLIterator.tagName == "option")
                                {
                                    if (XMLIterator.tagType == XMLTagType.Start || XMLIterator.tagType == XMLTagType.Void)
                                    {
                                        sHelperList2.Add(XMLIterator.GetAttribute("value", string.Empty));
                                    }
                                    else
                                    {
                                        sHelperList1.Add(XMLIterator.GetText());
                                    }
                                }
                            }
                            element.Set("items", sHelperList1.ToArray());
                            element.Set("values", sHelperList2.ToArray());
                        }
                        element.name = element.GetString("name");
                        element.format.CopyFrom(_format);
                        _elements.Add(element);
                    }
                }
                break;

                case "p":
                    if (XMLIterator.tagType == XMLTagType.Start)
                    {
                        PushTextFormat();
                        string align = XMLIterator.GetAttribute("align");
                        _format.align = FieldTypes.ParseAlign(align);

                        if (!IsNewLine())
                        {
                            AppendText("\n");
                        }
                    }
                    else if (XMLIterator.tagType == XMLTagType.End)
                    {
                        if (!IsNewLine())
                        {
                            AppendText("\n");
                        }

                        PopTextFormat();
                    }
                    break;

                case "ui":
                case "div":
                case "li":
                    if (!IsNewLine())
                    {
                        AppendText("\n");
                    }
                    break;

                case "html":
                case "body":
                    //full html
                    _ignoreWhiteSpace = true;
                    break;

                case "head":
                case "style":
                case "script":
                case "form":
                    if (XMLIterator.tagType == XMLTagType.Start)
                    {
                        _skipText++;
                    }
                    else if (XMLIterator.tagType == XMLTagType.End)
                    {
                        _skipText--;
                    }
                    break;
                }
            }

            if (_skipText == 0)
            {
                text = XMLIterator.GetText(_ignoreWhiteSpace);
                if (text.Length > 0)
                {
                    AppendText(text);
                }
            }

            _elements = null;
        }
Пример #3
0
 public void FetchAttributes()
 {
     attributes = XMLIterator.GetAttributes(attributes);
 }
Пример #4
0
        void Parse(string aSource)
        {
            XML lastOpenNode = null;

            sNodeStack.Clear();

            XMLIterator.Begin(aSource);
            while (XMLIterator.NextTag())
            {
                if (XMLIterator.tagType == XMLTagType.Start || XMLIterator.tagType == XMLTagType.Void)
                {
                    XML childNode;
                    if (lastOpenNode != null)
                    {
                        childNode = new XML();
                    }
                    else
                    {
                        if (this.name != null)
                        {
                            Cleanup();
                            throw new Exception("Invalid xml format - no root node.");
                        }
                        childNode = this;
                    }

                    childNode.name        = XMLIterator.tagName;
                    childNode._attributes = XMLIterator.GetAttributes(childNode._attributes);

                    if (lastOpenNode != null)
                    {
                        if (XMLIterator.tagType != XMLTagType.Void)
                        {
                            sNodeStack.Push(lastOpenNode);
                        }
                        if (lastOpenNode._children == null)
                        {
                            lastOpenNode._children = new XMLList();
                        }
                        lastOpenNode._children.Add(childNode);
                    }
                    if (XMLIterator.tagType != XMLTagType.Void)
                    {
                        lastOpenNode = childNode;
                    }
                }
                else if (XMLIterator.tagType == XMLTagType.End)
                {
                    if (lastOpenNode == null || lastOpenNode.name != XMLIterator.tagName)
                    {
                        Cleanup();
                        throw new Exception("Invalid xml format - <" + XMLIterator.tagName + "> dismatched.");
                    }

                    if (lastOpenNode._children == null || lastOpenNode._children.Count == 0)
                    {
                        lastOpenNode.text = XMLIterator.GetText();
                    }

                    if (sNodeStack.Count > 0)
                    {
                        lastOpenNode = sNodeStack.Pop();
                    }
                    else
                    {
                        lastOpenNode = null;
                    }
                }
            }
        }