Exemplo n.º 1
0
    public override void OnPreviewGUI(Rect rect, GUIStyle background)
    {
        Graphics.DrawTexture(
            rect,
            script.material.mainTexture,
            new Rect(0, 0, 1, 1),
            0, 0, 0, 0,
            Color.white,
            script.material);

        foreach (var c in script.data.charTable.Keys)
        {
            if (c == ' ')
            {
                continue; // ignore space
            }

            var glyph = script.GlyphFor(c);

            var glyphRect = new Rect(
                rect.x + glyph.x * rect.width,
                rect.y + glyph.y * rect.height,
                glyph.width * rect.width,
                glyph.height * rect.height);

            DrawRect(glyphRect, Color.green);
        }
    }
Exemplo n.º 2
0
    public override Rect GetBounds()
    {
        if (!CanDraw())
        {
            return(new Rect());
        }

        UpdatePivotPoint();

        float width  = 0;
        float height = 0;

        foreach (char c in text)
        {
            var glyph = font.GlyphFor(c);
            if (glyph == null)
            {
                Debug.LogWarning("No glyph found for '" + c + "'");
                continue;
            }

            float xAdvance;
            var   bounds = GlyphBounds(glyph, out xAdvance);
            width  += xAdvance;
            height += bounds.height;

//
//            float scaleMod = scale / font.data.infoSize;
//
//            float w = (scale / glyph.height) * glyph.width * font.textureAspect;
//            width += w;
//
//            if (c != ' ') {
//                width += letterSpacing;
//            }
        }

        var rawBounds = new Rect(0, 0, width, scale);

        var start = PivotPointTranslate(new Vector2(0, 0), rawBounds);
        var end   = PivotPointTranslate(new Vector2(width, scale), rawBounds);

        return(new Rect(start.x, start.y, end.x - start.x, end.y - start.y));
    }
Exemplo n.º 3
0
    private float LineWidth(string text)
    {
        float lineWidth = 0;

        foreach (char c in text)
        {
            var glyph = font.GlyphFor(c);
            if (glyph == null)
            {
                Debug.LogWarning("No glyph found for '" + c + "' (code " + (int)c + ")");
                continue;
            }

            float xAdvance;
            GlyphBounds(glyph, out xAdvance);
            lineWidth += xAdvance;
        }

        return(lineWidth);
    }