Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ jobs:
key: ${{github.event.repository.name}}-${{github.job}}-${{matrix.os}}-${{matrix.type}}

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DTOMATO_ASAN=${{matrix.type == 'asan' && 'ON' || 'OFF'}}
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DTOMATO_ASAN=${{matrix.type == 'asan' && 'ON' || 'OFF'}} -DBUILD_TESTING=ON

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato test_font_loaders

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -V -C ${{env.BUILD_TYPE}}

android:
timeout-minutes: 30
Expand Down Expand Up @@ -144,7 +148,11 @@ jobs:
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato test_font_loaders

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -V -C ${{env.BUILD_TYPE}}

windows:
timeout-minutes: 15
Expand Down Expand Up @@ -190,5 +198,9 @@ jobs:
-DPKG_CONFIG_EXECUTABLE=C:/vcpkg/installed/x64-windows/tools/pkgconf/pkgconf.exe

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4 -t tomato test_font_loaders

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -V -C ${{env.BUILD_TYPE}}

4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ message(STATUS "${tomato_VERSION_MAJOR}.${tomato_VERSION_MINOR}.${tomato_VERSION

# cmake setup end

if (BUILD_TESTING)
include(CTest)
endif()

add_subdirectory(./src)

# TODO: move to src
Expand Down
4 changes: 3 additions & 1 deletion external/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ if (NOT TARGET imgui)
#GIT_TAG 85b2fe8486190fa9326565a2fb5fccb6caea4396 # v1.92.0
#GIT_TAG 5d4126876bc10396d4c6511853ff10964414c776 # v1.92.1
#GIT_TAG bf75bfec48fc00f532af8926130b70c0e26eb099 # v1.92.3
GIT_TAG 349dbf9c57a15e2148fbfa7cb88df30280e0a362 # v1.92.3 + bitmap scaling patches
#GIT_TAG 349dbf9c57a15e2148fbfa7cb88df30280e0a362 # v1.92.3 + bitmap scaling patches
#GIT_TAG bitmaps_and_emsize
GIT_TAG fixed_sized_bitmaps_density1
EXCLUDE_FROM_ALL
)

Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)

add_subdirectory(./font_loading)

########################################

if (TOMATO_MAIN_SO)
Expand Down Expand Up @@ -199,6 +201,8 @@ target_link_libraries(tomato PUBLIC

solanaceae_object_store

font_loading

SDL3::SDL3

imgui
Expand Down
5 changes: 3 additions & 2 deletions src/chat_gui4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,9 @@ float ChatGui4::render(float time_delta, bool window_hidden, bool window_focused
constexpr ImGuiInputTextFlags input_flags =
//ImGuiInputTextFlags_AllowTabInput |
ImGuiInputTextFlags_NoHorizontalScroll |
ImGuiInputTextFlags_CallbackCharFilter |
ImGuiInputTextFlags_WordWrap;
ImGuiInputTextFlags_CallbackCharFilter
//ImGuiInputTextFlags_WordWrap
;

bool text_input_validate {false};
ImGui::InputTextMultiline(
Expand Down
49 changes: 49 additions & 0 deletions src/font_loading/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.9...3.24 FATAL_ERROR)

########################################

add_library(font_loading STATIC)

target_sources(font_loading PUBLIC
./font_finder.hpp
./font_finder.cpp
./font_finder_i.hpp
./font_finder_fs.hpp
./font_finder_fs.cpp
./font_finder_fc_sdl.hpp
./font_finder_fc_sdl.cpp
)

# TODO: conditionally compile fontconfig
#if (TOMATO_BREAKPAD)
# target_sources(tomato PUBLIC
# ./breakpad_client.hpp
# ./breakpad_client.cpp
# )

# target_link_libraries(tomato PUBLIC breakpad_client)
# target_compile_definitions(tomato PUBLIC TOMATO_BREAKPAD)
#endif()

target_compile_features(font_loading PUBLIC cxx_std_17)
target_link_libraries(font_loading PUBLIC
SDL3::SDL3
imgui
)

set_target_properties(font_loading PROPERTIES POSITION_INDEPENDENT_CODE ON)

########################################

if (BUILD_TESTING)
add_executable(test_font_loaders
./test_ff.cpp
)

target_link_libraries(test_font_loaders
font_loading
)

add_test(NAME test_font_loaders COMMAND test_font_loaders)
endif()

128 changes: 128 additions & 0 deletions src/font_loading/font_finder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include "./font_finder.hpp"

#include "./font_finder_fc_sdl.hpp"
#include "./font_finder_fs.hpp"

#include <stdexcept>

#include <iostream>

std::vector<std::string_view> getPlatformDefaultUIFamilies(void) {
#if defined(_WIN32) || defined(WIN32)
return {
"Segoe UI",
"sans-serif",
"Noto Sans",
"Helvetica",
"serif",
};
#elif __ANDROID__
return {
"Noto Sans",
"sans-serif",
"Droid Sans",
"Roboto",
"serif",
};
#elif __APPLE__
return {
"Helvetica",
"sans-serif",
"Noto Sans",
"serif",
};
#else // assume linux, prs welcome
return {
"sans-serif",
"Noto Sans",
"Ubuntu",
"serif",
};
#endif
}

std::vector<std::string_view> getPlatformDefaultColorEmojiFamilies(void) {
#if defined(_WIN32) || defined(WIN32)
return {
"Seguiemj", // Segoe UI Emoji
"Color Emoji",
"Emoji",
};
#elif __ANDROID__
return {
"Noto Color Emoji",
"Color Emoji",
"Emoji",
};
#elif __APPLE__
return {
"Apple Color Emoji",
"Color Emoji",
"Emoji",
};
#else // assume linux, other platform prs welcome
return {
"Color Emoji",
"Emoji",
};
#endif
}

std::vector<std::unique_ptr<FontFinderInterface>> constructPlatformDefaultFinderBackends(void) {
std::vector<std::unique_ptr<FontFinderInterface>> list;

try {
// TODO: should we skip this on windows?
std::unique_ptr<FontFinderInterface> ff = std::make_unique<FontFinder_FontConfigSDL>();
list.push_back(std::move(ff));
} catch (const std::runtime_error& e) {
std::cerr << "caught runtime_error exception '" << e.what() << "'\n";
} catch (...) {
std::cerr << "caught exception\n";
}

try {

#if defined(_WIN32) || defined(WIN32)
std::unique_ptr<FontFinderInterface> ff = std::make_unique<FontFinder_FileSystem>("C:\\Windows\\Fonts");
#elif __ANDROID__
std::unique_ptr<FontFinderInterface> ff = std::make_unique<FontFinder_FileSystem>("/system/fonts");
#elif __APPLE__
// TODO: macos only
std::unique_ptr<FontFinderInterface> ff = std::make_unique<FontFinder_FileSystem>("/System/Library/Fonts");
#else
std::unique_ptr<FontFinderInterface> ff = std::make_unique<FontFinder_FileSystem>("/usr/share/fonts");
#endif

list.push_back(std::move(ff));
} catch (const std::runtime_error& e) {
std::cerr << "caught runtime_error exception '" << e.what() << "'\n";
} catch (...) {
std::cerr << "caught exception\n";
}

return list;
}

std::string getBestMatch(
const std::vector<std::unique_ptr<FontFinderInterface>>& backends,
std::string_view family,
std::string_view lang,
bool color
) {
for (const auto& backend : backends) {
try {
auto res = backend->findBest(family, lang, color);
if (!res.empty()) {
return res;
}
} catch (const std::runtime_error& e) {
std::cerr << "caught runtime_error exception '" << e.what() << "'\n";
} catch (...) {
std::cerr << "caught exception\n";
}
}

return ""; // none found
}

28 changes: 28 additions & 0 deletions src/font_loading/font_finder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "./font_finder_i.hpp"

#include <string_view>
#include <vector>
#include <memory>

// for typical usage, you want to:
// 1. construct finder backends once
// 2. have a desired font family or get the family list eg. getPlatformDefaultUIFamilies()
// 3. pass it to the getBestMatch() function


// returns a list of "family" names, that when put into the backends
// on current platform, will likely yield a match.
std::vector<std::string_view> getPlatformDefaultUIFamilies(void);
std::vector<std::string_view> getPlatformDefaultColorEmojiFamilies(void);

std::vector<std::unique_ptr<FontFinderInterface>> constructPlatformDefaultFinderBackends(void);

std::string getBestMatch(
const std::vector<std::unique_ptr<FontFinderInterface>>& backends,
std::string_view family,
std::string_view lang = "",
bool color = false
);

Loading
Loading