private IEnumerable DoSyncDownloadOutline(string fontid, string characters)
    {
        GetFontOutline(this.TTFTextServerUrl, fontid, characters);
        // we shall now wait .... for the download to be complete...
        TTFTextFontStoreFont f = null;

        for (int i = 0; i < 10; i++)
        {
            yield return(new WaitForSeconds(1));

            foreach (TTFTextFontStoreFont cf in embeddedFonts)
            {
                if (cf.fontid == fontid)
                {
                    f = cf;
                    break;
                }
            }
        }
        if (f == null)
        {
            throw new System.Exception("TIME OUT ");
        }
        yield break;
    }
        public void DecRef(object parameters, string fontid)
        {
            TTFTextFontStoreFont fnt = TTFTextFontStore.Instance.GetEmbeddedFont(fontid);

            if (fnt != null)
            {
                fnt.decref();
                TTFTextFontStore.Instance.SetGarbageCollectUnusedFonts();
            }
        }
        public void IncRef(object parameters, string fontid)
        {
            TTFTextFontStoreFont fnt = TTFTextFontStore.Instance.GetEmbeddedFont(fontid);

            if (fnt == null)
            {
                fnt = TTFTextFontStore.Instance.EnsureFont(fontid);
                fnt.BuildCharSet(fontid);
            }
            fnt.incref();
        }
    //
    public void UpdateClient(TTFText tm)
    {
        // may be used to update the necessary charmap of
        // a font on the fly
        TTFTextFontStoreFont x = GetFont(tm.FontId);

        x.AddRequiredCharacters(x.additionalChar);
        if (x.needRebuild)
        {
            x.BuildCharSet(tm.FontId);
        }
        Debug.LogWarning("Not yet implemented");
    }
    public TTFTextFontStoreFont EnsureFont(string fontid)
    {
        // ensures that a specific font is present the store
        // this function does not update the reference counts

        TTFTextFontStoreFont f = GetFont(fontid);

        if (f == null)
        {
            TTFTextFontStoreFont nf = new TTFTextFontStoreFont();
            if (fontid.Length > 0)
            {
                nf.fontid  = fontid;
                nf.charset = null;
                nf.AddRequiredCharacters(this.defaultAdditionalCharacters);         // addd this
                embeddedFonts.Add(nf);
                f = nf;
#if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    string d = Application.dataPath;
                    d = System.IO.Path.Combine(d, "Resources");
                    if (!System.IO.Directory.Exists(d))
                    {
                        UnityEditor.AssetDatabase.CreateFolder("Assets", "Resources");
                    }
                    d = System.IO.Path.Combine(d, "TTFText");
                    if (!System.IO.Directory.Exists(d))
                    {
                        UnityEditor.AssetDatabase.CreateFolder("Assets/Resources", "TTFText");
                    }
                    d = System.IO.Path.Combine(d, "Fonts");
                    if (!System.IO.Directory.Exists(d))
                    {
                        UnityEditor.AssetDatabase.CreateFolder("Assets/Resources/TTFText", "Fonts");
                    }
                    f.BuildCharSet(f.fontid);

                    UnityEditor.AssetDatabase.CreateAsset(TTFTextFontStoreFontAsset.CreateInstance <TTFTextFontStoreFontAsset>().Init(f), "Assets/Resources/TTFText/Fonts/" + f.fontid + ".asset");
                    Debug.Log("Font " + f.fontid + " has been embedded");
                }
#endif
            }
        }

        return(f);
    }
 public void ResetFontStore()
 {
     embeddedFonts = new List <TTFTextFontStoreFont>();
     foreach (TTFText client in Clients)
     {
         EnsureFont(client.FontId);
     }
     foreach (TTFText client in Clients)
     {
         TTFTextFontStoreFont f = GetFont(client.FontId);
         f.incref();
         if (f.charset == null)
         {
             f.BuildCharSet(client);
         }
     }
 }
    public TTFTextFontStoreFont EnsureFont(string fontid)
    {
        // ensures that a specific font is present the store
        // this function does not update the reference counts

        TTFTextFontStoreFont f = GetFont(fontid);

        if (f==null) {
            TTFTextFontStoreFont nf=new TTFTextFontStoreFont();
            if (fontid.Length>0) {
            nf.fontid=fontid;
            nf.charset=null;
            nf.AddRequiredCharacters(this.defaultAdditionalCharacters); // addd this
            embeddedFonts.Add(nf);
            f=nf;
        #if UNITY_EDITOR
                if (!Application.isPlaying) {
                string d=Application.dataPath;
                d=System.IO.Path.Combine(d,"Resources");
                if (!System.IO.Directory.Exists(d)) {
                        UnityEditor.AssetDatabase.CreateFolder("Assets","Resources");
                }
                d=System.IO.Path.Combine(d,"TTFText");
                if (!System.IO.Directory.Exists(d)) {
                        UnityEditor.AssetDatabase.CreateFolder("Assets/Resources","TTFText");
                }
                d=System.IO.Path.Combine(d,"Fonts");
                if (!System.IO.Directory.Exists(d)) {
                        UnityEditor.AssetDatabase.CreateFolder("Assets/Resources/TTFText","Fonts");
                }
                f.BuildCharSet(f.fontid);

                UnityEditor.AssetDatabase.CreateAsset(TTFTextFontStoreFontAsset.CreateInstance<TTFTextFontStoreFontAsset>().Init(f),"Assets/Resources/TTFText/Fonts/"+f.fontid+".asset");
                Debug.Log("Font "+ f.fontid+ " has been embedded");
                }
        #endif
            }
        }

        return f;
    }
    // this version will block until all character are downloaded...
    public IEnumerable SyncGetOutlineForLetter(string fontid, string characters)
    {
        TTFTextOutline [] res = new TTFTextOutline[characters.Length];
        // for each character

        TTFTextFontStoreFont f = GetFont(fontid);

        if (f == null)
        {
            IEnumerable r = null;
            do
            {
                r = DoSyncDownloadOutline(fontid, f.additionalChar);
                if (r.GetType() == typeof(WaitForSeconds))
                {
                    yield return(r);
                }
            } while (r.GetType() == typeof(WaitForSeconds));
        }

        foreach (char c in characters)
        {
            if (!f.HasCharacter(c))
            {
                f.AddRequiredCharacters(characters);
                IEnumerable r = null;
                do
                {
                    r = DoSyncDownloadOutline(fontid, f.additionalChar);
                    if (r.GetType() == typeof(WaitForSeconds))
                    {
                        yield return(r);
                    }
                } while (r.GetType() == typeof(WaitForSeconds));
            }
        }

        yield return(res);
    }
    public void GetFontOutlineReply(string reply)
    {
        JsonData             fontoutlinereply = JsonMapper.ToObject(reply);
        string               fontid           = (string)fontoutlinereply["fontid"];
        TTFTextFontStoreFont tfsf             = GetDynamiclyLoadedFont(fontid);

        if (tfsf == null)
        {
            tfsf        = new TTFTextFontStoreFont();
            tfsf.fontid = fontid;
        }

        /*
         *
         * byte[] outlinebytes = System.Convert.FromBase64String((string) fontoutlinereply["characters"]);
         * MemoryStream ms=new MemoryStream(outlinebytes);
         * BinaryReader br=new BinaryReader(ms);
         *
         * //tfsf.AddOutlines();
         * Debug.Log("received reply");
         */
    }
    public void GetFontOutlineReply(string reply)
    {
        JsonData fontoutlinereply=JsonMapper.ToObject(reply);
        string fontid=(string)fontoutlinereply["fontid"];
        TTFTextFontStoreFont tfsf = GetDynamiclyLoadedFont(fontid);
        if (tfsf==null) {
            tfsf=new TTFTextFontStoreFont();
            tfsf.fontid=fontid;
        }

        /*

        byte[] outlinebytes = System.Convert.FromBase64String((string) fontoutlinereply["characters"]);
        MemoryStream ms=new MemoryStream(outlinebytes);
        BinaryReader br=new BinaryReader(ms);

        //tfsf.AddOutlines();
        Debug.Log("received reply");
        */
    }
Beispiel #11
0
    public override void OnInspectorGUI()
    {
        TTFTextFontStore tfs = target as TTFTextFontStore;

        if (tfs == null)
        {
            GUI.color = Color.red;
            EditorGUILayout.LabelField("Cannot find the component");
            return;
        }

        tfs.dontDestroyOnLoad = EditorGUILayout.Toggle("Don't Destroy On Scene Change", tfs.dontDestroyOnLoad);

        //tfs.destroyWhenUnused=EditorGUILayout.Toggle("Destroy Font Store When Unused", tfs.destroyWhenUnused);


        showFonts = EditorGUILayout.Foldout(showFonts, "Embedded Fonts");

        if (showFonts)
        {
            EditorGUI.indentLevel += 2;
            int i = 0;

            if (tfs.embeddedFonts != null && tfs.embeddedFonts.Count != 0)
            {
                string d = System.IO.Path.Combine(
                    System.IO.Path.Combine(Application.dataPath, "Resources"),
                    System.IO.Path.Combine("TTFText", "Fonts"));

                string fonttoberemoved = null;

                foreach (TTFTextFontStoreFont f in tfs.embeddedFonts)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(System.String.Format("{0} - {1} [{2}] {3}kb", i, f.fontid, f.GetRefCount(), f.BoundaryMemoryUsage() / 1024));

                    /*
                     * if (GUILayout.Button("Save As Asset")) {
                     *
                     *      if (System.IO.Directory.Exists(d)) {
                     *              System.IO.Directory.CreateDirectory(d);
                     *              UnityEditor.AssetDatabase.Refresh();
                     *      }
                     *      f.BuildCharSet(f.fontid);
                     *      UnityEditor.AssetDatabase.CreateAsset(TTFTextFontStoreFontAsset.CreateInstance<TTFTextFontStoreFontAsset>().Init(f),"Assets/Resources/TTFText/Fonts/"+f.fontid+".asset");
                     * }
                     */
                    if (System.IO.File.Exists(d + "/" + f.fontid + ".asset"))
                    {
                        if (GUILayout.Button("Delete Asset"))
                        {
                            //Debug.Log(d +"/"+f.fontid+".asset");
                            //AssetDatabase.DeleteAsset(d+"/" +f.fontid+".asset");
                            fonttoberemoved = f.fontid;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    ++i;
                }

                if (fonttoberemoved != null)
                {
                    System.IO.File.Delete(d + "/" + fonttoberemoved + ".asset");
                    if (System.IO.File.Exists(d + "/" + fonttoberemoved + ".asset.meta"))
                    {
                        System.IO.File.Delete(d + "/" + fonttoberemoved + ".asset.meta");
                    }

                    tfs.RemoveFont(fonttoberemoved);
                    AssetDatabase.Refresh();
                }
            }
            else
            {
                //Color sc = GUI.color ;
                //GUI.color = Color.red;
                EditorGUILayout.LabelField("No font is currently embedded");
                //GUI.color = sc;
            }
            EditorGUI.indentLevel -= 2;
        }


        showClients = EditorGUILayout.Foldout(showClients, "Clients");
        if (showClients)
        {
            EditorGUI.indentLevel += 2;
            int i = 0;
            foreach (TTFText tm in tfs.Clients)
            {
                EditorGUILayout.LabelField(System.String.Format("{0} - {1}", i, tm.gameObject.name));
                i++;
            }
            EditorGUI.indentLevel -= 2;
        }


        showOptions = EditorGUILayout.Foldout(showOptions, "Shared Options");
        if (showOptions)
        {
            EditorGUI.indentLevel += 2;
            int    pi  = TTFTextFontStore.Instance.defaultInterpolationSteps;
            string das = TTFTextFontStore.Instance.defaultAdditionalCharacters;
            TTFTextFontStore.Instance.defaultInterpolationSteps = EditorGUILayout.IntField("Interpolation Steps", TTFTextFontStore.Instance.defaultInterpolationSteps);
            if (TTFTextFontStore.Instance.defaultInterpolationSteps < 1)
            {
                TTFTextFontStore.Instance.defaultInterpolationSteps = 1;
            }
            if (TTFTextFontStore.Instance.defaultInterpolationSteps > 10)
            {
                TTFTextFontStore.Instance.defaultInterpolationSteps = 10;
            }
            TTFTextFontStore.Instance.defaultAdditionalCharacters = EditorGUILayout.TextField("Additional Characters", TTFTextFontStore.Instance.defaultAdditionalCharacters);
            if ((pi != TTFTextFontStore.Instance.defaultInterpolationSteps) || (TTFTextFontStore.Instance.defaultAdditionalCharacters != das))
            {
                TTFTextFontStore.Instance.RebuildAllCharsets();
            }
            EditorGUI.indentLevel -= 2;
        }

        showControl = EditorGUILayout.Foldout(showControl, "Advanced FontStore Control");
        if (showControl)
        {
            if (GUILayout.Button(new GUIContent("Embed All Project Fonts", "Embed all the fonts that are contained in the project folder in the application")))
            {
                List <string> tl = new List <string>();
                foreach (var f in TTFTextFontListManager.Instance.LocalFonts)
                {
                    tl.Add(f.Key);
                }
                foreach (string f in tl)
                {
                    tfs.EnsureFont(f);
                }
                AssetDatabase.Refresh();
            }

            if (GUILayout.Button("Reset FontStore"))
            {
                tfs.ResetFontStore();
            }

            GUILayout.Label("Add specific fonts to the font store");
            TTFTextFontListManager flm = TTFTextFontListManager.Instance;

            Color selectedColor  = new Color(1, 1, 0, 1);
            Color selectedColor2 = new Color(0, 1, 0, 1);

            Color defcolor = GUI.color;

            List <string> fontIDs = new List <string>(flm.LocalFonts.Keys);

            if (showSystemFonts)
            {
                fontIDs.AddRange(flm.SystemFonts.Keys);
            }



            {
                scrollpos = GUILayout.BeginScrollView(scrollpos,
                                                      false,
                                                      true,
                                                      GUILayout.MinHeight(150),
                                                      GUILayout.MaxHeight(150));

                for (int i = 0; i < fontIDs.Count; ++i)
                {
                    string id = fontIDs[i];


                    //tfs.embeddedFonts			 *
                    TTFTextFontStoreFont cf = tfs.GetEmbeddedFont(id);
                    if (cf != null)
                    {
                        if (cf.refcount == 0)
                        {
                            GUI.color = selectedColor;
                        }
                        else
                        {
                            GUI.color = selectedColor2;
                        }
                    }
                    else
                    {
                        GUI.color = defcolor;
                    }


                    TTFontInfo finfo = flm.GetFontInfo(id);

                    if (finfo != null)
                    {
                        if (GUILayout.Button(finfo.Name))
                        {
                            if ((cf == null))
                            {
                                cf = tfs.EnsureFont(id);
                                cf.BuildCharSet(id);
                            }
                            else
                            {
                                if (cf.refcount == 0)
                                {
                                    tfs.embeddedFonts.Remove(cf);
                                }
                            }
                            //f.incref();
                        }
                    }
                }

                GUILayout.EndScrollView();
                GUI.color = defcolor;
            }
        }
    }
 public TTFTextFontStoreFontAsset Init(TTFTextFontStoreFont f)
 {
     font=f;
     _name=f.fontid;
     return this;
 }
 public TTFTextFontStoreFontAsset Init(TTFTextFontStoreFont f)
 {
     font  = f;
     _name = f.fontid;
     return(this);
 }
        public float GetHeight(object parameters, object font)
        {
            TTFTextFontStoreFont fnt = (TTFTextFontStoreFont)font;

            return(fnt.height);
        }