diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index 9a9174ed7..9ecc655c0 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -1,7 +1,9 @@ #include "stdafx.h" #include "Tests.h" +#include #include +#include using namespace wiSceneSystem; @@ -101,6 +103,7 @@ TestsRenderer::TestsRenderer() testSelector->AddItem("Physics Test"); testSelector->AddItem("Cloth Physics Test"); testSelector->AddItem("Job System Test"); + testSelector->AddItem("Font Test"); testSelector->SetMaxVisibleItemCount(100); testSelector->OnSelect([=](wiEventArgs args) { @@ -168,6 +171,12 @@ TestsRenderer::TestsRenderer() case 10: RunJobSystemTest(); break; + case 11: + RunFontTest(); + break; + default: + assert(0); + break; } }); @@ -226,3 +235,62 @@ void TestsRenderer::RunJobSystemTest() font.props.size = 24; this->addFont(&font); } +void TestsRenderer::RunFontTest() +{ + static wiFont font; + static wiFont font_upscaled; + + font.SetText("This is Arial, size 32 wiFont"); + font_upscaled.SetText("This is Arial, size 14 wiFont, but upscaled to 32"); + + font.props.posX = wiRenderer::GetDevice()->GetScreenWidth() / 2; + font.props.posY = wiRenderer::GetDevice()->GetScreenHeight() / 6; + + font_upscaled.props = font.props; + font_upscaled.props.posY += font.textHeight() + 10; + + font.style = wiFont::AddFontStyle(wiFont::GetFontPath() + "arial.ttf", 32); + font_upscaled.style = wiFont::AddFontStyle(wiFont::GetFontPath() + "arial.ttf", 14); + font_upscaled.props.size = 32; // upscale + + addFont(&font); + addFont(&font_upscaled); + + static wiFont font_aligned; + font_aligned = font; + font_aligned.props.posY += font.textHeight() * 2; + font_aligned.props.size = 38; + font_aligned.props.shadowColor = wiColor::Red; + font_aligned.props.h_align = WIFALIGN_CENTER; + font_aligned.SetText("Center aligned, red shadow, bigger"); + addFont(&font_aligned); + + static wiFont font_aligned2; + font_aligned2 = font_aligned; + font_aligned2.props.posY += font_aligned.textHeight() + 10; + font_aligned2.props.shadowColor = wiColor::Purple; + font_aligned2.props.h_align = WIFALIGN_RIGHT; + font_aligned2.SetText("Right aligned, purple shadow"); + addFont(&font_aligned2); + + std::stringstream ss(""); + std::ifstream file("font_test.txt"); + if (file.is_open()) + { + while (!file.eof()) + { + std::string s; + file >> s; + ss << s; + } + } + static wiFont font_japanese; + font_japanese = font_aligned2; + font_japanese.props.posY += font_aligned2.textHeight(); + font_japanese.style = wiFont::AddFontStyle("yumin.ttf", 34); + font_japanese.props.shadowColor = wiColor::Transparent; + font_japanese.props.h_align = WIFALIGN_CENTER; + font_japanese.props.size = -1; // no scaling, it will use 34 (that was specified with AddFontStyle second argument) + font_japanese.SetText(ss.str()); + addFont(&font_japanese); +} diff --git a/Tests/Tests.h b/Tests/Tests.h index 59ce4f2e2..9a4e07a89 100644 --- a/Tests/Tests.h +++ b/Tests/Tests.h @@ -19,5 +19,6 @@ public: void RunJobSystemTest(); + void RunFontTest(); }; diff --git a/Tests/font_test.txt b/Tests/font_test.txt new file mode 100644 index 000000000..e4e0a6c2a --- /dev/null +++ b/Tests/font_test.txt @@ -0,0 +1 @@ +ウィけっどエンジンです。よろしくお願いします。 \ No newline at end of file diff --git a/Tests/yumin.ttf b/Tests/yumin.ttf new file mode 100644 index 000000000..66882ad26 Binary files /dev/null and b/Tests/yumin.ttf differ