Exemple #1
0
        public float[] GetCharacterWidths(string text, int startIndex, int endIndex, out float totalWidth)
        {
            totalWidth = 0f;
            dfDynamicFont font = (dfDynamicFont)base.Font;
            int           num  = Mathf.CeilToInt((float)font.FontSize * base.TextScale);

            CharacterInfo[] characterInfoArray = font.RequestCharacters(text, num, FontStyle.Normal);
            float[]         pixelRatio         = new float[text.Length];
            float           single             = 0f;
            float           tabSize            = 0f;
            int             num1 = startIndex;

            while (num1 <= endIndex)
            {
                CharacterInfo characterInfo = characterInfoArray[num1];
                if (text[num1] != '\t')
                {
                    tabSize = (text[num1] != ' ' ? tabSize + (characterInfo.vert.x + characterInfo.vert.width) : tabSize + characterInfo.width);
                }
                else
                {
                    tabSize = tabSize + (float)base.TabSize;
                }
                pixelRatio[num1] = (tabSize - single) * base.PixelRatio;
                num1++;
                single = tabSize;
            }
            return(pixelRatio);
        }
    private void renderText(string text)
    {
        dfDynamicFont    font      = this.Style.Font;
        int              fontSize  = this.Style.FontSize;
        FontStyle        fontStyle = this.Style.FontStyle;
        dfList <Vector3> vertices  = this.renderData.Vertices;
        dfList <int>     triangles = this.renderData.Triangles;
        dfList <Vector2> uV        = this.renderData.UV;
        dfList <Color32> colors    = this.renderData.Colors;
        float            single    = (float)fontSize / (float)font.FontSize;
        float            descent   = (float)font.Descent * single;
        float            num       = 0f;

        CharacterInfo[] characterInfoArray = font.RequestCharacters(text, fontSize, fontStyle);
        this.renderData.Material = font.Material;
        for (int i = 0; i < text.Length; i++)
        {
            CharacterInfo characterInfo = characterInfoArray[i];
            dfMarkupBoxText.addTriangleIndices(vertices, triangles);
            float   fontSize1 = (float)font.FontSize + characterInfo.vert.y - (float)fontSize + descent;
            float   single1   = num + characterInfo.vert.x;
            float   single2   = fontSize1;
            float   single3   = single1 + characterInfo.vert.width;
            float   single4   = single2 + characterInfo.vert.height;
            Vector3 vector3   = new Vector3(single1, single2);
            Vector3 vector31  = new Vector3(single3, single2);
            Vector3 vector32  = new Vector3(single3, single4);
            Vector3 vector33  = new Vector3(single1, single4);
            vertices.Add(vector3);
            vertices.Add(vector31);
            vertices.Add(vector32);
            vertices.Add(vector33);
            Color color = this.Style.Color;
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            Rect  rect    = characterInfo.uv;
            float single5 = rect.x;
            float single6 = rect.y + rect.height;
            float single7 = single5 + rect.width;
            float single8 = rect.y;
            if (!characterInfo.flipped)
            {
                uV.Add(new Vector2(single5, single6));
                uV.Add(new Vector2(single7, single6));
                uV.Add(new Vector2(single7, single8));
                uV.Add(new Vector2(single5, single8));
            }
            else
            {
                uV.Add(new Vector2(single7, single8));
                uV.Add(new Vector2(single7, single6));
                uV.Add(new Vector2(single5, single6));
                uV.Add(new Vector2(single5, single8));
            }
            num = num + (float)Mathf.CeilToInt(characterInfo.vert.x + characterInfo.vert.width);
        }
    }
    private void renderText(string text)
    {
        dfDynamicFont    font      = this.Style.Font;
        int              fontSize  = this.Style.FontSize;
        FontStyle        fontStyle = this.Style.FontStyle;
        dfList <Vector3> vertices  = this.renderData.Vertices;
        dfList <int>     triangles = this.renderData.Triangles;
        dfList <Vector2> uV        = this.renderData.UV;
        dfList <Color32> colors    = this.renderData.Colors;
        float            num2      = ((float)fontSize) / ((float)font.FontSize);
        float            num3      = font.Descent * num2;
        float            num4      = 0f;

        CharacterInfo[] infoArray = font.RequestCharacters(text, fontSize, fontStyle);
        this.renderData.Material = font.Material;
        for (int i = 0; i < text.Length; i++)
        {
            CharacterInfo info = infoArray[i];
            addTriangleIndices(vertices, triangles);
            float   num6    = ((font.FontSize + info.vert.y) - fontSize) + num3;
            float   x       = num4 + info.vert.x;
            float   y       = num6;
            float   num9    = x + info.vert.width;
            float   num10   = y + info.vert.height;
            Vector3 item    = new Vector3(x, y);
            Vector3 vector2 = new Vector3(num9, y);
            Vector3 vector3 = new Vector3(num9, num10);
            Vector3 vector4 = new Vector3(x, num10);
            vertices.Add(item);
            vertices.Add(vector2);
            vertices.Add(vector3);
            vertices.Add(vector4);
            Color color = this.Style.Color;
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            Rect  uv    = info.uv;
            float num11 = uv.x;
            float num12 = uv.y + uv.height;
            float num13 = num11 + uv.width;
            float num14 = uv.y;
            if (info.flipped)
            {
                uV.Add(new Vector2(num13, num14));
                uV.Add(new Vector2(num13, num12));
                uV.Add(new Vector2(num11, num12));
                uV.Add(new Vector2(num11, num14));
            }
            else
            {
                uV.Add(new Vector2(num11, num12));
                uV.Add(new Vector2(num13, num12));
                uV.Add(new Vector2(num13, num14));
                uV.Add(new Vector2(num11, num14));
            }
            num4 += Mathf.CeilToInt(info.vert.x + info.vert.width);
        }
    }
Exemple #4
0
 private void calculateTokenRenderSize(dfMarkupToken token)
 {
     try
     {
         int           num  = 0;
         char          item = '\0';
         bool          flag = (token.TokenType == dfMarkupTokenType.Whitespace ? true : token.TokenType == dfMarkupTokenType.Text);
         dfDynamicFont font = (dfDynamicFont)base.Font;
         if (flag)
         {
             int             num1 = Mathf.CeilToInt((float)font.FontSize * base.TextScale);
             CharacterInfo[] characterInfoArray = font.RequestCharacters(token.Value, num1, FontStyle.Normal);
             for (int i = 0; i < token.Length; i++)
             {
                 item = token[i];
                 if (item != '\t')
                 {
                     CharacterInfo characterInfo = characterInfoArray[i];
                     num = num + (item == ' ' ? Mathf.CeilToInt(characterInfo.width) : Mathf.CeilToInt(characterInfo.vert.x + characterInfo.vert.width));
                     if (i > 0)
                     {
                         num = num + Mathf.CeilToInt((float)base.CharacterSpacing * base.TextScale);
                     }
                 }
                 else
                 {
                     num = num + base.TabSize;
                 }
             }
             token.Height = base.Font.LineHeight;
             token.Width  = num;
         }
         else if (token.TokenType == dfMarkupTokenType.StartTag && token.Matches("sprite") && this.SpriteAtlas != null && token.AttributeCount == 1)
         {
             Texture2D        texture  = this.SpriteAtlas.Texture;
             float            baseline = (float)font.Baseline * base.TextScale;
             string           value    = token.GetAttribute(0).Value.Value;
             dfAtlas.ItemInfo itemInfo = this.SpriteAtlas[value];
             if (itemInfo != null)
             {
                 float single = itemInfo.region.width * (float)texture.width / (itemInfo.region.height * (float)texture.height);
                 num = Mathf.CeilToInt(baseline * single);
             }
             token.Height = Mathf.CeilToInt(baseline);
             token.Width  = num;
         }
     }
     finally
     {
     }
 }
Exemple #5
0
 private void renderText(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData renderData)
 {
     try
     {
         dfDynamicFont    font               = (dfDynamicFont)base.Font;
         int              num                = Mathf.CeilToInt((float)font.FontSize * base.TextScale);
         FontStyle        fontStyle          = FontStyle.Normal;
         int              descent            = font.Descent;
         dfList <Vector3> vertices           = renderData.Vertices;
         dfList <int>     triangles          = renderData.Triangles;
         dfList <Vector2> uV                 = renderData.UV;
         dfList <Color32> colors             = renderData.Colors;
         string           value              = token.Value;
         float            characterSpacing   = position.x;
         float            single             = position.y;
         CharacterInfo[]  characterInfoArray = font.RequestCharacters(value, num, fontStyle);
         renderData.Material = font.Material;
         Color32 color32  = this.applyOpacity(this.multiplyColors(color, base.DefaultColor));
         Color32 color321 = color32;
         if (base.BottomColor.HasValue)
         {
             Color   color1      = color;
             Color32?bottomColor = base.BottomColor;
             color321 = this.applyOpacity(this.multiplyColors(color1, bottomColor.Value));
         }
         for (int i = 0; i < value.Length; i++)
         {
             if (i > 0)
             {
                 characterSpacing = characterSpacing + (float)base.CharacterSpacing * base.TextScale;
             }
             CharacterInfo characterInfo = characterInfoArray[i];
             float         fontSize      = (float)font.FontSize + characterInfo.vert.y - (float)num + (float)descent;
             float         single1       = characterSpacing + characterInfo.vert.x;
             float         single2       = single + fontSize;
             float         single3       = single1 + characterInfo.vert.width;
             float         single4       = single2 + characterInfo.vert.height;
             Vector3       vector3       = new Vector3(single1, single2) * base.PixelRatio;
             Vector3       vector31      = new Vector3(single3, single2) * base.PixelRatio;
             Vector3       vector32      = new Vector3(single3, single4) * base.PixelRatio;
             Vector3       vector33      = new Vector3(single1, single4) * base.PixelRatio;
             if (base.Shadow)
             {
                 dfDynamicFont.DynamicFontRenderer.addTriangleIndices(vertices, triangles);
                 Vector3 shadowOffset = base.ShadowOffset * base.PixelRatio;
                 vertices.Add(vector3 + shadowOffset);
                 vertices.Add(vector31 + shadowOffset);
                 vertices.Add(vector32 + shadowOffset);
                 vertices.Add(vector33 + shadowOffset);
                 Color32 color322 = this.applyOpacity(base.ShadowColor);
                 colors.Add(color322);
                 colors.Add(color322);
                 colors.Add(color322);
                 colors.Add(color322);
                 dfDynamicFont.DynamicFontRenderer.addUVCoords(uV, characterInfo);
             }
             if (base.Outline)
             {
                 for (int j = 0; j < (int)dfDynamicFont.DynamicFontRenderer.OUTLINE_OFFSETS.Length; j++)
                 {
                     dfDynamicFont.DynamicFontRenderer.addTriangleIndices(vertices, triangles);
                     Vector3 oUTLINEOFFSETS = (dfDynamicFont.DynamicFontRenderer.OUTLINE_OFFSETS[j] * (float)base.OutlineSize) * base.PixelRatio;
                     vertices.Add(vector3 + oUTLINEOFFSETS);
                     vertices.Add(vector31 + oUTLINEOFFSETS);
                     vertices.Add(vector32 + oUTLINEOFFSETS);
                     vertices.Add(vector33 + oUTLINEOFFSETS);
                     Color32 color323 = this.applyOpacity(base.OutlineColor);
                     colors.Add(color323);
                     colors.Add(color323);
                     colors.Add(color323);
                     colors.Add(color323);
                     dfDynamicFont.DynamicFontRenderer.addUVCoords(uV, characterInfo);
                 }
             }
             dfDynamicFont.DynamicFontRenderer.addTriangleIndices(vertices, triangles);
             vertices.Add(vector3);
             vertices.Add(vector31);
             vertices.Add(vector32);
             vertices.Add(vector33);
             colors.Add(color32);
             colors.Add(color32);
             colors.Add(color321);
             colors.Add(color321);
             dfDynamicFont.DynamicFontRenderer.addUVCoords(uV, characterInfo);
             characterSpacing = characterSpacing + (float)Mathf.CeilToInt(characterInfo.vert.x + characterInfo.vert.width);
         }
     }
     finally
     {
     }
 }