added new meaasure_text() and measure_glyph() methods

pull/252/head
Jonathan Williamson 2022-02-23 05:42:25 +00:00 zatwierdzone przez Phil Howard
rodzic 2820b62e8c
commit e69115ea2e
2 zmienionych plików z 26 dodań i 3 usunięć

Wyświetl plik

@ -205,7 +205,6 @@ namespace pimoroni {
}
int32_t Badger2040::glyph(unsigned char c, int32_t x, int32_t y, float s, float a) {
// if space character then return a width to move the caret by
const hershey_font_glyph_t *gd = glyph_data(c);
// if glyph data not found (id too great) then skip
@ -266,6 +265,26 @@ namespace pimoroni {
}
}
int32_t Badger2040::measure_text(std::string message, float s) {
int32_t width = 0;
for(auto &c : message) {
width += measure_glyph(c, s);
}
return width;
}
int32_t Badger2040::measure_glyph(unsigned char c, float s) {
const hershey_font_glyph_t *gd = glyph_data(c);
// if glyph data not found (id too great) then skip
if(!gd) {
return 0;
}
return gd->width * s;
}
void Badger2040::font(std::string name) {
// check that font exists and assign it
if(fonts.find(name) != fonts.end()) {

Wyświetl plik

@ -56,9 +56,13 @@ namespace pimoroni {
void image(const uint8_t *data);
// text (fonts: sans, sans_bold, gothic, cursive_bold, cursive, serif_italic, serif, serif_bold)
void text(std::string message, int32_t x, int32_t y, float s = 1.0f, float a = 0.0f);
const hershey_font_glyph_t* glyph_data(unsigned char c);
int32_t glyph(unsigned char c, int32_t x, int32_t y, float s, float a = 0.0f);
void text(std::string message, int32_t x, int32_t y, float s = 1.0f, float a = 0.0f);
int32_t glyph(unsigned char c, int32_t x, int32_t y, float s = 1.0f, float a = 0.0f);
int32_t measure_text(std::string message, float s = 1.0f);
int32_t measure_glyph(unsigned char c, float s = 1.0f);
void debug_command(uint8_t command, size_t len, const uint8_t *data);
void dump_otp(uint8_t *otp_data);