private void OnMyEnable() { TMProFontCustomizedCreater.CustomizedCreaterSettings settings = TMProFontCustomizedCreater.GetCustomizedCreaterSettings(); // 以字体做索引,相同的字体只会生成一次字体纹理 string str1 = "t:Font"; string[] fonts = AssetDatabase.FindAssets(str1, new[] { settings.fontFolderPath }); m_FontAssetInfos.Clear(); foreach (var font in fonts) { FontAssetInfo info = new FontAssetInfo(); info.fontPath = AssetDatabase.GUIDToAssetPath(font); info.fontName = Path.GetFileNameWithoutExtension(info.fontPath); List <string> assetPaths = new List <string>(); str1 = "t:TMP_FontAsset " + info.fontName + " SDF"; var assets = AssetDatabase.FindAssets(str1, new[] { settings.fontMaterialsFolderPath }); foreach (var asset in assets) { assetPaths.Add(AssetDatabase.GUIDToAssetPath(asset)); } if (assetPaths.Count > 0) { info.assets = assetPaths.ToArray(); m_FontAssetInfos.Add(info); } } m_PointSizeSamplingMode = settings.pointSizeSamplingMode; m_PointSize = settings.pointSize; m_Padding = settings.padding; m_PackingMode = (FontPackingModes)settings.packingMode; m_AtlasWidth = settings.atlasWidth; m_AtlasHeight = settings.atlasHeight; m_CharacterSetSelectionMode = settings.characterSetSelectionMode; m_CharacterSequenceFile = settings.characterSequenceFile; m_FontStyle = (FaceStyles)settings.fontStyle; m_FontStyleValue = settings.fontStyleModifier; m_RenderMode = (RenderModes)settings.renderMode; m_IncludeKerningPairs = settings.includeFontFeatures; m_FontBackupPaths = settings.fontBackupPaths; m_CharacterUseFontBackup = settings.characterUseFontBackup; if (string.IsNullOrEmpty(m_WarningMessage) || m_SelectedFontAsset || m_LegacyFontAsset || m_SavedFontAtlas || m_IsFontAtlasInvalid) { // 仅为了去除警告 } }
void DrawControls() { GUILayout.BeginVertical(); GUILayout.Label("<b>TextMeshPro - Font Asset Creator</b>", TMP_UIStyleManager.Section_Label, GUILayout.Width(300)); GUILayout.Label("Font Settings", TMP_UIStyleManager.Section_Label, GUILayout.Width(300)); GUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox, GUILayout.Width(300)); EditorGUIUtility.LookLikeControls(120f, 160f); // FONT TTF SELECTION font_TTF = EditorGUILayout.ObjectField("Font Source", font_TTF, typeof(Font), false, GUILayout.Width(290)) as Font; // FONT SIZING if (FontSizingOption_Selection == 0) { FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(290)); } else { EditorGUIUtility.LookLikeControls(120f, 40f); GUILayout.BeginHorizontal(GUILayout.Width(290)); FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(225)); font_size = EditorGUILayout.IntField(font_size); GUILayout.EndHorizontal(); } EditorGUIUtility.LookLikeControls(120f, 160f); // FONT PADDING font_padding = EditorGUILayout.IntField("Font Padding", font_padding, GUILayout.Width(290)); font_padding = (int)Mathf.Clamp(font_padding, 0f, 64f); // FONT PACKING METHOD SELECTION m_fontPackingSelection = (FontPackingModes)EditorGUILayout.EnumPopup("Packing Method", m_fontPackingSelection, GUILayout.Width(225)); //font_renderingMode = (FontRenderingMode)EditorGUILayout.EnumPopup("Rendering Mode", font_renderingMode, GUILayout.Width(290)); // FONT ATLAS RESOLUTION SELECTION GUILayout.BeginHorizontal(GUILayout.Width(290)); GUI.changed = false; EditorGUIUtility.LookLikeControls(120f, 40f); GUILayout.Label("Atlas Resolution:", GUILayout.Width(116)); font_atlas_width = EditorGUILayout.IntPopup(font_atlas_width, FontResolutionLabels, FontAtlasResolutions); //, GUILayout.Width(80)); font_atlas_height = EditorGUILayout.IntPopup(font_atlas_height, FontResolutionLabels, FontAtlasResolutions); //, GUILayout.Width(80)); GUILayout.EndHorizontal(); // FONT CHARACTER SET SELECTION GUI.changed = false; font_CharacterSet_Selection = EditorGUILayout.Popup("Character Set", font_CharacterSet_Selection, FontCharacterSets, GUILayout.Width(290)); if (GUI.changed) { characterSequence = ""; //Debug.Log("Resetting Sequence!"); } switch (font_CharacterSet_Selection) { case 0: // ASCII //characterSequence = "32 - 126, 130, 132 - 135, 139, 145 - 151, 153, 155, 161, 166 - 167, 169 - 174, 176, 181 - 183, 186 - 187, 191, 8210 - 8226, 8230, 8240, 8242 - 8244, 8249 - 8250, 8252 - 8254, 8260, 8286"; characterSequence = "32 - 126, 8230"; break; case 1: // EXTENDED ASCII characterSequence = "32 - 126, 160 - 255, 8210 - 8226, 8230, 8240, 8242 - 8244, 8249 - 8250, 8252, 8254, 8260, 8286, 8364"; break; case 2: // Lowercase characterSequence = "32 - 64, 91 - 126"; break; case 3: // Uppercase characterSequence = "32 - 96, 123 - 126"; break; case 4: // Numbers & Symbols characterSequence = "32 - 64, 91 - 96, 123 - 126"; break; case 5: // Custom Range GUILayout.BeginHorizontal(GUILayout.Width(290)); GUILayout.Label("Custom Range (Dec)", GUILayout.Width(116)); // Filter out unwanted characters. char chr = Event.current.character; if ((chr < '0' || chr > '9') && (chr < ',' || chr > '-')) { Event.current.character = '\0'; } characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(32), GUILayout.MaxWidth(170)); GUILayout.EndHorizontal(); break; case 6: // Unicode HEX Range GUILayout.BeginHorizontal(GUILayout.Width(290)); GUILayout.Label("Unicode Range (Hex)", GUILayout.Width(116)); // Filter out unwanted characters. chr = Event.current.character; if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F') && (chr < ',' || chr > '-')) { Event.current.character = '\0'; } characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(32), GUILayout.MaxWidth(170)); GUILayout.EndHorizontal(); break; case 7: // Custom Characters GUILayout.BeginHorizontal(GUILayout.Width(290)); GUILayout.Label("Custom Characters", GUILayout.Width(116)); characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(32), GUILayout.MaxWidth(170)); GUILayout.EndHorizontal(); break; case 8: // Character List from File characterList = EditorGUILayout.ObjectField("Character File", characterList, typeof(TextAsset), false, GUILayout.Width(290)) as TextAsset; if (characterList != null) { characterSequence = characterList.text; } break; } EditorGUIUtility.LookLikeControls(120f, 40f); // FONT STYLE SELECTION GUILayout.BeginHorizontal(GUILayout.Width(290)); font_style = (FaceStyles)EditorGUILayout.EnumPopup("Font Style:", font_style, GUILayout.Width(225)); font_style_mod = EditorGUILayout.IntField((int)font_style_mod); GUILayout.EndHorizontal(); // Render Mode Selection font_renderMode = (RenderModes)EditorGUILayout.EnumPopup("Font Render Mode:", font_renderMode, GUILayout.Width(290)); includeKerningPairs = EditorGUILayout.Toggle("Get Kerning Pairs?", includeKerningPairs, GUILayout.MaxWidth(290)); EditorGUIUtility.LookLikeControls(120f, 160f); GUILayout.Space(20); GUI.enabled = font_TTF == null || isProcessing ? false : true; // Enable Preview if we are not already rendering a font. if (GUILayout.Button("Generate Font Atlas", GUILayout.Width(290)) && characterSequence.Length != 0 && GUI.enabled) { if (font_TTF != null) { int error_Code; error_Code = TMPro_FontPlugin.Initialize_FontEngine(); // Initialize Font Engine if (error_Code != 0) { if (error_Code == 99) { //Debug.Log("Font Library was already initialized!"); error_Code = 0; } else Debug.Log("Error Code: " + error_Code + " occurred while Initializing the FreeType Library."); } string fontPath = AssetDatabase.GetAssetPath(font_TTF); // Get file path of TTF Font. if (error_Code == 0) { error_Code = TMPro_FontPlugin.Load_TrueType_Font(fontPath); // Load the selected font. if (error_Code != 0) { if (error_Code == 99) { //Debug.Log("Font was already loaded!"); error_Code = 0; } else Debug.Log("Error Code: " + error_Code + " occurred while Loading the font."); } } if (error_Code == 0) { if (FontSizingOption_Selection == 0) font_size = 72; // If Auto set size to 72 pts. error_Code = TMPro_FontPlugin.FT_Size_Font(font_size); // Load the selected font and size it accordingly. if (error_Code != 0) Debug.Log("Error Code: " + error_Code + " occurred while Sizing the font."); } // Define an array containing the characters we will render. if (error_Code == 0) { int[] character_Set = null; if (font_CharacterSet_Selection == 7 || font_CharacterSet_Selection == 8) { List<int> char_List = new List<int>(); for (int i = 0; i < characterSequence.Length; i++) { // Check to make sure we don't include duplicates if (char_List.FindIndex(item => item == characterSequence[i]) == -1) char_List.Add(characterSequence[i]); else { //Debug.Log("Character [" + characterSequence[i] + "] is a duplicate."); } } character_Set = char_List.ToArray(); } else if (font_CharacterSet_Selection == 6) { character_Set = ParseHexNumberSequence(characterSequence); } else { character_Set = ParseNumberSequence(characterSequence); } m_character_Count = character_Set.Length; m_texture_buffer = new byte[font_atlas_width * font_atlas_height]; m_font_faceInfo = new FT_FaceInfo(); m_font_glyphInfo = new FT_GlyphInfo[m_character_Count]; int padding = font_padding; bool autoSizing = FontSizingOption_Selection == 0 ? true : false; float strokeSize = font_style_mod; if (font_renderMode == RenderModes.DistanceField16) strokeSize = font_style_mod * 16; if (font_renderMode == RenderModes.DistanceField32) strokeSize = font_style_mod * 32; isProcessing = true; ThreadPool.QueueUserWorkItem(SomeTask => { isRenderingDone = false; error_Code = TMPro_FontPlugin.Render_Characters(m_texture_buffer, font_atlas_width, font_atlas_height, padding, character_Set, m_character_Count, font_style, strokeSize, autoSizing, font_renderMode,(int)m_fontPackingSelection, ref m_font_faceInfo, m_font_glyphInfo); isRenderingDone = true; //Debug.Log("Font Rendering is completed."); }); previewSelection = PreviewSelectionTypes.PreviewFont; } } } // FONT RENDERING PROGRESS BAR GUILayout.Space(1); progressRect = GUILayoutUtility.GetRect(288, 20, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Width(288), GUILayout.Height(20)); GUI.BeginGroup(progressRect); GUI.DrawTextureWithTexCoords(new Rect(2, 0, 288, 20), TMP_UIStyleManager.progressTexture, new Rect(1 - m_renderingProgress, 0, 1, 1)); GUI.EndGroup(); // FONT STATUS & INFORMATION GUISkin skin = GUI.skin; GUI.skin = TMP_UIStyleManager.TMP_GUISkin; GUILayout.Space(5); GUILayout.BeginVertical(TMP_UIStyleManager.TextAreaBoxWindow); output_ScrollPosition = EditorGUILayout.BeginScrollView(output_ScrollPosition, GUILayout.Height(145)); EditorGUILayout.LabelField(output_feedback, TMP_UIStyleManager.Label); EditorGUILayout.EndScrollView(); GUILayout.EndVertical(); GUI.skin = skin; GUILayout.Space(10); // SAVE TEXTURE & CREATE and SAVE FONT XML FILE GUI.enabled = m_font_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null. if (GUILayout.Button("Save TextMeshPro Font Asset", GUILayout.Width(290)) && GUI.enabled) { string filePath = string.Empty; if (font_renderMode < RenderModes.DistanceField16) // == RenderModes.HintedSmooth || font_renderMode == RenderModes.RasterHinted) { filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name, "asset"); if (filePath.Length == 0) return; Save_Normal_FontAsset(filePath); } else if (font_renderMode >= RenderModes.DistanceField16) { filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name + " SDF", "asset"); if (filePath.Length == 0) return; Save_SDF_FontAsset(filePath); } } GUI.enabled = true; // Re-enable GUI GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.Space(25); /* // GENERATE DISTANCE FIELD TEXTURE GUILayout.Label("Distance Field Options", SectionLabel, GUILayout.Width(300)); GUILayout.BeginVertical(textureAreaBox, GUILayout.Width(300)); GUILayout.Space(5); font_spread = EditorGUILayout.IntField("Spread", font_spread, GUILayout.Width(280)); font_scaledownFactor = EditorGUILayout.IntField("Scale down factor", font_scaledownFactor, GUILayout.Width(280)); if (GUI.changed) { EditorPrefs.SetInt("Font_Spread", font_spread); EditorPrefs.SetInt("Font_ScaleDownFactor", font_scaledownFactor); } GUILayout.Space(20); GUI.enabled = m_font_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null. if (GUILayout.Button("Preview Distance Field Font Atlas", GUILayout.Width(290))) { if (m_font_Atlas != null && isProcessing == false) { // Generate Distance Field int width = m_font_Atlas.width; int height = m_font_Atlas.height; Color[] colors = m_font_Atlas.GetPixels(); // Should modify this to use Color32 instead isProcessing = true; ThreadPool.QueueUserWorkItem(SomeTask => { TMPro_DistanceTransform.Generate(colors, width, height, font_spread, font_scaledownFactor); }); previewSelection = PreviewSelectionTypes.PreviewDistanceField; } } GUILayout.Space(1); progressRect = GUILayoutUtility.GetRect(290, 20, textAreaBox, GUILayout.Width(290), GUILayout.Height(20)); GUI.BeginGroup(progressRect); GUI.DrawTextureWithTexCoords(new Rect(0, 0, 290, 20), progressTexture, new Rect(1 - ProgressPercentage, 0, 1, 1)); GUI.EndGroup(); //GUILayout.Space(5); GUI.enabled = m_destination_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null. if (GUILayout.Button("Save TextMeshPro (SDF) Font Asset", GUILayout.Width(290))) { string filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name + " SDF", "asset"); if (filePath.Length == 0) return; Save_SDF_FontAsset(filePath); } GUILayout.EndVertical(); */ // Figure out the size of the current UI Panel Rect rect = EditorGUILayout.GetControlRect(false, 5); if (Event.current.type == EventType.Repaint) m_UI_Panel_Size = rect; GUILayout.EndVertical(); }
void DrawControls() { GUILayout.BeginVertical(); GUILayout.Label("<b>TextMeshPro - Font Asset Creator</b>", TMP_UIStyleManager.Section_Label, GUILayout.Width(300)); GUILayout.Label("Font Settings", TMP_UIStyleManager.Section_Label, GUILayout.Width(300)); GUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox, GUILayout.Width(300)); EditorGUIUtility.LookLikeControls(120f, 160f); // FONT TTF SELECTION font_TTF = EditorGUILayout.ObjectField("Font Source", font_TTF, typeof(Font), false, GUILayout.Width(290)) as Font; // FONT SIZING if (FontSizingOption_Selection == 0) { FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(290)); } else { EditorGUIUtility.LookLikeControls(120f, 40f); GUILayout.BeginHorizontal(GUILayout.Width(290)); FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(225)); font_size = EditorGUILayout.IntField(font_size); GUILayout.EndHorizontal(); } EditorGUIUtility.LookLikeControls(120f, 160f); // FONT PADDING font_padding = EditorGUILayout.IntField("Font Padding", font_padding, GUILayout.Width(290)); font_padding = (int)Mathf.Clamp(font_padding, 0f, 64f); // FONT PACKING METHOD SELECTION m_fontPackingSelection = (FontPackingModes)EditorGUILayout.EnumPopup("Packing Method", m_fontPackingSelection, GUILayout.Width(225)); //font_renderingMode = (FontRenderingMode)EditorGUILayout.EnumPopup("Rendering Mode", font_renderingMode, GUILayout.Width(290)); // FONT ATLAS RESOLUTION SELECTION GUILayout.BeginHorizontal(GUILayout.Width(290)); GUI.changed = false; EditorGUIUtility.LookLikeControls(120f, 40f); GUILayout.Label("Atlas Resolution:", GUILayout.Width(116)); font_atlas_width = EditorGUILayout.IntPopup(font_atlas_width, FontResolutionLabels, FontAtlasResolutions); //, GUILayout.Width(80)); font_atlas_height = EditorGUILayout.IntPopup(font_atlas_height, FontResolutionLabels, FontAtlasResolutions); //, GUILayout.Width(80)); GUILayout.EndHorizontal(); // FONT CHARACTER SET SELECTION GUI.changed = false; font_CharacterSet_Selection = EditorGUILayout.Popup("Character Set", font_CharacterSet_Selection, FontCharacterSets, GUILayout.Width(290)); if (GUI.changed) { characterSequence = ""; //Debug.Log("Resetting Sequence!"); } switch (font_CharacterSet_Selection) { case 0: // ASCII //characterSequence = "32 - 126, 130, 132 - 135, 139, 145 - 151, 153, 155, 161, 166 - 167, 169 - 174, 176, 181 - 183, 186 - 187, 191, 8210 - 8226, 8230, 8240, 8242 - 8244, 8249 - 8250, 8252 - 8254, 8260, 8286"; characterSequence = "32 - 126, 8230"; break; case 1: // EXTENDED ASCII characterSequence = "32 - 126, 161 - 255, 8210 - 8226, 8230, 8240, 8242 - 8244, 8249 - 8250, 8252 - 8254, 8260, 8286"; break; case 2: // Lowercase characterSequence = "32 - 64, 91 - 126"; break; case 3: // Uppercase characterSequence = "32 - 96, 123 - 126"; break; case 4: // Numbers & Symbols characterSequence = "32 - 64, 91 - 96, 123 - 126"; break; case 5: // Custom Range GUILayout.BeginHorizontal(GUILayout.Width(290)); GUILayout.Label("Custom Range", GUILayout.Width(116)); // Filter out unwanted characters. char chr = Event.current.character; if ((chr < '0' || chr > '9') && (chr < ',' || chr > '-')) { Event.current.character = '\0'; } characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(32), GUILayout.MaxWidth(170)); GUILayout.EndHorizontal(); break; case 6: // Custom Characters GUILayout.BeginHorizontal(GUILayout.Width(290)); GUILayout.Label("Custom Characters", GUILayout.Width(116)); characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(32), GUILayout.MaxWidth(170)); GUILayout.EndHorizontal(); break; case 7: // Character List from File characterList = EditorGUILayout.ObjectField("Character File", characterList, typeof(TextAsset), false, GUILayout.Width(290)) as TextAsset; if (characterList != null) { characterSequence = characterList.text; } break; } EditorGUIUtility.LookLikeControls(120f, 40f); // FONT STYLE SELECTION GUILayout.BeginHorizontal(GUILayout.Width(290)); font_style = (FaceStyles)EditorGUILayout.EnumPopup("Font Style:", font_style, GUILayout.Width(225)); font_style_mod = EditorGUILayout.IntField((int)font_style_mod); GUILayout.EndHorizontal(); // Render Mode Selection font_renderMode = (RenderModes)EditorGUILayout.EnumPopup("Font Render Mode:", font_renderMode, GUILayout.Width(290)); includeKerningPairs = EditorGUILayout.Toggle("Get Kerning Pairs?", includeKerningPairs, GUILayout.MaxWidth(290)); EditorGUIUtility.LookLikeControls(120f, 160f); GUILayout.Space(20); GUI.enabled = font_TTF == null || isProcessing ? false : true; // Enable Preview if we are not already rendering a font. if (GUILayout.Button("Generate Font Atlas", GUILayout.Width(290)) && characterSequence.Length != 0 && GUI.enabled) { if (font_TTF != null) { int error_Code; error_Code = TMPro_FontPlugin.Initialize_FontEngine(); // Initialize Font Engine if (error_Code != 0) { if (error_Code == 99) { //Debug.Log("Font Library was already initialized!"); error_Code = 0; } else { Debug.Log("Error Code: " + error_Code + " occurred while Initializing the FreeType Library."); } } string fontPath = AssetDatabase.GetAssetPath(font_TTF); // Get file path of TTF Font. if (error_Code == 0) { error_Code = TMPro_FontPlugin.Load_TrueType_Font(fontPath); // Load the selected font. if (error_Code != 0) { if (error_Code == 99) { //Debug.Log("Font was already loaded!"); error_Code = 0; } else { Debug.Log("Error Code: " + error_Code + " occurred while Loading the font."); } } } if (error_Code == 0) { if (FontSizingOption_Selection == 0) { font_size = 72; // If Auto set size to 72 pts. } error_Code = TMPro_FontPlugin.FT_Size_Font(font_size); // Load the selected font and size it accordingly. if (error_Code != 0) { Debug.Log("Error Code: " + error_Code + " occurred while Sizing the font."); } } // Define an array containing the characters we will render. if (error_Code == 0) { int[] character_Set = null; if (font_CharacterSet_Selection == 6 || font_CharacterSet_Selection == 7) { List <int> char_List = new List <int>(); for (int i = 0; i < characterSequence.Length; i++) { // Check to make sure we don't include duplicates if (char_List.FindIndex(item => item == characterSequence[i]) == -1) { char_List.Add(characterSequence[i]); } else { //Debug.Log("Character [" + characterSequence[i] + "] is a duplicate."); } } character_Set = char_List.ToArray(); } else { character_Set = ParseNumberSequence(characterSequence); } m_character_Count = character_Set.Length; m_texture_buffer = new byte[font_atlas_width * font_atlas_height]; m_font_faceInfo = new FT_FaceInfo(); m_font_glyphInfo = new FT_GlyphInfo[m_character_Count]; int padding = font_padding; bool autoSizing = FontSizingOption_Selection == 0 ? true : false; float strokeSize = font_style_mod; if (font_renderMode == RenderModes.DistanceField16) { strokeSize = font_style_mod * 16; } if (font_renderMode == RenderModes.DistanceField32) { strokeSize = font_style_mod * 32; } isProcessing = true; ThreadPool.QueueUserWorkItem(SomeTask => { isRenderingDone = false; error_Code = TMPro_FontPlugin.Render_Characters(m_texture_buffer, font_atlas_width, font_atlas_height, padding, character_Set, m_character_Count, font_style, strokeSize, autoSizing, font_renderMode, (int)m_fontPackingSelection, ref m_font_faceInfo, m_font_glyphInfo); isRenderingDone = true; //Debug.Log("Font Rendering is completed."); }); previewSelection = PreviewSelectionTypes.PreviewFont; } } } // FONT RENDERING PROGRESS BAR GUILayout.Space(1); progressRect = GUILayoutUtility.GetRect(288, 20, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Width(288), GUILayout.Height(20)); GUI.BeginGroup(progressRect); GUI.DrawTextureWithTexCoords(new Rect(2, 0, 288, 20), TMP_UIStyleManager.progressTexture, new Rect(1 - m_renderingProgress, 0, 1, 1)); GUI.EndGroup(); // FONT STATUS & INFORMATION GUILayout.Space(5); EditorGUILayout.LabelField(output_feedback, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(48), GUILayout.MaxWidth(290)); GUILayout.Space(10); // SAVE TEXTURE & CREATE and SAVE FONT XML FILE GUI.enabled = m_font_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null. if (GUILayout.Button("Save TextMeshPro Font Asset", GUILayout.Width(290)) && GUI.enabled) { string filePath = string.Empty; if (font_renderMode < RenderModes.DistanceField16) // == RenderModes.HintedSmooth || font_renderMode == RenderModes.RasterHinted) { filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name, "asset"); if (filePath.Length == 0) { return; } Save_Normal_FontAsset(filePath); } else if (font_renderMode >= RenderModes.DistanceField16) { filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name + " SDF", "asset"); if (filePath.Length == 0) { return; } Save_SDF_FontAsset(filePath); } } GUI.enabled = true; // Re-enable GUI GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.Space(25); /* * // GENERATE DISTANCE FIELD TEXTURE * GUILayout.Label("Distance Field Options", SectionLabel, GUILayout.Width(300)); * * GUILayout.BeginVertical(textureAreaBox, GUILayout.Width(300)); * * GUILayout.Space(5); * * * font_spread = EditorGUILayout.IntField("Spread", font_spread, GUILayout.Width(280)); * font_scaledownFactor = EditorGUILayout.IntField("Scale down factor", font_scaledownFactor, GUILayout.Width(280)); * if (GUI.changed) * { * EditorPrefs.SetInt("Font_Spread", font_spread); * EditorPrefs.SetInt("Font_ScaleDownFactor", font_scaledownFactor); * } * * GUILayout.Space(20); * * GUI.enabled = m_font_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null. * if (GUILayout.Button("Preview Distance Field Font Atlas", GUILayout.Width(290))) * { * * if (m_font_Atlas != null && isProcessing == false) * { * // Generate Distance Field * int width = m_font_Atlas.width; * int height = m_font_Atlas.height; * Color[] colors = m_font_Atlas.GetPixels(); // Should modify this to use Color32 instead * * isProcessing = true; * * ThreadPool.QueueUserWorkItem(SomeTask => { TMPro_DistanceTransform.Generate(colors, width, height, font_spread, font_scaledownFactor); }); * * previewSelection = PreviewSelectionTypes.PreviewDistanceField; * } * } * * GUILayout.Space(1); * * progressRect = GUILayoutUtility.GetRect(290, 20, textAreaBox, GUILayout.Width(290), GUILayout.Height(20)); * * GUI.BeginGroup(progressRect); * * GUI.DrawTextureWithTexCoords(new Rect(0, 0, 290, 20), progressTexture, new Rect(1 - ProgressPercentage, 0, 1, 1)); * GUI.EndGroup(); * * //GUILayout.Space(5); * * GUI.enabled = m_destination_Atlas != null ? true : false; // Enable Save Button if font_Atlas is not Null. * if (GUILayout.Button("Save TextMeshPro (SDF) Font Asset", GUILayout.Width(290))) * { * string filePath = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name + " SDF", "asset"); * * if (filePath.Length == 0) * return; * * Save_SDF_FontAsset(filePath); * * } * * GUILayout.EndVertical(); */ // Figure out the size of the current UI Panel Rect rect = EditorGUILayout.GetControlRect(false, 5); if (Event.current.type == EventType.Repaint) { m_UI_Panel_Size = rect; } GUILayout.EndVertical(); }
private void DrawControls() { GUILayout.BeginVertical(); GUILayout.Label("<b>TextMeshPro - Font Asset Creator</b>", TMP_UIStyleManager.Section_Label, GUILayout.Width(300f)); GUILayout.Label("Font Settings", TMP_UIStyleManager.Section_Label, GUILayout.Width(300f)); GUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox, GUILayout.Width(300f)); EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 160f; EditorGUI.BeginChangeCheck(); font_TTF = (EditorGUILayout.ObjectField("Font Source", font_TTF, typeof(Font), false, GUILayout.Width(290f)) as Font); if (EditorGUI.EndChangeCheck()) { } if (FontSizingOption_Selection == 0) { FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(290f)); } else { EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 40f; GUILayout.BeginHorizontal(GUILayout.Width(290f)); FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(225f)); font_size = EditorGUILayout.IntField(font_size); GUILayout.EndHorizontal(); } EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 160f; font_padding = EditorGUILayout.IntField("Font Padding", font_padding, GUILayout.Width(290f)); font_padding = (int)Mathf.Clamp(font_padding, 0f, 64f); m_fontPackingSelection = (FontPackingModes)(object)EditorGUILayout.EnumPopup("Packing Method", m_fontPackingSelection, GUILayout.Width(225f)); GUILayout.BeginHorizontal(GUILayout.Width(290f)); GUI.changed = false; EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 40f; GUILayout.Label("Atlas Resolution:", GUILayout.Width(116f)); font_atlas_width = EditorGUILayout.IntPopup(font_atlas_width, FontResolutionLabels, FontAtlasResolutions); font_atlas_height = EditorGUILayout.IntPopup(font_atlas_height, FontResolutionLabels, FontAtlasResolutions); GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); bool flag = false; font_CharacterSet_Selection = EditorGUILayout.Popup("Character Set", font_CharacterSet_Selection, FontCharacterSets, GUILayout.Width(290f)); if (EditorGUI.EndChangeCheck()) { characterSequence = ""; flag = true; } switch (font_CharacterSet_Selection) { case 0: characterSequence = "32 - 126, 160, 8203, 8230, 9633"; break; case 1: characterSequence = "32 - 126, 160 - 255, 8192 - 8303, 8364, 8482, 9633"; break; case 2: characterSequence = "32 - 64, 91 - 126, 160"; break; case 3: characterSequence = "32 - 96, 123 - 126, 160"; break; case 4: characterSequence = "32 - 64, 91 - 96, 123 - 126, 160"; break; case 5: { EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox); GUILayout.Label("Enter a sequence of decimal values to define the characters to be included in the font asset or retrieve one from another font asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); EditorGUI.BeginChangeCheck(); m_fontAssetSelection = (EditorGUILayout.ObjectField("Select Font Asset", m_fontAssetSelection, typeof(TMP_FontAsset), false, GUILayout.Width(290f)) as TMP_FontAsset); if ((EditorGUI.EndChangeCheck() || flag) && m_fontAssetSelection != null) { characterSequence = TMP_EditorUtility.GetDecimalCharacterSequence(TMP_FontAsset.GetCharactersArray(m_fontAssetSelection)); } EditorGUIUtility.labelWidth = 120f; char character = Event.current.character; if ((character < '0' || character > '9') && (character < ',' || character > '-')) { Event.current.character = '\0'; } GUILayout.Label("Character Sequence (Decimal)", TMP_UIStyleManager.Section_Label); characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120f), GUILayout.MaxWidth(290f)); EditorGUILayout.EndVertical(); break; } case 6: { EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox); GUILayout.Label("Enter a sequence of Unicode (hex) values to define the characters to be included in the font asset or retrieve one from another font asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); EditorGUI.BeginChangeCheck(); m_fontAssetSelection = (EditorGUILayout.ObjectField("Select Font Asset", m_fontAssetSelection, typeof(TMP_FontAsset), false, GUILayout.Width(290f)) as TMP_FontAsset); if ((EditorGUI.EndChangeCheck() || flag) && m_fontAssetSelection != null) { characterSequence = TMP_EditorUtility.GetUnicodeCharacterSequence(TMP_FontAsset.GetCharactersArray(m_fontAssetSelection)); } EditorGUIUtility.labelWidth = 120f; char character = Event.current.character; if ((character < '0' || character > '9') && (character < 'a' || character > 'f') && (character < 'A' || character > 'F') && (character < ',' || character > '-')) { Event.current.character = '\0'; } GUILayout.Label("Character Sequence (Hex)", TMP_UIStyleManager.Section_Label); characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120f), GUILayout.MaxWidth(290f)); EditorGUILayout.EndVertical(); break; } case 7: EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox); GUILayout.Label("Type the characters to be included in the font asset or retrieve them from another font asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); EditorGUI.BeginChangeCheck(); m_fontAssetSelection = (EditorGUILayout.ObjectField("Select Font Asset", m_fontAssetSelection, typeof(TMP_FontAsset), false, GUILayout.Width(290f)) as TMP_FontAsset); if ((EditorGUI.EndChangeCheck() || flag) && m_fontAssetSelection != null) { characterSequence = TMP_FontAsset.GetCharacters(m_fontAssetSelection); } EditorGUIUtility.labelWidth = 120f; EditorGUI.indentLevel = 0; GUILayout.Label("Custom Character List", TMP_UIStyleManager.Section_Label); characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120f), GUILayout.MaxWidth(290f)); EditorGUILayout.EndVertical(); break; case 8: characterList = (EditorGUILayout.ObjectField("Character File", characterList, typeof(TextAsset), false, GUILayout.Width(290f)) as TextAsset); if (characterList != null) { characterSequence = characterList.text; } break; } EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 40f; GUILayout.BeginHorizontal(GUILayout.Width(290f)); font_style = (FaceStyles)(object)EditorGUILayout.EnumPopup("Font Style:", font_style, GUILayout.Width(225f)); font_style_mod = EditorGUILayout.IntField((int)font_style_mod); GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); font_renderMode = (RenderModes)(object)EditorGUILayout.EnumPopup("Font Render Mode:", font_renderMode, GUILayout.Width(290f)); if (EditorGUI.EndChangeCheck()) { } includeKerningPairs = EditorGUILayout.Toggle("Get Kerning Pairs?", includeKerningPairs, GUILayout.MaxWidth(290f)); EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 160f; GUILayout.Space(20f); GUI.enabled = ((!(font_TTF == null) && !isProcessing) ? true : false); if (GUILayout.Button("Generate Font Atlas", GUILayout.Width(290f)) && characterSequence.Length != 0 && GUI.enabled && font_TTF != null) { int error_Code = TMPro_FontPlugin.Initialize_FontEngine(); if (error_Code != 0) { if (error_Code == 99) { error_Code = 0; } else { Debug.Log("Error Code: " + error_Code + " occurred while Initializing the FreeType Library."); } } string assetPath = AssetDatabase.GetAssetPath(font_TTF); if (error_Code == 0) { error_Code = TMPro_FontPlugin.Load_TrueType_Font(assetPath); if (error_Code != 0) { if (error_Code == 99) { error_Code = 0; } else { Debug.Log("Error Code: " + error_Code + " occurred while Loading the font."); } } } if (error_Code == 0) { if (FontSizingOption_Selection == 0) { font_size = 72; } error_Code = TMPro_FontPlugin.FT_Size_Font(font_size); if (error_Code != 0) { Debug.Log("Error Code: " + error_Code + " occurred while Sizing the font."); } } if (error_Code == 0) { int[] character_Set = null; if (font_CharacterSet_Selection == 7 || font_CharacterSet_Selection == 8) { List <int> list = new List <int>(); int i; for (i = 0; i < characterSequence.Length; i++) { if (list.FindIndex((int item) => item == characterSequence[i]) == -1) { list.Add(characterSequence[i]); } } character_Set = list.ToArray(); } else if (font_CharacterSet_Selection == 6) { character_Set = ParseHexNumberSequence(characterSequence); } else { character_Set = ParseNumberSequence(characterSequence); } m_character_Count = character_Set.Length; m_texture_buffer = new byte[font_atlas_width * font_atlas_height]; m_font_faceInfo = default(FT_FaceInfo); m_font_glyphInfo = new FT_GlyphInfo[m_character_Count]; int padding = font_padding; bool autoSizing = (FontSizingOption_Selection == 0) ? true : false; float strokeSize = font_style_mod; if (font_renderMode == RenderModes.DistanceField16) { strokeSize = font_style_mod * 16f; } if (font_renderMode == RenderModes.DistanceField32) { strokeSize = font_style_mod * 32f; } isProcessing = true; ThreadPool.QueueUserWorkItem(delegate { isRenderingDone = false; error_Code = TMPro_FontPlugin.Render_Characters(m_texture_buffer, font_atlas_width, font_atlas_height, padding, character_Set, m_character_Count, font_style, strokeSize, autoSizing, font_renderMode, (int)m_fontPackingSelection, ref m_font_faceInfo, m_font_glyphInfo); isRenderingDone = true; }); previewSelection = PreviewSelectionTypes.PreviewFont; } } GUILayout.Space(1f); progressRect = GUILayoutUtility.GetRect(288f, 20f, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Width(288f), GUILayout.Height(20f)); GUI.BeginGroup(progressRect); GUI.DrawTextureWithTexCoords(new Rect(2f, 0f, 288f, 20f), TMP_UIStyleManager.progressTexture, new Rect(1f - m_renderingProgress, 0f, 1f, 1f)); GUI.EndGroup(); GUISkin skin = GUI.skin; GUI.skin = TMP_UIStyleManager.TMP_GUISkin; GUILayout.Space(5f); GUILayout.BeginVertical(TMP_UIStyleManager.TextAreaBoxWindow); output_ScrollPosition = EditorGUILayout.BeginScrollView(output_ScrollPosition, GUILayout.Height(145f)); EditorGUILayout.LabelField(output_feedback, TMP_UIStyleManager.Label); EditorGUILayout.EndScrollView(); GUILayout.EndVertical(); GUI.skin = skin; GUILayout.Space(10f); GUI.enabled = ((m_font_Atlas != null) ? true : false); if (GUILayout.Button("Save TextMeshPro Font Asset", GUILayout.Width(290f)) && GUI.enabled) { string empty = string.Empty; if (font_renderMode < RenderModes.DistanceField16) { empty = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name, "asset"); if (empty.Length == 0) { return; } Save_Normal_FontAsset(empty); } else if (font_renderMode >= RenderModes.DistanceField16) { empty = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name + " SDF", "asset"); if (empty.Length == 0) { return; } Save_SDF_FontAsset(empty); } } GUI.enabled = true; GUILayout.Space(5f); GUILayout.EndVertical(); GUILayout.Space(25f); Rect controlRect = EditorGUILayout.GetControlRect(false, 5f); if (Event.current.type == EventType.Repaint) { m_UI_Panel_Size = controlRect; } GUILayout.EndVertical(); }