add MSDFsize to FontAsset

This commit is contained in:
fibref
2026-08-08 16:12:37 +08:00
parent 70498fa42c
commit 74327aa8cd
5 changed files with 47 additions and 9 deletions
@@ -1,5 +1,6 @@
// Copyright (c) Wojciech Figat. All rights reserved.
using System;
using System.ComponentModel;
using FlaxEditor.Content;
using FlaxEditor.CustomEditors;
@@ -25,6 +26,10 @@ namespace FlaxEditor.Windows.Assets
[EditorOrder(5), EditorDisplay("Properties"), Tooltip("The rasterization mode used when generating font atlases.")]
public FontRasterMode RasterMode;
[DefaultValue(32.0f)]
[EditorOrder(6), EditorDisplay("Properties"), Tooltip("The font size used when generating MSDF font atlases.")]
public float MSDFSize;
[DefaultValue(FontHinting.Default)]
[EditorOrder(10), EditorDisplay("Properties"), Tooltip("The font hinting used when rendering characters.")]
public FontHinting Hinting;
@@ -47,6 +52,7 @@ namespace FlaxEditor.Windows.Assets
{
Hinting = Hinting,
RasterMode = RasterMode,
MSDFSize = MSDFSize,
};
if (AntiAliasing)
options.Flags |= FontFlags.AntiAliasing;
@@ -63,6 +69,7 @@ namespace FlaxEditor.Windows.Assets
Bold = (options.Flags & FontFlags.Bold) == FontFlags.Bold;
Italic = (options.Flags & FontFlags.Italic) == FontFlags.Italic;
RasterMode = options.RasterMode;
MSDFSize = options.MSDFSize;
}
}
@@ -19,12 +19,13 @@ public:
const Upgrader upgraders[] =
{
{ 3, 4, &Upgrade_3_To_4 },
{ 4, 5, &Upgrade_4_To_5 },
};
setup(upgraders, ARRAY_COUNT(upgraders));
}
private:
struct FontOptionsOld
struct FontOptions3
{
FontHinting Hinting;
FontFlags Flags;
@@ -34,8 +35,8 @@ private:
{
ASSERT(context.Input.SerializedVersion == 3 && context.Output.SerializedVersion == 4);
FontOptionsOld optionsOld;
Platform::MemoryCopy(&optionsOld, context.Input.CustomData.Get(), sizeof(FontOptionsOld));
FontOptions3 optionsOld;
Platform::MemoryCopy(&optionsOld, context.Input.CustomData.Get(), sizeof(FontOptions3));
FontOptions options;
options.Hinting = optionsOld.Hinting;
@@ -45,6 +46,30 @@ private:
return CopyChunk(context, 0);
}
struct FontOptions4
{
FontHinting Hinting;
FontFlags Flags;
FontRasterMode RasterMode;
};
static bool Upgrade_4_To_5(AssetMigrationContext& context)
{
ASSERT(context.Input.SerializedVersion == 4 && context.Output.SerializedVersion == 5);
FontOptions4 optionsOld;
Platform::MemoryCopy(&optionsOld, context.Input.CustomData.Get(), sizeof(FontOptions4));
FontOptions options;
options.Hinting = optionsOld.Hinting;
options.Flags = optionsOld.Flags;
options.RasterMode = optionsOld.RasterMode;
options.MSDFSize = 32.0f;
context.Output.CustomData.Copy(&options);
return CopyChunk(context, 0);
}
};
#endif
@@ -12,13 +12,14 @@
CreateAssetResult ImportFont::Import(CreateAssetContext& context)
{
// Base
IMPORT_SETUP(FontAsset, 4);
IMPORT_SETUP(FontAsset, 5);
// Setup header
FontOptions options;
options.Hinting = FontHinting::Default;
options.Flags = FontFlags::AntiAliasing;
options.RasterMode = FontRasterMode::Bitmap;
options.MSDFSize = 32.0f;
context.Data.CustomData.Copy(&options);
// Open the file
+4 -4
View File
@@ -13,7 +13,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if this object has the same value as <paramref name="other" />; otherwise, <c>false</c> </returns>
public bool Equals(FontOptions other)
{
return Hinting == other.Hinting && Flags == other.Flags && RasterMode == other.RasterMode;
return Hinting == other.Hinting && Flags == other.Flags && RasterMode == other.RasterMode && MSDFSize == other.MSDFSize;
}
/// <inheritdoc />
@@ -25,7 +25,7 @@ namespace FlaxEngine
/// <inheritdoc />
public override int GetHashCode()
{
return HashCode.Combine((int)Hinting, (int)Flags, (int)RasterMode);
return HashCode.Combine((int)Hinting, (int)Flags, (int)RasterMode, MSDFSize);
}
/// <summary>
@@ -36,7 +36,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns>
public static bool operator ==(FontOptions left, FontOptions right)
{
return left.Hinting == right.Hinting && left.Flags == right.Flags && left.RasterMode == right.RasterMode;
return left.Hinting == right.Hinting && left.Flags == right.Flags && left.RasterMode == right.RasterMode && left.MSDFSize == right.MSDFSize;
}
/// <summary>
@@ -47,7 +47,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise,<c>false</c>.</returns>
public static bool operator !=(FontOptions left, FontOptions right)
{
return left.Hinting != right.Hinting || left.Flags != right.Flags || left.RasterMode != right.RasterMode;
return left.Hinting != right.Hinting || left.Flags != right.Flags || left.RasterMode != right.RasterMode || left.MSDFSize != right.MSDFSize;
}
}
}
+6 -1
View File
@@ -105,6 +105,11 @@ API_STRUCT() struct FontOptions
/// The font rasterization mode.
/// </summary>
API_FIELD() FontRasterMode RasterMode;
/// <summary>
/// The font size used when generating MSDF font atlases.
/// </summary>
API_FIELD() float MSDFSize;
};
/// <summary>
@@ -112,7 +117,7 @@ API_STRUCT() struct FontOptions
/// </summary>
API_CLASS(NoSpawn) class FLAXENGINE_API FontAsset : public BinaryAsset
{
DECLARE_BINARY_ASSET_HEADER(FontAsset, 4);
DECLARE_BINARY_ASSET_HEADER(FontAsset, 5);
friend Font;
private: