Initial freetype support.
This commit is contained in:
parent
c10c5412b9
commit
a4d3019f04
9 changed files with 118 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
0
src/fonts/BasicFontEngine.cpp
Normal file
0
src/fonts/BasicFontEngine.cpp
Normal file
0
src/fonts/BasicFontEngine.h
Normal file
0
src/fonts/BasicFontEngine.h
Normal file
|
@ -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 )
|
0
src/fonts/FreeTypeFontEngine.cpp
Normal file
0
src/fonts/FreeTypeFontEngine.cpp
Normal file
64
src/fonts/FreeTypeFontEngine.h
Normal file
64
src/fonts/FreeTypeFontEngine.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
#pragma once
|
||||
|
||||
#include "IFontEngine.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <ft2build.h>
|
||||
#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;
|
||||
}
|
||||
};
|
8
src/fonts/IFontEngine.h
Normal file
8
src/fonts/IFontEngine.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
class IFontEngine
|
||||
{
|
||||
public:
|
||||
IFontEngine() = default;
|
||||
virtual ~IFontEngine() = default;
|
||||
};
|
|
@ -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)
|
||||
|
|
13
test/fonts/TestFreeTypeFontEngine.cpp
Normal file
13
test/fonts/TestFreeTypeFontEngine.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
#include "FreeTypeFontEngine.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
FreeTypeFontEngine engine;
|
||||
engine.run();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue