| 902 | |
| 903 | static FT_Vector shadow_delta = { 83, -83 }; |
| 904 | void SysFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) { |
| 905 | struct SysFont* font = (struct SysFont*)args->font->handle; |
| 906 | FT_BitmapGlyph* glyphs = font->glyphs; |
| 907 | |
| 908 | FT_Face face = font->face; |
| 909 | cc_string text = args->text; |
| 910 | int descender, height, begX = x; |
| 911 | BitmapCol color; |
| 912 | |
| 913 | /* glyph state */ |
| 914 | FT_BitmapGlyph glyph; |
| 915 | FT_Bitmap* img; |
| 916 | int i, offset; |
| 917 | FT_Error res; |
| 918 | cc_unichar uc; |
| 919 | |
| 920 | if (shadow) { |
| 921 | glyphs = font->shadow_glyphs; |
| 922 | FT_Set_Transform(face, NULL, &shadow_delta); |
| 923 | } |
| 924 | |
| 925 | height = args->font->height; |
| 926 | descender = TEXT_CEIL(face->size->metrics.descender); |
| 927 | |
| 928 | color = Drawer2D.Colors['f']; |
| 929 | if (shadow) color = GetShadowColor(color); |
| 930 | |
| 931 | for (i = 0; i < text.length; i++) { |
| 932 | char c = text.buffer[i]; |
| 933 | if (c == '&' && Drawer2D_ValidColorCodeAt(&text, i + 1)) { |
| 934 | color = Drawer2D_GetColor(text.buffer[i + 1]); |
| 935 | |
| 936 | if (shadow) color = GetShadowColor(color); |
| 937 | i++; continue; /* skip over the color code */ |
| 938 | } |
| 939 | |
| 940 | glyph = glyphs[(cc_uint8)c]; |
| 941 | if (!glyph) { |
| 942 | uc = Convert_CP437ToUnicode(c); |
| 943 | res = FT_Load_Char(face, uc, FT_LOAD_RENDER); |
| 944 | |
| 945 | if (res) { |
| 946 | Platform_Log2("Error %e drawing %r", &res, &text.buffer[i]); |
| 947 | continue; |
| 948 | } |
| 949 | |
| 950 | /* due to FT_LOAD_RENDER, glyph is always a bitmap one */ |
| 951 | FT_Get_Glyph(face->glyph, (FT_Glyph*)&glyph); /* TODO: Check error */ |
| 952 | glyphs[(cc_uint8)c] = glyph; |
| 953 | } |
| 954 | |
| 955 | offset = (height + descender) - glyph->top; |
| 956 | x += glyph->left; y += offset; |
| 957 | |
| 958 | img = &glyph->bitmap; |
| 959 | if (img->num_grays == 2) { |
| 960 | DrawBlackWhiteGlyph(img, bmp, x, y, color); |
| 961 | } else { |
no test coverage detected