Exemplo n.º 1
0
 private void renderSprite(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination)
 {
     try
     {
         string           value = token.GetAttribute(0).Value.Value;
         dfAtlas.ItemInfo item  = this.SpriteAtlas[value];
         if (item != null)
         {
             dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions();
             dfSprite.RenderOptions spriteAtlas  = renderOption;
             spriteAtlas.atlas         = this.SpriteAtlas;
             spriteAtlas.color         = color;
             spriteAtlas.fillAmount    = 1f;
             spriteAtlas.offset        = position;
             spriteAtlas.pixelsToUnits = base.PixelRatio;
             spriteAtlas.size          = new Vector2((float)token.Width, (float)token.Height);
             spriteAtlas.spriteInfo    = item;
             renderOption = spriteAtlas;
             dfSprite.renderSprite(this.SpriteBuffer, renderOption);
         }
     }
     finally
     {
     }
 }
Exemplo n.º 2
0
        private void renderSprite(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination)
        {
            try
            {
                //@Profiler.BeginSample( "Render embedded sprite" );

                var spriteName = token.GetAttribute(0).Value.Value;
                var spriteInfo = SpriteAtlas[spriteName];
                if (spriteInfo == null)
                {
                    return;
                }

                var options = new dfSprite.RenderOptions()
                {
                    atlas         = SpriteAtlas,
                    color         = color,
                    fillAmount    = 1,
                    flip          = dfSpriteFlip.None,
                    offset        = position,
                    pixelsToUnits = PixelRatio,
                    size          = new Vector2(token.Width, token.Height),
                    spriteInfo    = spriteInfo
                };

                dfSprite.renderSprite(SpriteBuffer, options);
            }
            finally
            {
                //@Profiler.EndSample();
            }
        }
Exemplo n.º 3
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
     {
     }
 }
Exemplo n.º 4
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
     {
     }
 }
Exemplo n.º 5
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
     {
     }
 }
Exemplo n.º 6
0
 private void renderSprite(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;
         string           str       = token.GetAttribute(0).Value.Value;
         dfAtlas.ItemInfo info      = font.Atlas[str];
         if (info != null)
         {
             float num   = (token.Height * base.TextScale) * base.PixelRatio;
             float num2  = (token.Width * base.TextScale) * base.PixelRatio;
             float x     = position.x;
             float y     = position.y;
             int   count = vertices.Count;
             vertices.Add(new Vector3(x, y));
             vertices.Add(new Vector3(x + num2, y));
             vertices.Add(new Vector3(x + num2, y - num));
             vertices.Add(new Vector3(x, y - num));
             triangles.Add(count);
             triangles.Add(count + 1);
             triangles.Add(count + 3);
             triangles.Add(count + 3);
             triangles.Add(count + 1);
             triangles.Add(count + 2);
             Color32 item = !base.ColorizeSymbols ? this.applyOpacity(base.DefaultColor) : this.applyOpacity(color);
             colors.Add(item);
             colors.Add(item);
             colors.Add(item);
             colors.Add(item);
             Rect region = info.region;
             uV.Add(new Vector2(region.x, region.yMax));
             uV.Add(new Vector2(region.xMax, region.yMax));
             uV.Add(new Vector2(region.xMax, region.y));
             uV.Add(new Vector2(region.x, region.y));
         }
     }
     finally
     {
     }
 }
Exemplo n.º 7
0
 private void renderSprite(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;
         string           value     = token.GetAttribute(0).Value.Value;
         dfAtlas.ItemInfo item      = font.Atlas[value];
         if (item != null)
         {
             float height  = (float)token.Height * base.TextScale * base.PixelRatio;
             float width   = (float)token.Width * base.TextScale * base.PixelRatio;
             float single  = position.x;
             float single1 = position.y;
             int   count   = vertices.Count;
             vertices.Add(new Vector3(single, single1));
             vertices.Add(new Vector3(single + width, single1));
             vertices.Add(new Vector3(single + width, single1 - height));
             vertices.Add(new Vector3(single, single1 - height));
             triangles.Add(count);
             triangles.Add(count + 1);
             triangles.Add(count + 3);
             triangles.Add(count + 3);
             triangles.Add(count + 1);
             triangles.Add(count + 2);
             Color32 color32 = (!base.ColorizeSymbols ? this.applyOpacity(base.DefaultColor) : this.applyOpacity(color));
             colors.Add(color32);
             colors.Add(color32);
             colors.Add(color32);
             colors.Add(color32);
             Rect rect = item.region;
             uV.Add(new Vector2(rect.x, rect.yMax));
             uV.Add(new Vector2(rect.xMax, rect.yMax));
             uV.Add(new Vector2(rect.xMax, rect.y));
             uV.Add(new Vector2(rect.x, rect.y));
         }
     }
     finally
     {
     }
 }
Exemplo n.º 8
0
        private Color32 parseColor(dfMarkupToken token)
        {
            Color color = Color.white;

            if (token.AttributeCount == 1)
            {
                string value = token.GetAttribute(0).Value.Value;
                if (value.Length != 7 || value[0] != '#')
                {
                    color = dfMarkupStyle.ParseColor(value, base.DefaultColor);
                }
                else
                {
                    uint num = 0;
                    uint.TryParse(value.Substring(1), NumberStyles.HexNumber, null, out num);
                    color = this.UIntToColor(num | -16777216);
                }
            }
            return(this.applyOpacity(color));
        }
Exemplo n.º 9
0
        private Color32 parseColor(dfMarkupToken token)
        {
            Color white = Color.white;

            if (token.AttributeCount == 1)
            {
                string color = token.GetAttribute(0).Value.Value;
                if ((color.Length == 7) && (color[0] == '#'))
                {
                    uint result = 0;
                    uint.TryParse(color.Substring(1), NumberStyles.HexNumber, null, out result);
                    white = (Color)this.UIntToColor(result | 0xff000000);
                }
                else
                {
                    white = dfMarkupStyle.ParseColor(color, (Color)base.DefaultColor);
                }
            }
            return(this.applyOpacity(white));
        }
Exemplo n.º 10
0
        private Color32 parseColor(dfMarkupToken token)
        {
            var color = UnityEngine.Color.white;

            if (token.AttributeCount == 1)
            {
                var value = token.GetAttribute(0).Value.Value;

                if (value.Length == 7 && value[0] == '#')
                {
                    uint intColor = 0;
                    uint.TryParse(value.Substring(1), NumberStyles.HexNumber, null, out intColor);

                    color = UIntToColor(intColor | 0xFF000000);
                }
                else
                {
                    color = dfMarkupStyle.ParseColor(value, DefaultColor);
                }
            }

            return(applyOpacity(color));
        }
Exemplo n.º 11
0
 private void renderSprite(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination)
 {
     try
     {
         string value = token.GetAttribute(0).Value.Value;
         dfAtlas.ItemInfo item = this.SpriteAtlas[value];
         if (item != null)
         {
             dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions();
             dfSprite.RenderOptions spriteAtlas = renderOption;
             spriteAtlas.atlas = this.SpriteAtlas;
             spriteAtlas.color = color;
             spriteAtlas.fillAmount = 1f;
             spriteAtlas.offset = position;
             spriteAtlas.pixelsToUnits = base.PixelRatio;
             spriteAtlas.size = new Vector2((float)token.Width, (float)token.Height);
             spriteAtlas.spriteInfo = item;
             renderOption = spriteAtlas;
             dfSprite.renderSprite(this.SpriteBuffer, renderOption);
         }
     }
     finally
     {
     }
 }
Exemplo n.º 12
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
     {
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Calculates the size, in pixels, required to render this
        /// token on screen. Does not account for scale.
        /// </summary>
        /// <param name="token"></param>
        private void calculateTokenRenderSize(dfMarkupToken token)
        {
            try
            {
                //@Profiler.BeginSample( "Calculate token render size" );

                var totalWidth = 0f;
                var ch         = '\0';

                var font = (dfDynamicFont)Font;

                if (token.TokenType == dfMarkupTokenType.Text)
                {
                    var fontSize = Mathf.CeilToInt(font.FontSize * TextScale);
                    var glyphs   = font.RequestCharacters(token.Value, fontSize, FontStyle.Normal);

                    for (int i = 0; i < token.Length; i++)
                    {
                        // Dereference the original character
                        ch = token[i];

                        // TODO: Implement 'tab stops' calculation
                        if (ch == '\t')
                        {
                            totalWidth += this.TabSize;
                            continue;
                        }

                        // Attempt to obtain a reference to the glyph data that
                        // represents the character
                        var glyph = glyphs[i];

                        // Add the character width to the total
                        totalWidth += (ch != ' ')
                                                        ? (glyph.vert.x + glyph.vert.width)
                                                        : (glyph.width + CharacterSpacing * TextScale);
                    }

                    if (token.Length > 2)
                    {
                        totalWidth += (token.Length - 2) * CharacterSpacing * TextScale;
                    }

                    token.Height = Font.LineHeight;
                    token.Width  = Mathf.CeilToInt(totalWidth);
                }
                else if (token.TokenType == dfMarkupTokenType.Whitespace)
                {
                    var fontSize = Mathf.CeilToInt(font.FontSize * TextScale);
                    var glyphs   = font.RequestCharacters(token.Value, fontSize, FontStyle.Normal);
                    var spacing  = CharacterSpacing * TextScale;

                    for (int i = 0; i < token.Length; i++)
                    {
                        // Dereference the original character
                        ch = token[i];

                        // TODO: Implement 'tab stops' calculation
                        if (ch == '\t')
                        {
                            totalWidth += this.TabSize;
                        }
                        else if (ch == ' ')
                        {
                            totalWidth += glyphs[i].width + spacing;
                        }
                    }

                    token.Height = Font.LineHeight;
                    token.Width  = Mathf.CeilToInt(totalWidth);
                }
                else if (token.TokenType == dfMarkupTokenType.StartTag)
                {
                    if (token.Matches("sprite") && SpriteAtlas != null)
                    {
                        if (token.AttributeCount == 1)
                        {
                            var texture    = SpriteAtlas.Texture;
                            var lineHeight = font.Baseline * TextScale;

                            var spriteName = token.GetAttribute(0).Value.Value;
                            var sprite     = SpriteAtlas[spriteName];

                            if (sprite != null)
                            {
                                var aspectRatio = (sprite.region.width * texture.width) / (sprite.region.height * texture.height);
                                totalWidth = Mathf.CeilToInt(lineHeight * aspectRatio);
                            }

                            token.Height = Mathf.CeilToInt(lineHeight);
                            token.Width  = Mathf.CeilToInt(totalWidth);
                        }
                    }
                }
            }
            finally
            {
                //@Profiler.EndSample();
            }
        }
Exemplo n.º 14
0
		private Color32 parseColor( dfMarkupToken token )
		{

			var color = UnityEngine.Color.white;

			if( token.AttributeCount == 1 )
			{

				var value = token.GetAttribute( 0 ).Value.Value;

				if( value.Length == 7 && value[ 0 ] == '#' )
				{

					uint intColor = 0;
					uint.TryParse( value.Substring( 1 ), NumberStyles.HexNumber, null, out intColor );

					color = UIntToColor( intColor | 0xFF000000 );

				}
				else
				{
					color = dfMarkupStyle.ParseColor( value, DefaultColor );
				}

			}

			return applyOpacity( color );

		}
Exemplo n.º 15
0
		private void renderSprite( dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination )
		{

			try
			{

				//@Profiler.BeginSample( "Render embedded sprite" );

				var spriteName = token.GetAttribute( 0 ).Value.Value;
				var spriteInfo = SpriteAtlas[ spriteName ];
				if( spriteInfo == null )
					return;

				var options = new dfSprite.RenderOptions()
				{
					atlas = SpriteAtlas,
					color = color,
					fillAmount = 1,
					flip = dfSpriteFlip.None,
					offset = position,
					pixelsToUnits = PixelRatio,
					size = new Vector2( token.Width, token.Height ),
					spriteInfo = spriteInfo
				};

				dfSprite.renderSprite( SpriteBuffer, options );

			}
			finally
			{
				//@Profiler.EndSample();
			}

		}
Exemplo n.º 16
0
		/// <summary>
		/// Calculates the size, in pixels, required to render this
		/// token on screen. Does not account for scale.
		/// </summary>
		/// <param name="token"></param>
		private void calculateTokenRenderSize( dfMarkupToken token )
		{

			try
			{

				//@Profiler.BeginSample( "Calculate token render size" );

				var totalWidth = 0f;
				var ch = '\0';

				var font = (dfDynamicFont)Font;
				var glyph = new UnityEngine.CharacterInfo();

				if( token.TokenType == dfMarkupTokenType.Text )
				{

					var fontSize = Mathf.CeilToInt( font.FontSize * TextScale );

					for( int i = 0; i < token.Length; i++ )
					{

						// Dereference the original character and obtain character information
						ch = token[ i ];
						font.baseFont.GetCharacterInfo( ch, out glyph, fontSize, FontStyle.Normal );

						// TODO: Implement 'tab stops' calculation
						if( ch == '\t' )
						{
							totalWidth += this.TabSize;
							continue;
						}

						// Add the character width to the total
						totalWidth += ( ch != ' ' )
							? ( glyph.vert.x + glyph.vert.width )
							: ( glyph.width + CharacterSpacing * TextScale );

					}

					if( token.Length > 2 )
					{
						totalWidth += ( token.Length - 2 ) * CharacterSpacing * TextScale;
					}

					token.Height = Font.LineHeight;
					token.Width = Mathf.CeilToInt( totalWidth );

				}
				else if( token.TokenType == dfMarkupTokenType.Whitespace )
				{

					var fontSize = Mathf.CeilToInt( font.FontSize * TextScale );
					var spacing = CharacterSpacing * TextScale;

					for( int i = 0; i < token.Length; i++ )
					{

						// Dereference the original character
						ch = token[ i ];

						// TODO: Implement 'tab stops' calculation
						if( ch == '\t' )
						{
							totalWidth += this.TabSize;
						}
						else if( ch == ' ' )
						{
							font.baseFont.GetCharacterInfo( ch, out glyph, fontSize, FontStyle.Normal );
							totalWidth += glyph.width + spacing;
						}

					}

					token.Height = Font.LineHeight;
					token.Width = Mathf.CeilToInt( totalWidth );

				}
				else if( token.TokenType == dfMarkupTokenType.StartTag )
				{

					if( token.Matches( "sprite" ) && SpriteAtlas != null )
					{

						if( token.AttributeCount == 1 )
						{

							var texture = SpriteAtlas.Texture;
							var lineHeight = font.Baseline * TextScale;

							var spriteName = token.GetAttribute( 0 ).Value.Value;
							var sprite = SpriteAtlas[ spriteName ];

							if( sprite != null )
							{
								var aspectRatio = ( sprite.region.width * texture.width ) / ( sprite.region.height * texture.height );
								totalWidth = Mathf.CeilToInt( lineHeight * aspectRatio );
							}

							token.Height = Mathf.CeilToInt( lineHeight );
							token.Width = Mathf.CeilToInt( totalWidth );

						}

					}

				}

			}
			finally
			{
				//@Profiler.EndSample();
			}

		}
Exemplo n.º 17
0
 private Color32 parseColor(dfMarkupToken token)
 {
     Color color = Color.white;
     if (token.AttributeCount == 1)
     {
         string value = token.GetAttribute(0).Value.Value;
         if (value.Length != 7 || value[0] != '#')
         {
             color = dfMarkupStyle.ParseColor(value, base.DefaultColor);
         }
         else
         {
             uint num = 0;
             uint.TryParse(value.Substring(1), NumberStyles.HexNumber, null, out num);
             color = this.UIntToColor(num | -16777216);
         }
     }
     return this.applyOpacity(color);
 }