This commit is contained in:
2022-07-31 10:02:29 +02:00
parent 9213a1d5dd
commit 1ae4ff72d3
4 changed files with 45 additions and 33 deletions

View File

@ -111,6 +111,7 @@ namespace RenderD7
}
}
#define I2U82I(val) RenderD7::utf8_decode(RenderD7::IntToUtf8(val).c_str())
class NFontApi
{
@ -118,12 +119,13 @@ namespace RenderD7
NFontApi();
~NFontApi();
void LoadTTF(std::string path);
std::vector<unsigned char> GetGlyphBitmap(int glyph);
unsigned char* GetGlyphBitmap(char glyph);
std::string GetStatus(){ return status; }
float GetScale() {return scale; }
int GetGlyphWidth(int glyph);
int GetGlyphHeight(int glyph);
int GetGlyphWidth(char glyph);
int GetGlyphHeight(char glyph);
int GetLineHeight(){ return l_h; }
int GetBaseHeight(){ return height; }
private:
std::string status;
@ -138,7 +140,9 @@ namespace RenderD7
int h;
int x0,y0,x1,y1;
int ascent,baseline, decent;
int ascent,baseline,decent,linegap;
int linespace;
stbtt_fontinfo font;
};

View File

@ -288,19 +288,20 @@ struct BMP {
}
unsigned fill_region(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint8_t B, uint8_t G, uint8_t R, uint8_t A) {
if (x0 + w > (uint32_t)bmp_info_header.width || y0 + h > (uint32_t)bmp_info_header.height) {
return 59;
}
uint32_t channels = bmp_info_header.bit_count / 8;
for (uint32_t y = y0; y < y0 + h; ++y) {
for (uint32_t x = x0; x < x0 + w; ++x) {
data[channels * (y * bmp_info_header.width + x) + 0] = B;
data[channels * (y * bmp_info_header.width + x) + 1] = G;
data[channels * (y * bmp_info_header.width + x) + 2] = R;
if (channels == 4) {
data[channels * (y * bmp_info_header.width + x) + 3] = A;
}
/*if (x + w > (uint32_t)bmp_info_header.width || y + h > (uint32_t)bmp_info_header.height) {
//
}*/
//else{
data[channels * (y * bmp_info_header.width + x) + 0] = B;
data[channels * (y * bmp_info_header.width + x) + 1] = G;
data[channels * (y * bmp_info_header.width + x) + 2] = R;
if (channels == 4) {
data[channels * (y * bmp_info_header.width + x) + 3] = A;
}
//}
}
}
return 0;