Exemple #1
0
    private void Start()
    {
        var source = new FontSource(_font.bytes);

        var fontModel = FontModel.Load(source);

        var codePoints = UnicodeUtility.ToCodePoints(_text);

        _contourPoints = new List <GlyphContourInfoV2>(codePoints.Length);

        var offset = 0f;

        for (var i = 0; i < codePoints.Length; i++)
        {
            try
            {
                var codePoint = codePoints[i];
                var glyph     = fontModel.GetGlyph(codePoint, source);
                var con       = glyph.ToVector2(fontModel, source);
                ShowPoint(con, offset);
                offset += con.AdvancedWidth;
                _contourPoints.Add(con);
            }
            catch (FontException e)
            {
                Debug.LogWarning(e);

                // Replace with a tofu glyph.
                var glyph = fontModel.GetNotDefGlyph(source);
                var con   = glyph.ToVector2(fontModel, source);
                ShowPoint(con, offset);
                offset += con.AdvancedWidth;
                _contourPoints.Add(con);
            }
        }
    }