示例#1
0
        /// <summary>
        /// Renders a single line of text
        /// </summary>
        private void renderLine(LineRenderInfo line, Stack <Color32> colors, Vector3 position, dfRenderData destination)
        {
            position.x += calculateLineAlignment(line);

            for (int i = line.startOffset; i <= line.endOffset; i++)
            {
                var token = tokens[i];
                var type  = token.TokenType;

                if (type == dfMarkupTokenType.Text)
                {
                    renderText(token, colors.Peek(), position, destination);
                }
                else if (type == dfMarkupTokenType.StartTag)
                {
                    if (token.Matches("sprite") && SpriteAtlas != null && SpriteBuffer != null)
                    {
                        renderSprite(token, colors.Peek(), position, SpriteBuffer);
                    }
                    else if (token.Matches("color"))
                    {
                        colors.Push(parseColor(token));
                    }
                }
                else if (type == dfMarkupTokenType.EndTag)
                {
                    if (token.Matches("color") && colors.Count > 1)
                    {
                        colors.Pop();
                    }
                }

                position.x += token.Width;
            }
        }
示例#2
0
        private void calculateLineSize(LineRenderInfo line)
        {
            var font = (dfDynamicFont)Font;

            line.lineHeight = font.Baseline * TextScale;

            var width = 0;

            for (int i = line.startOffset; i <= line.endOffset; i++)
            {
                width += tokens[i].Width;
            }

            line.lineWidth = width;
        }
示例#3
0
        public override void Release()
        {
            this.Reset();

            this.tokens = null;

            if (lines != null)
            {
                lines.Release();
                lines = null;
            }

            LineRenderInfo.ResetPool();

            this.BottomColor = (Color32?)null;

            objectPool.Enqueue(this);
        }
示例#4
0
        private int calculateLineAlignment(LineRenderInfo line)
        {
            var width = line.lineWidth;

            if (TextAlign == TextAlignment.Left || width < 1)
            {
                return(0);
            }

            var x = 0f;

            if (TextAlign == TextAlignment.Right)
            {
                x = MaxSize.x - width;
            }
            else
            {
                x = (MaxSize.x - width) * 0.5f;
            }

            return(Mathf.CeilToInt(Mathf.Max(0f, x)));
        }
示例#5
0
        /// <summary>
        /// Determine where each line of text starts. Assumes that the
        /// tokens array is already populated and that the render size
        /// of each token has already been determined.
        /// </summary>
        /// <returns></returns>
        private dfList <LineRenderInfo> calculateLinebreaks()
        {
            try
            {
                //@Profiler.BeginSample( "Calculate line breaks" );

                if (lines != null)
                {
                    return(lines);
                }

                lines = dfList <LineRenderInfo> .Obtain();

                var font       = (dfDynamicFont)Font;
                var lastBreak  = 0;
                var startIndex = 0;
                var index      = 0;
                var lineWidth  = 0;
                var lineHeight = font.Baseline * TextScale;

                while (index < tokens.Count && lines.Count * lineHeight <= MaxSize.y + lineHeight)
                {
                    var token = tokens[index];
                    var type  = token.TokenType;

                    if (type == dfMarkupTokenType.Newline)
                    {
                        lines.Add(LineRenderInfo.Obtain(startIndex, index));

                        startIndex = lastBreak = ++index;
                        lineWidth  = 0;

                        continue;
                    }

                    var tokenWidth = Mathf.CeilToInt(token.Width);

                    var canWrap =
                        WordWrap &&
                        lastBreak > startIndex &&
                        (
                            type == dfMarkupTokenType.Text ||
                            (type == dfMarkupTokenType.StartTag && token.Matches("sprite"))
                        );

                    if (canWrap && lineWidth + tokenWidth >= MaxSize.x)
                    {
                        if (lastBreak > startIndex)
                        {
                            lines.Add(LineRenderInfo.Obtain(startIndex, lastBreak - 1));

                            startIndex = index = ++lastBreak;
                            lineWidth  = 0;
                        }
                        else
                        {
                            lines.Add(LineRenderInfo.Obtain(startIndex, lastBreak - 1));

                            startIndex = lastBreak = ++index;
                            lineWidth  = 0;
                        }

                        continue;
                    }

                    if (type == dfMarkupTokenType.Whitespace)
                    {
                        lastBreak = index;
                    }

                    lineWidth += tokenWidth;
                    index     += 1;
                }

                if (startIndex < tokens.Count)
                {
                    lines.Add(LineRenderInfo.Obtain(startIndex, tokens.Count - 1));
                }

                for (int i = 0; i < lines.Count; i++)
                {
                    calculateLineSize(lines[i]);
                }

                return(lines);
            }
            finally
            {
                //@Profiler.EndSample();
            }
        }
示例#6
0
		/// <summary>
		/// Renders a single line of text
		/// </summary>
		private void renderLine( LineRenderInfo line, Stack<Color32> colors, Vector3 position, dfRenderData destination )
		{

			position.x += calculateLineAlignment( line );

			for( int i = line.startOffset; i <= line.endOffset; i++ )
			{

				var token = tokens[ i ];
				var type = token.TokenType;

				if( type == dfMarkupTokenType.Text )
				{
					renderText( token, colors.Peek(), position, destination );
				}
				else if( type == dfMarkupTokenType.StartTag )
				{
					if( token.Matches( "sprite" ) && SpriteAtlas != null && SpriteBuffer != null )
					{
						renderSprite( token, colors.Peek(), position, SpriteBuffer );
					}
					else if( token.Matches( "color" ) )
					{
						colors.Push( parseColor( token ) );
					}
				}
				else if( type == dfMarkupTokenType.EndTag )
				{
					if( token.Matches( "color" ) && colors.Count > 1 )
					{
						colors.Pop();
					}
				}

				position.x += token.Width;

			}

		}
示例#7
0
		private void calculateLineSize( LineRenderInfo line )
		{

			var font = (dfDynamicFont)Font;
			line.lineHeight = font.Baseline * TextScale;

			var width = 0;
			for( int i = line.startOffset; i <= line.endOffset; i++ )
			{
				width += tokens[ i ].Width;
			}

			line.lineWidth = width;

		}
示例#8
0
		private int calculateLineAlignment( LineRenderInfo line )
		{

			var width = line.lineWidth;

			if( TextAlign == TextAlignment.Left || width < 1 )
				return 0;

			var x = 0f;

			if( TextAlign == TextAlignment.Right )
			{
				x = MaxSize.x - width;
			}
			else
			{
				x = ( MaxSize.x - width ) * 0.5f;
			}

			return Mathf.CeilToInt( Mathf.Max( 0f, x ) );

		}