diff --git a/bin/unit_tests/assets/fontrendering/eepp-editor-monospace-tab-stop-test.webp b/bin/unit_tests/assets/fontrendering/eepp-editor-monospace-tab-stop-test.webp new file mode 100644 index 000000000..f6ecfe136 Binary files /dev/null and b/bin/unit_tests/assets/fontrendering/eepp-editor-monospace-tab-stop-test.webp differ diff --git a/bin/unit_tests/assets/fontrendering/eepp-editor-monospace-tabs-test.webp b/bin/unit_tests/assets/fontrendering/eepp-editor-monospace-tabs-test.webp new file mode 100644 index 000000000..255403f7b Binary files /dev/null and b/bin/unit_tests/assets/fontrendering/eepp-editor-monospace-tabs-test.webp differ diff --git a/bin/unit_tests/assets/fontrendering/eepp-text-edit-tab-stop-test.webp b/bin/unit_tests/assets/fontrendering/eepp-text-edit-tab-stop-test.webp new file mode 100644 index 000000000..d6927db4b Binary files /dev/null and b/bin/unit_tests/assets/fontrendering/eepp-text-edit-tab-stop-test.webp differ diff --git a/bin/unit_tests/assets/fontrendering/eepp-text-edit-tabs-test.webp b/bin/unit_tests/assets/fontrendering/eepp-text-edit-tabs-test.webp new file mode 100644 index 000000000..8e73a15cf Binary files /dev/null and b/bin/unit_tests/assets/fontrendering/eepp-text-edit-tabs-test.webp differ diff --git a/bin/unit_tests/assets/fontrendering/eepp-textview.webp b/bin/unit_tests/assets/fontrendering/eepp-textview.webp new file mode 100644 index 000000000..52bcc3d06 Binary files /dev/null and b/bin/unit_tests/assets/fontrendering/eepp-textview.webp differ diff --git a/bin/unit_tests/assets/fontrendering/tabs_test.txt b/bin/unit_tests/assets/fontrendering/tabs_test.txt new file mode 100644 index 000000000..d58c45cf4 --- /dev/null +++ b/bin/unit_tests/assets/fontrendering/tabs_test.txt @@ -0,0 +1,21 @@ + + { + { "u8", "type" }, { "u16", "type" }, { "u32", "type" }, + { "u64", "type" }, { "s8", "type" }, { "s16", "type" }, + { "s32", "type" }, { "s64", "type" }, { "int", "type" }, + { "float", "type" }, { "float32", "type" }, { "float64", "type" }, + { "Any", "type" }, { "array", "type" }, { "bool", "type" }, + { "enum", "keyword" }, { "null", "type" }, { "pointer", "type" }, + { "procedure", "keyword" }, { "string", "type" }, { "struct", "keyword" }, + { "void", "type" }, { "complex", "type" }, { "const", "keyword" }, + { "union", "keyword" }, { "defer", "keyword" }, { "do", "keyword" }, + { "for", "keyword" }, { "macro", "keyword" }, { "remove", "keyword" }, + { "bit_set", "keyword" }, { "switch", "keyword" }, { "if", "keyword" }, + { "case", "keyword" }, { "foreign", "keyword" }, { "new", "keyword" }, + { "inline", "keyword" }, { "import", "keyword" }, { "false", "literal" }, + { "assert", "type" }, { "return", "keyword" }, { "true", "literal" }, + { "when", "keyword" }, { "using", "keyword" }, { "continue", "keyword" }, + { "in", "keyword" }, { "break", "keyword" }, { "else", "keyword" }, + { "while", "keyword" }, { "count", "keyword" }, { "delete", "keyword" }, + + }, diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 4fc933dce..0321b412f 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -2162,6 +2162,7 @@ void Text::ensureGeometryUpdate() { mLinesWidth.push_back( x ); x = 0; + prevChar = 0; break; case '\r': break; diff --git a/src/tests/unit_tests/fontrendering.cpp b/src/tests/unit_tests/fontrendering.cpp index 9e7e15025..a0220bcd6 100644 --- a/src/tests/unit_tests/fontrendering.cpp +++ b/src/tests/unit_tests/fontrendering.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -193,7 +194,7 @@ UTEST( FontRendering, editorTest ) { WindowBackend::Default, 32, {}, 1, false, true ), UIApplication::Settings( Sys::getProcessPath() + ".." + FileSystem::getOSSlash(), 1 ) ); FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); - UICodeEditor* editor = UICodeEditor::New(); + auto* editor = UICodeEditor::New(); editor->setPixelsSize( app.getUI()->getPixelsSize() ); editor->loadFromFile( "assets/textformat/english.utf8.lf.bom.txt" ); SceneManager::instance()->update(); @@ -218,7 +219,7 @@ UTEST( FontRendering, textEditTest ) { WindowBackend::Default, 32, {}, 1, false, true ), UIApplication::Settings( Sys::getProcessPath() + ".." + FileSystem::getOSSlash(), 1 ) ); FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); - UITextEdit* editor = UITextEdit::New(); + auto* editor = UITextEdit::New(); editor->setPixelsSize( app.getUI()->getPixelsSize() ); editor->loadFromFile( "assets/textformat/english.utf8.lf.bom.txt" ); SceneManager::instance()->update(); @@ -235,3 +236,134 @@ UTEST( FontRendering, textEditTest ) { runTest(); } } + +UTEST( FontRendering, tabsTest ) { + const auto runTest = [&]() { + UIApplication app( + WindowSettings( 1024, 650, "eepp - Tabs Test", WindowStyle::Default, + WindowBackend::Default, 32, {}, 1, false, true ), + UIApplication::Settings( Sys::getProcessPath() + ".." + FileSystem::getOSSlash(), 1 ) ); + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + auto* editor = UICodeEditor::New(); + editor->setPixelsSize( app.getUI()->getPixelsSize() ); + editor->loadFromFile( "assets/fontrendering/tabs_test.txt" ); + SceneManager::instance()->update(); + SceneManager::instance()->draw(); + compareImages( utest_state, utest_result, app.getWindow(), + "eepp-editor-monospace-tabs-test" ); + }; + + UTEST_PRINT_STEP( "Text Shaper disabled" ); + runTest(); + + UTEST_PRINT_STEP( "Text Shaper enabled" ); + { + BoolScopedOp op( Text::TextShaperEnabled, true ); + runTest(); + } +} + +UTEST( FontRendering, tabStopTest ) { + const auto runTest = [&]() { + UIApplication app( + WindowSettings( 1024, 650, "eepp - Tab Stop Test", WindowStyle::Default, + WindowBackend::Default, 32, {}, 1, false, true ), + UIApplication::Settings( Sys::getProcessPath() + ".." + FileSystem::getOSSlash(), 1 ) ); + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + auto* editor = UICodeEditor::New(); + editor->setTabStops( true ); + editor->setPixelsSize( app.getUI()->getPixelsSize() ); + editor->loadFromFile( "assets/fontrendering/tabs_test.txt" ); + SceneManager::instance()->update(); + SceneManager::instance()->draw(); + compareImages( utest_state, utest_result, app.getWindow(), + "eepp-editor-monospace-tab-stop-test" ); + }; + + UTEST_PRINT_STEP( "Text Shaper disabled" ); + runTest(); + + UTEST_PRINT_STEP( "Text Shaper enabled" ); + { + BoolScopedOp op( Text::TextShaperEnabled, true ); + runTest(); + } +} + +UTEST( FontRendering, tabsTextEditTest ) { + const auto runTest = [&]() { + UIApplication app( + WindowSettings( 1024, 650, "eepp - TextEdit - Tabs Test", WindowStyle::Default, + WindowBackend::Default, 32, {}, 1, false, true ), + UIApplication::Settings( Sys::getProcessPath() + ".." + FileSystem::getOSSlash(), 1 ) ); + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + auto* editor = UITextEdit::New(); + editor->setPixelsSize( app.getUI()->getPixelsSize() ); + editor->loadFromFile( "assets/fontrendering/tabs_test.txt" ); + SceneManager::instance()->update(); + SceneManager::instance()->draw(); + compareImages( utest_state, utest_result, app.getWindow(), "eepp-text-edit-tabs-test" ); + }; + + UTEST_PRINT_STEP( "Text Shaper disabled" ); + runTest(); + + UTEST_PRINT_STEP( "Text Shaper enabled" ); + { + BoolScopedOp op( Text::TextShaperEnabled, true ); + runTest(); + } +} + +UTEST( FontRendering, tabStopTextEditTest ) { + const auto runTest = [&]() { + UIApplication app( + WindowSettings( 1024, 650, "eepp - TextEdit - Tab Stop Test", WindowStyle::Default, + WindowBackend::Default, 32, {}, 1, false, true ), + UIApplication::Settings( Sys::getProcessPath() + ".." + FileSystem::getOSSlash(), 1 ) ); + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + auto* editor = UITextEdit::New(); + editor->setTabStops( true ); + editor->setPixelsSize( app.getUI()->getPixelsSize() ); + editor->loadFromFile( "assets/fontrendering/tabs_test.txt" ); + SceneManager::instance()->update(); + SceneManager::instance()->draw(); + compareImages( utest_state, utest_result, app.getWindow(), "eepp-text-edit-tab-stop-test" ); + }; + + UTEST_PRINT_STEP( "Text Shaper disabled" ); + runTest(); + + UTEST_PRINT_STEP( "Text Shaper enabled" ); + { + BoolScopedOp op( Text::TextShaperEnabled, true ); + runTest(); + } +} + +UTEST( FontRendering, textViewTest ) { + const auto runTest = [&]() { + UIApplication app( WindowSettings( 1024, 650, "eepp - TextView", WindowStyle::Default, + WindowBackend::Default, 32, {}, 1, false, true ), + UIApplication::Settings( + Sys::getProcessPath() + ".." + FileSystem::getOSSlash(), 1.5f ) ); + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + auto* view = UITextView::New(); + view->setPixelsSize( app.getUI()->getPixelsSize() ); + std::string file; + FileSystem::fileGet( "assets/textformat/english.utf8.lf.bom.txt", file ); + view->setText( file ); + SceneManager::instance()->update(); + SceneManager::instance()->draw(); + compareImages( utest_state, utest_result, app.getWindow(), "eepp-textview" ); + }; + + UTEST_PRINT_STEP( "Text Shaper disabled" ); + runTest(); + + UTEST_PRINT_STEP( "Text Shaper enabled" ); + { + BoolScopedOp op( Text::TextShaperEnabled, true ); + runTest(); + } +}