Exemplo n.º 1
0
    /// <summary>
    /// Builds a whole charset for a specific fontid
    /// </summary>
    public void BuildCharSet(string fontid)
    {
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR
        int  istep    = TTFTextFontStore.Instance.defaultInterpolationSteps;
        bool reversed = false;
        charset         = new TTFTextOutline[0x80];
        charset_advance = new Vector3[0x80];
        System.Text.ASCIIEncoding ae = new System.Text.ASCIIEncoding();

        TTF.Font font = TTFTextInternal.Utilities.TryOpenFont(fontid, ref reversed, "", 72); // TODO: < Check the last bool

        if (font == null)
        {
            Debug.LogError("BuildCharSet: no font found");
            return;
        }

        for (byte i = 0x20; i < 0x7F; i++)
        {
            string s = ae.GetString(new byte [] { i });
            charset[i] = TTFTextInternal.Engine.MakeNativeOutline(s, 1, 0, font, reversed, istep);
            //TTFTextInternal.MakeOutline(s, font, 1, 0, null,false,null,null);
            charset_advance[i] = charset[i].advance;
        }


        addCharset = new TTFTextOutline[additionalChar.Length];

        int idx = 0;
        foreach (char c in additionalChar)
        {
            addCharset[idx] = TTFTextInternal.Engine.MakeNativeOutline(
                "" + c, 1, 0, font,
                reversed, istep);
            ++idx;
        }

        font.Dispose();
        _needRebuild = false;
#endif
    }
Exemplo n.º 2
0
    /// <summary>
    /// Tries to build a whole charset according current parameters of a textmesh object
    /// </summary>
    public void BuildCharSet(TTFText tm)
    {
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR
        int istep = TTFTextFontStore.Instance.defaultInterpolationSteps;
        charset         = new TTFTextOutline[0x80];
        charset_advance = new Vector3[0x80];
        System.Text.ASCIIEncoding ae = new System.Text.ASCIIEncoding();

        TTF.Font font = TTFTextInternal.Utilities.TryOpenFont(tm.InitTextStyle, 1);

        if (font == null)
        {
            Debug.LogError("(TTFText) BuildCharSet: no font found");
            return;
        }
        height = font.Height;
        for (byte i = 0x20; i < 0x7F; i++)
        {
            string s = ae.GetString(new byte [] { i });
            charset[i]         = TTFTextInternal.Engine.MakeNativeOutline(s, 1, 0, font, tm.OrientationReversed, istep);
            charset_advance[i] = charset[i].advance;
        }


        // Additional Custom Characters
        AddRequiredCharacters(TTFTextFontStore.Instance.defaultAdditionalCharacters + (tm.InitTextStyle.GetFontEngineParameters(1)
                                                                                       as TTFTextInternal.FontStoreFontEngine.Parameters).additionalCharacters);

        addCharset = new TTFTextOutline[additionalChar.Length];

        int idx = 0;
        foreach (char c in additionalChar)
        {
            addCharset[idx] = TTFTextInternal.Engine.MakeNativeOutline("" + c, 1, 0, font, tm.OrientationReversed, istep);
            ++idx;
        }

        font.Dispose();
        _needRebuild = false;
#endif
    }