Exemple #1
0
        /// <summary>
        /// 调整(调整顶点坐标)
        /// </summary>
        /// <param name="cd">字符数据</param>
        /// <param name="frag">片段数据</param>
        public override void adjust(QuestionTextParser.CharData cd, FragmentData frag)
        {
            var offset = textObj.enterHeight * OffsetRate;

            cd.offset(0, -offset);
            base.adjust(cd, frag);
        }
Exemple #2
0
        /// <summary>
        /// 获取匹配的具体信息
        /// </summary>
        /// <param name="frag">片段数据</param>
        /// <param name="maxWidth">最大宽度</param>
        /// <param name="texture">纹理</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        void getMatchInfo(FragmentData frag, float maxWidth,
                          out Texture2D texture, out float width, out float height)
        {
            var info = (FragmentData.MatchInfo)frag.info;

            getMatchInfo(info.match, maxWidth, out texture, out width, out height);
        }
Exemple #3
0
        /// <summary>
        /// 处理(进行实际处理)
        /// </summary>
        /// <param name="cd">字符数据</param>
        /// <param name="frag">片段数据</param>
        public override void handle(QuestionTextParser.CharData cd, FragmentData frag)
        {
            QuestionText.TestLog("handle: "); cd.display();
            var image = getImageObject(handleCnt);

            setImagePosition(image, cd.verts);
            base.handle(cd, frag);
        }
Exemple #4
0
        /// <summary>
        /// 处理(生成片段数据)
        /// </summary>
        /// <param name="text">原文本</param>
        string generateResText(string text)
        {
            fragData = new FragmentData(text, 0, oriText.Length);
            string resText = "";

            build(fragData); // 递归构建片段树
            fragData.traverse(ref resText);

            QuestionText.TestLog("====== Processed ======");
            fragData.display();

            return(resText);
        }
Exemple #5
0
        /// <summary>
        /// 预处理
        /// </summary>
        /// <param name="cd">字符数据</param>
        /// <param name="frag">片段数据</param>
        public override void config(QuestionTextParser.CharData cd, FragmentData frag)
        {
            var image = getImageObject(imageCnt++);

            if (embedImage())
            {
                Texture2D texture; float width, height;
                var       mw = textObj.rectTransform.rect.width;
                getMatchInfo(frag, mw, out texture, out width, out height);
                setImageTexture(image, texture, width, height);
                setRectTransform(image.rectTransform, width, height);
            }
            else
            {
                var index = getTextureIndex(frag);
                var size  = setImageLink(image, index);
                setRectTransform(image.rectTransform, size.x, size.y);
            }
            base.config(cd, frag);
        }
Exemple #6
0
        /// <summary>
        /// 递归构建片段树
        /// </summary>
        /// <param name="parent">父片段</param>
        void build(FragmentData parent)
        {
            var matchInfo = new List <FragmentData.MatchInfo>();
            var text      = parent.text;

            // 进行正则表达式匹配,找到每个标签项的范围
            for (int i = 0; i < handlers.Count; ++i)
            {
                var             handler    = handlers[i];
                MatchCollection tmpMatches = handler.matches(text);
                foreach (Match match in tmpMatches)
                {
                    matchInfo.Add(new FragmentData.MatchInfo(match, handler));
                }
            }
            if (matchInfo.Count <= 0)
            {
                return;                       // 如果没有特殊标签,直接返回
            }
            QuestionText.TestLog("====== Matched ======");
            foreach (var m in matchInfo)
            {
                m.display();
            }

            matchInfo.Sort();

            int    ls = -1, le = -1;        // 上一个(有记录的) s 和 e
            int    ms, me;                  // 每个匹配项的 s 和 e
            var    lastInfo = matchInfo[0]; // 上一个匹配项
            string subText;

            // 遍历每个匹配项
            //for (int i = mi; i < mj; ++i) {
            foreach (var info in matchInfo)
            {
                ms = info.start(); me = info.end();
                if (ls == -1 && le == -1)   // 如果是第一个匹配项(0...ms[.....)

                // 该匹配项之前的文本均为普通文本,建立叶子结点
                {
                    subText = text.Substring(0, ms);
                    var child = new FragmentData(subText, 0, ms);
                    parent.children.Add(child);

                    lastInfo = info;
                    ls       = ms; le = me; // 记录当前匹配项数据

                    /* } else if (ms < le && me > le) { // 当两个匹配项重叠的时候(ls[..ms[..]le..]me..)
                     *  // 这时候只有当两个标签相同才处理(因为正则表达式无法处理内嵌的情况,在这里进行处理)
                     *  if (info.handler.tag() == lastInfo.handler.tag()) {
                     *      // 只生成一段:ls - me
                     *      subText = text.Substring(ls, me - ls);
                     *      QuestionText.TestLog("SubText = " + subText);
                     *      var child = new FragmentData(subText, ls, me, lastInfo);
                     *      parent.children.Add(child); // 添加子树
                     *      build(child); // 递归建树
                     *
                     *      le = me;
                     *  } */
                }
                if (ms >= le)   // 当当前匹配项起始位置大于已有匹配项的末位置(ls[...]le..ms[...)

                // 建立上一个匹配项的子节点
                {
                    var child1 = new FragmentData(ls, le, lastInfo);
                    parent.children.Add(child1); // 添加子树
                    build(child1);               // 递归建树

                    // 建立两个匹配项之间的子节点
                    subText = text.Substring(le, ms - le);
                    var child2 = new FragmentData(subText, le, ms);
                    parent.children.Add(child2); // 添加子树

                    lastInfo = info;
                    ls       = ms; le = me; // 记录当前匹配项数据
                }
            }

            // 处理最后一个匹配项(ls[....]le....text.Length)
            // 建立最后一个匹配项的子节点
            var lastChild1 = new FragmentData(ls, le, lastInfo);

            parent.children.Add(lastChild1); // 添加子树
            build(lastChild1);               // 递归建树

            // 建立到文本末尾的子节点
            subText = text.Substring(le, text.Length - le);
            var lastChild2 = new FragmentData(subText, le, text.Length);

            parent.children.Add(lastChild2); // 添加子树
        }
Exemple #7
0
 /// <summary>
 /// 获取纹理
 /// </summary>
 /// <param name="frag">片段</param>
 /// <returns>纹理</returns>
 Texture2D getTexture(FragmentData frag)
 {
     return(getTexture(getTextureIndex(frag)));
 }
Exemple #8
0
        /// <summary>
        /// 获取图片尺寸
        /// </summary>
        /// <param name="frag">片段</param>
        /// <returns>返回图片尺寸(宽度)</returns>
        int getTextureSize(FragmentData frag)
        {
            var info = (FragmentData.MatchInfo)frag.info;

            return(getTextureIndex(info.match));
        }
Exemple #9
0
 /// <summary>
 /// 处理(进行实际处理)
 /// </summary>
 /// <param name="cd">字符数据</param>
 /// <param name="frag">片段数据</param>
 public virtual void handle(QuestionTextParser.CharData cd,
                            FragmentData frag)
 {
     handleCnt++;
 }
Exemple #10
0
 /// <summary>
 /// 调整(调整顶点坐标)
 /// </summary>
 /// <param name="cd">字符数据</param>
 /// <param name="frag">片段数据</param>
 public virtual void adjust(QuestionTextParser.CharData cd,
                            FragmentData frag)
 {
     adjustCnt++;
 }
Exemple #11
0
 /// <summary>
 /// 配置(OnPopulateMesh 前执行)
 /// </summary>
 /// <param name="cd">字符数据</param>
 /// <param name="frag">片段数据</param>
 public virtual void config(QuestionTextParser.CharData cd,
                            FragmentData frag)
 {
     configCnt++;
 }