1
0
mirror of https://github.com/fumiama/CMoe-Counter.git synced 2024-11-27 23:20:49 +01:00

优化显示长度

This commit is contained in:
源文雨 2022-03-02 17:50:33 +08:00
parent 0bc9d3d478
commit 8521110a78
2 changed files with 6 additions and 5 deletions

7
cmoe.c
View File

@ -85,7 +85,7 @@ static int add_user(char* name, uint32_t count, FILE* fp) {
} }
static uint32_t get_content_len(int isbig, uint16_t* len_type, char* cntstr) { static uint32_t get_content_len(int isbig, uint16_t* len_type, char* cntstr) {
uint32_t len = sizeof(svg_small) - 1 uint32_t len = sizeof(svg_small)
+ 16 + isbig + 16 + isbig
+ sizeof(svg_tail) - 1; + sizeof(svg_tail) - 1;
for(int i = 0; cntstr[i]; i++) { for(int i = 0; cntstr[i]; i++) {
@ -119,7 +119,8 @@ static void return_count(char* name, char* theme) {
free(spb); free(spb);
char* cntstr; char* cntstr;
for(cntstr = cntstrbuf+9; cntstr > cntstrbuf; cntstr--) if(*cntstr == '0') break; for(cntstr = cntstrbuf+9; cntstr > cntstrbuf; cntstr--) if(*cntstr == '0') break;
if(cntstr != cntstrbuf) cntstr--; // 保留 2 位 0 if(cntstr - cntstrbuf > 2) cntstr -= 2; // 保留 3 位 0
else cntstr = cntstrbuf; // 保留所有 0
int isbig = 0; int isbig = 0;
char** theme_type = mb; char** theme_type = mb;
uint16_t* len_type = mbl; uint16_t* len_type = mbl;
@ -143,7 +144,7 @@ static void return_count(char* name, char* theme) {
head = svg_small; head = svg_small;
} }
headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml"); headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml");
write(1, head, sizeof(svg_small)-1); printf(head, w*(10+cntstrbuf-cntstr));
for(int i = 0; cntstr[i]; i++) { for(int i = 0; cntstr[i]; i++) {
printf(img_slot_front, w * i, w, h); printf(img_slot_front, w * i, w, h);
int n = cntstr[i] - '0'; int n = cntstr[i] - '0';

4
cmoe.h
View File

@ -40,12 +40,12 @@ const uint16_t gbhl[] = {1550, 1702, 1870, 1778, 1618, 2370, 1830, 2234, 1914, 1
#define H_BIG 150 #define H_BIG 150
const char svg_small[] = const char svg_small[] =
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"450\" height=\"100\" version=\"1.1\">\n" "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%d\" height=\"100\" version=\"1.1\">\n"
" <title>Moe Count</title>\n" " <title>Moe Count</title>\n"
" <g>\n" " <g>\n"
" \n"; " \n";
const char svg_big[] = const char svg_big[] =
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"680\" height=\"150\" version=\"1.1\">\n" "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%d\" height=\"150\" version=\"1.1\">\n"
" <title>Moe Count</title>\n" " <title>Moe Count</title>\n"
" <g>\n" " <g>\n"
" \n"; " \n";