From 04f680c8993b6e3a59d0b35dfef8ed18552614d3 Mon Sep 17 00:00:00 2001 From: nihuini Date: Fri, 8 Dec 2023 15:05:46 +0800 Subject: [PATCH] skip space rendering --- src/mat_pixel_drawing.cpp | 42 ++++++++++++++++++++++++++++------- src/mat_pixel_drawing_font.h | 43 +----------------------------------- 2 files changed, 35 insertions(+), 50 deletions(-) diff --git a/src/mat_pixel_drawing.cpp b/src/mat_pixel_drawing.cpp index ba95f090717..34906ff39af 100644 --- a/src/mat_pixel_drawing.cpp +++ b/src/mat_pixel_drawing.cpp @@ -1316,10 +1316,10 @@ void resize_bilinear_font(const unsigned char* font_bitmap, unsigned char* resiz short* rows1 = (short*)rowsbuf1; { - short* rows0p = rows0; + short* rows1p = rows1; for (int dx = 0; dx < w; dx++) { - rows0p[dx] = 0; + rows1p[dx] = 0; } } @@ -1580,11 +1580,18 @@ void draw_text_c1(unsigned char* pixels, int w, int h, int stride, const char* t // newline cursor_x = x; cursor_y += fontpixelsize * 2; + continue; + } + + if (ch == ' ') + { + cursor_x += fontpixelsize; + continue; } if (isprint(ch) != 0) { - const unsigned char* font_bitmap = mono_font_data[ch - ' ']; + const unsigned char* font_bitmap = mono_font_data[ch - '!']; // draw resized character resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize); @@ -1640,12 +1647,18 @@ void draw_text_c2(unsigned char* pixels, int w, int h, int stride, const char* t // newline cursor_x = x; cursor_y += fontpixelsize * 2; + continue; + } + + if (ch == ' ') + { + cursor_x += fontpixelsize; + continue; } if (isprint(ch) != 0) { - int font_bitmap_index = ch - ' '; - const unsigned char* font_bitmap = mono_font_data[font_bitmap_index]; + const unsigned char* font_bitmap = mono_font_data[ch - '!']; // draw resized character resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize); @@ -1702,12 +1715,18 @@ void draw_text_c3(unsigned char* pixels, int w, int h, int stride, const char* t // newline cursor_x = x; cursor_y += fontpixelsize * 2; + continue; + } + + if (ch == ' ') + { + cursor_x += fontpixelsize; + continue; } if (isprint(ch) != 0) { - int font_bitmap_index = ch - ' '; - const unsigned char* font_bitmap = mono_font_data[font_bitmap_index]; + const unsigned char* font_bitmap = mono_font_data[ch - '!']; // draw resized character resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize); @@ -1765,11 +1784,18 @@ void draw_text_c4(unsigned char* pixels, int w, int h, int stride, const char* t // newline cursor_x = x; cursor_y += fontpixelsize * 2; + continue; + } + + if (ch == ' ') + { + cursor_x += fontpixelsize; + continue; } if (isprint(ch) != 0) { - const unsigned char* font_bitmap = mono_font_data[ch - ' ']; + const unsigned char* font_bitmap = mono_font_data[ch - '!']; // draw resized character resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize); diff --git a/src/mat_pixel_drawing_font.h b/src/mat_pixel_drawing_font.h index 941be6a27ee..4db71049433 100644 --- a/src/mat_pixel_drawing_font.h +++ b/src/mat_pixel_drawing_font.h @@ -1,45 +1,4 @@ -static const unsigned char mono_font_data[95][40 * 10] = { - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 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