diff --git a/libraries/hershey_fonts/hershey_fonts.cmake b/libraries/hershey_fonts/hershey_fonts.cmake index 2c390203..e21ff56c 100644 --- a/libraries/hershey_fonts/hershey_fonts.cmake +++ b/libraries/hershey_fonts/hershey_fonts.cmake @@ -6,4 +6,14 @@ target_sources(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}_data.cpp ) +if(NOT HERSHEY_FONTS) + # TODO: Swap this to disabled by default when we're ready to deprecate + # Hershey has all but been replaced by PicoVector's "alright fonts." + set(HERSHEY_FONTS 1) +endif() + +target_compile_definitions(${LIB_NAME} INTERFACE + HERSHEY_FONTS=${HERSHEY_FONTS} +) + target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) diff --git a/libraries/pico_graphics/pico_graphics.cpp b/libraries/pico_graphics/pico_graphics.cpp index c457ca99..e0394f2d 100644 --- a/libraries/pico_graphics/pico_graphics.cpp +++ b/libraries/pico_graphics/pico_graphics.cpp @@ -37,13 +37,17 @@ namespace pimoroni { void PicoGraphics::set_font(const bitmap::font_t *font){ this->bitmap_font = font; +#ifdef HERSHEY_FONTS this->hershey_font = nullptr; +#endif } +#ifdef HERSHEY_FONTS void PicoGraphics::set_font(const hershey::font_t *font){ this->bitmap_font = nullptr; this->hershey_font = font; } +#endif void PicoGraphics::set_font(std::string_view name){ if (name == "bitmap6") { @@ -53,10 +57,12 @@ namespace pimoroni { } else if (name == "bitmap14_outline") { set_font(&font14_outline); } else { +#ifdef HERSHEY_FONTS // check that font exists and assign it if(hershey::has_font(name)) { set_font(hershey::font(name)); } +#endif } } @@ -146,12 +152,14 @@ namespace pimoroni { return; } +#ifdef HERSHEY_FONTS if (hershey_font) { hershey::glyph(hershey_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) { line(Point(x1, y1), Point(x2, y2)); }, c, p.x, p.y, s, a); return; } +#endif } void PicoGraphics::text(const std::string_view &t, const Point &p, int32_t wrap, float s, float a, uint8_t letter_spacing, bool fixed_width) { @@ -162,6 +170,7 @@ namespace pimoroni { return; } +#ifdef HERSHEY_FONTS if (hershey_font) { if(thickness == 1) { hershey::text(hershey_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) { @@ -174,11 +183,14 @@ namespace pimoroni { } return; } +#endif } int32_t PicoGraphics::measure_text(const std::string_view &t, float s, uint8_t letter_spacing, bool fixed_width) { if (bitmap_font) return bitmap::measure_text(bitmap_font, t, std::max(1.0f, s), letter_spacing, fixed_width); +#ifdef HERSHEY_FONTS if (hershey_font) return hershey::measure_text(hershey_font, t, s); +#endif return 0; } diff --git a/libraries/pico_graphics/pico_graphics.hpp b/libraries/pico_graphics/pico_graphics.hpp index 9953f754..244d1d84 100644 --- a/libraries/pico_graphics/pico_graphics.hpp +++ b/libraries/pico_graphics/pico_graphics.hpp @@ -9,7 +9,9 @@ #include #include +#ifdef HERSHEY_FONTS #include "libraries/hershey_fonts/hershey_fonts.hpp" +#endif #include "libraries/bitmap_fonts/bitmap_fonts.hpp" #include "libraries/bitmap_fonts/font6_data.hpp" #include "libraries/bitmap_fonts/font8_data.hpp" @@ -245,7 +247,10 @@ namespace pimoroni { //scanline_interrupt_func scanline_interrupt = nullptr; const bitmap::font_t *bitmap_font; + +#ifdef HERSHEY_FONTS const hershey::font_t *hershey_font; +#endif static constexpr RGB332 rgb_to_rgb332(uint8_t r, uint8_t g, uint8_t b) { return RGB(r, g, b).to_rgb332(); @@ -316,7 +321,9 @@ namespace pimoroni { virtual bool render_tile(const Tile *tile) { return false; } void set_font(const bitmap::font_t *font); +#ifdef HERSHEY_FONTS void set_font(const hershey::font_t *font); +#endif void set_font(std::string_view name); void set_dimensions(int width, int height); diff --git a/micropython/modules/hershey_fonts/micropython.cmake b/micropython/modules/hershey_fonts/micropython.cmake index 14ae6c61..30183c21 100644 --- a/micropython/modules/hershey_fonts/micropython.cmake +++ b/micropython/modules/hershey_fonts/micropython.cmake @@ -12,4 +12,14 @@ target_include_directories(usermod_${MOD_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../../../libraries/hershey_fonts ) +if(NOT HERSHEY_FONTS) +# TODO: Swap this to disabled by default when we're ready to deprecate +# Hershey has all but been replaced by PicoVector's "alright fonts." +set(HERSHEY_FONTS 1) +endif() + +target_compile_definitions(usermod_${MOD_NAME} INTERFACE +HERSHEY_FONTS=${HERSHEY_FONTS} +) + target_link_libraries(usermod INTERFACE usermod_${MOD_NAME}) \ No newline at end of file