Skip to content

Commit

Permalink
Fixed: linux compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNicker committed Oct 19, 2023
1 parent 78a6b99 commit 885f458
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 62 deletions.
16 changes: 11 additions & 5 deletions Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ set(CMAKE_CXX_STANDARD 20)
if(NOT TARGET FreeTypeTest)
include_directories(../External/FreeTypeWrapper/Include)
# Add source to this project's executable.
add_executable (FreeTypeTest "Test.cpp")
set(TargetName FreeTypeTest)
add_executable (${TargetName} "Test.cpp")

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
#enabled warnings flags
Expand All @@ -25,9 +26,14 @@ if(NOT TARGET FreeTypeTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
endif()
endif()

target_include_directories(FreeTypeTest PRIVATE ../FreeTypeWrapper/Include)
target_include_directories(FreeTypeTest PRIVATE ../FreeTypeWrapper/External/LLUtils/Include)
target_include_directories(${TargetName} PRIVATE ../FreeTypeWrapper/Include)
target_include_directories(${TargetName} PRIVATE ../FreeTypeWrapper/External/LLUtils/Include)
target_link_libraries(${TargetName} PRIVATE FreeTypeWrapper)

#Copy font to output dir
add_custom_command(TARGET ${TargetName} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/CascadiaCode.ttf ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/)

target_link_libraries(FreeTypeTest PRIVATE FreeTypeWrapper)
endif()

Binary file added Test/CascadiaCode.ttf
Binary file not shown.
110 changes: 53 additions & 57 deletions Test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ SOFTWARE.

std::filesystem::path folderToSaveFiles = "./testImages/";
#if LLUTILS_PLATFORM == LLUTILS_PLATFORM_WIN32
std::filesystem::path fontPathSegoei = L"c:/Windows/Fonts/segoeui.ttf";
std::filesystem::path fontPathSegoeib = L"c:/Windows/Fonts/segoeuib.ttf";
std::filesystem::path fontPathConsola = L"c:/Windows/Fonts/consola.ttf";
std::filesystem::path fontPathSegoei = L"c:/Windows/Fonts/segoeui.ttf";
std::filesystem::path fontPathSegoeib = L"c:/Windows/Fonts/segoeuib.ttf";
std::filesystem::path fontPathFixed = L"c:/Windows/Fonts/consola.ttf";
#elif LLUTILS_PLATFORM == LLUTILS_PLATFORM_LINUX
std::filesystem::path fontPathSegoei = L"c:/Windows/Fonts/segoeui.ttf";
std::filesystem::path fontPathSegoeib = L"c:/Windows/Fonts/segoeuib.ttf";
std::filesystem::path fontPathConsola = L"c:/Windows/Fonts/consola.ttf";
std::filesystem::path fontPathFixed = L"./CascadiaCode.ttf";
#else
#pragma error "Non-compatible platform detected."
#endif
Expand Down Expand Up @@ -78,7 +76,7 @@ void runTest(FreeType::FreeTypeConnector& freeType, FreeType::TextCreateParams f
FreeTypeConnector::Bitmap textBitmap;
freeType.CreateBitmap(freetypeParams, textBitmap, nullptr);

auto hash = XXH3_64bits(static_cast<const void*>(textBitmap.buffer.data()), textBitmap.height * textBitmap.rowPitch);
[[maybe_unused]] auto hash = XXH3_64bits(static_cast<const void*>(textBitmap.buffer.data()), textBitmap.height * textBitmap.rowPitch);

if (testParams.saveToFile)
SaveToFile(textBitmap, testParams.fileName);
Expand All @@ -97,10 +95,12 @@ int runtests()
TestParams testParams{};
testParams.saveToFile = shouldSaveToFile;
//Several test cases, for now mostly checks for out of bounds errors, if there's no exceptions test is considered passed.

params.DPIx = 120;
params.DPIy = 120;
params.fontPath = fontPathSegoeib.wstring();

#if LLUTILS_PLATFORM == LLUTILS_PLATFORM_WIN32
params.fontPath = fontPathSegoeib.wstring();

params.text = L"ijkjojujrjaj";
params.textColor = LLUtils::Colors::Black;
params.outlineColor = { 0,0,0,255 };
Expand All @@ -121,6 +121,8 @@ int runtests()
params.DPIx = 120;
params.DPIy = 120;
params.fontPath = fontPathSegoei.wstring();


params.text = L"<textcolor=#000000ff>|This| is זה משהו\n באמת משהו\nabcdefghijklmnopqrstuvwwxyz\nABCDEFGHIJKLMNOPQVWXYZ\n|!#_+";

params.backgroundColor = LLUtils::Colors::White;
Expand All @@ -136,8 +138,6 @@ int runtests()

runTest(freeType, params, testParams);



//Several test cases, for now mostly checks for out of bounds errors, if there's no exceptions test is considered passed.

params.DPIx = 120;
Expand All @@ -164,45 +164,56 @@ int runtests()
runTest(freeType, params, testParams);





//params.text = L"3000 X 1712 X 32 BPP | loaded in 92.7 ms";
params.text = L"Texel: 1218.3 X 584.6";
params.textColor = Colors::Lava;
params.fontPath = fontPathConsola.wstring();
params.text = L"<textcolor=#ff8930>windowed";
params.fontPath = fontPathSegoeib.wstring();
params.renderMode = FreeType::RenderMode::SubpixelAntiAliased;
params.fontSize = 11;
params.backgroundColor = { 255, 255, 255, 192 };
params.DPIx = 120;
params.DPIy = 120;
//params.padding = 1;
testParams.fileName = (folderToSaveFiles / "test2.bmp").wstring();
testParams.expectedHash = 11320992707252375232u;
params.padding = 0;

testParams.fileName = (folderToSaveFiles / "test3.bmp").wstring();
testParams.expectedHash = 9753445643566658639u;
runTest(freeType, params, testParams);


//Lower dpi mode
params.text = L"abcdefg.tif";
params.fontPath = fontPathSegoeib.wstring();
params.renderMode = FreeType::RenderMode::Antialiased;
params.fontSize = 12;
params.backgroundColor = { 255, 255, 255, 192 };
params.DPIx = 96;
params.DPIy = 96;
params.padding = 0;
params.outlineWidth = 2;

testParams.fileName = (folderToSaveFiles / L"test6.bmp").wstring();
testParams.expectedHash = 3439216908320477038u;
runTest(freeType, params, testParams);


// Test very thick outline
params.text = L"<textcolor=#ff8930>windowed";
params.fontPath = fontPathSegoeib.wstring();
params.renderMode = FreeType::RenderMode::SubpixelAntiAliased;
params.renderMode = FreeType::RenderMode::Antialiased;
params.fontSize = 11;
params.backgroundColor = { 255, 255, 255, 192 };
params.DPIx = 120;
params.DPIy = 120;
params.padding = 0;
params.outlineWidth = 20;

testParams.fileName = (folderToSaveFiles / "test3.bmp").wstring();
testParams.expectedHash = 9753445643566658639u;
testParams.fileName = (folderToSaveFiles / "test5.bmp").wstring();
testParams.expectedHash = 4822496049661565882u;
runTest(freeType, params, testParams);


#endif

//Test Fixed width font

params.text = L"<textcolor=#ff8930>444";
params.fontPath = fontPathConsola.wstring();
params.fontPath = fontPathFixed.wstring();
params.renderMode = FreeType::RenderMode::Antialiased;
params.fontSize = 11;
params.backgroundColor = { 255, 255, 255, 192 };
Expand All @@ -227,40 +238,14 @@ int runtests()
LL_EXCEPTION(LLUtils::Exception::ErrorCode::InvalidState, "mismatch size");*/


//test very thick outline
params.text = L"<textcolor=#ff8930>windowed";
params.fontPath = fontPathSegoeib.wstring();
params.renderMode = FreeType::RenderMode::Antialiased;
params.fontSize = 11;
params.backgroundColor = { 255, 255, 255, 192 };
params.DPIx = 120;
params.DPIy = 120;
params.padding = 0;
params.outlineWidth = 20;

testParams.fileName = (folderToSaveFiles / "test5.bmp").wstring();
testParams.expectedHash = 4822496049661565882u;
runTest(freeType, params, testParams);

//Lower dpi mode
params.text = L"abcdefg.tif";
params.fontPath = fontPathSegoeib.wstring();
params.renderMode = FreeType::RenderMode::Antialiased;
params.fontSize = 12;
params.backgroundColor = { 255, 255, 255, 192 };
params.DPIx = 96;
params.DPIy = 96;
params.padding = 0;
params.outlineWidth = 2;

testParams.fileName = (folderToSaveFiles / L"test6.bmp").wstring();
testParams.expectedHash = 3439216908320477038u;
runTest(freeType, params, testParams);


//Test aliased text
params.text = L"<textcolor=#ff8930>aliased text";
params.fontPath = fontPathConsola.wstring();
params.fontPath = fontPathFixed.wstring();
params.outlineColor = { 0, 0, 0, 255 };
params.outlineWidth = 0;
params.renderMode = FreeType::RenderMode::Aliased;
Expand All @@ -274,6 +259,20 @@ int runtests()
testParams.expectedHash = 11631623323771771341u;
runTest(freeType, params, testParams);

//params.text = L"3000 X 1712 X 32 BPP | loaded in 92.7 ms";
params.text = L"Texel: 1218.3 X 584.6";
params.textColor = Colors::Lava;
params.fontPath = fontPathFixed.wstring();
params.renderMode = FreeType::RenderMode::SubpixelAntiAliased;
params.fontSize = 11;
params.backgroundColor = { 255, 255, 255, 192 };
params.DPIx = 120;
params.DPIy = 120;
//params.padding = 1;
testParams.fileName = (folderToSaveFiles / "test2.bmp").wstring();
testParams.expectedHash = 11320992707252375232u;
runTest(freeType, params, testParams);


return 0;
}
Expand All @@ -283,11 +282,8 @@ int main()

try
{
#if LLUTILS_PLATFORM == LLUTILS_PLATFORM_WIN32

if (runtests() == 0)
std::cout << "All tests passed successfully.";
#endif

}
catch (...)
Expand Down

0 comments on commit 885f458

Please sign in to comment.