示例#1
0
文件: HtmlLink.cs 项目: mengtest/u1
        public void SetArea(Rect r0, Rect r1)
        {
            r1.yMin = r0.yMax;

            Rect unionRect = ToolSet.Union(ref r0, ref r1);

            r0.position -= unionRect.position;
            r1.position -= unionRect.position;
            shape.SetXY(unionRect.x, unionRect.y);
            shape.SetSize(unionRect.width, unionRect.height);

            if (_points8 == null)
            {
                _points8 = new Vector2[8];
            }

            _points8[0] = new Vector2(r0.xMin, r0.yMax);
            _points8[1] = new Vector2(r0.xMin, r0.yMin);
            _points8[2] = new Vector2(r0.xMax, r0.yMin);
            _points8[3] = new Vector2(r0.xMax, r0.yMax);

            _points8[4] = new Vector2(r1.xMax, r1.yMin);
            _points8[5] = new Vector2(r1.xMax, r1.yMax);
            _points8[6] = new Vector2(r1.xMin, r1.yMax);
            _points8[7] = new Vector2(r1.xMin, r1.yMin);

            shape.DrawPolygon(_owner.htmlParseOptions.linkBgColor, _points8);
        }
示例#2
0
文件: HtmlLink.cs 项目: mengtest/u1
        public void SetArea(Rect r0, Rect r1, Rect r2)
        {
            Rect unionRect = ToolSet.Union(ref r0, ref r1);

            unionRect    = ToolSet.Union(ref unionRect, ref r2);
            r0.position -= unionRect.position;
            r1.position -= unionRect.position;
            r2.position -= unionRect.position;
            shape.SetXY(unionRect.x, unionRect.y);
            shape.SetSize(unionRect.width, unionRect.height);

            if (_points12 == null)
            {
                _points12 = new Vector2[12];
            }

            _points12[0] = new Vector2(r0.xMin, r0.yMax);
            _points12[1] = new Vector2(r0.xMin, r0.yMin);
            _points12[2] = new Vector2(r0.xMax, r0.yMin);
            _points12[3] = new Vector2(r0.xMax, r0.yMax);

            _points12[4] = new Vector2(r1.xMax, r1.yMin);
            _points12[5] = new Vector2(r1.xMax, r1.yMax);

            _points12[6] = new Vector2(r2.xMax, r2.yMin);
            _points12[7] = new Vector2(r2.xMax, r2.yMax);
            _points12[8] = new Vector2(r2.xMin, r2.yMax);
            _points12[9] = new Vector2(r2.xMin, r2.yMin);

            _points12[10] = new Vector2(r1.xMin, r1.yMax);
            _points12[11] = new Vector2(r1.xMin, r1.yMin);

            shape.DrawPolygon(_owner.htmlParseOptions.linkBgColor, _points12);
        }
示例#3
0
        public Color GetColor(string attrName, Color defValue)
        {
            string value = GetString(attrName);

            if (value == null || value.Length == 0)
            {
                return(defValue);
            }

            return(ToolSet.ConvertFromHtmlColor(value));
        }
示例#4
0
        public void SetArea(Rect rect)
        {
            Rect contentRect = _owner.contentRect;

            rect = ToolSet.Intersection(ref contentRect, ref rect);
            if (rect.width == 0 || rect.height == 0)
            {
                shape.Clear();
            }
            else
            {
                shape.SetXY(rect.x, rect.y);
                shape.SetSize(rect.width, rect.height);
                shape.DrawRect(0, Color.clear, _owner.htmlParseOptions.linkBgColor);
            }
        }
示例#5
0
        virtual public void FreeObject(IHtmlObject obj)
        {
            obj.Release();
            if (!Application.isPlaying)
            {
                obj.Dispose();
                return;
            }

            //可能已经被GameObject tree deleted了,不再回收
            if (obj.displayObject != null && obj.displayObject.isDisposed)
            {
                return;
            }

            if (obj is HtmlImage)
            {
                _imagePool.Push(obj);
            }
            else if (obj is HtmlInput)
            {
                _inputPool.Push(obj);
            }
            else if (obj is HtmlButton)
            {
                _buttonPool.Push(obj);
            }
            else if (obj is HtmlLink)
            {
                _linkPool.Push(obj);
            }

            if (obj.displayObject != null)
            {
                if (_poolManager == null)
                {
                    _poolManager = Stage.inst.CreatePoolManager("HtmlObjectPool");
                }

                ToolSet.SetParent(obj.displayObject.cachedTransform, _poolManager);
            }
        }
示例#6
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;
        }
示例#7
0
        static public void Parse(string aSource, TextFormat defaultFormat, List <HtmlElement> elements)
        {
            _elements = elements;

            int    pos = 0, pos2, length = 0, tagType = 0;
            string tagName = null;
            string tagSource;
            int    skipText = 0;

            sTextFormatStackTop = 0;
            _format.CopyFrom(defaultFormat);

            while ((pos2 = EnumTag(aSource, pos, ref tagName, ref length, ref tagType)) != -1)
            {
                if (pos != pos2 && skipText == 0)
                {
                    AppendText(aSource.Substring(pos, pos2 - pos), true);
                }

                tagSource = aSource.Substring(pos2, length);
                switch (tagName)
                {
                case "b":
                    if (tagType == 0)
                    {
                        PushTextFormat(_format);
                        _format.bold = true;
                    }
                    else
                    {
                        PopTextFormat(_format);
                    }
                    break;

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

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

                case "sub":
                    break;

                case "sup":
                    break;

                case "font":
                    if (tagType == 0)
                    {
                        PushTextFormat(_format);
                        string[] values = GetAttributeValue(tagSource, fontAttrNames);
                        string   size   = values[0];
                        if (size != null)
                        {
                            _format.size = Convert.ToInt32(size);
                        }
                        string color = values[1];
                        if (color != null)
                        {
                            _format.color = ToolSet.ConvertFromHtmlColor(color);
                        }
                    }
                    else if (tagType == 1)
                    {
                        PopTextFormat(_format);
                    }
                    break;

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

                case "img":
                    if (tagType == 0 || tagType == 2)
                    {
                        string[]        values = GetAttributeValue(tagSource, imgAttrNames);
                        HtmlElement_Img element;
                        if (sImgElementPool.Count > 0)
                        {
                            element = sImgElementPool.Pop();
                        }
                        else
                        {
                            element = new HtmlElement_Img();
                        }
                        element.src = values[0];
                        if (values[1] != null)
                        {
                            element.width = Convert.ToInt32(values[1]);
                        }
                        else
                        {
                            element.width = 0;
                        }
                        if (values[2] != null)
                        {
                            element.height = Convert.ToInt32(values[2]);
                        }
                        else
                        {
                            element.height = 0;
                        }
                        _elements.Add(element);
                    }
                    break;

                case "a":
                    if (tagType == 0)
                    {
                        string[]      values = GetAttributeValue(tagSource, aAttrNames);
                        HtmlElement_A element;
                        if (sAElementPool.Count > 0)
                        {
                            element = sAElementPool.Pop();
                        }
                        else
                        {
                            element = new HtmlElement_A();
                        }
                        element.href   = values[0];
                        element.target = values[1];
                        element.end    = false;
                        _elements.Add(element);
                    }
                    else if (tagType == 1)
                    {
                        HtmlElement_A element;
                        if (sAElementPool.Count > 0)
                        {
                            element = sAElementPool.Pop();
                        }
                        else
                        {
                            element = new HtmlElement_A();
                        }
                        element.end = true;
                        _elements.Add(element);
                    }
                    break;
                }

                pos = pos2 + length;
            }

            if (pos != aSource.Length)
            {
                AppendText(aSource.Substring(pos, aSource.Length - pos), true);
            }

            _elements = null;
        }