Hi All,
I am trying to determine the width in screen pixels of a character array. The character array can be any length up to 25 characters and is input by the user.
The font data table contains the width information in a struct called __PRGMTAG_. The following is the data for the number "1" with the width information highlighted in red:
Here is the define for the struct (lines 48 - 52 font.h linked below):
I would like to read each character in the array and extract the width for each from the data table. Then add them together to get the total width for the array. I have been able to do the following:
This produces the following in the serial monitor:
The hex code for each character (e.g. 0x31 for "1") can be read and attached to the font name using printf. Also, the width for individual characters can be extracted (e.g. 16 for 0x31 "1"). However, I can't find a way to combine the two operations into one.
I have tried various combinations of the following examples, but none work (most don't even compile):
Does anyone know how I can extract the 'image_width' data on a character by character basis and use it to calculate the array width?
Thank you for any help and suggestions.
The font file is attached.
https://github.com/sumotoy/RA8875/blob/0.70/_settings/font.h
I am trying to determine the width in screen pixels of a character array. The character array can be any length up to 25 characters and is input by the user.
The font data table contains the width information in a struct called __PRGMTAG_. The following is the data for the number "1" with the width information highlighted in red:
Code:
static const uint8_t image_data_MagUbuntuCond_36_0x31[84] __PRGMTAG_ = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x01, 0xe0, 0x07, 0xe0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, 0xe0, 0x1f, 0xe0, 0x09, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};////character: '1'
static const tImage MagUbuntuCond_36_0x31 __PRGMTAG_ = { image_data_MagUbuntuCond_36_0x31,
[COLOR="#FF0000"]16[/COLOR], 84};//character: '1' , height: 42, (charW,total bytes)
Here is the define for the struct (lines 48 - 52 font.h linked below):
Code:
typedef struct __PRGMTAG_ {
const uint8_t *data;
uint8_t image_width;
int image_datalen;
} tImage;
I would like to read each character in the array and extract the width for each from the data table. Then add them together to get the total width for the array. I have been able to do the following:
Code:
char Name[6] = {"123AB"};
byte lengthName = strlen(Name);
for (byte i = 0; i < lengthName; i ++) {
Serial.printf("MagUbuntuCond_36_0x%x", Name[i]);
Serial.println();
}
Serial.println(__PRGMTAG_ MagUbuntuCond_36_0x31.image_width);
This produces the following in the serial monitor:
MagUbuntuCond_36_0x31
MagUbuntuCond_36_0x32
MagUbuntuCond_36_0x33
MagUbuntuCond_36_0x41
MagUbuntuCond_36_0x42
16
The hex code for each character (e.g. 0x31 for "1") can be read and attached to the font name using printf. Also, the width for individual characters can be extracted (e.g. 16 for 0x31 "1"). However, I can't find a way to combine the two operations into one.
I have tried various combinations of the following examples, but none work (most don't even compile):
Code:
char widthChar = (Name[i], HEX);
char fontName[22] = "MagUbuntuCond_36_0x";
strcat(fontName, widthChar);
char fontName = printf("MagUbuntuCond_36_0x%x", Name[i]);
char fontName = printf("MagUbuntuCond_36_0x", (Name[i], HEX));
char widthChar = __PRGMTAG_ MagUbuntuCond_36_0x, Name[i].image_width;
char widthChar = __PRGMTAG_ MagUbuntuCond_36_0x, (Name[i], HEX).image_width;
strcat(fontName, (Name[i], HEX));
Does anyone know how I can extract the 'image_width' data on a character by character basis and use it to calculate the array width?
Thank you for any help and suggestions.
The font file is attached.
https://github.com/sumotoy/RA8875/blob/0.70/_settings/font.h