Beispiel #1
0
        private void ParseSpriteTags(string strText)
        {
            if (string.IsNullOrEmpty(strText) || -1 == strText.IndexOf("quad"))
            {
                _ResetSpriteTags(0);
                return;
            }
            ImageCache imageCache = null;

            if (m_SupportCache)
            {
                imageCache = CacheManager.Instance.GetImgCache(strText.GetHashCode());
                if (imageCache != null)
                {
                    List <ImageCache.CacheImageTag> imageCacheParms = imageCache.GetParams();
                    for (int i = 0; i < imageCacheParms.Count; ++i)
                    {
                        SpriteTag tag = _GetSpriteTag(1);
                        if (imageCacheParms[i].paramDic != null)
                        {
                            var iter = imageCacheParms[i].paramDic.GetEnumerator();
                            while (iter.MoveNext())
                            {
                                tag.CheckSetValue(imageCacheParms[i].position, iter.Current.Key, iter.Current.Value);
                            }
                            iter.Dispose();
                        }
                    }
                    _ResetSpriteTags(imageCacheParms.Count);
                }
            }

            int imgCount = 0;

            XMLIterator.Begin(strText, false);
            string textBlock = string.Empty;

            mTagPos.Clear();
            int tagLength       = 0;
            int mImgTagCount    = 0;
            int line            = 0;
            int richXMLTagCount = 0;

            while (XMLIterator.NextTag())
            {
                mParses.Clear();
                if (XMLIterator.tagName == mImgTag)
                {
                    {
                        line = Regex.Matches(strText.Substring(0, XMLIterator.parsePos), "\n").Count;

                        mTagPos[mImgTag] = XMLIterator.parsePos + XMLIterator.tagLength;
                        XMLIterator.GetAttributes(mParses);
                        SpriteTag tag = _GetSpriteTag(imgCount);
                        tagLength += XMLIterator.tagLength;
                        foreach (var val in mParses)
                        {
                            tag.CheckSetValue(XMLIterator.parsePos + mImgTagCount - tagLength - line - richXMLTagCount, val.Key, val.Value);
                        }
                        mImgTagCount++;
                    }

                    if (m_SupportCache)
                    {
                        SpriteTag tag = _GetSpriteTag(imgCount);
                        imageCache = CacheManager.Instance.AddImgCache(strText.GetHashCode());
                        ImageCache.CacheImageTag cacheTag = new ImageCache.CacheImageTag();
                        if (cacheTag.paramDic == null)
                        {
                            cacheTag.paramDic = new Dictionary <string, string>();
                        }
                        cacheTag.position           = tag.GetVertexStartIndex();
                        cacheTag.paramDic["name"]   = tag.GetName();
                        cacheTag.paramDic["src"]    = tag.GetSrc();
                        cacheTag.paramDic["width"]  = tag.GetWidth();
                        cacheTag.paramDic["height"] = tag.GetHeight();
                        if (m_SupportDynamicChart)
                        {
                            cacheTag.paramDic["start"] = tag.GetStartFrame().ToString();
                            cacheTag.paramDic["end"]   = tag.GetEndFrame().ToString();
                        }

                        imageCache.AddParams(cacheTag);
                    }
                    ++imgCount;
                }
                else
                {
                    if (XMLIterator.tagName.StartsWith("color") || XMLIterator.tagName.StartsWith("b") || XMLIterator.tagName.StartsWith("i") || XMLIterator.tagName.StartsWith("size"))
                    {
                        richXMLTagCount += XMLIterator.tagLength;
                    }
                }
            }
            _ResetSpriteTags(imgCount);
        }