Hershey Fonts: Replace map lookup to avoid std::string.

pull/711/head
Phil Howard 2023-03-10 21:44:03 +00:00
rodzic 375df60ff3
commit 73f50e43ec
3 zmienionych plików z 25 dodań i 2 usunięć

Wyświetl plik

@ -14,6 +14,26 @@ namespace hershey {
//{ "serif_bold", &timesrb }
};
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 &timesi;
else if(font == "serif") return &timesr;
return &futural;
}
inline float deg2rad(float degrees) {
return (degrees * M_PI) / 180.0f;
}

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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));
}
}
}