| 84 | } |
| 85 | |
| 86 | int DrawString(const char* str, int x, int y, uint8_t r, uint8_t g, uint8_t b, surface_t* surface, rect_t limits, Font* font) { |
| 87 | if(y >= surface->height || x >= surface->width || y >= limits.y + limits.height || x >= limits.x + limits.width) return 0; |
| 88 | |
| 89 | if((fontState != 1 && fontState != -1) || !font->face) InitializeFonts(); |
| 90 | if(fontState == -1){ |
| 91 | int xOffset = 0; |
| 92 | while (*str != 0) { |
| 93 | DrawChar(*str, x + xOffset, y, r, g, b, surface); |
| 94 | xOffset += 8; |
| 95 | str++; |
| 96 | } |
| 97 | return xOffset; |
| 98 | } |
| 99 | |
| 100 | uint32_t colour_i = 0xFF000000 | (r << 16) | (g << 8) | b; |
| 101 | uint32_t* buffer = (uint32_t*)surface->buffer; |
| 102 | |
| 103 | unsigned int maxHeight = font->lineHeight; |
| 104 | |
| 105 | if(y < 0 && static_cast<unsigned>(-y) > maxHeight){ |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | if(y + static_cast<int>(maxHeight) >= limits.y + limits.height){ |
| 110 | maxHeight = limits.y + limits.height - y; |
| 111 | } |
| 112 | |
| 113 | if(y + static_cast<int>(maxHeight) >= surface->height){ |
| 114 | maxHeight = surface->height - y; |
| 115 | } |
| 116 | |
| 117 | int xOffset = 0; |
| 118 | while (*str != 0) { |
| 119 | if(*str == '\n'){ |
| 120 | break; |
| 121 | } else if (!isprint(*str)) { |
| 122 | str++; |
| 123 | continue; |
| 124 | } |
| 125 | |
| 126 | if(int err = FT_Load_Char(font->face, *str, FT_LOAD_RENDER)) { |
| 127 | printf("Freetype Error (%d)\n", err); |
| 128 | throw new FontException(FontException::FontRenderError, err); |
| 129 | fontState = 0; |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | unsigned i = 0; |
| 134 | if(y < 0){ |
| 135 | i = -y; |
| 136 | } |
| 137 | |
| 138 | if(y + (font->height - font->face->glyph->bitmap_top) < limits.y){ |
| 139 | i = limits.y - (y + (font->height - font->face->glyph->bitmap_top)); |
| 140 | } |
| 141 | |
| 142 | for(; i < font->face->glyph->bitmap.rows && i + (font->height - font->face->glyph->bitmap_top) < maxHeight; i++){ |
| 143 | uint32_t yOffset = (i + y + (font->height - font->face->glyph->bitmap_top)) * (surface->width); |
no test coverage detected