Initial font work

This commit is contained in:
2026-05-05 23:18:50 +10:00
parent fd0ebb8d40
commit 3e8b472f74
20 changed files with 873 additions and 84 deletions

View File

@@ -100,6 +100,26 @@ void TestEnumAndDefaults()
error.clear();
Expect(!NormalizeAndValidateParameterValue(definition, JsonValue("other"), value, error), "enum rejects unknown options");
}
void TestTextNormalization()
{
ShaderParameterDefinition definition;
definition.id = "titleText";
definition.type = ShaderParameterType::Text;
definition.defaultTextValue = "DEFAULT";
definition.maxLength = 6;
ShaderParameterValue defaultValue = DefaultValueForDefinition(definition);
Expect(defaultValue.textValue == "DEFAUL", "text default is clamped to max length");
ShaderParameterValue value;
std::string error;
Expect(NormalizeAndValidateParameterValue(definition, JsonValue("ABC\tDEF\x01GHI"), value, error), "text accepts string values");
Expect(value.textValue == "ABCDEF", "text drops non-printable characters and clamps length");
error.clear();
Expect(!NormalizeAndValidateParameterValue(definition, JsonValue(12.0), value, error), "text rejects non-string values");
}
}
int main()
@@ -108,6 +128,7 @@ int main()
TestFloatNormalization();
TestVectorNormalization();
TestEnumAndDefaults();
TestTextNormalization();
if (gFailures != 0)
{

View File

@@ -47,6 +47,7 @@ void TestValidManifest()
{
const std::filesystem::path root = MakeTestRoot();
WriteFile(root / "look" / "mask.png", "not a real png, but enough for existence checks");
WriteFile(root / "look" / "Inter.ttf", "not a real font, but enough for existence checks");
WriteShaderPackage(root, "look", R"({
"id": "look-01",
"name": "Look 01",
@@ -54,9 +55,11 @@ void TestValidManifest()
"category": "Tests",
"entryPoint": "shadeVideo",
"textures": [{ "id": "maskTex", "path": "mask.png" }],
"fonts": [{ "id": "inter", "path": "Inter.ttf" }],
"temporal": { "enabled": true, "historySource": "source", "historyLength": 8 },
"parameters": [
{ "id": "gain", "label": "Gain", "type": "float", "default": 0.5, "min": 0, "max": 1 },
{ "id": "titleText", "label": "Title", "type": "text", "default": "LIVE", "font": "inter", "maxLength": 32 },
{ "id": "mode", "label": "Mode", "type": "enum", "default": "soft", "options": [
{ "value": "soft", "label": "Soft" },
{ "value": "hard", "label": "Hard" }
@@ -70,8 +73,29 @@ void TestValidManifest()
Expect(registry.ParseManifest(root / "look" / "shader.json", package, error), "valid manifest parses");
Expect(package.id == "look-01", "manifest id is preserved");
Expect(package.textureAssets.size() == 1 && package.textureAssets[0].id == "maskTex", "texture assets parse");
Expect(package.fontAssets.size() == 1 && package.fontAssets[0].id == "inter", "font assets parse");
Expect(package.temporal.enabled && package.temporal.effectiveHistoryLength == 4, "temporal history is capped");
Expect(package.parameters.size() == 2, "parameters parse");
Expect(package.parameters.size() == 3, "parameters parse");
Expect(package.parameters[1].type == ShaderParameterType::Text && package.parameters[1].defaultTextValue == "LIVE", "text parameter parses");
std::filesystem::remove_all(root);
}
void TestMissingFontAsset()
{
const std::filesystem::path root = MakeTestRoot();
WriteShaderPackage(root, "bad-font", R"({
"id": "bad-font",
"name": "Bad Font",
"fonts": [{ "id": "missingFont", "path": "missing.ttf" }],
"parameters": []
})");
ShaderPackageRegistry registry(4);
ShaderPackage package;
std::string error;
Expect(!registry.ParseManifest(root / "bad-font" / "shader.json", package, error), "missing font asset is rejected");
Expect(error.find("font asset not found") != std::string::npos, "missing font error is clear");
std::filesystem::remove_all(root);
}
@@ -115,6 +139,7 @@ void TestDuplicateScan()
int main()
{
TestValidManifest();
TestMissingFontAsset();
TestInvalidManifest();
TestDuplicateScan();