summaryrefslogtreecommitdiff
path: root/src/displayapp/fonts
diff options
context:
space:
mode:
Diffstat (limited to 'src/displayapp/fonts')
-rw-r--r--src/displayapp/fonts/CMakeLists.txt42
-rwxr-xr-xsrc/displayapp/fonts/generate.py9
2 files changed, 34 insertions, 17 deletions
diff --git a/src/displayapp/fonts/CMakeLists.txt b/src/displayapp/fonts/CMakeLists.txt
index ea61c3a2..d00c802b 100644
--- a/src/displayapp/fonts/CMakeLists.txt
+++ b/src/displayapp/fonts/CMakeLists.txt
@@ -1,19 +1,35 @@
-cmake_minimum_required(VERSION 3.10)
-
set(FONTS jetbrains_mono_42 jetbrains_mono_76 jetbrains_mono_bold_20
jetbrains_mono_extrabold_compressed lv_font_navi_80 lv_font_sys_48
open_sans_light)
-find_program(LV_FONT_CONV "lv_font_conv" NO_CACHE REQUIRED)
+find_program(LV_FONT_CONV "lv_font_conv" NO_CACHE REQUIRED
+ HINTS "${CMAKE_SOURCE_DIR}/node_modules/.bin")
+message(STATUS "Using ${LV_FONT_CONV} to generate font files")
configure_file(${CMAKE_CURRENT_LIST_DIR}/jetbrains_mono_bold_20.c_zero.patch
- displayapp/fonts/jetbrains_mono_bold_20.c_zero.patch COPYONLY)
-foreach(FONT ${FONTS})
- set_source_files_properties(displayapp/fonts/${FONT}.c
- PROPERTIES GENERATED TRUE)
+ ${CMAKE_CURRENT_BINARY_DIR}/jetbrains_mono_bold_20.c_zero.patch COPYONLY)
+if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
+ # FindPython3 module introduces with CMake 3.12
+ # https://cmake.org/cmake/help/latest/module/FindPython3.html
+ find_package(Python3 REQUIRED)
+else()
+ set(Python3_EXECUTABLE "python")
+endif()
- add_custom_command(OUTPUT displayapp/fonts/${FONT}.c
- COMMAND python ${CMAKE_CURRENT_LIST_DIR}/generate.py
- -f ${FONT} ${CMAKE_CURRENT_LIST_DIR}/fonts.json
- DEPENDS ${CMAKE_CURRENT_LIST_DIR}/fonts.json
- WORKING_DIRECTORY displayapp/fonts
- )
+# create static library building fonts
+add_library(infinitime_fonts STATIC)
+# add include directory to lvgl headers needed to compile the font files on its own
+target_include_directories(infinitime_fonts PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../libs")
+foreach(FONT ${FONTS})
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FONT}.c
+ COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/generate.py
+ --lv-font-conv "${LV_FONT_CONV}"
+ --font ${FONT} ${CMAKE_CURRENT_SOURCE_DIR}/fonts.json
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fonts.json
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ )
+ add_custom_target(infinitime_fonts_${FONT}
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FONT}.c
+ )
+ target_sources(infinitime_fonts PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${FONT}.c")
+ add_dependencies(infinitime_fonts infinitime_fonts_${FONT})
endforeach()
diff --git a/src/displayapp/fonts/generate.py b/src/displayapp/fonts/generate.py
index 401d47ab..89810614 100755
--- a/src/displayapp/fonts/generate.py
+++ b/src/displayapp/fonts/generate.py
@@ -18,8 +18,8 @@ class Source(object):
self.symbols = d.get('symbols')
-def gen_lvconv_line(dest: str, size: int, bpp: int, sources: typing.List[Source], compress:bool=False):
- args = ['lv_font_conv', '--size', str(size), '--output', dest, '--bpp', str(bpp), '--format', 'lvgl']
+def gen_lvconv_line(lv_font_conv: str, dest: str, size: int, bpp: int, sources: typing.List[Source], compress:bool=False):
+ args = [lv_font_conv, '--size', str(size), '--output', dest, '--bpp', str(bpp), '--format', 'lvgl']
if not compress:
args.append('--no-compress')
for source in sources:
@@ -35,9 +35,10 @@ def main():
ap = argparse.ArgumentParser(description='auto generate LVGL font files from fonts')
ap.add_argument('config', type=str, help='config file to use')
ap.add_argument('-f', '--font', type=str, action='append', help='Choose specific fonts to generate (default: all)', default=[])
+ ap.add_argument('--lv-font-conv', type=str, help='Path to "lv_font_conf" executable', default="lv_font_conv")
args = ap.parse_args()
- if not shutil.which('lv_font_conv'):
+ if not shutil.which(args.lv_font_conv):
sys.exit(f'Missing lv_font_conv. (make sure it is installed and in PATH)')
if not os.path.exists(args.config):
sys.exit(f'Error: the config file {args.config} does not exist.')
@@ -62,7 +63,7 @@ def main():
sources = font.pop('sources')
patches = font.pop('patches') if 'patches' in font else []
font['sources'] = [Source(thing) for thing in sources]
- line = gen_lvconv_line(f'{name}.c', **font)
+ line = gen_lvconv_line(args.lv_font_conv, f'{name}.c', **font)
subprocess.check_call(line)
if patches:
for patch in patches: