Example #1
0
        public void Export()
        {
            TEXPreference.Initialize();
            var path = TEXPreference.main.MainFolderPath + "Core/Editor/Resources/" + id + ".json";
            var json = JsonUtility.ToJson(this);

            Directory.CreateDirectory(path);
            File.WriteAllText(path, json);
            Debug.Log("Successfully written to " + path);
        }
Example #2
0
     static void LoadPrimaryDefinitionSubset(TEXPreference pref, List <TexFont> fontList, string folderPath, string typeStr, TexFontType typeEnum, int mode)
     {
         if (!AssetDatabase.IsValidFolder(folderPath))
         {
             return;
         }
         string[] customF = AssetDatabase.FindAssets(typeStr, new string[] { folderPath });
         for (int i = 0; i < customF.Length; i++)
         {
             if (fontList.Count >= 31)
             {
                 Debug.LogWarning("Font/Sprite database count are beyond 31, ignoring any assets after " + fontList[fontList.Count - 1].id);
                 break;
             }
             string realPath = AssetDatabase.GUIDToAssetPath(customF[i]);
             string id       = Path.GetFileNameWithoutExtension(realPath).ToLower();
             UpdateProgress(mode, id, i, customF.Length);
             if (!isNameValid(id))
             {
                 // We show this for information purpose, since *-Regular or *_ is very common mistake
                 // We are not showing this for frequent update, since this behavior is 'intended' for giving an alternative styling
                 if (id.Contains("-Regular") || id.Substring(id.Length - 1) == "_")
                 {
                     Debug.LogWarning("File " + id + " is ignored since it has invalid character in it's name");
                 }
                 continue;
             }
             var metaPath = pref.MainFolderPath + resourceFontMetaPath + id + ".asset";
             var metadata = AssetDatabase.LoadAssetAtPath <TexFont>(metaPath);
             if (!metadata)
             {
                 metadata = ScriptableObject.CreateInstance <TexFont>();
                 AssetDatabase.CreateAsset(metadata, metaPath);
                 metadata.importCatalog = TexCharPresets.legacyChars;
             }
             metadata.id = id;
             metadata.ClearAssetData();
             metadata.index = fontList.Count;
             metadata.type  = typeEnum;
             metadata.GrabAssetData(realPath);
 #if TEXDRAW_TMP
             string sdfPath = pref.MainFolderPath + "/Fonts/TMPro/" + id + ".asset";
             if (typeEnum == TexFontType.Font && AssetDatabase.LoadAssetAtPath <TMPro.TMP_FontAsset>(sdfPath))
             {
                 metadata.type = TexFontType.Font_SDF;
                 metadata.GrabAssetData(sdfPath);
             }
 #endif
             metadata.Populate(false);
             fontList.Add(metadata);
         }
     }
Example #3
0
        static public void Initialize()
        {
#if UNITY_EDITOR
            if (!main)
            {
                //Get the Preference
                string[] targetData = AssetDatabase.FindAssets("t:TEXPreference");
                if (targetData.Length > 0)
                {
                    var path = AssetDatabase.GUIDToAssetPath(targetData[0]);
                    main = AssetDatabase.LoadAssetAtPath <TEXPreference>(path);
                    main.MainFolderPath = Path.GetDirectoryName(path);
                    // TEXDraw preference now put into resources files after 3.0
                    if (main.MainFolderPath.Contains("Resources"))
                    {
                        main.MainFolderPath = Path.GetDirectoryName(main.MainFolderPath);
                    }
                    if (targetData.Length > 1)
                    {
                        Debug.LogWarning("You have more than one TEXDraw preference, ensure that only one Preference exist in your Project");
                    }
                }
                else
                {
                    //Create New One
                    main = CreateInstance <TEXPreference>();
                    if (AssetDatabase.IsValidFolder(DefaultTexFolder))
                    {
                        AssetDatabase.CreateAsset(main, DefaultTexFolder + "/Resources/TEXDrawPreference.asset");
                        main.FirstInitialize(DefaultTexFolder);
                    }
                    else
                    {
                        //Find alternative path to the TEXPreference, that's it: Parent path of TEXPreference script.
                        string AlternativePath = AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(main));
                        AlternativePath = Directory.GetParent(AlternativePath).Parent.FullName;
                        AssetDatabase.CreateAsset(main, AlternativePath + "/Resources/TEXDrawPreference.asset");
                        main.FirstInitialize(AlternativePath);
                    }
                }
            }
#else
            if (!main)
            {
                // The only thing that we can found is in the Resource folder
                main = (TEXPreference)Resources.Load("TEXDrawPreference");
            }
#endif
            // also init the neighborhood
            TEXConfiguration.Initialize();
        }
Example #4
0
        public static void ReadLegacyPreferences(TEXPreference pref, string XMLFontDef, string XMLConfigDef)
        {
            //Clean up first
            pref.glueTable = new int[100];
//            pref.defaultTypefaces = new TexTypeFaceDictionary();

            //Look up all font & sprites
            XmlDocument doc = new XmlDocument();
            XmlNode     cNode, configNodes;
            List <TEXConfigurationMember> configs = new List <TEXConfigurationMember>();

            doc.LoadXml(XMLFontDef);

            //Load all configurations. (the thing with bunch of sliders)
            configNodes = doc.SelectSingleNode("/TexFont/Params");
            for (int i = 0; i < configNodes.ChildNodes.Count; i++)
            {
                cNode = configNodes.ChildNodes[i];
                configs.Add(new TEXConfigurationMember(cNode.Attributes["name"].Value, cNode.Attributes["desc"].Value,
                                                       float.Parse(cNode.Attributes["value"].Value), float.Parse(cNode.Attributes["min"].Value), float.Parse(cNode.Attributes["max"].Value)));
            }

            //pref.configs = configs.ToArray();

            doc.LoadXml(XMLConfigDef);

            // No longer importing config via XML

            /*XmlNode Params = doc.SelectSingleNode("/TEXConfigurations/Parameters");
             * for (int i = 0; i < Params.ChildNodes.Count; i++) {
             *  var att = Params.ChildNodes[i].Attributes[0];
             *  pref.preferences[att.Name] = float.Parse(att.Value);
             *  pref.configs.First(x => x.name == att.Name).value = pref.preferences[att.Name];
             * }*/

            /*          XmlNode Typefaces = doc.SelectSingleNode("/TEXConfigurations/DefaultTypefaces");
             * foreach (XmlNode node in Typefaces.ChildNodes) {
             * pref.defaultTypefaces.Add((TexCharKind)int.Parse(node.Attributes["code"].Value), int.Parse(node.Attributes["fontId"].Value));
             * }*/

            XmlNode GlueTables = doc.SelectSingleNode("/TexConfigurations/GlueTable");

            foreach (XmlNode node in GlueTables.ChildNodes)
            {
                pref.glueTable[int.Parse(node.Attributes["leftType"].Value) * 10 + int.Parse(node.Attributes["rightType"].Value)]
                    = int.Parse(node.Attributes["glueSize"].Value);
            }

            pref.PushToDictionaries();
        }
Example #5
0
        public static void ReadFromResources(TEXPreference pref)
        {
            var fontList = new List <TexAsset>();

            if (!AssetDatabase.IsValidFolder(pref.MainFolderPath + "/Resources/TexFontMetaData"))
            {
                AssetDatabase.CreateFolder(pref.MainFolderPath + "/Resources", "TexFontMetaData");
            }
            LoadPrimaryDefinitionSubset <TexFont>(pref, fontList, pref.MainFolderPath + "/Fonts/Math", "t:Font", TexAssetType.Font, 0);
            pref.header_mathCount = fontList.Count;
            LoadPrimaryDefinitionSubset <TexFont>(pref, fontList, pref.MainFolderPath + "/Fonts/User", "t:Font", TexAssetType.Font, 1);
            pref.header_userCount = fontList.Count;
            LoadPrimaryDefinitionSubset <TexSprite>(pref, fontList, pref.MainFolderPath + "/Fonts/Sprites", "t:Sprite", TexAssetType.Sprite, 2);
            EditorUtility.DisplayProgressBar("Reloading", "Preparing Stuff...", .93f);

            pref.fonts = fontList.ToArray();
        }
Example #6
0
        static void LoadPrimaryDefinitionSubset <T>(TEXPreference pref, List <TexAsset> fontList, string folderPath, string typeStr, TexAssetType typeEnum, int mode) where T : TexAsset
        {
            if (!AssetDatabase.IsValidFolder(folderPath))
            {
                return;
            }
            string[] customF = AssetDatabase.FindAssets(typeStr, new string[] { folderPath });
            for (int i = 0; i < customF.Length; i++)
            {
                if (fontList.Count >= 31)
                {
                    Debug.LogWarning("Font/Sprite database count are beyond 31, ignoring any assets after " + fontList[fontList.Count - 1].id);
                    break;
                }
                string realPath = AssetDatabase.GUIDToAssetPath(customF[i]);
                string id       = Path.GetFileNameWithoutExtension(realPath).ToLower();

                if (fontList.Any((x) => x.id == id))
                {
                    continue;
                }

                if (!isNameValid(id))
                {
                    // We show this for information purpose, since *-Regular or *_ is very common mistake
                    // We are not showing this for frequent update, since this behavior is 'intended' for giving an alternative styling
                    if (id.Contains("-Regular") || id.Substring(id.Length - 1) == "_")
                    {
                        Debug.LogWarning("File " + id + " is ignored since it has invalid character(s) in its name");
                    }
                    continue;
                }

                UpdateProgress(mode, id, i, customF.Length);

                string   json     = null;
                var      metaPath = pref.MainFolderPath + resourceFontMetaPath + id + ".asset";
                TexAsset metadata = AssetDatabase.LoadAssetAtPath <T>(metaPath);

#if TEXDRAW_TMP
                string sdfPath = pref.MainFolderPath + "/Fonts/TMPro/" + id + ".asset";
                if (typeEnum == TexAssetType.Font && File.Exists(sdfPath))
                {
                    metadata = AssetDatabase.LoadAssetAtPath <TexFontSigned>(metaPath);
                    if (!metadata)
                    {
                        metadata = CreateAndRecover <TexFontSigned>(metaPath);
                        ((TexFontSigned)metadata).rawpath = realPath;
                        AssetDatabase.CreateAsset(metadata, metaPath);
                    }
                    realPath = sdfPath;
                }
#endif
                if (!metadata)
                {
                    metadata = CreateAndRecover <T>(metaPath);
                    AssetDatabase.CreateAsset(metadata, metaPath);
                }
                else
                {
                    json = JsonUtility.ToJson(metadata);
                }

                metadata.id    = id;
                metadata.index = fontList.Count;
                metadata.ImportAsset(realPath);
                metadata.ImportDictionary();

                if (json != JsonUtility.ToJson(metadata))
                {
                    // this is necessary to avoid messing with Git version control
                    EditorUtility.SetDirty(metadata);
                }

                fontList.Add(metadata);
            }
        }
Example #7
0
        public static void ReadLegacyXMLSymbols(TEXPreference pref, bool isMath, string XMLData)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(XMLData);
            TexChar c;

            XmlNode    SyncMap = doc.SelectSingleNode("/TexSymbols/FontIDs");
            List <int> sMap    = new List <int>();

            for (int i = 0; i < SyncMap.ChildNodes.Count; i++)
            {
                XmlAttributeCollection attr = SyncMap.ChildNodes[i].Attributes;
                int idx = pref.GetFontIndexByID(attr["id"].Value);
                var max = int.Parse(attr["index"].Value);
                if (max > sMap.Count)
                {
                    for (int j = 0; j < max; j++)
                    {
                        sMap.Add(j);
                    }
                }
                sMap.Add(idx);
                if (idx >= 0)
                {
                    var  font          = pref.fontData[idx];
                    bool catalogChange = false;
                    for (int j = 0; j < attr.Count; j++)
                    {
                        switch (attr[j].Name)
                        {
                        case "xLength":
                            font.sprite_xLength = int.Parse(attr[j].Value);
                            break;

                        case "yLength":
                            font.sprite_yLength = int.Parse(attr[j].Value);
                            break;

                        case "scale":
                            font.sprite_scale = float.Parse(attr[j].Value);
                            break;

                        case "lineOffset":
                            font.sprite_lineOffset = float.Parse(attr[j].Value);
                            break;

                        case "alphaOnly":
                            font.sprite_alphaOnly = int.Parse(attr[j].Value) > 0;
                            break;

                        case "importCatalog":
                            if (catalogChange |= !string.IsNullOrEmpty(attr[j].Value))
                            {
                                font.importCatalog = attr[j].Value;
                            }
                            break;
                        }
                    }

                    font.importCatalog = font.importCatalog == null ? TexCharPresets.legacyChars : font.importCatalog;
                    font.Populate(false);
                }
            }

            XmlNode SymbolMap = doc.SelectSingleNode("/TexSymbols/SymbolMap");

            foreach (XmlNode node in SymbolMap.ChildNodes)
            {
                int hash = int.Parse(node.Attributes["hash"].Value);
                if (!isMath && hash >> 8 < pref.header_mathCount)
                {
                    continue;
                }
                hash = SyncHash(hash, sMap);
                if (hash >= 0)
                {
                    c = pref.GetChar(hash);
                    var attr = node.Attributes;
                    for (int j = 0; j < attr.Count; j++)
                    {
                        switch (attr[j].Name)
                        {
                        case "name":
                            c.symbolName = attr[j].Value;
                            break;

                        case "nameAlt":
                            c.symbolAlt = attr[j].Value;
                            break;

                        case "typeId":
                            c.type = (CharType)int.Parse(attr[j].Value);
                            break;
                        }
                    }

                    //                   pref.symbolData.Add(c.symbolName, c.ToHash());
                    //                 if (!string.IsNullOrEmpty(c.symbolAlt))
                    //                   pref.symbolData.Add(c.symbolAlt, c.ToHash());
                }
            }

            XmlNode LargerMap = doc.SelectSingleNode("/TexSymbols/LargerMap");

            foreach (XmlNode node in LargerMap.ChildNodes)
            {
                int hash = int.Parse(node.Attributes["hash"].Value);
                if (!isMath && hash >> 8 < pref.header_mathCount)
                {
                    continue;
                }
                hash = SyncHash(hash, sMap);
                if (hash >= 0)
                {
                    c            = pref.GetChar(hash);
                    c.nextLarger = pref.GetChar(SyncHash(int.Parse(node.Attributes["targetHash"].Value), sMap));
                }
            }

            XmlNode ExtensionMap = doc.SelectSingleNode("/TexSymbols/ExtensionMap");

            foreach (XmlNode node in ExtensionMap.ChildNodes)
            {
                int hash = int.Parse(node.Attributes["hash"].Value);
                if (!isMath && hash >> 8 < pref.header_mathCount)
                {
                    continue;
                }
                hash = SyncHash(hash, sMap);
                if (hash >= 0)
                {
                    c = pref.GetChar(hash);
                    c.extensionExist = true;
                    var attr = node.Attributes;
                    for (int j = 0; j < attr.Count; j++)
                    {
                        switch (attr[j].Name)
                        {
                        case "top":
                            c.extentTopHash = SyncHash(int.Parse(attr[j].Value), sMap);
                            break;

                        case "middle":
                            c.extentMiddleHash = SyncHash(int.Parse(attr[j].Value), sMap);
                            break;

                        case "bottom":
                            c.extentBottomHash = SyncHash(int.Parse(attr[j].Value), sMap);
                            break;

                        case "repeat":
                            c.extentRepeatHash = SyncHash(int.Parse(attr[j].Value), sMap);
                            break;

                        case "horizontal":
                            c.extensionHorizontal = int.Parse(attr[j].Value) > 0;
                            break;
                        }
                    }
                }
            }

            XmlNode CharMap = doc.SelectSingleNode("/TexSymbols/CharMap");

            foreach (XmlNode node in CharMap.ChildNodes)
            {
                int hash = int.Parse(node.Attributes["hash"].Value);
                if (!isMath && hash >> 8 < pref.header_mathCount)
                {
                    continue;
                }
                hash = SyncHash(hash, sMap);
                if (hash >= 0)
                {
                    c = pref.GetChar(hash);
                    c.characterMap = int.Parse(node.Attributes["char"].Value);
                    //           if (c.characterMap > 0)
                    //                 pref.charMapData.Add(TexChar.possibleCharMaps[c.characterMap], c.ToHash());
                }
            }
            pref.PushToDictionaries();
        }