コード例 #1
0
 public TextInfo(string text, TextStyle style = null)
 {
     Text   = text;
     Styles = new TextStyle(style);
 }
コード例 #2
0
        /// <summary>
        /// Attach content to end of this paragraph by same styles
        /// </summary>
        /// <param name="contentOffset">The offset of attached content inflowing of this paragraph</param>
        /// <param name="content">Text of content which is want to attached at this paragraph</param>
        /// <param name="contentStyle">The given styles will be applied on the all of given content</param>
        public void AddContent(int contentOffset, string content, TextStyle contentStyle)
        {
            var wordBuffer = "";
            var offset     = contentOffset;

            for (var i = 0; i < content.Length; i++)
            {
                var charPointer = content[i];
                // is current char a space char?
                if (charPointer == ' ')
                {
                    if (wordBuffer.Length > 0)
                    {
                        AddWord(new WordInfo(wordBuffer, offset, WordType.Normal, contentStyle))
                        .Styles.SetDirection(IsRtl(wordBuffer));
                    }

                    wordBuffer = "";

                    // add space char as word
                    // note: space.IsRtl will complete calculate after adding all words
                    var spaceIsRtl = Styles.IsRtl == Words.LastOrDefault()?.Styles.IsRtl;
                    AddWord(new SpaceWord(contentOffset + i, contentStyle))
                    .Styles.SetDirection(spaceIsRtl);

                    // maybe there are exist multiple sequence space, so we set offset outside of the keeping word buffer.
                    offset = contentOffset + i + 1; // set next word offset
                    continue;
                }
                // is current char a inert char?
                if (InertChars.Contains(charPointer))
                {
                    if (wordBuffer.Length > 0)
                    {
                        AddWord(new WordInfo(wordBuffer, offset, WordType.Normal | WordType.Attached, contentStyle))
                        .Styles.SetDirection(IsRtl(wordBuffer));
                    }

                    wordBuffer = "";

                    // add inert char as word
                    var isInnerWord = i + 1 < content.Length && content[i + 1] != ' ';
                    var inertIsRtl  = IsRtl(charPointer) || Styles.IsRtl == Words.LastOrDefault()?.Styles.IsRtl;
                    AddWord(new WordInfo(charPointer.ToString(), contentOffset + i,
                                         isInnerWord ? WordType.Attached | WordType.InertChar : WordType.InertChar, contentStyle))
                    .Styles.SetDirection(inertIsRtl);

                    offset = contentOffset + i + 1; // set next word offset
                    continue;
                }
                //
                // keep letter or digit in buffer
                wordBuffer += charPointer;
            }
            //
            // keep last word from buffer
            if (wordBuffer.Length > 0)
            {
                AddWord(new WordInfo(wordBuffer, offset, WordType.Normal, contentStyle))
                .Styles.SetDirection(IsRtl(wordBuffer));
            }
        }