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 75 of file C4FontLoader.h.

Member Typedef Documentation

Definition at line 78 of file C4FontLoader.h.

Constructor & Destructor Documentation

CStdFont::CStdFont ( )

Definition at line 278 of file C4FontLoader.cpp.

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

279 {
280 #ifndef USE_CONSOLE
281  // set default values
282  sfcCurrent = nullptr;
283  iSfcSizes = 64;
285  iFontZoom=1; // default: no internal font zooming - likely no antialiasing either...
286  iHSpace=-1;
289  fDoShadow=false;
290  // font not yet initialized
291  *szFontName=0;
292  id=0;
293  pCustomImages=nullptr;
294  pVectorFont = nullptr;
295 #endif
296 }
DWORD dwWeight
Definition: C4FontLoader.h:95
int iFontZoom
Definition: C4FontLoader.h:88
int iLineHgt
Definition: C4FontLoader.h:115
bool fDoShadow
Definition: C4FontLoader.h:96
int iGfxLineHgt
Definition: C4FontLoader.h:94
C4Surface * sfcCurrent
Definition: C4FontLoader.h:90
DWORD dwDefFontHeight
Definition: C4FontLoader.h:83
char szFontName[80+1]
Definition: C4FontLoader.h:84
CStdVectorFont * pVectorFont
Definition: C4FontLoader.h:103
#define FW_NORMAL
Definition: C4FontLoader.h:36
int iHSpace
Definition: C4FontLoader.h:93
CustomImages * pCustomImages
Definition: C4FontLoader.h:101
int iSfcSizes
Definition: C4FontLoader.h:87
CStdFont::~CStdFont ( )
inline

Definition at line 150 of file C4FontLoader.h.

References Clear().

150 { 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 332 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().

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool CStdFont::AddSurface ( )
protected

Definition at line 299 of file C4FontLoader.cpp.

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

Referenced by CheckRenderedCharSpace(), and Init().

300 {
301  // add new surface as render target
302  auto sfcNew = std::make_unique<C4Surface>(iSfcSizes, iSfcSizes, 0);
303  // If old surface was locked, unlock it and lock the new one in its stead
304  if (sfcCurrent && sfcCurrent->IsLocked())
305  {
306  sfcCurrent->Unlock();
307  sfcNew->Lock();
308  }
309  sfcCurrent = sfcNew.get();
310  psfcFontData.push_back(std::move(sfcNew));
312  return true;
313 }
bool Unlock()
Definition: C4Surface.cpp:464
int32_t iCurrentSfcX
Definition: C4FontLoader.h:91
int32_t iCurrentSfcY
Definition: C4FontLoader.h:91
std::vector< std::unique_ptr< C4Surface > > psfcFontData
Definition: C4FontLoader.h:86
int IsLocked() const
Definition: C4Surface.h:93
C4Surface * sfcCurrent
Definition: C4FontLoader.h:90
int iSfcSizes
Definition: C4FontLoader.h:87

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 599 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().

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

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 563 of file C4FontLoader.cpp.

References BreakMessage().

564 {
565 #ifdef USE_CONSOLE
566  return 0;
567 #else
568  // note iMaxOutLen does not include terminating null character
569  // safety
570  if (!iMaxOutLen) return 0;
571  if (!szMsg)
572  {
573  if (szOut) *szOut=0;
574  return 0;
575  }
576  auto t = BreakMessage(szMsg, iWdt, fCheckMarkup, fZoom);
577  auto str = std::get<0>(t);
578  auto len = str.copy(szOut, iMaxOutLen);
579  szOut[len] = '\0';
580  return std::get<1>(t);
581 #endif
582 }
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 584 of file C4FontLoader.cpp.

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

585 {
586 #ifdef USE_CONSOLE
587  return 0;
588 #else
589  if (!szMsg || !pOut) return 0;
590  auto t = BreakMessage(szMsg, iWdt, fCheckMarkup, fZoom);
591  auto str = std::get<0>(t);
592  pOut->Clear();
593  pOut->Append(str.c_str(), str.size());
594  return std::get<1>(t);
595 #endif
596 }
void Clear()
Definition: StdBuf.h:466
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
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 315 of file C4FontLoader.cpp.

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

Referenced by AddRenderedChar().

316 {
317  // need to do a line break?
318  if (iCurrentSfcX + iCharWdt >= (uint32_t)iSfcSizes) if (iCurrentSfcX)
319  {
320  iCurrentSfcX = 0;
321  iCurrentSfcY += iCharHgt;
322  if (iCurrentSfcY + iCharHgt >= (uint32_t)iSfcSizes)
323  {
324  // surface is full: Next one
325  if (!AddSurface()) return false;
326  }
327  }
328  // OK draw it there
329  return true;
330 }
bool AddSurface()
int32_t iCurrentSfcX
Definition: C4FontLoader.h:91
int32_t iCurrentSfcY
Definition: C4FontLoader.h:91
int iSfcSizes
Definition: C4FontLoader.h:87

Here is the call graph for this function:

Here is the caller graph for this function:

void CStdFont::Clear ( )

Definition at line 480 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().

481 {
482 #ifndef USE_CONSOLE
484  pVectorFont = nullptr;
485 
486  // clear font sfcs
487  sfcCurrent = nullptr;
488  psfcFontData.clear();
489  for (int c=' '; c<256; ++c) fctAsciiTexCoords[c-' '].Default();
490  fctUnicodeMap.clear();
491  // set default values
493  iFontZoom=1; // default: no internal font zooming - likely no antialiasing either...
494  iHSpace=-1;
497  fDoShadow=false;
498  // font not yet initialized
499  *szFontName=0;
500  id=0;
501 #endif
502 }
std::map< uint32_t, C4Facet > fctUnicodeMap
Definition: C4FontLoader.h:99
DWORD dwWeight
Definition: C4FontLoader.h:95
int iFontZoom
Definition: C4FontLoader.h:88
int iLineHgt
Definition: C4FontLoader.h:115
std::vector< std::unique_ptr< C4Surface > > psfcFontData
Definition: C4FontLoader.h:86
bool fDoShadow
Definition: C4FontLoader.h:96
int iGfxLineHgt
Definition: C4FontLoader.h:94
C4Facet fctAsciiTexCoords[256-' ']
Definition: C4FontLoader.h:98
C4Surface * sfcCurrent
Definition: C4FontLoader.h:90
DWORD dwDefFontHeight
Definition: C4FontLoader.h:83
C4FontLoader FontLoader
void DestroyFont(CStdVectorFont *pFont)
char szFontName[80+1]
Definition: C4FontLoader.h:84
CStdVectorFont * pVectorFont
Definition: C4FontLoader.h:103
#define FW_NORMAL
Definition: C4FontLoader.h:36
int iHSpace
Definition: C4FontLoader.h:93

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 789 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().

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

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 109 of file C4FontLoader.h.

References GetUnicodeCharacterFacet().

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

110  {
111  if (c<128) return fctAsciiTexCoords[c-' ']; else return GetUnicodeCharacterFacet(c);
112  }
C4Facet & GetUnicodeCharacterFacet(uint32_t c)
C4Facet fctAsciiTexCoords[256-' ']
Definition: C4FontLoader.h:98

Here is the call graph for this function:

Here is the caller graph for this function:

int CStdFont::GetFontHeight ( ) const
inline

Definition at line 134 of file C4FontLoader.h.

References GetLineHeight().

135  {
136  // Currently, we do not use spacing between lines - if someone implements that, this needs to be adjusted.
137  return GetLineHeight();
138  }
int GetLineHeight() const
Definition: C4FontLoader.h:125

Here is the call graph for this function:

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

Definition at line 911 of file C4FontLoader.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

int CStdFont::GetLineHeight ( ) const
inline

Definition at line 125 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().

126  {
127 #ifdef USE_CONSOLE
128  return 0;
129 #else
130  return iLineHgt;
131 #endif
132  }
int iLineHgt
Definition: C4FontLoader.h:115

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 731 of file C4FontLoader.cpp.

References fctAsciiTexCoords, iFontZoom, and iHSpace.

Referenced by C4LogBuffer::AppendLines().

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

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 505 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().

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

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 140 of file C4FontLoader.h.

References GetTextExtent().

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

140 { 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 415 of file C4FontLoader.cpp.

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

Referenced by GetCharacterFacet().

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

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 426 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().

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool CStdFont::IsInitialized ( ) const
inline

Definition at line 159 of file C4FontLoader.h.

References szFontName.

Referenced by C4FontLoader::InitFont().

159  {
160 #ifdef USE_CONSOLE
161  return true;
162 #else
163  return !!*szFontName;
164 #endif
165  }
char szFontName[80+1]
Definition: C4FontLoader.h:84

Here is the caller graph for this function:

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

Definition at line 176 of file C4FontLoader.h.

References dwWeight, and SEqual().

Referenced by C4FontLoader::InitFont().

177  {
178 #ifdef USE_CONSOLE
179  return true;
180 #else
181  return SEqual(szCFontName, szFontName) && !id && iCHeight==dwDefFontHeight && dwCWeight==dwWeight;
182 #endif
183  }
DWORD dwWeight
Definition: C4FontLoader.h:95
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
DWORD dwDefFontHeight
Definition: C4FontLoader.h:83
char szFontName[80+1]
Definition: C4FontLoader.h:84

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 168 of file C4FontLoader.h.

References iHSpace, and SEqual().

169  {
170 #ifdef USE_CONSOLE
171  return true;
172 #else
173  return SEqual(szCFontName, szFontName) && iCID==id && iCIndent==-iHSpace;
174 #endif
175  }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
char szFontName[80+1]
Definition: C4FontLoader.h:84
int iHSpace
Definition: C4FontLoader.h:93

Here is the call graph for this function:

void CStdFont::SetCustomImages ( CustomImages pHandler)
inline

Definition at line 186 of file C4FontLoader.h.

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

187  {
188 #ifndef USE_CONSOLE
189  pCustomImages = pHandler;
190 #endif
191  }
CustomImages * pCustomImages
Definition: C4FontLoader.h:101

Here is the caller graph for this function:

Member Data Documentation

DWORD CStdFont::dwDefFontHeight
protected

Definition at line 83 of file C4FontLoader.h.

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

DWORD CStdFont::dwWeight
protected

Definition at line 95 of file C4FontLoader.h.

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

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

Definition at line 98 of file C4FontLoader.h.

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

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

Definition at line 99 of file C4FontLoader.h.

Referenced by Clear(), and GetUnicodeCharacterFacet().

bool CStdFont::fDoShadow
protected

Definition at line 96 of file C4FontLoader.h.

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

int32_t CStdFont::iCurrentSfcX
protected

Definition at line 91 of file C4FontLoader.h.

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

int32_t CStdFont::iCurrentSfcY
protected

Definition at line 91 of file C4FontLoader.h.

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

int CStdFont::id

Definition at line 79 of file C4FontLoader.h.

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

Definition at line 94 of file C4FontLoader.h.

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

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

Definition at line 115 of file C4FontLoader.h.

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

int CStdFont::iSfcSizes
protected

Definition at line 87 of file C4FontLoader.h.

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

CustomImages* CStdFont::pCustomImages
protected

Definition at line 101 of file C4FontLoader.h.

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

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

Definition at line 86 of file C4FontLoader.h.

Referenced by AddSurface(), and Clear().

CStdVectorFont* CStdFont::pVectorFont
protected

Definition at line 103 of file C4FontLoader.h.

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

C4Surface* CStdFont::sfcCurrent
protected

Definition at line 90 of file C4FontLoader.h.

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

char CStdFont::szFontName[80+1]
protected

Definition at line 84 of file C4FontLoader.h.

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


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