Example #1
0
 private void calculateTokenRenderSize(dfMarkupToken token)
 {
     try
     {
         dfFont font         = (dfFont)base.Font;
         int    num          = 0;
         char   previousChar = '\0';
         char   id           = '\0';
         if ((token.TokenType == dfMarkupTokenType.Whitespace) || (token.TokenType == dfMarkupTokenType.Text))
         {
             int num2 = 0;
             while (num2 < token.Length)
             {
                 id = token[num2];
                 if (id == '\t')
                 {
                     num += base.TabSize;
                 }
                 else
                 {
                     dfFont.GlyphDefinition glyph = font.GetGlyph(id);
                     if (glyph != null)
                     {
                         if (num2 > 0)
                         {
                             num += font.GetKerning(previousChar, id);
                             num += base.CharacterSpacing;
                         }
                         num += glyph.xadvance;
                     }
                 }
                 num2++;
                 previousChar = id;
             }
         }
         else if ((token.TokenType == dfMarkupTokenType.StartTag) && token.Matches("sprite"))
         {
             if (token.AttributeCount < 1)
             {
                 throw new Exception("Missing sprite name in markup");
             }
             Texture          texture    = font.Texture;
             int              lineHeight = font.LineHeight;
             string           str        = token.GetAttribute(0).Value.Value;
             dfAtlas.ItemInfo info       = font.atlas[str];
             if (info != null)
             {
                 float num4 = (info.region.width * texture.width) / (info.region.height * texture.height);
                 num = Mathf.CeilToInt(lineHeight * num4);
             }
         }
         token.Height = base.Font.LineHeight;
         token.Width  = num;
     }
     finally
     {
     }
 }
Example #2
0
 private void calculateTokenRenderSize(dfMarkupToken token)
 {
     try
     {
         dfFont font    = (dfFont)base.Font;
         int    kerning = 0;
         char   chr     = '\0';
         char   item    = '\0';
         if ((token.TokenType == dfMarkupTokenType.Whitespace ? true : token.TokenType == dfMarkupTokenType.Text))
         {
             int num = 0;
             while (num < token.Length)
             {
                 item = token[num];
                 if (item != '\t')
                 {
                     dfFont.GlyphDefinition glyph = font.GetGlyph(item);
                     if (glyph != null)
                     {
                         if (num > 0)
                         {
                             kerning = kerning + font.GetKerning(chr, item);
                             kerning = kerning + base.CharacterSpacing;
                         }
                         kerning = kerning + glyph.xadvance;
                     }
                 }
                 else
                 {
                     kerning = kerning + base.TabSize;
                 }
                 num++;
                 chr = item;
             }
         }
         else if (token.TokenType == dfMarkupTokenType.StartTag && token.Matches("sprite"))
         {
             if (token.AttributeCount < 1)
             {
                 throw new Exception("Missing sprite name in markup");
             }
             UnityEngine.Texture texture = font.Texture;
             int              lineHeight = font.LineHeight;
             string           value      = token.GetAttribute(0).Value.Value;
             dfAtlas.ItemInfo itemInfo   = font.atlas[value];
             if (itemInfo != null)
             {
                 float single = itemInfo.region.width * (float)texture.width / (itemInfo.region.height * (float)texture.height);
                 kerning = Mathf.CeilToInt((float)lineHeight * single);
             }
         }
         token.Height = base.Font.LineHeight;
         token.Width  = kerning;
     }
     finally
     {
     }
 }
Example #3
0
 private void renderText(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination)
 {
     try
     {
         dfList <Vector3> vertices     = destination.Vertices;
         dfList <int>     triangles    = destination.Triangles;
         dfList <Color32> colors       = destination.Colors;
         dfList <Vector2> uV           = destination.UV;
         dfFont           font         = (dfFont)base.Font;
         dfAtlas.ItemInfo info         = font.Atlas[font.sprite];
         Texture          texture      = font.Texture;
         float            num          = 1f / ((float)texture.width);
         float            num2         = 1f / ((float)texture.height);
         float            num3         = num * 0.125f;
         float            num4         = num2 * 0.125f;
         float            num5         = base.TextScale * base.PixelRatio;
         char             previousChar = '\0';
         char             id           = '\0';
         Color32          item         = this.applyOpacity(this.multiplyColors((Color)color, (Color)base.DefaultColor));
         Color32          color3       = item;
         if (base.BottomColor.HasValue)
         {
             color3 = this.applyOpacity(this.multiplyColors((Color)color, base.BottomColor.Value));
         }
         int num6 = 0;
         while (num6 < token.Length)
         {
             id = token[num6];
             if (id != '\0')
             {
                 dfFont.GlyphDefinition glyph = font.GetGlyph(id);
                 if (glyph != null)
                 {
                     int     kerning = font.GetKerning(previousChar, id);
                     float   x       = position.x + ((glyph.xoffset + kerning) * num5);
                     float   y       = position.y - (glyph.yoffset * num5);
                     float   num10   = glyph.width * num5;
                     float   num11   = glyph.height * num5;
                     float   num12   = x + num10;
                     float   num13   = y - num11;
                     Vector3 vector  = new Vector3(x, y);
                     Vector3 vector2 = new Vector3(num12, y);
                     Vector3 vector3 = new Vector3(num12, num13);
                     Vector3 vector4 = new Vector3(x, num13);
                     float   num14   = (info.region.x + (glyph.x * num)) - num3;
                     float   num15   = (info.region.yMax - (glyph.y * num2)) - num4;
                     float   num16   = (num14 + (glyph.width * num)) - num3;
                     float   num17   = (num15 - (glyph.height * num2)) + num4;
                     if (base.Shadow)
                     {
                         addTriangleIndices(vertices, triangles);
                         Vector3 vector5 = (Vector3)(base.ShadowOffset * num5);
                         vertices.Add(vector + vector5);
                         vertices.Add(vector2 + vector5);
                         vertices.Add(vector3 + vector5);
                         vertices.Add(vector4 + vector5);
                         Color32 color4 = this.applyOpacity(base.ShadowColor);
                         colors.Add(color4);
                         colors.Add(color4);
                         colors.Add(color4);
                         colors.Add(color4);
                         uV.Add(new Vector2(num14, num15));
                         uV.Add(new Vector2(num16, num15));
                         uV.Add(new Vector2(num16, num17));
                         uV.Add(new Vector2(num14, num17));
                     }
                     if (base.Outline)
                     {
                         for (int i = 0; i < OUTLINE_OFFSETS.Length; i++)
                         {
                             addTriangleIndices(vertices, triangles);
                             Vector3 vector6 = (Vector3)((OUTLINE_OFFSETS[i] * base.OutlineSize) * num5);
                             vertices.Add(vector + vector6);
                             vertices.Add(vector2 + vector6);
                             vertices.Add(vector3 + vector6);
                             vertices.Add(vector4 + vector6);
                             Color32 color5 = this.applyOpacity(base.OutlineColor);
                             colors.Add(color5);
                             colors.Add(color5);
                             colors.Add(color5);
                             colors.Add(color5);
                             uV.Add(new Vector2(num14, num15));
                             uV.Add(new Vector2(num16, num15));
                             uV.Add(new Vector2(num16, num17));
                             uV.Add(new Vector2(num14, num17));
                         }
                     }
                     addTriangleIndices(vertices, triangles);
                     vertices.Add(vector);
                     vertices.Add(vector2);
                     vertices.Add(vector3);
                     vertices.Add(vector4);
                     colors.Add(item);
                     colors.Add(item);
                     colors.Add(color3);
                     colors.Add(color3);
                     uV.Add(new Vector2(num14, num15));
                     uV.Add(new Vector2(num16, num15));
                     uV.Add(new Vector2(num16, num17));
                     uV.Add(new Vector2(num14, num17));
                     position.x += ((glyph.xadvance + kerning) + base.CharacterSpacing) * num5;
                 }
             }
             num6++;
             previousChar = id;
         }
     }
     finally
     {
     }
 }
Example #4
0
 private void renderText(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination)
 {
     try
     {
         dfList <Vector3>    vertices  = destination.Vertices;
         dfList <int>        triangles = destination.Triangles;
         dfList <Color32>    colors    = destination.Colors;
         dfList <Vector2>    uV        = destination.UV;
         dfFont              font      = (dfFont)base.Font;
         dfAtlas.ItemInfo    item      = font.Atlas[font.sprite];
         UnityEngine.Texture texture   = font.Texture;
         float   single    = 1f / (float)texture.width;
         float   single1   = 1f / (float)texture.height;
         float   single2   = single * 0.125f;
         float   single3   = single1 * 0.125f;
         float   textScale = base.TextScale * base.PixelRatio;
         char    chr       = '\0';
         char    item1     = '\0';
         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));
         }
         int num = 0;
         while (num < token.Length)
         {
             item1 = token[num];
             if (item1 != 0)
             {
                 dfFont.GlyphDefinition glyph = font.GetGlyph(item1);
                 if (glyph != null)
                 {
                     int     kerning  = font.GetKerning(chr, item1);
                     float   single4  = position.x + (float)(glyph.xoffset + kerning) * textScale;
                     float   single5  = position.y - (float)glyph.yoffset * textScale;
                     float   single6  = (float)glyph.width * textScale;
                     float   single7  = (float)glyph.height * textScale;
                     float   single8  = single4 + single6;
                     float   single9  = single5 - single7;
                     Vector3 vector3  = new Vector3(single4, single5);
                     Vector3 vector31 = new Vector3(single8, single5);
                     Vector3 vector32 = new Vector3(single8, single9);
                     Vector3 vector33 = new Vector3(single4, single9);
                     float   single10 = item.region.x + (float)glyph.x * single - single2;
                     float   single11 = item.region.yMax - (float)glyph.y * single1 - single3;
                     float   single12 = single10 + (float)glyph.width * single - single2;
                     float   single13 = single11 - (float)glyph.height * single1 + single3;
                     if (base.Shadow)
                     {
                         dfFont.BitmappedFontRenderer.addTriangleIndices(vertices, triangles);
                         Vector3 shadowOffset = base.ShadowOffset * textScale;
                         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);
                         uV.Add(new Vector2(single10, single11));
                         uV.Add(new Vector2(single12, single11));
                         uV.Add(new Vector2(single12, single13));
                         uV.Add(new Vector2(single10, single13));
                     }
                     if (base.Outline)
                     {
                         for (int i = 0; i < (int)dfFont.BitmappedFontRenderer.OUTLINE_OFFSETS.Length; i++)
                         {
                             dfFont.BitmappedFontRenderer.addTriangleIndices(vertices, triangles);
                             Vector3 oUTLINEOFFSETS = (dfFont.BitmappedFontRenderer.OUTLINE_OFFSETS[i] * (float)base.OutlineSize) * textScale;
                             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);
                             uV.Add(new Vector2(single10, single11));
                             uV.Add(new Vector2(single12, single11));
                             uV.Add(new Vector2(single12, single13));
                             uV.Add(new Vector2(single10, single13));
                         }
                     }
                     dfFont.BitmappedFontRenderer.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);
                     uV.Add(new Vector2(single10, single11));
                     uV.Add(new Vector2(single12, single11));
                     uV.Add(new Vector2(single12, single13));
                     uV.Add(new Vector2(single10, single13));
                     position.x = position.x + (float)(glyph.xadvance + kerning + base.CharacterSpacing) * textScale;
                 }
             }
             num++;
             chr = item1;
         }
     }
     finally
     {
     }
 }