kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Hershey Fonts: Replace map lookup to avoid std::string.
rodzic
375df60ff3
commit
73f50e43ec
|
@ -14,6 +14,26 @@ namespace hershey {
|
|||
//{ "serif_bold", ×rb }
|
||||
};
|
||||
|
||||
bool has_font(std::string_view font) {
|
||||
if(font == "sans"
|
||||
|| font == "gothic"
|
||||
|| font == "cursive"
|
||||
|| font == "serif_italic"
|
||||
|| font == "serif") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const font_t* font(std::string_view font) {
|
||||
if(font == "sans") return &futural;
|
||||
else if(font == "gothic") return &gothgbt;
|
||||
else if(font == "cursive") return &scripts;
|
||||
else if(font == "serif_italic") return ×i;
|
||||
else if(font == "serif") return ×r;
|
||||
return &futural;
|
||||
}
|
||||
|
||||
inline float deg2rad(float degrees) {
|
||||
return (degrees * M_PI) / 180.0f;
|
||||
}
|
||||
|
|
|
@ -47,4 +47,7 @@ namespace hershey {
|
|||
int32_t measure_text(const font_t* font, std::string_view message, float s);
|
||||
int32_t glyph(const font_t* font, line_func line, unsigned char c, int32_t x, int32_t y, float s, float a);
|
||||
void text(const font_t* font, line_func line, std::string_view message, int32_t x, int32_t y, float s, float a);
|
||||
|
||||
bool has_font(std::string_view font);
|
||||
const font_t* font(std::string_view font);
|
||||
}
|
|
@ -44,8 +44,8 @@ namespace pimoroni {
|
|||
set_font(&font14_outline);
|
||||
} else {
|
||||
// check that font exists and assign it
|
||||
if(hershey::fonts.find((std::string)name) != hershey::fonts.end()) {
|
||||
set_font(hershey::fonts[(std::string)name]);
|
||||
if(hershey::has_font(name)) {
|
||||
set_font(hershey::font(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue