Beispiel #1
0
        public int SetText(TextLabel label, string str)
        {
            if (label == null || str == null)
            {
                return(0);
            }

            // perform this operation to match the utf32 character used in native Dali.
            bool previousMarkup = label.EnableMarkup;

            label.EnableMarkup = false;
            label.Text         = str;
            pageString         = label.Text;
            label.EnableMarkup = previousMarkup;
            label.MultiLine    = true;
            label.Ellipsis     = false;

            int length       = pageString.Length;
            int remainLength = length;
            int offset       = 0;
            int cutOffIndex  = 0;

            // init
            totalPageCnt  = 0;
            pageList      = new List <PageData>();
            tagList       = new List <TagData>();
            characterList = new List <char>();

            stream = new StringReader(pageString);

            RendererParameters textParameters = new RendererParameters();

            textParameters.Text = pageString;
            textParameters.HorizontalAlignment = label.HorizontalAlignment;
            textParameters.VerticalAlignment   = label.VerticalAlignment;
            textParameters.FontFamily          = label.FontFamily;
            textParameters.FontWeight          = "";
            textParameters.FontWidth           = "";
            textParameters.FontSlant           = "";
            textParameters.Layout          = TextLayout.MultiLine;
            textParameters.TextColor       = Color.Black;
            textParameters.FontSize        = label.PointSize;
            textParameters.TextWidth       = (uint)label.Size.Width;
            textParameters.TextHeight      = (uint)label.Size.Height;
            textParameters.EllipsisEnabled = true;
            textParameters.MarkupEnabled   = previousMarkup;
            textParameters.MinLineSize     = label.MinLineSize;
            textParameters.Padding         = label.Padding;


            Tizen.NUI.PropertyArray cutOffIndexArray = TextUtils.GetLastCharacterIndex(textParameters);
            uint count = cutOffIndexArray.Count();

            for (uint i = 0; i < count; i++)
            {
                var temp = cutOffIndexArray.GetElementAt(i);
                temp.Get(out cutOffIndex); // Gets the last index of text shown on the actual screen.
                temp.Dispose();

                // If markup is enabled, It should parse markup
                if (label.EnableMarkup)
                {
                    int preOffset = offset;
                    offset        = MarkupProcess(offset, cutOffIndex - preOffset);
                    remainLength -= (offset - preOffset);
                }
                //If markup is not enabled, parsing is not required.
                else
                {
                    PageData pageData = new PageData();
                    pageData.StartOffset = offset;
                    int cnt = (cutOffIndex - offset) < remainLength ? (cutOffIndex - offset) : remainLength;
                    remainLength      -= cnt;
                    offset            += cnt;
                    pageData.EndOffset = offset;
                    pageList.Add(pageData);
                }
                totalPageCnt++;
                if (offset <= 0 || remainLength <= 0)
                {
                    break;
                }
            }

            textParameters.Dispose();
            cutOffIndexArray.Dispose();
            stream = null;
            return(totalPageCnt);
        }
Beispiel #2
0
        private int MarkupProcess(int startOffset, int cutOffIndex)
        {
            int count     = 0;
            int offset    = startOffset;
            int character = 0;

            characterList.Clear();
            PageData pageData = new PageData();

            pageData.StartOffset = offset;

            // If the markup was previously open, the markup tag should be attached to the front.
            string tag = "";

            foreach (TagData data in tagList)
            {
                tag += "<" + data.TagName + data.AttributeName + ">";
            }
            pageData.PreviousTag = tag;


            bool isTag = false;

            while ((character = stream.Read()) != -1)
            {
                offset++;
                characterList.Add((char)character);

                TagData tagData = new TagData();
                isTag = false;
                if (LESS_THAN == character) // '<'
                {
                    isTag = IsTag(tagData, ref offset);
                }

                if (isTag)
                {
                    if (tagData.IsEndTag)
                    {
                        int lastIndex = tagList.Count;
                        tagList.RemoveAt(lastIndex - 1);
                    }
                    else
                    {
                        tagList.Add(tagData);
                    }
                }
                else
                {
                    count++;
                }
                if (count >= cutOffIndex)
                {
                    break;
                }
            }

            // If the markup was previously open, you should attach the label tag.
            tag = "";
            foreach (TagData data in tagList)
            {
                tag = "</" + data.TagName + ">" + tag;
            }
            pageData.EndTag = tag;

            pageData.EndOffset = offset;
            pageList.Add(pageData);

            if (character == -1)
            {
                offset = -1;
            }
            return(offset);
        }