diff --git a/Source/Editor/Windows/Assets/FontWindow.cs b/Source/Editor/Windows/Assets/FontWindow.cs index 1a69f7724..e08a87b05 100644 --- a/Source/Editor/Windows/Assets/FontWindow.cs +++ b/Source/Editor/Windows/Assets/FontWindow.cs @@ -46,7 +46,7 @@ namespace FlaxEditor.Windows.Assets options = new FontOptions { Hinting = Hinting, - RasterMode = RasterMode + RasterMode = RasterMode, }; if (AntiAliasing) options.Flags |= FontFlags.AntiAliasing; diff --git a/Source/Engine/Render2D/FontManager.cpp b/Source/Engine/Render2D/FontManager.cpp index 7376173f8..d58394bb3 100644 --- a/Source/Engine/Render2D/FontManager.cpp +++ b/Source/Engine/Render2D/FontManager.cpp @@ -9,11 +9,11 @@ #include "Engine/Content/Content.h" #include "Engine/Engine/EngineService.h" #include "Engine/Threading/Threading.h" +#include "Engine/Render2D/MSDFGenerator.h" #include "IncludeFreeType.h" #include #include #include -#include "Engine/Render2D/MSDFGenerator.h" namespace FontManagerImpl { @@ -200,7 +200,8 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) FT_Bitmap* bitmap = &glyph->bitmap; FT_Bitmap tmpBitmap; - if (bitmap->pixel_mode != FT_PIXEL_MODE_GRAY) { + if (bitmap->pixel_mode != FT_PIXEL_MODE_GRAY) + { // Convert the bitmap to 8bpp grayscale FT_Bitmap_New(&tmpBitmap); FT_Bitmap_Convert(Library, bitmap, &tmpBitmap, 4); @@ -233,7 +234,7 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) } return false; } - + // Copy glyph data after rasterization (row by row) for (int32 row = 0; row < glyphHeight; row++) { @@ -241,15 +242,16 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) } // Normalize gray scale images not using 256 colors - if (bitmap->num_grays != 256) { + if (bitmap->num_grays != 256) + { const int32 scale = 255 / (bitmap->num_grays - 1); - for (byte& pixel : GlyphImageData) { + for (byte& pixel : GlyphImageData) pixel *= scale; - } } // Free temporary bitmap if used - if (bitmap == &tmpBitmap) { + if (bitmap == &tmpBitmap) + { FT_Bitmap_Done(Library, bitmap); bitmap = nullptr; } @@ -267,7 +269,8 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) MSDFGenerator::GenerateMSDF(glyph, GlyphImageData, glyphWidth, glyphHeight, msdf_top, msdf_left); // End for empty glyphs - if (GlyphImageData.IsEmpty()) { + if (GlyphImageData.IsEmpty()) + { entry.TextureIndex = MAX_uint8; return false; } @@ -281,11 +284,12 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) } // Find atlas for the character texture - PixelFormat requiredFormat = options.RasterMode == FontRasterMode::MSDF ? PixelFormat::R8G8B8A8_UNorm : PixelFormat::R8_UNorm; + PixelFormat atlasFormat = options.RasterMode == FontRasterMode::MSDF ? PixelFormat::R8G8B8A8_UNorm : PixelFormat::R8_UNorm; int32 atlasIndex = 0; const FontTextureAtlasSlot* slot = nullptr; - for (; atlasIndex < Atlases.Count() && slot == nullptr; atlasIndex++) { - if (Atlases[atlasIndex]->GetPixelFormat() != requiredFormat) + for (; atlasIndex < Atlases.Count() && slot == nullptr; atlasIndex++) + { + if (Atlases[atlasIndex]->GetFormat() != atlasFormat) continue; slot = Atlases[atlasIndex]->AddEntry(glyphWidth, glyphHeight, GlyphImageData); } @@ -296,7 +300,7 @@ bool FontManager::AddNewEntry(Font* font, Char c, FontCharacterEntry& entry) { // Create new atlas auto atlas = Content::CreateVirtualAsset(); - atlas->Setup(requiredFormat, FontTextureAtlas::PaddingStyle::PadWithZero); + atlas->Setup(atlasFormat, FontTextureAtlas::PaddingStyle::PadWithZero); Atlases.Add(atlas); atlasIndex++; diff --git a/Source/Engine/Render2D/FontTextureAtlas.h b/Source/Engine/Render2D/FontTextureAtlas.h index 3a6ca98ae..f688644ab 100644 --- a/Source/Engine/Render2D/FontTextureAtlas.h +++ b/Source/Engine/Render2D/FontTextureAtlas.h @@ -108,7 +108,7 @@ public: /// /// Gets the atlas pixel format. /// - FORCE_INLINE PixelFormat GetPixelFormat() const + FORCE_INLINE PixelFormat GetFormat() const { return _format; } diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index d33964be6..d9e052e6e 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1190,10 +1190,6 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color, float scale = 1.0f / FontManager::FontScale; const bool enableFallbackFonts = EnumHasAllFlags(Features, RenderingFeatures::FallbackFonts); - const FontAsset* asset = font->GetAsset(); - const FontOptions& options = asset->GetOptions(); - const bool useMSDF = options.RasterMode == FontRasterMode::MSDF; - // Render all characters FontCharacterEntry entry; Render2DDrawCall drawCall; @@ -1204,7 +1200,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color, } else { - drawCall.Type = useMSDF ? DrawCallType::DrawCharMSDF : DrawCallType::DrawChar; + drawCall.Type = font->GetAsset()->GetOptions().RasterMode == FontRasterMode::MSDF ? DrawCallType::DrawCharMSDF : DrawCallType::DrawChar; drawCall.AsChar.Mat = nullptr; } Float2 pointer = location; @@ -1309,10 +1305,6 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color, float scale = layout.Scale / FontManager::FontScale; const bool enableFallbackFonts = EnumHasAllFlags(Features, RenderingFeatures::FallbackFonts); - const FontAsset* asset = font->GetAsset(); - const FontOptions& options = asset->GetOptions(); - const bool useMSDF = options.RasterMode == FontRasterMode::MSDF; - // Process text to get lines Lines.Clear(); font->ProcessText(text, Lines, layout); @@ -1327,7 +1319,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color, } else { - drawCall.Type = useMSDF ? DrawCallType::DrawCharMSDF : DrawCallType::DrawChar; + drawCall.Type = font->GetAsset()->GetOptions().RasterMode == FontRasterMode::MSDF ? DrawCallType::DrawCharMSDF : DrawCallType::DrawChar; drawCall.AsChar.Mat = nullptr; } for (int32 lineIndex = 0; lineIndex < Lines.Count(); lineIndex++) diff --git a/Source/ThirdParty/msdfgen/msdfgen.Build.cs b/Source/ThirdParty/msdfgen/msdfgen.Build.cs index 4a98013d7..f798152b1 100644 --- a/Source/ThirdParty/msdfgen/msdfgen.Build.cs +++ b/Source/ThirdParty/msdfgen/msdfgen.Build.cs @@ -40,6 +40,6 @@ public class msdfgen : DepsModule default: throw new InvalidPlatformException(options.Platform.Target); } - options.PublicIncludePaths.Add(Path.Combine(Globals.EngineRoot, @"Source\ThirdParty\msdfgen")); + options.PublicIncludePaths.Add(Path.Combine(Globals.EngineRoot, "Source/ThirdParty/msdfgen")); } }