| 30 | } |
| 31 | |
| 32 | void SpriteFont::Initialize(const wchar* fontName, float fontSize, uint32 fontStyle, bool antiAliased) |
| 33 | { |
| 34 | texture.Shutdown(); |
| 35 | |
| 36 | size = fontSize; |
| 37 | |
| 38 | TextRenderingHint hint = antiAliased ? TextRenderingHintAntiAliasGridFit : TextRenderingHintSingleBitPerPixelGridFit; |
| 39 | |
| 40 | // Init GDI+ |
| 41 | ULONG_PTR token = 0; |
| 42 | GdiplusStartupInput startupInput(nullptr, true, true); |
| 43 | GdiplusStartupOutput startupOutput; |
| 44 | GdiPlusCall(GdiplusStartup(&token, &startupInput, &startupOutput)); |
| 45 | |
| 46 | try |
| 47 | { |
| 48 | // Create the font |
| 49 | Gdiplus::Font font(fontName, fontSize, fontStyle, UnitPixel, nullptr); |
| 50 | |
| 51 | // Check for error during construction |
| 52 | GdiPlusCall(font.GetLastStatus()); |
| 53 | |
| 54 | // Create a temporary Bitmap and Graphics for figuring out the rough size required |
| 55 | // for drawing all of the characters |
| 56 | int32 bmSize = static_cast<int32>(fontSize * NumChars * 2) + 1; |
| 57 | Bitmap sizeBitmap(bmSize, bmSize, PixelFormat32bppARGB); |
| 58 | GdiPlusCall(sizeBitmap.GetLastStatus()); |
| 59 | |
| 60 | Graphics sizeGraphics(&sizeBitmap); |
| 61 | GdiPlusCall(sizeGraphics.GetLastStatus()); |
| 62 | GdiPlusCall(sizeGraphics.SetTextRenderingHint(hint)); |
| 63 | |
| 64 | charHeight = font.GetHeight(&sizeGraphics) * 1.5f; |
| 65 | |
| 66 | wchar allChars[NumChars + 1]; |
| 67 | for(wchar i = 0; i < NumChars; ++i) |
| 68 | allChars[i] = i + StartChar; |
| 69 | allChars[NumChars] = 0; |
| 70 | |
| 71 | RectF sizeRect; |
| 72 | GdiPlusCall(sizeGraphics.MeasureString(allChars, NumChars, &font, PointF(0, 0), &sizeRect)); |
| 73 | int32 numRows = static_cast<int32>(sizeRect.Width / TexWidth) + 1; |
| 74 | texHeight = static_cast<int32>(numRows * charHeight) + 1; |
| 75 | |
| 76 | // Create a temporary Bitmap and Graphics for drawing the characters one by one |
| 77 | int32 tempSize = static_cast<int32>(fontSize * 2); |
| 78 | Bitmap drawBitmap(tempSize, tempSize, PixelFormat32bppARGB); |
| 79 | GdiPlusCall(drawBitmap.GetLastStatus()); |
| 80 | |
| 81 | Graphics drawGraphics(&drawBitmap); |
| 82 | GdiPlusCall(drawGraphics.GetLastStatus()); |
| 83 | GdiPlusCall(drawGraphics.SetTextRenderingHint(hint)); |
| 84 | |
| 85 | // Create a temporary Bitmap + Graphics for creating a full character set |
| 86 | Bitmap textBitmap (TexWidth, texHeight, PixelFormat32bppARGB); |
| 87 | GdiPlusCall(textBitmap.GetLastStatus()); |
| 88 | |
| 89 | Graphics textGraphics (&textBitmap); |
nothing calls this directly
no test coverage detected