Rise
The Vieneo Province
Font.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 //#include <d3dx10.h>
5 
6 class Font
7 {
9  std::string pathAndFilename;
10 
11 public:
12  //ID3DX10Font* pFont = nullptr;
13  ID3DXFont* pFont = nullptr;
14 
15  //Font(Logger* pLogger, ID3D10Device* pDevice, float width, float height, std::string name, std::string prmPathAndFilename)
16  Font(Logger* pLogger, IDirect3DDevice9* pDevice, int width, int height, std::string name, std::string prmPathAndFilename)
17  {
18  logger = pLogger;
19 
20  logger->AddToCallStack("Font::ctor");
21  pathAndFilename = prmPathAndFilename;
22 
23  char err[256];
24  sprintf_s(err, 256, "Font::ctor AddFontResourceExA: %s", pathAndFilename.c_str());
25  logger->Log(err);
26 
27  const int fontsAdded = AddFontResourceExA(pathAndFilename.c_str(), FR_PRIVATE, nullptr);
28  if (fontsAdded == 0)
29  {
30  sprintf_s(err, 256, "Font::ctor AddFontResourceExA: %s", pathAndFilename.c_str());
31  logger->Log(err, Logger::Warn);
32  }
33 
34  HRESULT hr;
35  if (FAILED(hr = D3DXCreateFontA(pDevice, height, width, FW_MEDIUM, 1, false, DEFAULT_CHARSET,
36  OUT_TT_ONLY_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
37  name.c_str(), &pFont)))
38  {
39  sprintf_s(err, 256, "Font::ctor D3DXCreateFontA failed: %s", name.c_str());
40  logger->Log(err, Logger::Error, hr);
41  }
42  }
43 
45  {
46  logger->AddToCallStack("Font::OnDestroyDevice");
47  // @todo this one gets called correctly before the references are counted but should not be handled in DTOR
48  SAFE_RELEASE(pFont);
49  logger->AddToCallStack("Font::OnDestroyDevice RemoveFontResourceExA");
50  RemoveFontResourceExA(pathAndFilename.c_str(), FR_PRIVATE, nullptr);
51  logger->AddToCallStack("Font::OnDestroyDevice DONE");
52  }
53 };
Logger * logger
Definition: Font.h:8
Definition: Font.h:6
Definition: Logger.h:9
void OnDestroyDevice()
Definition: Font.h:44
Font(Logger *pLogger, IDirect3DDevice9 *pDevice, int width, int height, std::string name, std::string prmPathAndFilename)
Definition: Font.h:16
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition: Logger.cpp:11
ID3DXFont * pFont
Definition: Font.h:13
std::string pathAndFilename
Definition: Font.h:9
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86