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; } }
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 { } }
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(); } }
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 { } }
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 { } }
public static dfMarkupTokenAttribute Obtain(dfMarkupToken key, dfMarkupToken value) { var instance = (pool.Count > 0) ? pool.Pop() : new dfMarkupTokenAttribute(); instance.Key = key; instance.Value = value; return(instance); }
internal void AddAttribute(dfMarkupToken key, dfMarkupToken value) { dfMarkupTokenAttribute attribute = dfMarkupTokenAttribute.Obtain(key, value); if (this.AttributeCount == 0) { this.startAttributeIndex = attribute.Index; } this.AttributeCount++; }
private dfMarkupToken parseTag() { if (this.Peek(0) != '[') { return(null); } if (this.Peek(1) == '/') { return(this.parseEndTag()); } this.Advance(1); if (!char.IsLetterOrDigit(this.Peek(0))) { return(null); } int num = this.index; int num1 = this.index; while (this.index < this.source.Length && char.IsLetterOrDigit(this.Advance(1))) { num1++; } dfMarkupToken _dfMarkupToken = dfMarkupToken.Obtain(this.source, dfMarkupTokenType.StartTag, num, num1); if (this.index < this.source.Length && this.Peek(0) != ']') { if (char.IsWhiteSpace(this.Peek(0))) { this.parseWhitespace(); } int num2 = this.index; int num3 = this.index; if (this.Peek(0) != '\"') { while (this.index < this.source.Length && this.Advance(1) != ']') { num3++; } dfMarkupToken _dfMarkupToken1 = dfMarkupToken.Obtain(this.source, dfMarkupTokenType.Text, num2, num3); _dfMarkupToken.AddAttribute(_dfMarkupToken1, _dfMarkupToken1); } else { dfMarkupToken _dfMarkupToken2 = this.parseQuotedString(); _dfMarkupToken.AddAttribute(_dfMarkupToken2, _dfMarkupToken2); } } if (this.Peek(0) == ']') { this.Advance(1); } return(_dfMarkupToken); }
private dfMarkupToken parseTag() { if (this.Peek(0) != '[') { return(null); } if (this.Peek(1) == '/') { return(this.parseEndTag()); } this.Advance(1); if (!char.IsLetterOrDigit(this.Peek(0))) { return(null); } int index = this.index; int endIndex = this.index; while ((this.index < this.source.Length) && char.IsLetterOrDigit(this.Advance(1))) { endIndex++; } dfMarkupToken token = dfMarkupToken.Obtain(this.source, dfMarkupTokenType.StartTag, index, endIndex); if ((this.index < this.source.Length) && (this.Peek(0) != ']')) { if (char.IsWhiteSpace(this.Peek(0))) { this.parseWhitespace(); } int startIndex = this.index; int num4 = this.index; if (this.Peek(0) == '"') { dfMarkupToken key = this.parseQuotedString(); token.AddAttribute(key, key); } else { while ((this.index < this.source.Length) && (this.Advance(1) != ']')) { num4++; } dfMarkupToken token3 = dfMarkupToken.Obtain(this.source, dfMarkupTokenType.Text, startIndex, num4); token.AddAttribute(token3, token3); } } if (this.Peek(0) == ']') { this.Advance(1); } return(token); }
internal void AddAttribute(dfMarkupToken key, dfMarkupToken value) { dfMarkupTokenAttribute _dfMarkupTokenAttribute = dfMarkupTokenAttribute.Obtain(key, value); if (this.AttributeCount == 0) { this.startAttributeIndex = _dfMarkupTokenAttribute.Index; } dfMarkupToken attributeCount = this; attributeCount.AttributeCount = attributeCount.AttributeCount + 1; }
private dfList <dfMarkupToken> tokenize(string source) { var tokens = dfList <dfMarkupToken> .Obtain(); tokens.EnsureCapacity(estimateTokenCount(source)); tokens.AutoReleaseItems = true; this.source = source; this.index = 0; while (index < source.Length) { var next = Peek(); if (AtTagPosition()) { var tagToken = parseTag(); if (tagToken != null) { tokens.Add(tagToken); } continue; } dfMarkupToken token = null; if (char.IsWhiteSpace(next)) { // Skip carriage return, parse all other whitespace if (next != '\r') { token = parseWhitespace(); } } else { token = parseNonWhitespace(); } if (token == null) { Advance(); } else { tokens.Add(token); } } return(tokens); }
private List <dfMarkupToken> tokenize(string source) { // Flush the object pools dfMarkupToken.Reset(); dfMarkupTokenAttribute.Reset(); tokens.Clear(); this.source = source; this.index = 0; while (index < source.Length) { var next = Peek(); if (AtTagPosition()) { var tagToken = parseTag(); if (tagToken != null) { tokens.Add(tagToken); } continue; } dfMarkupToken token = null; if (char.IsWhiteSpace(next)) { // Skip carriage return, parse all other whitespace if (next != '\r') { token = parseWhitespace(); } } else { token = parseNonWhitespace(); } if (token == null) { Advance(); } else { tokens.Add(token); } } return(this.tokens); }
public static dfMarkupTokenAttribute Obtain(dfMarkupToken key, dfMarkupToken value) { if (dfMarkupTokenAttribute.poolIndex >= dfMarkupTokenAttribute.pool.Count - 1) { dfMarkupTokenAttribute.pool.Add(new dfMarkupTokenAttribute()); } dfMarkupTokenAttribute item = dfMarkupTokenAttribute.pool[dfMarkupTokenAttribute.poolIndex]; item.Index = dfMarkupTokenAttribute.poolIndex; item.Key = key; item.Value = value; dfMarkupTokenAttribute.poolIndex = dfMarkupTokenAttribute.poolIndex + 1; return item; }
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 { } }
public static dfMarkupTokenAttribute Obtain(dfMarkupToken key, dfMarkupToken value) { if (dfMarkupTokenAttribute.poolIndex >= dfMarkupTokenAttribute.pool.Count - 1) { dfMarkupTokenAttribute.pool.Add(new dfMarkupTokenAttribute()); } dfMarkupTokenAttribute item = dfMarkupTokenAttribute.pool[dfMarkupTokenAttribute.poolIndex]; item.Index = dfMarkupTokenAttribute.poolIndex; item.Key = key; item.Value = value; dfMarkupTokenAttribute.poolIndex = dfMarkupTokenAttribute.poolIndex + 1; return(item); }
public static dfMarkupTokenAttribute Obtain(dfMarkupToken key, dfMarkupToken value) { if (poolIndex >= (pool.Count - 1)) { pool.Add(new dfMarkupTokenAttribute()); } dfMarkupTokenAttribute attribute = pool[poolIndex]; attribute.Index = poolIndex; attribute.Key = key; attribute.Value = value; poolIndex++; return(attribute); }
public static dfMarkupTokenAttribute Obtain(dfMarkupToken key, dfMarkupToken value) { if (poolIndex >= pool.Count - 1) { pool.Add(new dfMarkupTokenAttribute()); } var instance = pool[poolIndex]; instance.Index = poolIndex; instance.Key = key; instance.Value = value; poolIndex += 1; return(instance); }
private System.Collections.Generic.List <dfMarkupToken> tokenize(string source) { dfMarkupToken.Reset(); dfMarkupTokenAttribute.Reset(); this.tokens.Clear(); this.source = source; this.index = 0; while (this.index < source.Length) { char c = this.Peek(0); if (this.AtTagPosition()) { dfMarkupToken item = this.parseTag(); if (item != null) { this.tokens.Add(item); } } else { dfMarkupToken token2 = null; if (char.IsWhiteSpace(c)) { if (c != '\r') { token2 = this.parseWhitespace(); } } else { token2 = this.parseNonWhitespace(); } if (token2 == null) { this.Advance(1); } else { this.tokens.Add(token2); } } } return(this.tokens); }
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 { } }
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 { } }
internal bool Matches(dfMarkupToken other) { var length = this.Length; if (length != other.Length) { return(false); } for (int i = 0; i < length; i++) { if (char.ToLower(Source[StartOffset + i]) != char.ToLower(other.Source[other.StartOffset + i])) { return(false); } } return(true); }
public void Release() { if (this.Key != null) { this.Key.Release(); this.Key = null; } if (this.Value != null) { this.Value.Release(); this.Value = null; } if (!pool.Contains(this)) { pool.Add(this); } }
public static dfMarkupToken Obtain(string source, dfMarkupTokenType type, int startIndex, int endIndex) { if (poolIndex >= (pool.Count - 1)) { pool.Add(new dfMarkupToken()); } dfMarkupToken token = pool[poolIndex++]; token.Source = source; token.TokenType = type; token.value = null; token.StartOffset = startIndex; token.EndOffset = endIndex; token.AttributeCount = 0; token.startAttributeIndex = 0; token.Width = 0; token.Height = 0; return(token); }
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)); }
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)); }
private List <dfMarkupToken> tokenize(string source) { dfMarkupToken.Reset(); dfMarkupTokenAttribute.Reset(); this.tokens.Clear(); this.source = source; this.index = 0; while (this.index < source.Length) { char chr = this.Peek(0); if (!this.AtTagPosition()) { dfMarkupToken _dfMarkupToken = null; if (!char.IsWhiteSpace(chr)) { _dfMarkupToken = this.parseNonWhitespace(); } else if (chr != '\r') { _dfMarkupToken = this.parseWhitespace(); } if (_dfMarkupToken != null) { this.tokens.Add(_dfMarkupToken); } else { this.Advance(1); } } else { dfMarkupToken _dfMarkupToken1 = this.parseTag(); if (_dfMarkupToken1 != null) { this.tokens.Add(_dfMarkupToken1); } } } return(this.tokens); }
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)); }
public static dfMarkupToken Obtain(string source, dfMarkupTokenType type, int startIndex, int endIndex) { if (dfMarkupToken.poolIndex >= dfMarkupToken.pool.Count - 1) { dfMarkupToken.pool.Add(new dfMarkupToken()); } List <dfMarkupToken> dfMarkupTokens = dfMarkupToken.pool; int num = dfMarkupToken.poolIndex; dfMarkupToken.poolIndex = num + 1; dfMarkupToken item = dfMarkupTokens[num]; item.Source = source; item.TokenType = type; item.@value = null; item.StartOffset = startIndex; item.EndOffset = endIndex; item.AttributeCount = 0; item.startAttributeIndex = 0; item.Width = 0; item.Height = 0; return(item); }
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; } }
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); }
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 ); }
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(); } }
private void renderText( dfMarkupToken token, Color32 color, Vector3 position, dfRenderData renderData ) { try { //@Profiler.BeginSample( "Render text token" ); var font = (dfDynamicFont)Font; var fontSize = Mathf.CeilToInt( font.FontSize * TextScale ); var fontStyle = FontStyle.Normal; var glyph = new UnityEngine.CharacterInfo(); var descent = font.Descent; var verts = renderData.Vertices; var triangles = renderData.Triangles; var uvs = renderData.UV; var colors = renderData.Colors; var x = position.x; var y = position.y; // Set the render material in the output buffer *after* requesting // glyph data, which may result in CharacterInfo in the dfDynamicFont's // texture atlas being rebuilt. renderData.Material = font.Material; var topColor = applyOpacity( multiplyColors( color, DefaultColor ) ); var bottomColor = topColor; if( BottomColor.HasValue ) { bottomColor = applyOpacity( multiplyColors( color, BottomColor.Value ) ); } for( int i = 0; i < token.Length; i++ ) { if( i > 0 ) x += CharacterSpacing * TextScale; if( !font.baseFont.GetCharacterInfo( token[ i ], out glyph, fontSize, fontStyle ) ) continue; var yadjust = ( font.FontSize + glyph.vert.y ) - fontSize + descent; var quadLeft = ( x + glyph.vert.x ); var quadTop = ( y + yadjust ); var quadRight = ( quadLeft + glyph.vert.width ); var quadBottom = ( quadTop + glyph.vert.height ); var v0 = new Vector3( quadLeft, quadTop ) * PixelRatio; var v1 = new Vector3( quadRight, quadTop ) * PixelRatio; var v2 = new Vector3( quadRight, quadBottom ) * PixelRatio; var v3 = new Vector3( quadLeft, quadBottom ) * PixelRatio; if( Shadow ) { addTriangleIndices( verts, triangles ); var activeShadowOffset = (Vector3)ShadowOffset * PixelRatio; verts.Add( v0 + activeShadowOffset ); verts.Add( v1 + activeShadowOffset ); verts.Add( v2 + activeShadowOffset ); verts.Add( v3 + activeShadowOffset ); var activeShadowColor = applyOpacity( ShadowColor ); colors.Add( activeShadowColor ); colors.Add( activeShadowColor ); colors.Add( activeShadowColor ); colors.Add( activeShadowColor ); addUVCoords( uvs, glyph ); } if( Outline ) { for( int o = 0; o < OUTLINE_OFFSETS.Length; o++ ) { addTriangleIndices( verts, triangles ); var activeOutlineOffset = (Vector3)OUTLINE_OFFSETS[ o ] * OutlineSize * PixelRatio; verts.Add( v0 + activeOutlineOffset ); verts.Add( v1 + activeOutlineOffset ); verts.Add( v2 + activeOutlineOffset ); verts.Add( v3 + activeOutlineOffset ); var activeOutlineColor = applyOpacity( OutlineColor ); colors.Add( activeOutlineColor ); colors.Add( activeOutlineColor ); colors.Add( activeOutlineColor ); colors.Add( activeOutlineColor ); addUVCoords( uvs, glyph ); } } addTriangleIndices( verts, triangles ); verts.Add( v0 ); verts.Add( v1 ); verts.Add( v2 ); verts.Add( v3 ); colors.Add( topColor ); colors.Add( topColor ); colors.Add( bottomColor ); colors.Add( bottomColor ); addUVCoords( uvs, glyph ); x += Mathf.CeilToInt( glyph.vert.x + glyph.vert.width ); } } finally { //@Profiler.EndSample(); } }
/// <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(); } }
public void Release() { if( this.Key != null ) { this.Key.Release(); this.Key = null; } if( this.Value != null ) { this.Value.Release(); this.Value = null; } if( !pool.Contains( this ) ) { pool.Add( this ); } }
public static dfMarkupTokenAttribute Obtain( dfMarkupToken key, dfMarkupToken value ) { if( poolIndex >= pool.Count - 1 ) { pool.Add( new dfMarkupTokenAttribute() ); } var instance = pool[ poolIndex ]; instance.Index = poolIndex; instance.Key = key; instance.Value = value; poolIndex += 1; return instance; }
internal void AddAttribute( dfMarkupToken key, dfMarkupToken value ) { var attribute = dfMarkupTokenAttribute.Obtain( key, value ); if( AttributeCount == 0 ) { this.startAttributeIndex = attribute.Index; } this.AttributeCount += 1; }
internal bool Matches( dfMarkupToken other ) { var length = this.Length; if( length != other.Length ) return false; for( int i = 0; i < length; i++ ) { if( char.ToLower( Source[ StartOffset + i ] ) != char.ToLower( other.Source[ other.StartOffset + i ] ) ) return false; } return true; }
public static dfMarkupTokenAttribute Obtain( dfMarkupToken key, dfMarkupToken value ) { var instance = ( pool.Count > 0 ) ? pool.Pop() : new dfMarkupTokenAttribute(); instance.Key = key; instance.Value = value; return instance; }
/// <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(); } }
private void renderText(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData renderData) { try { //@Profiler.BeginSample( "Render text token" ); var font = (dfDynamicFont)Font; var fontSize = Mathf.CeilToInt(font.FontSize * TextScale); var fontStyle = FontStyle.Normal; var descent = font.Descent; var verts = renderData.Vertices; var triangles = renderData.Triangles; var uvs = renderData.UV; var colors = renderData.Colors; var text = token.Value; var x = position.x; var y = position.y; // Ensure that the baseFont's texture contains all characters before // rendering any text. UnityEngine.CharacterInfo[] glyphs = font.RequestCharacters(text, fontSize, fontStyle); // Set the render material in the output buffer *after* requesting // glyph data, which may result in CharacterInfo in the dfDynamicFont's // texture atlas being rebuilt. renderData.Material = font.Material; var topColor = applyOpacity(multiplyColors(color, DefaultColor)); var bottomColor = topColor; if (BottomColor.HasValue) { bottomColor = applyOpacity(multiplyColors(color, BottomColor.Value)); } for (int i = 0; i < text.Length; i++) { if (i > 0) { x += CharacterSpacing * TextScale; } var glyph = glyphs[i]; var yadjust = (font.FontSize + glyph.vert.y) - fontSize + descent; var quadLeft = (x + glyph.vert.x); var quadTop = (y + yadjust); var quadRight = (quadLeft + glyph.vert.width); var quadBottom = (quadTop + glyph.vert.height); var v0 = new Vector3(quadLeft, quadTop) * PixelRatio; var v1 = new Vector3(quadRight, quadTop) * PixelRatio; var v2 = new Vector3(quadRight, quadBottom) * PixelRatio; var v3 = new Vector3(quadLeft, quadBottom) * PixelRatio; if (Shadow) { addTriangleIndices(verts, triangles); var activeShadowOffset = (Vector3)ShadowOffset * PixelRatio; verts.Add(v0 + activeShadowOffset); verts.Add(v1 + activeShadowOffset); verts.Add(v2 + activeShadowOffset); verts.Add(v3 + activeShadowOffset); var activeShadowColor = applyOpacity(ShadowColor); colors.Add(activeShadowColor); colors.Add(activeShadowColor); colors.Add(activeShadowColor); colors.Add(activeShadowColor); addUVCoords(uvs, glyph); } if (Outline) { for (int o = 0; o < OUTLINE_OFFSETS.Length; o++) { addTriangleIndices(verts, triangles); var activeOutlineOffset = (Vector3)OUTLINE_OFFSETS[o] * OutlineSize * PixelRatio; verts.Add(v0 + activeOutlineOffset); verts.Add(v1 + activeOutlineOffset); verts.Add(v2 + activeOutlineOffset); verts.Add(v3 + activeOutlineOffset); var activeOutlineColor = applyOpacity(OutlineColor); colors.Add(activeOutlineColor); colors.Add(activeOutlineColor); colors.Add(activeOutlineColor); colors.Add(activeOutlineColor); addUVCoords(uvs, glyph); } } addTriangleIndices(verts, triangles); verts.Add(v0); verts.Add(v1); verts.Add(v2); verts.Add(v3); colors.Add(topColor); colors.Add(topColor); colors.Add(bottomColor); colors.Add(bottomColor); addUVCoords(uvs, glyph); x += Mathf.CeilToInt(glyph.vert.x + glyph.vert.width); } } finally { //@Profiler.EndSample(); } }
internal void AddAttribute( dfMarkupToken key, dfMarkupToken value ) { attributes.Add( dfMarkupTokenAttribute.Obtain( key, value ) ); }
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 { } }