| 810 | } |
| 811 | |
| 812 | int SysFont_TextWidth(struct DrawTextArgs* args) { |
| 813 | struct SysFont* font = (struct SysFont*)args->font->handle; |
| 814 | FT_Face face = font->face; |
| 815 | cc_string text = args->text; |
| 816 | int i, width = 0, charWidth; |
| 817 | FT_Error res; |
| 818 | cc_unichar uc; |
| 819 | |
| 820 | for (i = 0; i < text.length; i++) { |
| 821 | char c = text.buffer[i]; |
| 822 | if (c == '&' && Drawer2D_ValidColorCodeAt(&text, i + 1)) { |
| 823 | i++; continue; /* skip over the color code */ |
| 824 | } |
| 825 | |
| 826 | charWidth = font->widths[(cc_uint8)c]; |
| 827 | /* need to calculate glyph width */ |
| 828 | if (charWidth == UInt16_MaxValue) { |
| 829 | uc = Convert_CP437ToUnicode(c); |
| 830 | res = FT_Load_Char(face, uc, 0); |
| 831 | |
| 832 | if (res) { |
| 833 | Platform_Log2("Error %e measuring width of %r", &res, &c); |
| 834 | charWidth = 0; |
| 835 | } else { |
| 836 | charWidth = face->glyph->advance.x; |
| 837 | } |
| 838 | |
| 839 | font->widths[(cc_uint8)c] = charWidth; |
| 840 | } |
| 841 | width += charWidth; |
| 842 | } |
| 843 | if (!width) return 0; |
| 844 | |
| 845 | width = TEXT_CEIL(width); |
| 846 | if (args->useShadow) width += 2; |
| 847 | return width; |
| 848 | } |
| 849 | |
| 850 | static void DrawGrayscaleGlyph(FT_Bitmap* img, struct Bitmap* bmp, int x, int y, BitmapCol col) { |
| 851 | cc_uint8* src; |
no test coverage detected