public static bool TryGetGlyphFromFontFile(uint glyphIndex, TMP_FontAsset fontAsset, out Glyph glyph) { glyph = null; // Initialize Font Engine library if not already initialized if (k_IsFontEngineInitialized == false) { FontEngineError error = FontEngine.InitializeFontEngine(); if (error == 0) { k_IsFontEngineInitialized = true; } } // Load the font face for the given font asset. // TODO: Add manager to keep track of which font faces are currently loaded. FontEngine.LoadFontFace(fontAsset.sourceFontFile, fontAsset.faceInfo.pointSize); GlyphLoadFlags glyphLoadFlags = ((GlyphRasterModes)fontAsset.atlasRenderMode & GlyphRasterModes.RASTER_MODE_HINTED) == GlyphRasterModes.RASTER_MODE_HINTED ? GlyphLoadFlags.LOAD_RENDER : GlyphLoadFlags.LOAD_RENDER | GlyphLoadFlags.LOAD_NO_HINTING; if (FontEngine.TryGetGlyphWithIndexValue(glyphIndex, glyphLoadFlags, out glyph)) { // Add new glyph to font asset (if needed) //fontAsset.AddGlyph_Internal(glyph); return(true); } return(false); }
void Start() { text = GetComponent <Text>(); FontEngine.InitializeFontEngine(); FontEngine.LoadFontFace(text.font, text.font.fontSize); faceInfo = FontEngine.GetFaceInfo(); FontEngine.DestroyFontEngine(); }
private static bool TryGetCharacterFromFontFile(uint unicode, TMP_FontAsset fontAsset, out TMP_Character character) { character = null; // Initialize Font Engine library if not already initialized if (k_IsFontEngineInitialized == false) { FontEngineError error = FontEngine.InitializeFontEngine(); if (error == 0) { k_IsFontEngineInitialized = true; } } // Load the font face for the given font asset. // TODO: Add manager to keep track of which font faces are currently loaded. FontEngine.LoadFontFace(fontAsset.sourceFontFile, fontAsset.faceInfo.pointSize); Glyph glyph = null; uint glyphIndex = FontEngine.GetGlyphIndex(unicode); // Check if glyph is already contained in the font asset as the same glyph might be referenced by multiple character. if (fontAsset.glyphLookupTable.TryGetValue(glyphIndex, out glyph)) { character = fontAsset.AddCharacter_Internal(unicode, glyph); return(true); } GlyphLoadFlags glyphLoadFlags = ((GlyphRasterModes)fontAsset.atlasRenderMode & GlyphRasterModes.RASTER_MODE_HINTED) == GlyphRasterModes.RASTER_MODE_HINTED ? GlyphLoadFlags.LOAD_RENDER : GlyphLoadFlags.LOAD_RENDER | GlyphLoadFlags.LOAD_NO_HINTING; if (FontEngine.TryGetGlyphWithUnicodeValue(unicode, glyphLoadFlags, out glyph)) { // Add new character to font asset (if needed) character = fontAsset.AddCharacter_Internal(unicode, glyph); return(true); } return(false); }
public CostumeBuilder CostumeSprite(String name, Sprite sprite, float width, float height) { AddStep("COSTUME_SPRITE", (handler) => { // set texture var spriteAsset = ScriptableObject.CreateInstance <TMP_SpriteAsset>(); spriteAsset.spriteInfoList = new List <TMP_Sprite>(); spriteAsset.spriteInfoList.Add(new TMP_Sprite() { name = "ui_icon_entertainer_" + name, unicode = 0, scale = 1.0f, sprite = sprite, height = height, width = width, pivot = new Vector2(0, 0), x = 0, y = 0, yOffset = height, xAdvance = width }); spriteAsset.spriteSheet = sprite.texture; ShaderUtilities.GetShaderPropertyIDs(); Material material = new Material(Shader.Find("TextMeshPro/Sprite")); material.SetTexture(ShaderUtilities.ID_MainTex, spriteAsset.spriteSheet); material.hideFlags = HideFlags.HideInHierarchy; spriteAsset.material = material; spriteAsset.hashCode = TMP_TextUtilities.GetSimpleHashCode("ui_icon_entertainer_" + name); typeof(TMP_SpriteAsset).GetField("m_FaceInfo", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic) ?.SetValue(spriteAsset, FontEngine.GetFaceInfo()); spriteAsset.UpdateLookupTables(); MaterialReferenceManager.AddSpriteAsset(spriteAsset); handler.Target.costumeSpriteName = name; handler.Target.customeSprite = sprite; }); return(this); }
void Start() { block = new MaterialPropertyBlock(); // glyphLookUp = FontAsset.glyphLookupTable; // block.SetColor(ShaderIDConstants.Color, Color.green); // Material = Canvas.GetDefaultCanvasMaterial(); mesh = new Mesh(); vertexInfo = new List <VertexData>(); indices = new List <uint>(); FontEngine.InitializeFontEngine(); FontEngine.LoadFontFace(FontToUse, 90); faceInfo = FontEngine.GetFaceInfo(); // FontToUse.RequestCharactersInTexture(Text, 0, FontStyle.Italic | FontStyle.Normal | FontStyle.Bold | FontStyle.BoldAndItalic); FontToUse.RequestCharactersInTexture(Text); FontEngine.DestroyFontEngine(); }
static void CreateFontAssetFromSelectedObject(Object target) { Font sourceFont = (Font)target; string sourceFontFilePath = AssetDatabase.GetAssetPath(target); string folderPath = Path.GetDirectoryName(sourceFontFilePath); string assetName = Path.GetFileNameWithoutExtension(sourceFontFilePath); string newAssetFilePathWithName = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + assetName + " SDF.asset"); // Initialize FontEngine FontEngine.InitializeFontEngine(); // Load Font Face if (FontEngine.LoadFontFace(sourceFont, 90) != FontEngineError.Success) { Debug.LogWarning("Unable to load font face for [" + sourceFont.name + "]. Make sure \"Include Font Data\" is enabled in the Font Import Settings.", sourceFont); return; } // Create new Font Asset TMP_FontAsset fontAsset = ScriptableObject.CreateInstance<TMP_FontAsset>(); AssetDatabase.CreateAsset(fontAsset, newAssetFilePathWithName); fontAsset.version = "1.1.0"; fontAsset.faceInfo = FontEngine.GetFaceInfo(); // Set font reference and GUID fontAsset.m_SourceFontFileGUID = AssetDatabase.AssetPathToGUID(sourceFontFilePath); fontAsset.m_SourceFontFile_EditorRef = sourceFont; fontAsset.atlasPopulationMode = AtlasPopulationMode.Dynamic; // Default atlas resolution is 1024 x 1024. int atlasWidth = fontAsset.atlasWidth = 1024; int atlasHeight = fontAsset.atlasHeight = 1024; int atlasPadding = fontAsset.atlasPadding = 9; fontAsset.atlasRenderMode = GlyphRenderMode.SDFAA; // Initialize array for the font atlas textures. fontAsset.atlasTextures = new Texture2D[1]; // Create atlas texture of size zero. Texture2D texture = new Texture2D(0, 0, TextureFormat.Alpha8, false); texture.name = assetName + " Atlas"; fontAsset.atlasTextures[0] = texture; AssetDatabase.AddObjectToAsset(texture, fontAsset); // Add free rectangle of the size of the texture. int packingModifier = ((GlyphRasterModes)fontAsset.atlasRenderMode & GlyphRasterModes.RASTER_MODE_BITMAP) == GlyphRasterModes.RASTER_MODE_BITMAP ? 0 : 1; fontAsset.freeGlyphRects = new List<GlyphRect>() { new GlyphRect(0, 0, atlasWidth - packingModifier, atlasHeight - packingModifier) }; fontAsset.usedGlyphRects = new List<GlyphRect>(); // Create new Material and Add it as Sub-Asset Shader default_Shader = Shader.Find("TextMeshPro/Distance Field"); Material tmp_material = new Material(default_Shader); tmp_material.name = texture.name + " Material"; tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture); tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, atlasWidth); tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, atlasHeight); tmp_material.SetFloat(ShaderUtilities.ID_GradientScale, atlasPadding + packingModifier); tmp_material.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle); tmp_material.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle); fontAsset.material = tmp_material; AssetDatabase.AddObjectToAsset(tmp_material, fontAsset); // Add Font Asset Creation Settings fontAsset.creationSettings = new FontAssetCreationSettings(fontAsset.m_SourceFontFileGUID, fontAsset.faceInfo.pointSize, 0, atlasPadding, 0, 1024, 1024, 7, string.Empty, (int)GlyphRenderMode.SDFAA); // Not sure if this is still necessary in newer versions of Unity. EditorUtility.SetDirty(fontAsset); AssetDatabase.SaveAssets(); }
/// <summary> /// Initializes a new instance of the <see cref="Renderer"/> class. /// </summary> public Renderer() { Contract.Ensures(dx != null); dx = new D3DHelper(640, 480); LoadShaders(); LoadMeshes(); Sound.Audio sound = new Sound.Audio(); Wave wave = new Wave("Sound/Music/M.wav"); sound.AddSound(wave); CreateMatrices(); fontEngine = new FontEngine(dx.D3DDevice, "font.fnt", "font.png", dx.WindowWidth, dx.WindowHeight); input = new Pigment.Engine.Input.Input(); dx.Context.Flush(); }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { //Contract.Ensures(bumpShader == null, "lightShader must be disposed by this function."); Contract.Ensures(colourTextureShader == null, "colourTextureShader must be disposed by this function."); Contract.Ensures(bitmap == null, "bitmap must be disposed by this function."); Contract.Ensures(fontEngine == null, "fontEngine must be disposed by this function."); Contract.Ensures(dx == null, "dx must be disposed by this function."); if (disposing) { if (fogShader != null) { fogShader.Dispose(); fogShader = null; } if (colourTextureShader != null) { colourTextureShader.Dispose(); colourTextureShader = null; } if(bitmap != null) { bitmap.Dispose(); bitmap = null; } if(fontEngine != null) { fontEngine.Dispose(); fontEngine = null; } if (dx != null) { dx.Dispose(); dx = null; } } }
public void CreateTheCorrectFontStylesForEn(string lang) { var styles = FontEngine.CreateFontStyles(lang); Assert.IsNotNull(styles); }