From 0826cb9681a8b9e575535782abde2df5fabfd4e5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 19 Jul 2024 14:10:46 +1000 Subject: [PATCH] Unbreak WITH_HEADLESS builds --- source/blender/blenfont/CMakeLists.txt | 12 ++++++++++-- source/blender/blenfont/intern/blf.cc | 8 ++++++++ source/blender/blenfont/intern/blf_font.cc | 2 ++ source/blender/blenfont/intern/blf_glyph.cc | 14 ++++++++++---- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/source/blender/blenfont/CMakeLists.txt b/source/blender/blenfont/CMakeLists.txt index fd0c4252347..6e8e1fe04ef 100644 --- a/source/blender/blenfont/CMakeLists.txt +++ b/source/blender/blenfont/CMakeLists.txt @@ -33,8 +33,6 @@ set(LIB PRIVATE bf::dna bf_gpu PRIVATE bf::intern::guardedalloc - PRIVATE bf::extern::nanosvg - PRIVATE bf::editor::datafiles ${FREETYPE_LIBRARIES} ${BROTLI_LIBRARIES} ) @@ -51,6 +49,16 @@ if(WITH_PYTHON) ) endif() +if(WITH_HEADLESS) + add_definitions(-DWITH_HEADLESS) +else() + # SVG icons. + list(APPEND LIB + PRIVATE bf::extern::nanosvg + PRIVATE bf::editor::datafiles + ) + +endif() blender_add_lib(bf_blenfont "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") add_library(bf::blenfont ALIAS bf_blenfont) diff --git a/source/blender/blenfont/intern/blf.cc b/source/blender/blenfont/intern/blf.cc index 8771181cdb4..e2b3aa97e9d 100644 --- a/source/blender/blenfont/intern/blf.cc +++ b/source/blender/blenfont/intern/blf.cc @@ -612,6 +612,7 @@ int BLF_draw_mono(int fontid, const char *str, const size_t str_len, int cwidth, void BLF_draw_svg_icon( uint icon_id, float x, float y, float size, float color[4], float outline_alpha) { +#ifndef WITH_HEADLESS FontBLF *font = global_font[0]; if (font) { /* Avoid bgl usage to corrupt BLF drawing. */ @@ -620,14 +621,21 @@ void BLF_draw_svg_icon( blf_draw_svg_icon(font, icon_id, x, y, size, color, outline_alpha); blf_draw_gpu__end(font); } +#else + UNUSED_VARS(icon_id, x, y, size, color, outline_alpha); +#endif /* WITH_HEADLESS */ } blender::Array BLF_svg_icon_bitmap(uint icon_id, float size, int *r_width, int *r_height) { +#ifndef WITH_HEADLESS FontBLF *font = global_font[0]; if (font) { return blf_svg_icon_bitmap(font, icon_id, size, r_width, r_height); } +#else + UNUSED_VARS(icon_id, size, r_width, r_height); +#endif /* WITH_HEADLESS */ return {}; } diff --git a/source/blender/blenfont/intern/blf_font.cc b/source/blender/blenfont/intern/blf_font.cc index a29947b192e..78d9537ba69 100644 --- a/source/blender/blenfont/intern/blf_font.cc +++ b/source/blender/blenfont/intern/blf_font.cc @@ -524,6 +524,7 @@ int blf_font_draw_mono( return columns; } +#ifndef WITH_HEADLESS void blf_draw_svg_icon( FontBLF *font, uint icon_id, float x, float y, float size, float color[4], float outline_alpha) { @@ -595,6 +596,7 @@ blender::Array blf_svg_icon_bitmap( blf_glyph_cache_release(font); return bitmap; } +#endif /* WITH_HEADLESS */ /** \} */ diff --git a/source/blender/blenfont/intern/blf_glyph.cc b/source/blender/blenfont/intern/blf_glyph.cc index e586d59120e..4848edbee34 100644 --- a/source/blender/blenfont/intern/blf_glyph.cc +++ b/source/blender/blenfont/intern/blf_glyph.cc @@ -41,12 +41,14 @@ #include "BLI_math_vector.h" #include "BLI_string_utf8.h" +#ifndef WITH_HEADLESS +# include "nanosvgrast.h" + +# include "svg_icons.h" +#endif /* WITH_HEADLESS */ + #include "BLI_strict_flags.h" /* Keep last. */ -#include "nanosvgrast.h" - -#include "svg_icons.h" - /** * Convert glyph coverage amounts to lightness values. Uses a LUT that perceptually improves * anti-aliasing and results in text that looks a bit fuller and slightly brighter. This should @@ -336,6 +338,7 @@ static GlyphBLF *blf_glyph_cache_add_glyph( return result; } +#ifndef WITH_HEADLESS static GlyphBLF *blf_glyph_cache_add_blank(GlyphCacheBLF *gc, uint charcode) { /* Add an empty GlyphBLF to the cache and return it. With @@ -430,6 +433,7 @@ static GlyphBLF *blf_glyph_cache_add_svg(GlyphCacheBLF *gc, uint charcode, bool gc->glyphs.add(key, std::move(g)); return result; } +#endif /* WITH_HEADLESS */ /** \} */ @@ -1384,6 +1388,7 @@ GlyphBLF *blf_glyph_ensure(FontBLF *font, GlyphCacheBLF *gc, const uint charcode return g; } +#ifndef WITH_HEADLESS GlyphBLF *blf_glyph_ensure_icon(GlyphCacheBLF *gc, const uint icon_id, bool color) { GlyphBLF *g = blf_glyph_cache_find_glyph(gc, icon_id + BLF_ICON_OFFSET, 0); @@ -1392,6 +1397,7 @@ GlyphBLF *blf_glyph_ensure_icon(GlyphCacheBLF *gc, const uint icon_id, bool colo } return blf_glyph_cache_add_svg(gc, icon_id + BLF_ICON_OFFSET, color); } +#endif /* WITH_HEADLESS */ #ifdef BLF_SUBPIXEL_AA GlyphBLF *blf_glyph_ensure_subpixel(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, int32_t pen_x)