Exemplo n.º 1
0
 public void ScaleFont(float s)
 {
     if (!this._scaled)
     {
         this._scaled     = true;
         this.fontSize    = (int)((float)this.fontSize * s);
         this.lineHeight *= s;
         this.ascender   *= s;
         this.descender  *= s;
         for (int i = 0; i < this.characters.Length; i++)
         {
             AgeFont.Character character = this.characters[i];
             character.Advance   *= s;
             character.Offset    *= s;
             character.Dimension *= s;
             this.characters[i]   = character;
         }
         AgeFont.Log(string.Concat(new string[]
         {
             "Font ",
             base.name,
             "(",
             this.font.name,
             ") is scaled for ",
             s.ToString()
         }));
     }
 }
Exemplo n.º 2
0
    public float ComputeTextWidth(StringBuilder text, bool forcedCaps = false)
    {
        float num = 0f;

        this.CreateCharMap(false);
        for (int i = 0; i < text.Length; i++)
        {
            char charCode = text[i];
            if (forcedCaps)
            {
                charCode = AgeFont.RaiseChar(charCode);
            }
            AgeFont.Character character = null;
            if (this.TryGetCharacter(charCode, this.fontSize, out character))
            {
                num += character.Advance;
                if (this.HasKerningInfo && i + 1 < text.Length)
                {
                    char c = text[i + 1];
                    if (forcedCaps)
                    {
                        c = AgeFont.RaiseChar(c);
                    }
                    num += this.GetKerningOffset(text[i], c);
                }
            }
        }
        return(num);
    }
Exemplo n.º 3
0
    public int GetCharIndexInLineAtPosition(string text, float positionX, bool forcedCaps = false)
    {
        float num = 0f;

        this.CreateCharMap(false);
        for (int i = 0; i < text.Length; i++)
        {
            char charCode = text[i];
            if (forcedCaps)
            {
                charCode = AgeFont.RaiseChar(charCode);
            }
            AgeFont.Character character = null;
            if (this.TryGetCharacter(charCode, this.fontSize, out character))
            {
                num += character.Advance;
                if (this.HasKerningInfo && i + 1 < text.Length)
                {
                    char c = text[i + 1];
                    if (forcedCaps && c >= 'a' && c <= 'z')
                    {
                        c = (char)((int)c + -32);
                    }
                    num += this.GetKerningOffset(text[i], c);
                }
            }
            if (num > positionX)
            {
                return(i);
            }
        }
        return(text.Length);
    }
Exemplo n.º 4
0
    public float ComputeTextWidth(string text, bool forcedCaps = false, bool makeClean = false)
    {
        float num = 0f;

        this.CreateCharMap(false);
        if (makeClean)
        {
            AgeUtils.CleanLine(text, ref AgePrimitiveLabel.CleanLine);
            text = AgePrimitiveLabel.CleanLine.ToString();
        }
        for (int i = 0; i < text.Length; i++)
        {
            char charCode = text[i];
            if (forcedCaps)
            {
                charCode = AgeFont.RaiseChar(charCode);
            }
            AgeFont.Character character = null;
            if (this.TryGetCharacter(charCode, this.fontSize, out character))
            {
                num += character.Advance;
                if (this.HasKerningInfo && i + 1 < text.Length)
                {
                    char c = text[i + 1];
                    if (forcedCaps && c >= 'a' && c <= 'z')
                    {
                        c = (char)((int)c + -32);
                    }
                    num += this.GetKerningOffset(text[i], c);
                }
            }
        }
        return(num);
    }
Exemplo n.º 5
0
    private bool TryGetCharacter(char charCode, int fontSize, out AgeFont.Character character)
    {
        this.CreateCharMap(false);
        bool flag = this.charMap.TryGetValue(charCode, out character);

        if (!flag)
        {
            if (this.dynamicGlyphAltassing)
            {
                bool flag2 = this.freeTypeFont.IsGlyphDefined((uint)charCode);
                if (flag2)
                {
                    FreeTypeFont.GlyphPositioningInformation glyphPositioningInformation;
                    this.freeTypeFont.GetGlyphPositioningInformation((uint)charCode, (uint)fontSize, out glyphPositioningInformation);
                    AgeFont.Character character2 = new AgeFont.Character();
                    character2.Charcode  = (int)charCode;
                    character2.Advance   = glyphPositioningInformation.Advance;
                    character2.Dimension = new Vector2(glyphPositioningInformation.Width, glyphPositioningInformation.Height);
                    character2.Offset    = new Vector2(glyphPositioningInformation.BearingX, -glyphPositioningInformation.BearingY);
                    FontAtlasRenderer fontAtlasRenderer = AgeManager.Instance.FontAtlasRenderer;
                    Rect  orCreateInAtlas = fontAtlasRenderer.GetOrCreateInAtlas((uint)charCode, this, (uint)fontSize);
                    float num             = 128f;
                    orCreateInAtlas.x += num;
                    orCreateInAtlas.y += num;
                    character2.RuntimeTextureCoordinates = orCreateInAtlas;
                    character2.TextureCoordinates        = character2.RuntimeTextureCoordinates;
                    character = character2;
                    return(true);
                }
            }
            int num2 = this.fallbackFonts.Length;
            for (int i = 0; i < num2; i++)
            {
                AgeFont ageFont = this.fallbackFonts[i];
                if (ageFont.TryGetCharacter(charCode, fontSize, out character))
                {
                    return(true);
                }
            }
            return(false);
        }
        return(flag);
    }