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 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 { } }
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 { 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 { } }
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; } }
/// <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(); } }
/// <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(); } }
private dfList <dfFont.LineRenderInfo> calculateLinebreaks() { try { if (this.lines == null) { this.lines = dfList <dfFont.LineRenderInfo> .Obtain(); int num = 0; int start = 0; int end = 0; int num4 = 0; float num5 = base.Font.LineHeight * base.TextScale; while ((end < this.tokens.Count) && ((this.lines.Count * num5) < base.MaxSize.y)) { dfMarkupToken token = this.tokens[end]; dfMarkupTokenType tokenType = token.TokenType; if (tokenType == dfMarkupTokenType.Newline) { this.lines.Add(dfFont.LineRenderInfo.Obtain(start, end)); start = num = ++end; num4 = 0; } else { int num6 = Mathf.CeilToInt(token.Width * base.TextScale); if (((base.WordWrap && (num > start)) && ((tokenType == dfMarkupTokenType.Text) || ((tokenType == dfMarkupTokenType.StartTag) && token.Matches("sprite")))) && ((num4 + num6) >= base.MaxSize.x)) { if (num > start) { this.lines.Add(dfFont.LineRenderInfo.Obtain(start, num - 1)); start = end = ++num; num4 = 0; } else { this.lines.Add(dfFont.LineRenderInfo.Obtain(start, num - 1)); start = num = ++end; num4 = 0; } continue; } if (tokenType == dfMarkupTokenType.Whitespace) { num = end; } num4 += num6; end++; } } if (start < this.tokens.Count) { this.lines.Add(dfFont.LineRenderInfo.Obtain(start, this.tokens.Count - 1)); } for (int i = 0; i < this.lines.Count; i++) { this.calculateLineSize(this.lines[i]); } } return(this.lines); } finally { } }
private dfList <dfFont.LineRenderInfo> calculateLinebreaks() { dfList <dfFont.LineRenderInfo> lineRenderInfos; bool flag; try { if (this.lines == null) { this.lines = dfList <dfFont.LineRenderInfo> .Obtain(); int num = 0; int num1 = 0; int num2 = 0; int num3 = 0; float lineHeight = (float)base.Font.LineHeight * base.TextScale; while (num2 < this.tokens.Count) { Vector2 maxSize = base.MaxSize; if ((float)this.lines.Count * lineHeight >= maxSize.y) { break; } dfMarkupToken item = this.tokens[num2]; dfMarkupTokenType tokenType = item.TokenType; if (tokenType != dfMarkupTokenType.Newline) { int num4 = Mathf.CeilToInt((float)item.Width * base.TextScale); if (!base.WordWrap || num <= num1) { flag = false; } else if (tokenType == dfMarkupTokenType.Text) { flag = true; } else { flag = (tokenType != dfMarkupTokenType.StartTag ? false : item.Matches("sprite")); } if (!flag || (float)(num3 + num4) < base.MaxSize.x) { if (tokenType == dfMarkupTokenType.Whitespace) { num = num2; } num3 = num3 + num4; num2++; } else if (num <= num1) { this.lines.Add(dfFont.LineRenderInfo.Obtain(num1, num - 1)); int num5 = num2 + 1; num2 = num5; num = num5; num1 = num5; num3 = 0; } else { this.lines.Add(dfFont.LineRenderInfo.Obtain(num1, num - 1)); int num6 = num + 1; num = num6; num2 = num6; num1 = num6; num3 = 0; } } else { this.lines.Add(dfFont.LineRenderInfo.Obtain(num1, num2)); int num7 = num2 + 1; num2 = num7; num = num7; num1 = num7; num3 = 0; } } if (num1 < this.tokens.Count) { this.lines.Add(dfFont.LineRenderInfo.Obtain(num1, this.tokens.Count - 1)); } for (int i = 0; i < this.lines.Count; i++) { this.calculateLineSize(this.lines[i]); } lineRenderInfos = this.lines; } else { lineRenderInfos = this.lines; } } finally { } return(lineRenderInfos); }