Skip to content

Commit a2a70cd

Browse files
committed
Compile as esp-idf component
1 parent 212976a commit a2a70cd

File tree

13 files changed

+93
-14
lines changed

13 files changed

+93
-14
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "freetype"]
2-
path = freetype
2+
path = freetype/freetype
33
url = https://github.com/sindarin-inc/freetype.git

CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
file(GLOB_RECURSE SOURCES
2+
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
3+
${CMAKE_CURRENT_SOURCE_DIR}/src/IBMFDriver/*.cpp
4+
${CMAKE_CURRENT_SOURCE_DIR}/src/TTFDriver/*.cpp
5+
${CMAKE_CURRENT_SOURCE_DIR}/src/Misc/*.cpp
6+
)
7+
8+
if(DEFINED ESP_PLATFORM AND ESP_PLATFORM)
9+
set(compile_options
10+
-includesdkconfig.h
11+
)
12+
13+
idf_component_register(SRCS ${SOURCES}
14+
INCLUDE_DIRS "src"
15+
REQUIRES freetype)
16+
17+
target_compile_options(${COMPONENT_TARGET} PUBLIC ${compile_options})
18+
else()
19+
add_library(tiny-font STATIC
20+
${SOURCES}
21+
)
22+
target_include_directories(tiny-font PUBLIC
23+
${CMAKE_CURRENT_SOURCE_DIR}/src
24+
)
25+
endif()
26+
27+
28+
29+
project(tiny-font)

Kconfig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
menu "Tiny Font Options"
2+
3+
choice
4+
5+
prompt "Font System"
6+
default FONT_IBMF
7+
8+
config FONT_IBMF
9+
bool "IBMF 1bpp Sol Sans Font"
10+
11+
config FONT_TTF
12+
bool "TTF Font via FreeType"
13+
14+
endchoice
15+
16+
config DISPLAY_PIXEL_RESOLUTION_IS_FIX
17+
bool "Display pixel resolution is unchangeable at runtime."
18+
default y
19+
20+
config TTF_SCREEN_RES_PER_INCH
21+
int "Screen resolution per inch (for TTF sizing)"
22+
default 150
23+
24+
config USE_SPIRAM
25+
bool "Use SPIRAM heap when possible"
26+
default y
27+
28+
endmenu

examples/SDL/TTF/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ target_include_directories(ttf_sdl PRIVATE
2626
set(FT_DISABLE_PNG ON CACHE BOOL "Disable PNG support in FreeType" FORCE)
2727
set(FT_DISABLE_HARFBUZZ ON CACHE BOOL "Disable HarfBuzz support in FreeType" FORCE)
2828
set(FT_DISABLE_BROTLI ON CACHE BOOL "Disable Brotli support in FreeType" FORCE)
29-
add_subdirectory(${TINY_FONT_ROOT}/freetype ${CMAKE_CURRENT_BINARY_DIR}/freetype)
29+
add_subdirectory(${TINY_FONT_ROOT}/freetype/freetype ${CMAKE_CURRENT_BINARY_DIR}/freetype)
3030

3131
target_link_libraries(ttf_sdl PRIVATE SDL2::SDL2 freetype)
3232

freetype/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
idf_component_register()
2+
3+
# Override options defined in freetype/CMakeLists.txt.
4+
# We could have used normal set(...) here if freetype enabled CMake policy CMP0077.
5+
option(FT_DISABLE_HARFBUZZ "" ON)
6+
option(FT_DISABLE_BZIP2 "" ON)
7+
option(FT_DISABLE_BROTLI "" ON)
8+
option(FT_DISABLE_PNG "" ON)
9+
option(FT_DISABLE_ZLIB "" ON)
10+
11+
# These are regular CMake variables, so we can set them directly.
12+
set(SKIP_INSTALL_ALL TRUE)
13+
set(BUILD_SHARED_LIBS OFF)
14+
15+
add_subdirectory(freetype output)
16+
17+
# https://gitlab.freedesktop.org/freetype/freetype/-/issues/1299
18+
target_compile_options(freetype PRIVATE "-Wno-dangling-pointer")
19+
20+
target_link_libraries(${COMPONENT_LIB} INTERFACE freetype)

idf_component.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## IDF Component Manager Manifest File
2+
dependencies:
3+
freetype:
4+
path: ./freetype

src/FontDefs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <inttypes.h>
43
#include <cstdio>
4+
#include <inttypes.h>
55

66
// These are the definitions that are common to both IBMF and TTF Font types
77

src/Fonts.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,3 @@ extern Font fontFace1;
4141
extern Font fontFace2;
4242

4343
#endif
44-
45-
auto FontFromPrefs(int choice) -> Font *;

src/Misc/SpiramAllocator.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
#include <esp_heap_caps.h>
88

99
template <typename T>
10-
struct SpiramAllocator {
10+
struct FontSpiramAllocator {
1111
using value_type = T;
1212

13-
SpiramAllocator() = default;
13+
FontSpiramAllocator() = default;
1414

1515
template <typename U>
16-
SpiramAllocator(const SpiramAllocator<U> &) {}
16+
FontSpiramAllocator(const FontSpiramAllocator<U> &) {}
1717

1818
auto allocate(std::size_t n) -> T * {
1919
// Using a pointer type as T will otherwise raises a warning since a common bug is to use a
@@ -34,8 +34,4 @@ struct SpiramAllocator {
3434
void deallocate(T *p, std::size_t n) { heap_caps_free(reinterpret_cast<void *>(p)); }
3535
};
3636

37-
template <typename K, typename V>
38-
using SpiramMap = std::unordered_map<K, V, std::hash<K>, std::equal_to<K>,
39-
SpiramAllocator<std::pair<const K, V>>>;
40-
4137
#endif

0 commit comments

Comments
 (0)