OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 188 of file C4FontLoader.cpp.

Constructor & Destructor Documentation

CStdVectorFont::CStdVectorFont ( const char *  FontFaceName)
inline

Definition at line 194 of file C4FontLoader.cpp.

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

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

Here is the call graph for this function:

CStdVectorFont::CStdVectorFont ( StdBuf Data)
inline

Definition at line 245 of file C4FontLoader.cpp.

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

245  : Data(Data), RefCnt(1)
246  {
247  // Initialize Freetype
248  if (FT_Init_FreeType(&library))
249  throw std::runtime_error("Cannot init Freetype");
250  // Load the font
251  FT_Error e;
252  if ((e=FT_New_Memory_Face(library, static_cast<const FT_Byte *>(Data.getData()), Data.getSize(), 0, &face)))
253  throw std::runtime_error(std::string("Cannot load font: ") + FormatString("%d",e).getData());
254  }
const char * getData() const
Definition: StdBuf.h:450
const void * getData() const
Definition: StdBuf.h:107
size_t getSize() const
Definition: StdBuf.h:109
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

CStdVectorFont::~CStdVectorFont ( )
inline

Definition at line 255 of file C4FontLoader.cpp.

256  {
257  FT_Done_Face(face);
258  FT_Done_FreeType(library);
259  }

Member Function Documentation

CStdVectorFont::operator FT_Face ( )
inline

Definition at line 260 of file C4FontLoader.cpp.

260 { return face; }
FT_Face CStdVectorFont::operator-> ( )
inline

Definition at line 261 of file C4FontLoader.cpp.

261 { return face; }

Member Data Documentation

int CStdVectorFont::RefCnt

Definition at line 262 of file C4FontLoader.cpp.

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


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