diff --git a/README.md b/README.md index fdb1b67..7f3a8d7 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ In `xdg-shell-protocol.cpp` - we need access to `xdg_wm_base_interface` so expor sudo apt-get install libgl-dev ``` +#### fonts + +```bash +sudo apt-get install libfreetype-dev +``` + # Build from Source diff --git a/src/fonts/BasicFontEngine.cpp b/src/fonts/BasicFontEngine.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/fonts/BasicFontEngine.h b/src/fonts/BasicFontEngine.h new file mode 100644 index 0000000..e69de29 diff --git a/src/fonts/CMakeLists.txt b/src/fonts/CMakeLists.txt index 42d3aec..857443c 100644 --- a/src/fonts/CMakeLists.txt +++ b/src/fonts/CMakeLists.txt @@ -1,8 +1,25 @@ +set(fonts_LIB_DEPENDS "") + list(APPEND fonts_LIB_INCLUDES FontReader.cpp TrueTypeFont.cpp ) + +if(UNIX) + find_package(Freetype QUIET) + if(Freetype_FOUND) + list(APPEND font_LIB_INCLUDES + FreeTypeFontEngine.cpp + ) + + list(APPEND fonts_LIB_DEPENDS + Freetype::Freetype + ) + else() + message(STATUS "Did not find freetype - skipping font engine") + endif() +endif() add_library(fonts SHARED ${fonts_LIB_INCLUDES}) @@ -10,6 +27,6 @@ target_include_directories(fonts PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" ) -target_link_libraries(fonts PUBLIC core) +target_link_libraries(fonts PUBLIC core ${fonts_LIB_DEPENDS}) set_property(TARGET fonts PROPERTY FOLDER src) set_target_properties( fonts PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) \ No newline at end of file diff --git a/src/fonts/FreeTypeFontEngine.cpp b/src/fonts/FreeTypeFontEngine.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/fonts/FreeTypeFontEngine.h b/src/fonts/FreeTypeFontEngine.h new file mode 100644 index 0000000..0e4a86f --- /dev/null +++ b/src/fonts/FreeTypeFontEngine.h @@ -0,0 +1,64 @@ +#pragma once + +#include "IFontEngine.h" + +#include + +#include +#include FT_FREETYPE_H + +class FreeTypeFontEngine : public IFontEngine +{ +public: + FreeTypeFontEngine() = default; + + void run() + { + FT_Library library; + auto error = FT_Init_FreeType( &library ); + if ( error ) + { + std::cout << "Error initializing ft" << std::endl; + } + + FT_Face face; + error = FT_New_Face( library, + "/usr/share/fonts/truetype/tlwg/TlwgTypo-Bold.ttf", + 0, + &face ); + if ( error == FT_Err_Unknown_File_Format ) + { + std::cout << "Found file but format not supported" << std::endl; + } + else if ( error ) + { + std::cout << "Failed to find or open file" << std::endl; + } + + auto charcode = 65; + auto glyph_index = FT_Get_Char_Index( face, charcode ); + if (glyph_index == 0) + { + std::cout << "Got the null glyph" << std::endl; + } + + error = FT_Load_Glyph( + face, /* handle to face object */ + glyph_index, /* glyph index */ + FT_LOAD_DEFAULT ); + + if (face->glyph->format == FT_GLYPH_FORMAT_BITMAP) + { + std::cout << "It is bitmap format" << std::endl; + } + else + { + error = FT_Render_Glyph( face->glyph, /* glyph slot */ + FT_RENDER_MODE_NORMAL ); + } + + auto rows = face->glyph->bitmap.rows; + auto columns = face->glyph->bitmap.width; + std::cout << "We have a bitmap with rows " << rows << " and columns " << columns << std::endl; + } +}; diff --git a/src/fonts/IFontEngine.h b/src/fonts/IFontEngine.h new file mode 100644 index 0000000..0a0ef90 --- /dev/null +++ b/src/fonts/IFontEngine.h @@ -0,0 +1,8 @@ +#pragma once + +class IFontEngine +{ +public: + IFontEngine() = default; + virtual ~IFontEngine() = default; +}; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f440cfa..9115dd1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -56,6 +56,15 @@ if (DBUS_FOUND) ) endif() +if(UNIX) + find_package(Freetype QUIET) + if(Freetype_FOUND) + list(APPEND TestFiles + fonts/TestFreeTypeFontEngine.cpp + ) + endif() +endif() + foreach(TestFile ${TestFiles}) cmake_path(GET TestFile FILENAME TestFileName) cmake_path(GET TestFileName STEM TestName) diff --git a/test/fonts/TestFreeTypeFontEngine.cpp b/test/fonts/TestFreeTypeFontEngine.cpp new file mode 100644 index 0000000..b45fd00 --- /dev/null +++ b/test/fonts/TestFreeTypeFontEngine.cpp @@ -0,0 +1,13 @@ + +#include "FreeTypeFontEngine.h" + +#include + +int main() +{ + FreeTypeFontEngine engine; + engine.run(); + + + return 0; +}