OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
CStdFont Class Reference

#include <C4FontLoader.h>

Collaboration diagram for CStdFont:
[legend]

Public Types

typedef CStdFontCustomImages CustomImages
 

Public Member Functions

void DrawText (C4Surface *sfcDest, float iX, float iY, DWORD dwColor, const char *szText, DWORD dwFlags, C4Markup &Markup, float fZoom)
 
bool GetTextExtent (const char *szText, int32_t &rsx, int32_t &rsy, bool fCheckMarkup=true)
 
int GetLineHeight () const
 
int GetFontHeight () const
 
int32_t GetTextWidth (const char *szText, bool fCheckMarkup=true)
 
std::tuple< std::string, int > BreakMessage (const char *szMsg, int iWdt, bool fCheckMarkup, float fZoom=1.0f)
 
int BreakMessage (const char *szMsg, int iWdt, char *szOut, int iMaxOutLen, bool fCheckMarkup, float fZoom=1.0f)
 
int BreakMessage (const char *szMsg, int iWdt, StdStrBuf *pOut, bool fCheckMarkup, float fZoom=1.0f)
 
int GetMessageBreak (const char *szMsg, const char **ppNewPos, int iBreakWidth, float fZoom=1.0f)
 
 CStdFont ()
 
 ~CStdFont ()
 
void Init (CStdVectorFont &VectorFont, const char *font_face_name, DWORD dwHeight, DWORD dwFontWeight=FW_NORMAL, bool fDoShadow=true)
 
void Clear ()
 
bool IsInitialized () const
 
bool IsSameAsID (const char *szCFontName, int iCID, int iCIndent) const
 
bool IsSameAs (const char *szCFontName, DWORD iCHeight, DWORD dwCWeight) const
 
void SetCustomImages (CustomImages *pHandler)
 
bool GetFontImageSize (const char *szTag, int &width, int &height) const
 

Public Attributes

int id
 

Protected Member Functions

bool AddSurface ()
 
bool CheckRenderedCharSpace (uint32_t iCharWdt, uint32_t iCharHgt)
 
bool AddRenderedChar (uint32_t dwChar, C4Facet *pfctTarget)
 
C4FacetGetCharacterFacet (uint32_t c)
 
C4FacetGetUnicodeCharacterFacet (uint32_t c)
 

Protected Attributes

DWORD dwDefFontHeight
 
char szFontName [80+1]
 
std::vector< std::unique_ptr
< C4Surface > > 
psfcFontData
 
int iSfcSizes
 
int iFontZoom
 
C4SurfacesfcCurrent
 
int32_t iCurrentSfcX
 
int32_t iCurrentSfcY
 
int iHSpace
 
int iGfxLineHgt
 
DWORD dwWeight
 
bool fDoShadow
 
C4Facet fctAsciiTexCoords [256-' ']
 
std::map< uint32_t, C4FacetfctUnicodeMap
 
CustomImagespCustomImages
 
CStdVectorFontpVectorFont
 
int iLineHgt
 

Detailed Description

Definition at line 82 of file C4FontLoader.h.

Member Typedef Documentation

Definition at line 85 of file C4FontLoader.h.

Constructor & Destructor Documentation

CStdFont::CStdFont ( )

Definition at line 284 of file C4FontLoader.cpp.

References dwDefFontHeight, dwWeight, fDoShadow, FW_NORMAL, iFontZoom, iGfxLineHgt, iHSpace, iLineHgt, iSfcSizes, pCustomImages, pVectorFont, sfcCurrent, and szFontName.

285 {
286 #ifndef USE_CONSOLE
287  // set default values
288  sfcCurrent = nullptr;
289  iSfcSizes = 64;
291  iFontZoom=1; // default: no internal font zooming - likely no antialiasing either...
292  iHSpace=-1;
295  fDoShadow=false;
296  // font not yet initialized
297  *szFontName=0;
298  id=0;
299  pCustomImages=nullptr;
300  pVectorFont = nullptr;
301 #endif
302 }
DWORD dwWeight
Definition: C4FontLoader.h:102
int iFontZoom
Definition: C4FontLoader.h:95
int iLineHgt
Definition: C4FontLoader.h:122
bool fDoShadow
Definition: C4FontLoader.h:103
int iGfxLineHgt
Definition: C4FontLoader.h:101
C4Surface * sfcCurrent
Definition: C4FontLoader.h:97
DWORD dwDefFontHeight
Definition: C4FontLoader.h:90
char szFontName[80+1]
Definition: C4FontLoader.h:91
CStdVectorFont * pVectorFont
Definition: C4FontLoader.h:110
#define FW_NORMAL
Definition: C4FontLoader.h:39
CustomImages * pCustomImages
Definition: C4FontLoader.h:108
int iSfcSizes
Definition: C4FontLoader.h:94
CStdFont::~CStdFont ( )
inline

Definition at line 157 of file C4FontLoader.h.

References Clear().

157 { Clear(); }
void Clear()

Here is the call graph for this function:

Member Function Documentation

bool CStdFont::AddRenderedChar ( uint32_t  dwChar,
C4Facet pfctTarget 
)
protected

Definition at line 338 of file C4FontLoader.cpp.

References BltAlpha(), CheckRenderedCharSpace(), dwDefFontHeight, dwWeight, fDoShadow, iCurrentSfcX, iCurrentSfcY, iGfxLineHgt, C4Surface::Lock(), pVectorFont, RGBA(), C4Facet::Set(), C4Surface::SetPixDw(), sfcCurrent, C4Surface::Unlock(), and C4Facet::Wdt.

Referenced by GetUnicodeCharacterFacet(), and Init().

339 {
340  if (!pVectorFont) return false;
341  // Freetype character rendering
342  FT_Set_Pixel_Sizes(*pVectorFont, dwDefFontHeight, dwDefFontHeight);
343  int32_t iBoldness = dwWeight-400; // zero is normal; 300 is bold
344  if (iBoldness)
345  {
346  iBoldness = (1<<16) + (iBoldness<<16)/400;
347  FT_Matrix mat;
348  mat.xx = iBoldness; mat.xy = mat.yx = 0; mat.yy = 1<<16;
349  FT_Set_Transform(*pVectorFont, &mat, nullptr);
350  }
351  else
352  {
353  FT_Set_Transform(*pVectorFont, nullptr, nullptr);
354  }
355  // Render
356  if (FT_Load_Char(*pVectorFont, dwChar, FT_LOAD_RENDER | FT_LOAD_NO_HINTING))
357  {
358  // although the character was not drawn, assume it's not in the font and won't be needed
359  // so return success here
360  return true;
361  }
362  // Make a shortcut to the glyph
363  FT_GlyphSlot slot = (*pVectorFont)->glyph;
364  if (slot->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY)
365  {
366  // although the character was drawn in a strange way, assume it's not in the font and won't be needed
367  // so return success here
368  return true;
369  }
370  // linebreak/ new surface check
371  int width = std::max<int>(slot->advance.x / 64, std::max(slot->bitmap_left,0) + slot->bitmap.width) + fDoShadow;
372  if (!CheckRenderedCharSpace(width, iGfxLineHgt)) return false;
373  // offset from the top
374  int at_y = iCurrentSfcY + dwDefFontHeight * (*pVectorFont)->ascender / (*pVectorFont)->units_per_EM - slot->bitmap_top;
375  int at_x = iCurrentSfcX + std::max(slot->bitmap_left,0);
376  // Copy to the surface
377  if (!sfcCurrent->Lock()) return false;
378  for (unsigned int y = 0; y < slot->bitmap.rows + fDoShadow; ++y)
379  {
380  for (unsigned int x = 0; x < slot->bitmap.width + fDoShadow; ++x)
381  {
382  unsigned char bAlpha, bAlphaShadow;
383  if (x < slot->bitmap.width && y < slot->bitmap.rows)
384  bAlpha = (unsigned char)(slot->bitmap.buffer[slot->bitmap.width * y + x]);
385  else
386  bAlpha = 0;
387  // Make a shadow from the upper-left pixel, and blur with the eight neighbors
388  DWORD dwPixVal = 0u;
389  bAlphaShadow = 0;
390  if ((x || y) && fDoShadow)
391  {
392  int iShadow = 0;
393  if (x < slot->bitmap.width && y < slot->bitmap.rows) iShadow += slot->bitmap.buffer[(x - 0) + slot->bitmap.width * (y - 0)];
394  if (x > 1 && y < slot->bitmap.rows) iShadow += slot->bitmap.buffer[(x - 2) + slot->bitmap.width * (y - 0)];
395  if (x > 0 && y < slot->bitmap.rows) iShadow += slot->bitmap.buffer[(x - 1) + slot->bitmap.width * (y - 0)];
396  if (x < slot->bitmap.width && y > 1 ) iShadow += slot->bitmap.buffer[(x - 0) + slot->bitmap.width * (y - 2)];
397  if (x > 1 && y > 1 ) iShadow += slot->bitmap.buffer[(x - 2) + slot->bitmap.width * (y - 2)];
398  if (x > 0 && y > 1 ) iShadow += slot->bitmap.buffer[(x - 1) + slot->bitmap.width * (y - 2)];
399  if (x < slot->bitmap.width && y > 0 ) iShadow += slot->bitmap.buffer[(x - 0) + slot->bitmap.width * (y - 1)];
400  if (x > 1 && y > 0 ) iShadow += slot->bitmap.buffer[(x - 2) + slot->bitmap.width * (y - 1)];
401  if (x > 0 && y > 0 ) iShadow += slot->bitmap.buffer[(x - 1) + slot->bitmap.width * (y - 1)]*8;
402  bAlphaShadow += iShadow / 16;
403  // because blitting on a black pixel reduces luminosity as compared to shadowless font,
404  // assume luminosity as if blitting shadowless font on a 50% gray background
405  unsigned char cBack = bAlpha;
406  dwPixVal = RGBA(cBack/2, cBack/2, cBack/2, bAlphaShadow);
407  }
408  BltAlpha(dwPixVal, bAlpha << 24 | 0xffffff);
409  sfcCurrent->SetPixDw(at_x + x, at_y + y, dwPixVal);
410  }
411  }
412  sfcCurrent->Unlock();
413  // Save the position of the glyph for the rendering code
414  pfctTarget->Set(sfcCurrent, iCurrentSfcX, iCurrentSfcY, width, iGfxLineHgt);
415 
416  // advance texture position
417  iCurrentSfcX += pfctTarget->Wdt;
418  return true;
419 }
bool CheckRenderedCharSpace(uint32_t iCharWdt, uint32_t iCharHgt)
bool Lock()
Definition: C4Surface.cpp:463
DWORD dwWeight
Definition: C4FontLoader.h:102
bool Unlock()
Definition: C4Surface.cpp:474
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
int32_t iCurrentSfcX
Definition: C4FontLoader.h:98
int32_t iCurrentSfcY
Definition: C4FontLoader.h:98
bool fDoShadow
Definition: C4FontLoader.h:103
bool SetPixDw(int iX, int iY, DWORD dwCol)
Definition: C4Surface.cpp:586
int iGfxLineHgt
Definition: C4FontLoader.h:101
C4Surface * sfcCurrent
Definition: C4FontLoader.h:97
void BltAlpha(DWORD &dwDst, DWORD dwSrc)
Definition: StdColors.h:33
DWORD dwDefFontHeight
Definition: C4FontLoader.h:90
CStdVectorFont * pVectorFont
Definition: C4FontLoader.h:110
uint32_t RGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
Definition: StdColors.h:24
uint32_t DWORD
float Wdt
Definition: C4Facet.h:120

Here is the call graph for this function:

Here is the caller graph for this function:

bool CStdFont::AddSurface ( )
protected

Definition at line 305 of file C4FontLoader.cpp.

References iCurrentSfcX, iCurrentSfcY, iSfcSizes, C4Surface::IsLocked(), psfcFontData, sfcCurrent, and C4Surface::Unlock().

Referenced by CheckRenderedCharSpace(), and Init().

306 {
307  // add new surface as render target
308  auto sfcNew = std::make_unique<C4Surface>(iSfcSizes, iSfcSizes, 0);
309  // If old surface was locked, unlock it and lock the new one in its stead
310  if (sfcCurrent && sfcCurrent->IsLocked())
311  {
312  sfcCurrent->Unlock();
313  sfcNew->Lock();
314  }
315  sfcCurrent = sfcNew.get();
316  psfcFontData.push_back(std::move(sfcNew));
318  return true;
319 }
bool Unlock()
Definition: C4Surface.cpp:474
int32_t iCurrentSfcX
Definition: C4FontLoader.h:98
int32_t iCurrentSfcY
Definition: C4FontLoader.h:98
std::vector< std::unique_ptr< C4Surface > > psfcFontData
Definition: C4FontLoader.h:93
int IsLocked() const
Definition: C4Surface.h:95
C4Surface * sfcCurrent
Definition: C4FontLoader.h:97
int iSfcSizes
Definition: C4FontLoader.h:94

Here is the call graph for this function:

Here is the caller graph for this function:

std::tuple< std::string, int > CStdFont::BreakMessage ( const char *  szMsg,
int  iWdt,
bool  fCheckMarkup,
float  fZoom = 1.0f 
)

Definition at line 605 of file C4FontLoader.cpp.

References GetCharacterFacet(), GetFontImageSize(), GetNextCharacter(), iFontZoom, iHSpace, iLineHgt, SCharPos(), SCopy(), and C4Markup::SkipTags().

Referenced by BreakMessage(), C4LeagueSignupDialog::C4LeagueSignupDialog(), C4GameMessage::Draw(), C4ScriptGuiWindow::Draw(), C4MenuItem::DrawElement(), C4GUI::Screen::DrawToolTip(), C4Menu::InitLocation(), C4GUI::InputDialog::InputDialog(), C4GUI::MessageDialog::MessageDialog(), C4GUI::ProgressDialog::ProgressDialog(), C4Menu::UpdateElementPositions(), and C4ScriptGuiWindow::UpdateLayout().

606 {
607 #ifdef USE_CONSOLE
608  return std::make_tuple("", 0);
609 #else
610  if (!szMsg) return std::make_tuple("", 0);
611  std::string out;
612  // TODO: might szLastEmergenyBreakPos, iLastBreakOutLen or iXEmergencyBreak not be properly initialised before use?
613  uint32_t c;
614  const char *szPos=szMsg, // current parse position in the text
615  *szLastBreakPos = szMsg, // points to the char after at (whitespace) or after ('-') which text can be broken
616  *szLastEmergenyBreakPos = nullptr, // same, but at last char in case no suitable linebreak could be found
617  *szLastPos; // last position until which buffer has been transferred to output
618  int iLastBreakOutLen = 0, iLastEmergencyBreakOutLen = 0; // size of output string at break positions
619  int iX=0, // current text width at parse pos
620  iXBreak=0, // text width as it was at last break pos
621  iXEmergencyBreak = 0, // same, but at last char in case no suitable linebreak could be found
622  iHgt=iLineHgt; // total height of output text
623  int iCharHOverlap = std::max<int>(-iHSpace, 0); // character width exceeding placement of next character
624  bool fIsFirstLineChar = true;
625  // ignore any markup
626  C4Markup MarkupChecker(false);
627  // go through all text
628  while (*(szLastPos = szPos))
629  {
630  // ignore markup
631  if (fCheckMarkup) MarkupChecker.SkipTags(&szPos);
632  // get current char
633  c = GetNextCharacter(&szPos);
634  // done? (must check here, because markup-skip may have led to text end)
635  if (!c) break;
636  // manual break?
637  int iCharWdt = 0;
638  if (c != '\n' && (!fCheckMarkup || c != '|'))
639  {
640  // image?
641  int iImgLgt;
642  if (fCheckMarkup && c=='{' && szPos[0]=='{' && szPos[1]!='{' && (iImgLgt=SCharPos('}', szPos+1))>0 && szPos[iImgLgt+2]=='}')
643  {
644  char imgbuf[101];
645  SCopy(szPos+1, imgbuf, std::min(iImgLgt, 100));
646 
647  int iCharHgt;
648  if(!GetFontImageSize(imgbuf, iCharWdt, iCharHgt))
649  iCharWdt = 0;
650 
651  // skip image tag
652  szPos+=iImgLgt+3;
653  }
654  else
655  {
656  // regular char
657  // look up character width in texture coordinates table
658  if (c >= ' ')
659  iCharWdt = int(fZoom * GetCharacterFacet(c).Wdt / iFontZoom) + iHSpace;
660  else
661  iCharWdt = 0; // OMFG ctrl char
662  }
663  // add chars to output
664  out.append(szLastPos, szPos - szLastPos);
665  // add to line; always add one char at minimum
666  if ((iX+=iCharWdt)+iCharHOverlap <= iWdt || fIsFirstLineChar)
667  {
668  // check whether linebreak possibility shall be marked here
669  // 2do: What about unicode-spaces?
670  if (c<256) if (isspace((unsigned char)c) || c == '-')
671  {
672  szLastBreakPos = szPos;
673  iLastBreakOutLen = out.size();
674  // space: Break directly at space if it isn't the first char here
675  // first char spaces must remain, in case the output area is just one char width
676  if (c != '-' && !fIsFirstLineChar) --szLastBreakPos; // because c<256, the character length can be safely assumed to be 1 here
677  iXBreak = iX;
678  }
679  // always mark emergency break after char that fitted the line
680  szLastEmergenyBreakPos = szPos;
681  iXEmergencyBreak = iX;
682  iLastEmergencyBreakOutLen = out.size();
683  // line OK; continue filling it
684  fIsFirstLineChar = false;
685  continue;
686  }
687  // line must be broken now
688  // check if a linebreak is possible directly here, because it's a space
689  // only check for space and not for other breakable characters (such as '-'), because the break would happen after those characters instead of at them
690  if (c<128 && isspace((unsigned char)c))
691  {
692  szLastBreakPos = szPos-1;
693  iLastBreakOutLen = out.size();
694  iXBreak = iX;
695  }
696  // if there was no linebreak, do it at emergency pos
697  else if (szLastBreakPos == szMsg)
698  {
699  szLastBreakPos = szLastEmergenyBreakPos;
700  iLastBreakOutLen = iLastEmergencyBreakOutLen;
701  iXBreak = iXEmergencyBreak;
702  }
703  // insert linebreak at linebreak pos
704  // was it a space? Then just overwrite space with a linebreak
705  if (uint8_t(*szLastBreakPos)<128 && isspace((unsigned char)*szLastBreakPos))
706  out.at(iLastBreakOutLen-1) = '\n';
707  else
708  {
709  // otherwise, insert line break
710  out.insert(iLastBreakOutLen, 1, '\n');
711  }
712  // calc next line usage
713  iX -= iXBreak;
714  }
715  else
716  {
717  // a static linebreak: Everything's well; this just resets the line width
718  iX = 0;
719  // add to output
720  out.append(szLastPos, szPos - szLastPos);
721  }
722  // forced or manual line break: set new line beginning to char after line break
723  szLastBreakPos = szMsg = szPos;
724  // manual line break or line width overflow: add char to next line
725  iHgt += iLineHgt;
726  fIsFirstLineChar = true;
727  }
728  // transfer final data to buffer (any missing markup)
729  out.append(szLastPos, szPos - szLastPos);
730  // return text height
731  return std::make_tuple(out, iHgt);
732 #endif
733 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
uint32_t GetNextCharacter(const char **pszString)
Definition: Standard.h:88
int iFontZoom
Definition: C4FontLoader.h:95
int iLineHgt
Definition: C4FontLoader.h:122
bool GetFontImageSize(const char *szTag, int &width, int &height) const
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:210
C4Facet & GetCharacterFacet(uint32_t c)
Definition: C4FontLoader.h:116

Here is the call graph for this function:

Here is the caller graph for this function:

int CStdFont::BreakMessage ( const char *  szMsg,
int  iWdt,
char *  szOut,
int  iMaxOutLen,
bool  fCheckMarkup,
float  fZoom = 1.0f 
)

Definition at line 569 of file C4FontLoader.cpp.

References BreakMessage().

570 {
571 #ifdef USE_CONSOLE
572  return 0;
573 #else
574  // note iMaxOutLen does not include terminating null character
575  // safety
576  if (!iMaxOutLen) return 0;
577  if (!szMsg)
578  {
579  if (szOut) *szOut=0;
580  return 0;
581  }
582  auto t = BreakMessage(szMsg, iWdt, fCheckMarkup, fZoom);
583  auto str = std::get<0>(t);
584  auto len = str.copy(szOut, iMaxOutLen);
585  szOut[len] = '\0';
586  return std::get<1>(t);
587 #endif
588 }
std::tuple< std::string, int > BreakMessage(const char *szMsg, int iWdt, bool fCheckMarkup, float fZoom=1.0f)

Here is the call graph for this function:

int CStdFont::BreakMessage ( const char *  szMsg,
int  iWdt,
StdStrBuf pOut,
bool  fCheckMarkup,
float  fZoom = 1.0f 
)

Definition at line 590 of file C4FontLoader.cpp.

References StdStrBuf::Append(), BreakMessage(), and StdStrBuf::Clear().

591 {
592 #ifdef USE_CONSOLE
593  return 0;
594 #else
595  if (!szMsg || !pOut) return 0;
596  auto t = BreakMessage(szMsg, iWdt, fCheckMarkup, fZoom);
597  auto str = std::get<0>(t);
598  pOut->Clear();
599  pOut->Append(str.c_str(), str.size());
600  return std::get<1>(t);
601 #endif
602 }
void Clear()
Definition: StdBuf.h:474
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:527
std::tuple< std::string, int > BreakMessage(const char *szMsg, int iWdt, bool fCheckMarkup, float fZoom=1.0f)

Here is the call graph for this function:

bool CStdFont::CheckRenderedCharSpace ( uint32_t  iCharWdt,
uint32_t  iCharHgt 
)
protected

Definition at line 321 of file C4FontLoader.cpp.

References AddSurface(), iCurrentSfcX, iCurrentSfcY, and iSfcSizes.

Referenced by AddRenderedChar().

322 {
323  // need to do a line break?
324  if (iCurrentSfcX + iCharWdt >= (uint32_t)iSfcSizes) if (iCurrentSfcX)
325  {
326  iCurrentSfcX = 0;
327  iCurrentSfcY += iCharHgt;
328  if (iCurrentSfcY + iCharHgt >= (uint32_t)iSfcSizes)
329  {
330  // surface is full: Next one
331  if (!AddSurface()) return false;
332  }
333  }
334  // OK draw it there
335  return true;
336 }
bool AddSurface()
int32_t iCurrentSfcX
Definition: C4FontLoader.h:98
int32_t iCurrentSfcY
Definition: C4FontLoader.h:98
int iSfcSizes
Definition: C4FontLoader.h:94

Here is the call graph for this function:

Here is the caller graph for this function:

void CStdFont::Clear ( )

Definition at line 486 of file C4FontLoader.cpp.

References C4FontLoader::DestroyFont(), dwDefFontHeight, dwWeight, fctAsciiTexCoords, fctUnicodeMap, fDoShadow, FW_NORMAL, iFontZoom, iGfxLineHgt, iHSpace, iLineHgt, psfcFontData, pVectorFont, sfcCurrent, and szFontName.

Referenced by C4GraphicsResource::ClearFonts(), Init(), C4FontLoader::InitFont(), and ~CStdFont().

487 {
488 #ifndef USE_CONSOLE
490  pVectorFont = nullptr;
491 
492  // clear font sfcs
493  sfcCurrent = nullptr;
494  psfcFontData.clear();
495  for (int c=' '; c<256; ++c) fctAsciiTexCoords[c-' '].Default();
496  fctUnicodeMap.clear();
497  // set default values
499  iFontZoom=1; // default: no internal font zooming - likely no antialiasing either...
500  iHSpace=-1;
503  fDoShadow=false;
504  // font not yet initialized
505  *szFontName=0;
506  id=0;
507 #endif
508 }
std::map< uint32_t, C4Facet > fctUnicodeMap
Definition: C4FontLoader.h:106
DWORD dwWeight
Definition: C4FontLoader.h:102
int iFontZoom
Definition: C4FontLoader.h:95
int iLineHgt
Definition: C4FontLoader.h:122
std::vector< std::unique_ptr< C4Surface > > psfcFontData
Definition: C4FontLoader.h:93
bool fDoShadow
Definition: C4FontLoader.h:103
int iGfxLineHgt
Definition: C4FontLoader.h:101
C4Facet fctAsciiTexCoords[256-' ']
Definition: C4FontLoader.h:105
C4Surface * sfcCurrent
Definition: C4FontLoader.h:97
DWORD dwDefFontHeight
Definition: C4FontLoader.h:90
C4FontLoader FontLoader
void DestroyFont(CStdVectorFont *pFont)
char szFontName[80+1]
Definition: C4FontLoader.h:91
CStdVectorFont * pVectorFont
Definition: C4FontLoader.h:110
#define FW_NORMAL
Definition: C4FontLoader.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

void CStdFont::DrawText ( C4Surface sfcDest,
float  iX,
float  iY,
DWORD  dwColor,
const char *  szText,
DWORD  dwFlags,
C4Markup Markup,
float  fZoom 
)

Definition at line 795 of file C4FontLoader.cpp.

References C4Draw::ActivateBlitModulation(), C4Markup::Apply(), C4Draw::Blit(), C4Markup::Clean(), C4Draw::DeactivateBlitModulation(), CStdFontCustomImages::DrawFontImage(), C4Draw::GetBlitModulation(), GetCharacterFacet(), GetFontImageSize(), GetNextCharacter(), GetTextExtent(), C4Facet::Hgt, iFontZoom, iGfxLineHgt, iHSpace, IsValidUtf8(), C4BltTransform::mat, ModulateClr(), ModulateClrA(), pCustomImages, pDraw, C4Markup::Read(), SCharPos(), SCopy(), C4DrawTransform::Set(), C4Facet::Set(), STDFONT_CENTERED, STDFONT_NOMARKUP, STDFONT_RIGHTALGN, C4Facet::Surface, C4Facet::Wdt, C4Facet::X, and C4Facet::Y.

Referenced by C4Draw::StringOut().

796 {
797 #ifndef USE_CONSOLE
798  assert(IsValidUtf8(szText));
799  C4DrawTransform bt, *pbt=nullptr;
800  // set blit color
801  DWORD dwOldModClr;
802  bool fWasModulated = pDraw->GetBlitModulation(dwOldModClr);
803  if (fWasModulated) ModulateClr(dwColor, dwOldModClr);
804  // get alpha fade percentage
805  DWORD dwAlphaMod = std::min<uint32_t>(((dwColor>>0x18)*0xff)/0xaf, 255)<<0x18 | 0xffffff;
806 
807  /* char TEXT[8192];
808  sprintf(TEXT, "%s(%x-%x-%x)", szText, dwAlphaMod>>0x18, dwColor>>0x15, (((int)(dwColor>>0x15)-0x50)*0xff)/0xaf); szText=TEXT;*/
809  // adjust text starting position (horizontal only)
810  if (dwFlags & STDFONT_CENTERED)
811  {
812  // centered
813  int32_t sx,sy;
814  GetTextExtent(szText, sx,sy, !(dwFlags & STDFONT_NOMARKUP));
815  sx = int(fZoom*sx); sy = int(fZoom*sy);
816  iX-=sx/2;
817  }
818  else if (dwFlags & STDFONT_RIGHTALGN)
819  {
820  // right-aligned
821  int32_t sx,sy;
822  GetTextExtent(szText, sx,sy, !(dwFlags & STDFONT_NOMARKUP));
823  sx = int(fZoom*sx); sy = int(fZoom*sy);
824  iX-=sx;
825  }
826  // apply texture zoom
827  fZoom /= iFontZoom;
828  // set start markup transformation
829  if (!Markup.Clean()) pbt=&bt;
830  // output text
831  uint32_t c;
832  C4Facet fctFromBlt; // source facet
833  while ((c = GetNextCharacter(&szText)))
834  {
835  // ignore system characters
836  if (c < ' ') continue;
837  // apply markup
838  if (c=='<' && (~dwFlags & STDFONT_NOMARKUP))
839  {
840  // get tag
841  if (Markup.Read(&--szText))
842  {
843  // mark transform to be done
844  // (done only if tag was found, so most normal blits don't init a trasnformation matrix)
845  pbt=&bt;
846  // skip the tag
847  continue;
848  }
849  // invalid tag: render it as text
850  ++szText;
851  }
852  int w2, h2; // dst width/height
853  // custom image?
854  int iImgLgt;
855  char imgbuf[101] = "";
856  if (c=='{' && szText[0]=='{' && szText[1]!='{' && (iImgLgt=SCharPos('}', szText+1))>0 && szText[iImgLgt+2]=='}' && !(dwFlags & STDFONT_NOMARKUP))
857  {
858  SCopy(szText+1, imgbuf, std::min(iImgLgt, 100));
859  szText+=iImgLgt+3;
860  if(!GetFontImageSize(imgbuf, w2, h2))
861  continue;
862  //normal: not modulated, unless done by transform or alpha fadeout
863  if ((dwColor>>0x18) >= 0xaf)
865  else
866  pDraw->ActivateBlitModulation((dwColor&0xff000000) | 0xffffff);
867  }
868  else
869  {
870  // regular char
871  // get texture coordinates
872  fctFromBlt = GetCharacterFacet(c);
873  if(!fctFromBlt.Surface) continue;
874  w2=int(fctFromBlt.Wdt*fZoom); h2=int(fctFromBlt.Hgt*fZoom);
875  pDraw->ActivateBlitModulation(dwColor);
876  }
877  // do color/markup
878  if (pbt)
879  {
880  // reset data to be transformed by markup
881  DWORD dwBlitClr = dwColor;
882  bt.Set(1,0,0,0,1,0,0,0,1);
883  // apply markup
884  Markup.Apply(bt, dwBlitClr);
885  if (dwBlitClr != dwColor) ModulateClrA(dwBlitClr, dwAlphaMod);
886  pDraw->ActivateBlitModulation(dwBlitClr);
887  // move transformation center to center of letter
888  float fOffX=(float) w2/2 + iX;
889  float fOffY=(float) h2/2 + iY;
890  bt.mat[2] += fOffX - fOffX*bt.mat[0] - fOffY*bt.mat[1];
891  bt.mat[5] += fOffY - fOffX*bt.mat[3] - fOffY*bt.mat[4];
892  }
893  if(imgbuf[0])
894  {
895  C4Facet fct;
896  fct.Set(sfcDest, iX, iY + (iGfxLineHgt - h2)/2.0f, w2, h2);
897  pCustomImages->DrawFontImage(imgbuf, fct, pbt);
898  }
899  else
900  {
901  // blit character
902  pDraw->Blit(fctFromBlt.Surface, float(fctFromBlt.X), float(fctFromBlt.Y), float(fctFromBlt.Wdt),float(fctFromBlt.Hgt),
903  sfcDest, iX, iY, float(w2), float(h2),
904  true, pbt);
905  }
906  // advance pos and skip character indent
907  iX+=w2+iHSpace;
908  }
909  // reset blit modulation
910  if (fWasModulated)
911  pDraw->ActivateBlitModulation(dwOldModClr);
912  else
914 #endif
915 }
float Y
Definition: C4Facet.h:120
#define STDFONT_NOMARKUP
Definition: C4FontLoader.h:36
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
uint32_t GetNextCharacter(const char **pszString)
Definition: Standard.h:88
#define STDFONT_CENTERED
Definition: C4FontLoader.h:31
bool GetTextExtent(const char *szText, int32_t &rsx, int32_t &rsy, bool fCheckMarkup=true)
void ModulateClr(DWORD &dwDst, DWORD dwMod)
Definition: StdColors.h:55
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
int iFontZoom
Definition: C4FontLoader.h:95
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
Definition: C4Facet.h:78
int iGfxLineHgt
Definition: C4FontLoader.h:101
bool GetFontImageSize(const char *szTag, int &width, int &height) const
C4Draw * pDraw
Definition: C4Draw.cpp:45
bool IsValidUtf8(const char *text, int length)
Definition: Standard.cpp:673
bool Clean()
Definition: C4Markup.h:76
bool Read(const char **ppText, bool fSkip=false)
Definition: C4Markup.cpp:34
bool Blit(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:304
float Hgt
Definition: C4Facet.h:120
bool GetBlitModulation(DWORD &rdwColor)
Definition: C4Draw.h:190
void DeactivateBlitModulation()
Definition: C4Draw.h:189
void Apply(C4BltTransform &rBltTrf, DWORD &dwClr)
Definition: C4Markup.h:74
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:210
void ActivateBlitModulation(DWORD dwWithClr)
Definition: C4Draw.h:188
C4Surface * Surface
Definition: C4Facet.h:119
virtual bool DrawFontImage(const char *szImageTag, C4Facet &cgo, C4DrawTransform *transform)=0
uint32_t DWORD
C4Facet & GetCharacterFacet(uint32_t c)
Definition: C4FontLoader.h:116
float Wdt
Definition: C4Facet.h:120
#define STDFONT_RIGHTALGN
Definition: C4FontLoader.h:34
float X
Definition: C4Facet.h:120
CustomImages * pCustomImages
Definition: C4FontLoader.h:108
void ModulateClrA(DWORD &dwDst, DWORD dwMod)
Definition: StdColors.h:67

Here is the call graph for this function:

Here is the caller graph for this function:

C4Facet& CStdFont::GetCharacterFacet ( uint32_t  c)
inlineprotected

Definition at line 116 of file C4FontLoader.h.

References GetUnicodeCharacterFacet().

Referenced by BreakMessage(), DrawText(), and GetTextExtent().

117  {
118  if (c<128) return fctAsciiTexCoords[c-' ']; else return GetUnicodeCharacterFacet(c);
119  }
C4Facet & GetUnicodeCharacterFacet(uint32_t c)
C4Facet fctAsciiTexCoords[256-' ']
Definition: C4FontLoader.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

int CStdFont::GetFontHeight ( ) const
inline

Definition at line 141 of file C4FontLoader.h.

References GetLineHeight().

142  {
143  // Currently, we do not use spacing between lines - if someone implements that, this needs to be adjusted.
144  return GetLineHeight();
145  }
int GetLineHeight() const
Definition: C4FontLoader.h:132

Here is the call graph for this function:

bool CStdFont::GetFontImageSize ( const char *  szTag,
int &  width,
int &  height 
) const

Definition at line 917 of file C4FontLoader.cpp.

References CStdFontCustomImages::GetFontImageAspect(), iGfxLineHgt, and pCustomImages.

Referenced by BreakMessage(), DrawText(), and GetTextExtent().

918 {
919 #ifdef USE_CONSOLE
920  width = height = 0;
921 #else
922  const float aspect = pCustomImages ? pCustomImages->GetFontImageAspect(szTag) : -1.0f;
923 
924  // aspect < 0 means there is no such image
925  if (aspect < 0.0f) return false;
926 
927  // image found: adjust aspect by font height and calc appropriate width
928  height = iGfxLineHgt;
929  width = static_cast<int>(height * aspect + 0.5f);
930 
931  // make images not ridiciously wide
932  if(width > height)
933  {
934  float scale = static_cast<float>(height)/static_cast<float>(width);
935 
936  width = height;//static_cast<int32_t>(width*scale + 0.5f);
937  height = static_cast<int32_t>(height*scale + 0.5f);
938  }
939 #endif
940 
941  return true;
942 }
int iGfxLineHgt
Definition: C4FontLoader.h:101
virtual float GetFontImageAspect(const char *szImageTag)=0
CustomImages * pCustomImages
Definition: C4FontLoader.h:108

Here is the call graph for this function:

Here is the caller graph for this function:

int CStdFont::GetLineHeight ( ) const
inline

Definition at line 132 of file C4FontLoader.h.

References iLineHgt.

Referenced by C4GameOverDlg::C4GameOverDlg(), C4Network2ClientListDlg::C4Network2ClientListDlg(), C4StartupAboutDlg::C4StartupAboutDlg(), C4StartupNetListEntry::C4StartupNetListEntry(), C4StartupOptionsDlg::C4StartupOptionsDlg(), C4StartupPlrPropertiesDlg::C4StartupPlrPropertiesDlg(), C4StartupScenSelDlg::C4StartupScenSelDlg(), C4FileSelDlg::DefaultListItem::DefaultListItem(), C4UpperBoard::Draw(), C4LoaderScreen::Draw(), C4IDList::Draw(), C4ScriptGuiWindow::Draw(), C4GUI::Tabular::Sheet::DrawCaption(), C4Game::DrawCrewOverheadText(), C4ScoreboardDlg::DrawElement(), C4MenuItem::DrawElement(), C4Chart::DrawElement(), C4GUI::WoodenLabel::DrawElement(), C4GUI::MultilineLabel::DrawElement(), C4GUI::ProgressBar::DrawElement(), C4GUI::GroupBox::DrawElement(), C4GUI::Button::DrawElement(), C4GUI::Edit::DrawElement(), C4GUI::CheckBox::DrawElement(), C4GUI::ComboBox::DrawElement(), C4GUI::ContextMenu::Entry::Entry(), C4GUI::FullscreenDialog::FullscreenDialog(), C4StartupGraphics::GetBlackFontByHeight(), C4GUI::Tabular::Sheet::GetCaptionSize(), C4GUI::Edit::GetCustomEditHeight(), C4GUI::WoodenLabel::GetDefaultHeight(), C4GUI::ComboBox::GetDefaultHeight(), C4GUI::Dialog::GetDefaultTitleHeight(), C4GraphicsResource::GetFontByHeight(), GetFontHeight(), C4GUI::GroupBox::GetMarginTop(), C4UpperBoard::Init(), C4MessageBoard::Init(), C4FileSelDlg::InitElements(), C4Menu::InitLocation(), C4GUI::MessageDialog::MessageDialog(), C4ChatControl::ChatSheet::NickItem::NickItem(), C4Game::SaveGameTitle(), C4StartupScenSelDlg::ScenListItem::ScenListItem(), C4GUI::FullscreenDialog::SetTitle(), C4Draw::TextOut(), C4ScoreboardDlg::Update(), C4Menu::UpdateElementPositions(), and C4GUI::MultilineLabel::UpdateHeight().

133  {
134 #ifdef USE_CONSOLE
135  return 0;
136 #else
137  return iLineHgt;
138 #endif
139  }
int iLineHgt
Definition: C4FontLoader.h:122

Here is the caller graph for this function:

int CStdFont::GetMessageBreak ( const char *  szMsg,
const char **  ppNewPos,
int  iBreakWidth,
float  fZoom = 1.0f 
)

Definition at line 737 of file C4FontLoader.cpp.

References fctAsciiTexCoords, iFontZoom, and iHSpace.

Referenced by C4LogBuffer::AppendLines().

738 {
739 #ifdef USE_CONSOLE
740  *ppNewPos = szMsg;
741  while(**ppNewPos) ++*ppNewPos;
742  return *ppNewPos - szMsg;
743 #else
744  // safety
745  if (!szMsg || !*szMsg) { *ppNewPos = szMsg; return 0; }
746  const char *szPos = szMsg; unsigned char c;
747  int iWdt = 0; int iPos = 0;
748  // check all message until it's too wide
749  while ((c = *szPos++))
750  {
751  ++iPos;
752  // get char width
753  int iCharWdt = int(fZoom * fctAsciiTexCoords[c-' '].Wdt / iFontZoom) + iHSpace;
754  // add to overall line width
755  iWdt += iCharWdt;
756  // next char only if the line didn't overflow
757  if (iWdt > iBreakWidth) break;
758  }
759  // did it all fit?
760  if (!c)
761  {
762  // all OK then; use all the buffer
763  *ppNewPos = szPos-1;
764  return iPos;
765  }
766  // line must be broken - trace back until first break char
767  // szPos2 will be first char of next line
768  const char *szPos2 = szPos-1; int i=0;
769  while ((!i++ || *szPos2 != '-') && *szPos2 != ' ')
770  if (szPos2 == szMsg)
771  {
772  // do not go past beginning of line
773  // then better print out an unfitting break
774  szPos2 = szPos-1;
775  break;
776  }
777  else
778  --szPos2;
779  // but do print at least one char
780  if (szPos2 <= szMsg) szPos2 = szMsg+1;
781  // assign next line start pos - skip spaces
782  *ppNewPos = szPos2;
783  if (*szPos2 == ' ') ++*ppNewPos;
784  // return output string length
785  return szPos2 - szMsg;
786 #endif
787 }
int iFontZoom
Definition: C4FontLoader.h:95
C4Facet fctAsciiTexCoords[256-' ']
Definition: C4FontLoader.h:105

Here is the caller graph for this function:

bool CStdFont::GetTextExtent ( const char *  szText,
int32_t &  rsx,
int32_t &  rsy,
bool  fCheckMarkup = true 
)

Definition at line 511 of file C4FontLoader.cpp.

References GetCharacterFacet(), GetFontImageSize(), GetNextCharacter(), iFontZoom, iHSpace, iLineHgt, IsValidUtf8(), SCharPos(), SCopy(), C4Markup::SkipTags(), and C4Facet::Wdt.

Referenced by C4LogBuffer::AppendLines(), C4StartupNetDlg::C4StartupNetDlg(), C4StartupOptionsDlg::C4StartupOptionsDlg(), C4StartupScenSelDlg::C4StartupScenSelDlg(), C4LoaderScreen::Draw(), C4GameMessage::Draw(), C4Object::Draw(), C4ScriptGuiWindow::Draw(), C4Game::DrawCrewOverheadText(), C4Chart::DrawElement(), C4GUI::GroupBox::DrawElement(), C4GUI::Edit::DrawElement(), DrawText(), C4GUI::Screen::DrawToolTip(), C4Facet::DrawValue(), C4Facet::DrawValue2(), C4GUI::ContextMenu::Entry::Entry(), C4GUI::Tabular::Sheet::GetCaptionSize(), C4GUI::LabeledEdit::GetControlSize(), C4GUI::CheckBox::GetStandardCheckBoxSize(), GetTextWidth(), C4Menu::InitLocation(), C4GUI::InputDialog::InputDialog(), IsSmallInputQuery(), C4GUI::LabeledEdit::LabeledEdit(), C4GUI::MessageDialog::MessageDialog(), C4GUI::Label::SetText(), and C4Menu::UpdateElementPositions().

512 {
513  // safety
514  if (!szText) return false;
515  assert(IsValidUtf8(szText));
516 #ifdef USE_CONSOLE
517  rsx = rsy = 0;
518 #else
519  // keep track of each row's size
520  int iRowWdt=0,iWdt=0,iHgt=iLineHgt;
521  // ignore any markup
522  C4Markup MarkupChecker(false);
523  // go through all text
524  while (*szText)
525  {
526  // ignore markup
527  if (fCheckMarkup) MarkupChecker.SkipTags(&szText);
528  // get current char
529  uint32_t c = GetNextCharacter(&szText);
530  // done? (must check here, because markup-skip may have led to text end)
531  if (!c) break;
532  // line break?
533  if (c == '\n' || (fCheckMarkup && c == '|')) { iRowWdt=0; iHgt+=iLineHgt; continue; }
534  // ignore system characters
535  if (c < ' ') continue;
536  // image?
537  int iImgLgt;
538  if (fCheckMarkup && c=='{' && szText[0]=='{' && szText[1]!='{' && (iImgLgt=SCharPos('}', szText+1))>0 && szText[iImgLgt+2]=='}')
539  {
540  char imgbuf[101];
541  SCopy(szText+1, imgbuf, std::min(iImgLgt, 100));
542 
543  int w2, h2;
544  if(!GetFontImageSize(imgbuf, w2, h2))
545  { w2 = 0; h2 = 0; }
546 
547  iRowWdt += w2;
548  // skip image tag
549  szText+=iImgLgt+3;
550  }
551  else
552  {
553  // regular char
554  // look up character width in texture coordinates table
555  iRowWdt += GetCharacterFacet(c).Wdt / iFontZoom;
556  }
557  // apply horizontal indent for all but last char
558  if (*szText) iRowWdt += iHSpace;
559  // adjust max row size
560  if (iRowWdt>iWdt) iWdt=iRowWdt;
561  }
562  // store output
563  rsx=iWdt; rsy=iHgt;
564  // done, success
565 #endif
566  return true;
567 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
uint32_t GetNextCharacter(const char **pszString)
Definition: Standard.h:88
int iFontZoom
Definition: C4FontLoader.h:95
int iLineHgt
Definition: C4FontLoader.h:122
bool GetFontImageSize(const char *szTag, int &width, int &height) const
bool IsValidUtf8(const char *text, int length)
Definition: Standard.cpp:673
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:210
C4Facet & GetCharacterFacet(uint32_t c)
Definition: C4FontLoader.h:116
float Wdt
Definition: C4Facet.h:120

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t CStdFont::GetTextWidth ( const char *  szText,
bool  fCheckMarkup = true 
)
inline

Definition at line 147 of file C4FontLoader.h.

References GetTextExtent().

Referenced by C4GameOverDlg::C4GameOverDlg(), C4GameMessage::Draw(), C4GUI::WoodenLabel::DrawElement(), C4UpperBoard::Init(), C4FileSelDlg::InitElements(), and C4ScoreboardDlg::Update().

147 { int32_t x, y; GetTextExtent(szText, x, y, fCheckMarkup); return x; }
bool GetTextExtent(const char *szText, int32_t &rsx, int32_t &rsy, bool fCheckMarkup=true)

Here is the call graph for this function:

Here is the caller graph for this function:

C4Facet & CStdFont::GetUnicodeCharacterFacet ( uint32_t  c)
protected

Definition at line 421 of file C4FontLoader.cpp.

References AddRenderedChar(), fctUnicodeMap, and C4Facet::Surface.

Referenced by GetCharacterFacet().

422 {
423  // find/add facet in map
424  C4Facet &rFacet = fctUnicodeMap[c];
425  // create character on the fly if necessary and possible
426  if (!rFacet.Surface) AddRenderedChar(c, &rFacet);
427  // rendering might have failed, in which case rFacet remains empty. Should be OK; char won't be printed then
428  return rFacet;
429 }
std::map< uint32_t, C4Facet > fctUnicodeMap
Definition: C4FontLoader.h:106
bool AddRenderedChar(uint32_t dwChar, C4Facet *pfctTarget)
C4Surface * Surface
Definition: C4Facet.h:119

Here is the call graph for this function:

Here is the caller graph for this function:

void CStdFont::Init ( CStdVectorFont VectorFont,
const char *  font_face_name,
DWORD  dwHeight,
DWORD  dwFontWeight = FW_NORMAL,
bool  fDoShadow = true 
)

Definition at line 432 of file C4FontLoader.cpp.

References AddRenderedChar(), AddSurface(), Clear(), dwDefFontHeight, dwWeight, fctAsciiTexCoords, fDoShadow, iFontZoom, iGfxLineHgt, iHSpace, iLineHgt, iSfcSizes, C4Surface::Lock(), pVectorFont, CStdVectorFont::RefCnt, SCopy(), sfcCurrent, szFontName, and C4Surface::Unlock().

Referenced by C4FontLoader::InitFont().

433 {
434 #ifndef USE_CONSOLE
435  // clear previous
436  Clear();
437  // set values
438  iHSpace=fDoShadow ? -1 : 0; // horizontal shadow
439  dwWeight=dwFontWeight;
440  this->fDoShadow = fDoShadow;
441  // determine needed texture size
442  if (dwHeight * iFontZoom > 40)
443  iSfcSizes = 512;
444  else if (dwDefFontHeight * iFontZoom > 20)
445  iSfcSizes = 256;
446  else
447  iSfcSizes = 128;
448  SCopy(font_face_name, szFontName, 80);
449  dwDefFontHeight = dwHeight;
450  // create surface
451  if (!AddSurface())
452  {
453  Clear();
454  throw std::runtime_error(std::string("Cannot create surface (") + szFontName + ")");
455  }
456 
457  // Store vector font
458  pVectorFont = &VectorFont;
459  ++(pVectorFont->RefCnt);
460  // Get size
461  // FIXME: use bbox or dynamically determined line heights here
462  iLineHgt = (VectorFont->ascender - VectorFont->descender) * dwHeight / VectorFont->units_per_EM;
463  iGfxLineHgt = iLineHgt + fDoShadow; // vertical shadow
464 
465  // loop through all ASCII printable characters and prepare them
466  // Non-ASCII Unicode characters will be created on the fly
467  // now render all characters!
468 
469  int cMax = 127;
470  sfcCurrent->Lock();
471  for (int c=' '; c <= cMax; ++c)
472  {
473  if (!AddRenderedChar(c, &(fctAsciiTexCoords[c-' '])))
474  {
475  sfcCurrent->Unlock();
476  Clear();
477  throw std::runtime_error(std::string("Cannot render characters for Font (") + szFontName + ")");
478  }
479  }
480  sfcCurrent->Unlock();
481  // adjust line height
482  iLineHgt /= iFontZoom;
483 #endif
484 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
bool AddSurface()
bool Lock()
Definition: C4Surface.cpp:463
DWORD dwWeight
Definition: C4FontLoader.h:102
bool Unlock()
Definition: C4Surface.cpp:474
int iFontZoom
Definition: C4FontLoader.h:95
int iLineHgt
Definition: C4FontLoader.h:122
bool fDoShadow
Definition: C4FontLoader.h:103
int iGfxLineHgt
Definition: C4FontLoader.h:101
C4Facet fctAsciiTexCoords[256-' ']
Definition: C4FontLoader.h:105
C4Surface * sfcCurrent
Definition: C4FontLoader.h:97
bool AddRenderedChar(uint32_t dwChar, C4Facet *pfctTarget)
void Clear()
DWORD dwDefFontHeight
Definition: C4FontLoader.h:90
char szFontName[80+1]
Definition: C4FontLoader.h:91
CStdVectorFont * pVectorFont
Definition: C4FontLoader.h:110
int iSfcSizes
Definition: C4FontLoader.h:94

Here is the call graph for this function:

Here is the caller graph for this function:

bool CStdFont::IsInitialized ( ) const
inline

Definition at line 166 of file C4FontLoader.h.

References szFontName.

Referenced by C4FontLoader::InitFont().

166  {
167 #ifdef USE_CONSOLE
168  return true;
169 #else
170  return !!*szFontName;
171 #endif
172  }
char szFontName[80+1]
Definition: C4FontLoader.h:91

Here is the caller graph for this function:

bool CStdFont::IsSameAs ( const char *  szCFontName,
DWORD  iCHeight,
DWORD  dwCWeight 
) const
inline

Definition at line 183 of file C4FontLoader.h.

References dwWeight, and SEqual().

Referenced by C4FontLoader::InitFont().

184  {
185 #ifdef USE_CONSOLE
186  return true;
187 #else
188  return SEqual(szCFontName, szFontName) && !id && iCHeight==dwDefFontHeight && dwCWeight==dwWeight;
189 #endif
190  }
DWORD dwWeight
Definition: C4FontLoader.h:102
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
DWORD dwDefFontHeight
Definition: C4FontLoader.h:90
char szFontName[80+1]
Definition: C4FontLoader.h:91

Here is the call graph for this function:

Here is the caller graph for this function:

bool CStdFont::IsSameAsID ( const char *  szCFontName,
int  iCID,
int  iCIndent 
) const
inline

Definition at line 175 of file C4FontLoader.h.

References iHSpace, and SEqual().

176  {
177 #ifdef USE_CONSOLE
178  return true;
179 #else
180  return SEqual(szCFontName, szFontName) && iCID==id && iCIndent==-iHSpace;
181 #endif
182  }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
char szFontName[80+1]
Definition: C4FontLoader.h:91

Here is the call graph for this function:

void CStdFont::SetCustomImages ( CustomImages pHandler)
inline

Definition at line 193 of file C4FontLoader.h.

Referenced by C4GraphicsResource::Clear(), and C4GraphicsResource::InitFonts().

194  {
195 #ifndef USE_CONSOLE
196  pCustomImages = pHandler;
197 #endif
198  }
CustomImages * pCustomImages
Definition: C4FontLoader.h:108

Here is the caller graph for this function:

Member Data Documentation

DWORD CStdFont::dwDefFontHeight
protected

Definition at line 90 of file C4FontLoader.h.

Referenced by AddRenderedChar(), Clear(), CStdFont(), and Init().

DWORD CStdFont::dwWeight
protected

Definition at line 102 of file C4FontLoader.h.

Referenced by AddRenderedChar(), Clear(), CStdFont(), Init(), and IsSameAs().

C4Facet CStdFont::fctAsciiTexCoords[256-' ']
protected

Definition at line 105 of file C4FontLoader.h.

Referenced by Clear(), GetMessageBreak(), and Init().

std::map<uint32_t, C4Facet> CStdFont::fctUnicodeMap
protected

Definition at line 106 of file C4FontLoader.h.

Referenced by Clear(), and GetUnicodeCharacterFacet().

bool CStdFont::fDoShadow
protected

Definition at line 103 of file C4FontLoader.h.

Referenced by AddRenderedChar(), Clear(), CStdFont(), and Init().

int32_t CStdFont::iCurrentSfcX
protected

Definition at line 98 of file C4FontLoader.h.

Referenced by AddRenderedChar(), AddSurface(), and CheckRenderedCharSpace().

int32_t CStdFont::iCurrentSfcY
protected

Definition at line 98 of file C4FontLoader.h.

Referenced by AddRenderedChar(), AddSurface(), and CheckRenderedCharSpace().

int CStdFont::id

Definition at line 86 of file C4FontLoader.h.

int CStdFont::iFontZoom
protected
int CStdFont::iGfxLineHgt
protected

Definition at line 101 of file C4FontLoader.h.

Referenced by AddRenderedChar(), Clear(), CStdFont(), DrawText(), GetFontImageSize(), and Init().

int CStdFont::iHSpace
protected
int CStdFont::iLineHgt
protected

Definition at line 122 of file C4FontLoader.h.

Referenced by BreakMessage(), Clear(), CStdFont(), GetLineHeight(), GetTextExtent(), and Init().

int CStdFont::iSfcSizes
protected

Definition at line 94 of file C4FontLoader.h.

Referenced by AddSurface(), CheckRenderedCharSpace(), CStdFont(), and Init().

CustomImages* CStdFont::pCustomImages
protected

Definition at line 108 of file C4FontLoader.h.

Referenced by CStdFont(), DrawText(), and GetFontImageSize().

std::vector<std::unique_ptr<C4Surface> > CStdFont::psfcFontData
protected

Definition at line 93 of file C4FontLoader.h.

Referenced by AddSurface(), and Clear().

CStdVectorFont* CStdFont::pVectorFont
protected

Definition at line 110 of file C4FontLoader.h.

Referenced by AddRenderedChar(), Clear(), CStdFont(), and Init().

C4Surface* CStdFont::sfcCurrent
protected

Definition at line 97 of file C4FontLoader.h.

Referenced by AddRenderedChar(), AddSurface(), Clear(), CStdFont(), and Init().

char CStdFont::szFontName[80+1]
protected

Definition at line 91 of file C4FontLoader.h.

Referenced by Clear(), CStdFont(), Init(), and IsInitialized().


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