Example #1
0
        private void renderLine(dfFont.LineRenderInfo line, Stack <Color32> colors, Vector3 position, dfRenderData destination)
        {
            float textScale = base.TextScale * base.PixelRatio;

            position.x = position.x + (float)this.calculateLineAlignment(line) * textScale;
            for (int i = line.startOffset; i <= line.endOffset; i++)
            {
                dfMarkupToken     item      = this.tokens[i];
                dfMarkupTokenType tokenType = item.TokenType;
                if (tokenType == dfMarkupTokenType.Text)
                {
                    this.renderText(item, colors.Peek(), position, destination);
                }
                else if (tokenType != dfMarkupTokenType.StartTag)
                {
                    if (tokenType == dfMarkupTokenType.EndTag && item.Matches("color") && colors.Count > 1)
                    {
                        colors.Pop();
                    }
                }
                else if (item.Matches("sprite"))
                {
                    this.renderSprite(item, colors.Peek(), position, destination);
                }
                else if (item.Matches("color"))
                {
                    colors.Push(this.parseColor(item));
                }
                position.x = position.x + (float)item.Width * textScale;
            }
        }
Example #2
0
        public override void Render(string text, dfRenderData destination)
        {
            textColors.Clear();
            textColors.Push(Color.white);
            this.tokenize(text);
            dfList <dfFont.LineRenderInfo> list = this.calculateLinebreaks();
            int     b            = 0;
            int     num2         = 0;
            Vector3 vectorOffset = base.VectorOffset;
            float   num3         = base.TextScale * base.PixelRatio;

            for (int i = 0; i < list.Count; i++)
            {
                dfFont.LineRenderInfo info = list[i];
                int count = destination.Vertices.Count;
                this.renderLine(list[i], textColors, vectorOffset, destination);
                vectorOffset.y -= base.Font.LineHeight * num3;
                b     = Mathf.Max((int)info.lineWidth, b);
                num2 += (int)info.lineHeight;
                if ((info.lineWidth * base.TextScale) > base.MaxSize.x)
                {
                    this.clipRight(destination, count);
                }
                if ((num2 * base.TextScale) > base.MaxSize.y)
                {
                    this.clipBottom(destination, count);
                }
            }
            base.RenderedSize = (Vector2)(new Vector2(Mathf.Min(base.MaxSize.x, (float)b), Mathf.Min(base.MaxSize.y, (float)num2)) * base.TextScale);
        }
Example #3
0
        public override void Render(string text, dfRenderData destination)
        {
            dfFont.BitmappedFontRenderer.textColors.Clear();
            dfFont.BitmappedFontRenderer.textColors.Push(Color.white);
            this.tokenize(text);
            dfList <dfFont.LineRenderInfo> lineRenderInfos = this.calculateLinebreaks();
            int     num          = 0;
            int     num1         = 0;
            Vector3 vectorOffset = base.VectorOffset;
            float   textScale    = base.TextScale * base.PixelRatio;

            for (int i = 0; i < lineRenderInfos.Count; i++)
            {
                dfFont.LineRenderInfo item = lineRenderInfos[i];
                int count = destination.Vertices.Count;
                this.renderLine(lineRenderInfos[i], dfFont.BitmappedFontRenderer.textColors, vectorOffset, destination);
                vectorOffset.y = vectorOffset.y - (float)base.Font.LineHeight * textScale;
                num            = Mathf.Max((int)item.lineWidth, num);
                num1           = num1 + (int)item.lineHeight;
                if (item.lineWidth * base.TextScale > base.MaxSize.x)
                {
                    this.clipRight(destination, count);
                }
                if ((float)num1 * base.TextScale > base.MaxSize.y)
                {
                    this.clipBottom(destination, count);
                }
            }
            Vector2 maxSize = base.MaxSize;
            float   single  = Mathf.Min(maxSize.x, (float)num);
            Vector2 vector2 = base.MaxSize;

            base.RenderedSize = new Vector2(single, Mathf.Min(vector2.y, (float)num1)) * base.TextScale;
        }
Example #4
0
        private void calculateLineSize(dfFont.LineRenderInfo line)
        {
            line.lineHeight = base.Font.LineHeight;
            int num = 0;

            for (int i = line.startOffset; i <= line.endOffset; i++)
            {
                num += this.tokens[i].Width;
            }
            line.lineWidth = num;
        }
Example #5
0
        private void calculateLineSize(dfFont.LineRenderInfo line)
        {
            line.lineHeight = (float)base.Font.LineHeight;
            int width = 0;

            for (int i = line.startOffset; i <= line.endOffset; i++)
            {
                width = width + this.tokens[i].Width;
            }
            line.lineWidth = (float)width;
        }
Example #6
0
 public static dfFont.LineRenderInfo Obtain(int start, int end)
 {
     if (poolIndex >= (pool.Count - 1))
     {
         pool.Add(new dfFont.LineRenderInfo());
     }
     dfFont.LineRenderInfo info = pool[poolIndex++];
     info.startOffset = start;
     info.endOffset   = end;
     info.lineHeight  = 0f;
     return(info);
 }
Example #7
0
        public static dfFont.LineRenderInfo Obtain(int start, int end)
        {
            if (dfFont.LineRenderInfo.poolIndex >= dfFont.LineRenderInfo.pool.Count - 1)
            {
                dfFont.LineRenderInfo.pool.Add(new dfFont.LineRenderInfo());
            }
            dfList <dfFont.LineRenderInfo> lineRenderInfos = dfFont.LineRenderInfo.pool;
            int num = dfFont.LineRenderInfo.poolIndex;

            dfFont.LineRenderInfo.poolIndex = num + 1;
            dfFont.LineRenderInfo item = lineRenderInfos[num];
            item.startOffset = start;
            item.endOffset   = end;
            item.lineHeight  = 0f;
            return(item);
        }
Example #8
0
        private int calculateLineAlignment(dfFont.LineRenderInfo line)
        {
            float lineWidth = line.lineWidth;

            if ((base.TextAlign == TextAlignment.Left) || (lineWidth == 0f))
            {
                return(0);
            }
            int b = 0;

            if (base.TextAlign == TextAlignment.Right)
            {
                b = Mathf.FloorToInt((base.MaxSize.x / base.TextScale) - lineWidth);
            }
            else
            {
                b = Mathf.FloorToInt(((base.MaxSize.x / base.TextScale) - lineWidth) * 0.5f);
            }
            return(Mathf.Max(0, b));
        }
Example #9
0
        private int calculateLineAlignment(dfFont.LineRenderInfo line)
        {
            float single = line.lineWidth;

            if (base.TextAlign == TextAlignment.Left || single == 0f)
            {
                return(0);
            }
            int num = 0;

            if (base.TextAlign != TextAlignment.Right)
            {
                Vector2 maxSize = base.MaxSize;
                num = Mathf.FloorToInt((maxSize.x / base.TextScale - single) * 0.5f);
            }
            else
            {
                Vector2 vector2 = base.MaxSize;
                num = Mathf.FloorToInt(vector2.x / base.TextScale - single);
            }
            return(Mathf.Max(0, num));
        }
Example #10
0
        private void renderLine(dfFont.LineRenderInfo line, Stack <Color32> colors, Vector3 position, dfRenderData destination)
        {
            float num = base.TextScale * base.PixelRatio;

            position.x += this.calculateLineAlignment(line) * num;
            for (int i = line.startOffset; i <= line.endOffset; i++)
            {
                dfMarkupToken     token     = this.tokens[i];
                dfMarkupTokenType tokenType = token.TokenType;
                switch (tokenType)
                {
                case dfMarkupTokenType.Text:
                    this.renderText(token, colors.Peek(), position, destination);
                    break;

                case dfMarkupTokenType.StartTag:
                    if (token.Matches("sprite"))
                    {
                        this.renderSprite(token, colors.Peek(), position, destination);
                    }
                    else if (token.Matches("color"))
                    {
                        colors.Push(this.parseColor(token));
                    }
                    break;

                default:
                    if (((tokenType == dfMarkupTokenType.EndTag) && token.Matches("color")) && (colors.Count > 1))
                    {
                        colors.Pop();
                    }
                    break;
                }
                position.x += token.Width * num;
            }
        }