OpenClonk
CStdVectorFont Class Reference

Public Member Functions

 CStdVectorFont (const char *FontFaceName)
 
 CStdVectorFont (StdBuf &Data)
 
 ~CStdVectorFont ()
 
 operator FT_Face ()
 
FT_Face operator-> ()
 

Public Attributes

int RefCnt
 

Detailed Description

Definition at line 182 of file C4FontLoader.cpp.

Constructor & Destructor Documentation

◆ CStdVectorFont() [1/2]

CStdVectorFont::CStdVectorFont ( const char *  FontFaceName)
inline

Definition at line 188 of file C4FontLoader.cpp.

188  : RefCnt(1)
189  {
190 #if defined(_WIN32)
191  // Win32 using freetype: Load TrueType-data from WinGDI into Data-buffer to be used by FreeType
192  bool fSuccess = false;
193  HDC hDC = ::CreateCompatibleDC(nullptr);
194  if (hDC)
195  {
196  HFONT hFont = ::CreateFontA(0, 0, 0, 0, FW_DONTCARE, false,
197  false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
198  CLIP_DEFAULT_PRECIS, 5,
199  VARIABLE_PITCH, FontFaceName);
200  if (hFont)
201  {
202  SelectObject( hDC, hFont );
203  uint32_t dwTTFSize = ::GetFontData(hDC, 0, 0, nullptr, 0);
204  if (dwTTFSize && dwTTFSize != GDI_ERROR)
205  {
206  Data.SetSize(dwTTFSize);
207  uint32_t dwRealTTFSize = ::GetFontData(hDC, 0, 0, Data.getMData(), dwTTFSize);
208  if (dwRealTTFSize == dwTTFSize)
209  {
210  fSuccess = true;
211  }
212  else
213  Data.Clear();
214  }
215  DeleteObject(hFont);
216  }
217  DeleteDC(hDC);
218  }
219  if (!fSuccess)
220  throw std::runtime_error("Some Win32 error");
221  // Initialize Freetype
222  if (FT_Init_FreeType(&library))
223  throw std::runtime_error("Cannot init Freetype");
224  // Load the font
225  FT_Error e;
226  if ((e=FT_New_Memory_Face(library, static_cast<const FT_Byte *>(Data.getData()), Data.getSize(), 0, &face)))
227  throw std::runtime_error(std::string("Cannot load font: ") + FormatString("%d",e).getData());
228 #else
229  //FIXME: get path name from OS
230  // Initialize Freetype
231  if (FT_Init_FreeType(&library))
232  throw std::runtime_error("Cannot init Freetype");
233  // Load the font
234  FT_Error e;
235  if ((e=FT_New_Face(library, FontFaceName, 0, &face)))
236  throw std::runtime_error(std::string("Cannot load ") + FontFaceName + ": " + FormatString("%d",e).getData());
237 #endif
238  }
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
size_t getSize() const
Definition: StdBuf.h:101
void * getMData()
Definition: StdBuf.h:100
void SetSize(size_t inSize)
Definition: StdBuf.h:204
const void * getData() const
Definition: StdBuf.h:99
void Clear()
Definition: StdBuf.h:190

References StdBuf::Clear(), FormatString(), StdBuf::getData(), StdBuf::getMData(), StdBuf::getSize(), and StdBuf::SetSize().

Here is the call graph for this function:

◆ CStdVectorFont() [2/2]

CStdVectorFont::CStdVectorFont ( StdBuf Data)
inline

Definition at line 239 of file C4FontLoader.cpp.

239  : Data(Data), RefCnt(1)
240  {
241  // Initialize Freetype
242  if (FT_Init_FreeType(&library))
243  throw std::runtime_error("Cannot init Freetype");
244  // Load the font
245  FT_Error e;
246  if ((e=FT_New_Memory_Face(library, static_cast<const FT_Byte *>(Data.getData()), Data.getSize(), 0, &face)))
247  throw std::runtime_error(std::string("Cannot load font: ") + FormatString("%d",e).getData());
248  }

References FormatString(), StdBuf::getData(), and StdBuf::getSize().

Here is the call graph for this function:

◆ ~CStdVectorFont()

CStdVectorFont::~CStdVectorFont ( )
inline

Definition at line 249 of file C4FontLoader.cpp.

250  {
251  FT_Done_Face(face);
252  FT_Done_FreeType(library);
253  }

Member Function Documentation

◆ operator FT_Face()

CStdVectorFont::operator FT_Face ( )
inline

Definition at line 254 of file C4FontLoader.cpp.

254 { return face; }

◆ operator->()

FT_Face CStdVectorFont::operator-> ( )
inline

Definition at line 255 of file C4FontLoader.cpp.

255 { return face; }

Member Data Documentation

◆ RefCnt

int CStdVectorFont::RefCnt

Definition at line 256 of file C4FontLoader.cpp.

Referenced by C4FontLoader::DestroyFont(), and CStdFont::Init().


The documentation for this class was generated from the following file: