Code style cleanup for #3944

This commit is contained in:
Wojtek Figat
2026-03-12 17:22:43 +01:00
parent fc7abbf541
commit d784fddf95
5 changed files with 21 additions and 25 deletions

View File

@@ -46,7 +46,7 @@ namespace FlaxEditor.Windows.Assets
options = new FontOptions
{
Hinting = Hinting,
RasterMode = RasterMode
RasterMode = RasterMode,
};
if (AntiAliasing)
options.Flags |= FontFlags.AntiAliasing;

View File

@@ -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 <ThirdParty/freetype/ftsynth.h>
#include <ThirdParty/freetype/ftbitmap.h>
#include <ThirdParty/freetype/internal/ftdrv.h>
#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<FontTextureAtlas>();
atlas->Setup(requiredFormat, FontTextureAtlas::PaddingStyle::PadWithZero);
atlas->Setup(atlasFormat, FontTextureAtlas::PaddingStyle::PadWithZero);
Atlases.Add(atlas);
atlasIndex++;

View File

@@ -108,7 +108,7 @@ public:
/// <summary>
/// Gets the atlas pixel format.
/// </summary>
FORCE_INLINE PixelFormat GetPixelFormat() const
FORCE_INLINE PixelFormat GetFormat() const
{
return _format;
}

View File

@@ -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++)

View File

@@ -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"));
}
}