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