Hershey Fonts: ifdef guard hershey features for eventual deprecation.

Hershey fonts have all but been replaced by PicoVector's "Alright Fonts"
implementation and in many case we need this flash back!
pull/1064/head
Phil Howard 2025-02-01 16:46:58 +00:00
rodzic 7fee95d668
commit b3d7bd497d
4 zmienionych plików z 39 dodań i 0 usunięć

Wyświetl plik

@ -6,4 +6,14 @@ target_sources(${LIB_NAME} INTERFACE
${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}_data.cpp ${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}) target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})

Wyświetl plik

@ -37,13 +37,17 @@ namespace pimoroni {
void PicoGraphics::set_font(const bitmap::font_t *font){ void PicoGraphics::set_font(const bitmap::font_t *font){
this->bitmap_font = font; this->bitmap_font = font;
#ifdef HERSHEY_FONTS
this->hershey_font = nullptr; this->hershey_font = nullptr;
#endif
} }
#ifdef HERSHEY_FONTS
void PicoGraphics::set_font(const hershey::font_t *font){ void PicoGraphics::set_font(const hershey::font_t *font){
this->bitmap_font = nullptr; this->bitmap_font = nullptr;
this->hershey_font = font; this->hershey_font = font;
} }
#endif
void PicoGraphics::set_font(std::string_view name){ void PicoGraphics::set_font(std::string_view name){
if (name == "bitmap6") { if (name == "bitmap6") {
@ -53,10 +57,12 @@ namespace pimoroni {
} else if (name == "bitmap14_outline") { } else if (name == "bitmap14_outline") {
set_font(&font14_outline); set_font(&font14_outline);
} else { } else {
#ifdef HERSHEY_FONTS
// check that font exists and assign it // check that font exists and assign it
if(hershey::has_font(name)) { if(hershey::has_font(name)) {
set_font(hershey::font(name)); set_font(hershey::font(name));
} }
#endif
} }
} }
@ -146,12 +152,14 @@ namespace pimoroni {
return; return;
} }
#ifdef HERSHEY_FONTS
if (hershey_font) { if (hershey_font) {
hershey::glyph(hershey_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) { hershey::glyph(hershey_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
line(Point(x1, y1), Point(x2, y2)); line(Point(x1, y1), Point(x2, y2));
}, c, p.x, p.y, s, a); }, c, p.x, p.y, s, a);
return; 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) { 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; return;
} }
#ifdef HERSHEY_FONTS
if (hershey_font) { if (hershey_font) {
if(thickness == 1) { if(thickness == 1) {
hershey::text(hershey_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) { hershey::text(hershey_font, [this](int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
@ -174,11 +183,14 @@ namespace pimoroni {
} }
return; return;
} }
#endif
} }
int32_t PicoGraphics::measure_text(const std::string_view &t, float s, uint8_t letter_spacing, bool fixed_width) { 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); 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); if (hershey_font) return hershey::measure_text(hershey_font, t, s);
#endif
return 0; return 0;
} }

Wyświetl plik

@ -9,7 +9,9 @@
#include <functional> #include <functional>
#include <math.h> #include <math.h>
#ifdef HERSHEY_FONTS
#include "libraries/hershey_fonts/hershey_fonts.hpp" #include "libraries/hershey_fonts/hershey_fonts.hpp"
#endif
#include "libraries/bitmap_fonts/bitmap_fonts.hpp" #include "libraries/bitmap_fonts/bitmap_fonts.hpp"
#include "libraries/bitmap_fonts/font6_data.hpp" #include "libraries/bitmap_fonts/font6_data.hpp"
#include "libraries/bitmap_fonts/font8_data.hpp" #include "libraries/bitmap_fonts/font8_data.hpp"
@ -245,7 +247,10 @@ namespace pimoroni {
//scanline_interrupt_func scanline_interrupt = nullptr; //scanline_interrupt_func scanline_interrupt = nullptr;
const bitmap::font_t *bitmap_font; const bitmap::font_t *bitmap_font;
#ifdef HERSHEY_FONTS
const hershey::font_t *hershey_font; const hershey::font_t *hershey_font;
#endif
static constexpr RGB332 rgb_to_rgb332(uint8_t r, uint8_t g, uint8_t b) { static constexpr RGB332 rgb_to_rgb332(uint8_t r, uint8_t g, uint8_t b) {
return RGB(r, g, b).to_rgb332(); return RGB(r, g, b).to_rgb332();
@ -316,7 +321,9 @@ namespace pimoroni {
virtual bool render_tile(const Tile *tile) { return false; } virtual bool render_tile(const Tile *tile) { return false; }
void set_font(const bitmap::font_t *font); void set_font(const bitmap::font_t *font);
#ifdef HERSHEY_FONTS
void set_font(const hershey::font_t *font); void set_font(const hershey::font_t *font);
#endif
void set_font(std::string_view name); void set_font(std::string_view name);
void set_dimensions(int width, int height); void set_dimensions(int width, int height);

Wyświetl plik

@ -12,4 +12,14 @@ target_include_directories(usermod_${MOD_NAME} INTERFACE
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/hershey_fonts ${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}) target_link_libraries(usermod INTERFACE usermod_${MOD_NAME})