Beispiel #1
0
        /// <summary>
        /// 设置成对出现字符串
        /// </summary>
        /// <param name="lnpro"></param>
        /// <param name="startC"></param>
        /// <param name="endC"></param>
        /// <param name="index"></param>
        /// <param name="lineIndex"></param>
        private void SetCouple(LineNodeProperty lnpro, char startC, char endC, int index, int lineIndex, ECouplePropertyDirection epd)
        {
            var coupleProperty = new CoupleProperty()
            {
                FindChar   = endC,
                PChar      = startC,
                WordIndex  = index,
                LineIndex  = lineIndex,
                LNProperty = lnpro,
                PECouplePropertyDirection = epd
            };


            if (lnpro.Couple == null)
            {
                lnpro.Couple = new Dictionary <int, CoupleProperty>();
            }
            lnpro.Couple.Add(lineIndex, coupleProperty);
            if (this.pCoupleProperty == null)
            {
                this.pCoupleProperty = coupleProperty;
            }
            else
            {
                var last = pCoupleProperty;
                last.NextNode         = coupleProperty;
                coupleProperty.UpNode = last;
                this.pCoupleProperty  = coupleProperty;
            }
        }
Beispiel #2
0
 private void SetLNProperty(/*int y, */ ref LineNodeProperty lnPro)
 {
     if (lnPro == null)
     {
         lnPro = new LineNodeProperty();
     }
 }
Beispiel #3
0
        //private int pWIStyleY;

        /// <summary>
        /// 获取行字符串
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public LineString GetLineString(string line /*, int y*/)
        {
            this.pCoupleProperty = null;
            var pUseWord = new List <Tuple <Word, UseWordFont> >();

            line = line.TrimEnd(CharCommand.Char_Enter);
            int              length = 0;
            int              index  = 0;
            Word             w;
            WFontColor       wfc;
            WordIncluedStyle wiStyle    = null;
            LineNodeProperty lnProperty = null;
            var              lineString = GetLineString();

            lineString.PWord = new List <Word>();
            lineString.Text  = string.Empty;
            while (length < line.Length)
            {
                bool isSetWFC = true;
                char c        = line[length];
                w = new Word();
                switch (c)
                {
                case CharCommand.Char_Tab:
                    //for (var i = 0; i < this.pLanguageMode.TabSpaceCount - 1; i++) {
                    //    var wSpace = new Word();
                    //    wSpace.Text = " ";
                    //    wSpace.PEWordType = EWordType.Space;
                    //    lineString.Text += wSpace.Text;
                    //    wSpace.LineIndex = index++;
                    //    lineString.PWord.Add(wSpace);
                    //}
                    //w = new Word();
                    w.PEWordType = EWordType.Space;
                    w.Text       = " ";
                    line         = line.Substring(0, length) + " ".PadLeft(this.pLanguageMode.TabSpaceCount) + line.Substring(length + 1);
                    break;

                case CharCommand.Char_Space:
                    //w = new Word();
                    w.PEWordType = EWordType.Space;
                    w.Text       = c.ToString();
                    break;

                default:
                    if (pLanguageMode.CompartChars.Contains(c))
                    {
                        w.PEWordType = EWordType.Compart;
                        w.Text       = c.ToString();
                        if (pLanguageMode.CompartCharFont.TryGetValue(c, out wfc))
                        {
                            w.PFont = wfc;
                        }
                        #region 包含不换行颜色
                        if (wiStyle == null)
                        {
                            wiStyle = GetIncludeFont(c, wiStyle, line, ref length);
                            if (wiStyle != null)
                            {
                                w.Text  = wiStyle.Text;
                                wiStyle = SetMoreLineStartStyle(wiStyle, lineString, index);
                            }
                        }
                        else if (wiStyle.IsEndStr)
                        {
                            if (EndIncludeFont(c, wiStyle, w, line, ref length))
                            {
                                w.PIncluedFont = wiStyle.PFontColor;
                                wiStyle        = null;
                                isSetWFC       = false;
                            }
                        }
                        SetMoreLineEndStyle(lineString, c, w, line, index, ref length);
                        #endregion
                        #region 是否行属性
                        if (wiStyle == null)
                        {
                            lnProperty = GetLineNodeProperty(c, length, index, /*y,*/ lnProperty);
                        }
                        #endregion
                    }
                    else
                    {
                        //w = new Word();
                        w.PEWordType = EWordType.Word;
                        w.Text       = c.ToString() + GetTag(line, ref length);
                        if (pLanguageMode.WordFonts.TryGetValue(w.Text, out wfc))
                        {
                            w.PFont = wfc;
                        }

                        if (w.PEWordType == EWordType.Word && this.pIEdit.SetWordStyleEvent != null && w.PFont == null)
                        {
                            w.PFont = this.pIEdit.SetWordStyleEvent(w.Text);
                        }
                    }
                    #region  自定义样式
                    if (pLanguageMode.UseBefore != null)
                    {
                        if (pLanguageMode.UseBefore.ContainsKey(w.Text))
                        {
                            pUseWord.Add(Tuple.Create(w, pLanguageMode.UseBefore[w.Text]));
                        }
                    }
                    if (pLanguageMode.UseAfter != null)
                    {
                        if (pLanguageMode.UseAfter.ContainsKey(w.Text))
                        {
                            pUseWord.Add(Tuple.Create(w, pLanguageMode.UseAfter[w.Text]));
                        }
                    }
                    #endregion

                    break;
                }
                lineString.Text += w.Text;
                w.LineIndex      = index++;
                if (wiStyle != null && isSetWFC)
                {
                    w.PIncluedFont = wiStyle.PFontColor;
                }
                lineString.PWord.Add(w);
                length++;
            }

            lineString.PLNProperty = lnProperty;
            this.SetUseWordFont(pUseWord, lineString.PWord);
            return(lineString);
        }
Beispiel #4
0
        /// <summary>
        /// 设置当前行的属性值
        /// </summary>
        /// <param name="c">当前字符</param>
        /// <param name="length">当前字符出现在字符串中的位置</param>
        /// <param name="index">当前字符出现在字符串中WORDS中的位置</param>
        /// <param name="y">当前行</param>
        /// <param name="lnp">当前行属性</param>
        /// <returns></returns>
        private LineNodeProperty GetLineNodeProperty(char c, int length, int index, /* int y,*/ LineNodeProperty lnp)
        {
            #region 块
            if (this.pLanguageMode.Range != null)
            {
                if (c == this.pLanguageMode.Range.Item1)
                {
                    SetLNProperty(/*y,*/ ref lnp);
                    if (lnp.IsEndRange)
                    {
                        lnp.IsEndRange = false;
                    }
                    else
                    {
                        lnp.IsStartRange = true;
                    }
                    lnp.IndexForLineWords  = index;
                    lnp.IndexForLineString = length;
                }
                else if (c == this.pLanguageMode.Range.Item2)
                {
                    SetLNProperty(/*y,*/ ref lnp);
                    if (lnp.IsStartRange)
                    {
                        lnp.IsStartRange = false;
                    }
                    else
                    {
                        lnp.IsEndRange = true;
                    }
                    lnp.IndexForLineWords  = index;
                    lnp.IndexForLineString = length;
                }
            }
            #endregion
            #region 成对字符
            if (this.pLanguageMode.CoupleStart != null)
            {
                if (this.pLanguageMode.CoupleStart.ContainsKey(c))
                {
                    SetLNProperty(/*y, */ ref lnp);
                    SetCouple(lnp, c, this.pLanguageMode.CoupleStart[c], index, length, ECouplePropertyDirection.Rear);
                }
            }
            if (this.pLanguageMode.CoupleEnd != null)
            {
                if (this.pLanguageMode.CoupleEnd.ContainsKey(c))
                {
                    SetLNProperty(/*y, */ ref lnp);
                    SetCouple(lnp, c, this.pLanguageMode.CoupleEnd[c], index, length, ECouplePropertyDirection.Ahead);
                }
            }

            #endregion
            return(lnp);
        }