Beispiel #1
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);
    }
Beispiel #2
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);
    }
Beispiel #3
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);
    }