ManaPlus
Public Member Functions | Static Public Attributes | Static Private Member Functions | Private Attributes
Font Class Reference

#include <font.h>

Public Member Functions

 Font (std::string filename, int size, const int style)
 
 ~Font ()
 
void loadFont (std::string filename, const int size, const int style)
 
int getWidth (const std::string &text) const
 
int getHeight () const
 
const TextChunkListgetCache () const A_CONST
 
void drawString (Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
 
void clear ()
 
void doClean ()
 
void slowLogic (const int rnd)
 
unsigned int getCreateCounter () const
 
unsigned int getDeleteCounter () const
 
int getStringIndexAt (const std::string &text, const int x) const
 
void generate (TextChunk &chunk)
 
void insertChunk (TextChunk *const chunk)
 

Static Public Attributes

static bool mSoftMode
 

Static Private Member Functions

static TTF_Font * openFont (const char *const name, const int size)
 

Private Attributes

TTF_Font * mFont
 
unsigned int mCreateCounter
 
unsigned int mDeleteCounter
 
time_t mCleanTime
 
TextChunkList mCache [CACHES_NUMBER]
 

Detailed Description

A wrapper around SDL_ttf for allowing the use of TrueType fonts.

NOTE: This class initializes SDL_ttf as necessary.

Definition at line 88 of file font.h.

Constructor & Destructor Documentation

◆ Font()

Font::Font ( std::string  filename,
int  size,
const int  style 
)

Definition at line 105 of file font.cpp.

References Logger::error(), fixDirSeparators(), fontCounter, imageHelper, Logger::log(), logger, mFont, mSoftMode, openFont(), RENDER_SOFTWARE, reportAlways, ServerCommandType::size, strBuf, and ImageHelper::useOpenGL().

107  :
108  mFont(nullptr),
109  mCreateCounter(0),
110  mDeleteCounter(0),
112 {
113  if (fontCounter == 0)
114  {
116  if (TTF_Init() == -1)
117  {
118  logger->error("Unable to initialize SDL_ttf: " +
119  std::string(SDL_GetError()));
120  }
121  }
122 
123  if (size < 4)
124  {
125  reportAlways("Error: requested load font %s with size %d",
126  filename.c_str(),
127  size);
128  size = 4;
129  }
130 
131  if (fontCounter == 0)
132  {
133  strBuf = new char[65535];
134  memset(strBuf, 0, 65535);
135  }
136 
137  ++fontCounter;
138 
139  fixDirSeparators(filename);
140  logger->log("Attempt to load font: %s",
141  filename.c_str());
142  mFont = openFont(filename.c_str(), size);
143 
144  if (mFont == nullptr)
145  {
146  logger->log("Error normal loading font " + filename);
147 
148  filename = "fonts/dejavusans.ttf";
149  mFont = openFont(fixDirSeparators(filename).c_str(), size);
150  if (mFont == nullptr)
151  {
152 #ifdef UNITTESTS
153  reportAlways("Font load failed %s",
154  filename.c_str());
155 #endif // UNITTESTS
156  logger->error("Font::Font: " +
157  std::string(SDL_GetError()));
158  }
159  else
160  {
161  logger->log("Loaded fallback font %s, %d",
162  filename.c_str(),
163  size);
164  }
165  }
166  else
167  {
168  logger->log("Loaded font %s, %d",
169  filename.c_str(),
170  size);
171  }
172 
173  TTF_SetFontStyle(mFont, style);
174 }
static bool mSoftMode
Definition: font.h:139
virtual RenderType useOpenGL() const
Definition: imagehelper.h:106
ImageHelper * imageHelper
Definition: imagehelper.cpp:43
static int fontCounter
Definition: font.cpp:103
static TTF_Font * openFont(const char *const name, const int size)
Definition: font.cpp:190
Logger * logger
Definition: logger.cpp:95
unsigned int mCreateCounter
Definition: font.h:146
TTF_Font * mFont
Definition: font.h:145
volatile time_t cur_time
Definition: timer.cpp:57
char * strBuf
Definition: textchunk.cpp:45
std::string & fixDirSeparators(std::string &str)
Definition: paths.cpp:129
unsigned int mDeleteCounter
Definition: font.h:147
const unsigned int CLEAN_TIME
Definition: font.cpp:97
void error(const std::string &error_text) __attribute__((noreturn))
Definition: logger.cpp:415
void log(const char *const log_text,...)
Definition: logger.cpp:243
time_t mCleanTime
Definition: font.h:150
#define reportAlways(...)
Definition: checkutils.h:252

◆ ~Font()

Font::~Font ( )

Definition at line 176 of file font.cpp.

References clear(), fontCounter, mFont, and strBuf.

177 {
178  TTF_CloseFont(mFont);
179  mFont = nullptr;
180  --fontCounter;
181  clear();
182 
183  if (fontCounter == 0)
184  {
185  TTF_Quit();
186  delete []strBuf;
187  }
188 }
static int fontCounter
Definition: font.cpp:103
void clear()
Definition: font.cpp:247
TTF_Font * mFont
Definition: font.h:145
char * strBuf
Definition: textchunk.cpp:45

Member Function Documentation

◆ clear()

void Font::clear ( )

Definition at line 247 of file font.cpp.

References CACHES_NUMBER, and mCache.

Referenced by Gui::clearFonts(), loadFont(), and ~Font().

248 {
249  for (size_t f = 0; f < CACHES_NUMBER; f ++)
250  mCache[f].clear();
251 }
void clear()
Definition: font.cpp:247
TextChunkList mCache[CACHES_NUMBER]
Definition: font.h:151
const unsigned int CACHES_NUMBER
Definition: font.h:81

◆ doClean()

void Font::doClean ( )

Definition at line 365 of file font.cpp.

References CACHES_NUMBER, CAST_SIZE, Logger::log(), logger, mCache, mDeleteCounter, TextChunkList::removeBack(), TextChunkList::size, and ServerCommandType::size.

Referenced by Actions::doSit(), and slowLogic().

366 {
367  for (unsigned int f = 0; f < CACHES_NUMBER; f ++)
368  {
369  TextChunkList *const cache = &mCache[f];
370  const size_t size = CAST_SIZE(cache->size);
371 #ifdef DEBUG_FONT_COUNTERS
372  logger->log("ptr: %u, size: %ld", f, size);
373 #endif // DEBUG_FONT_COUNTERS
374 
375  if (size > CACHE_SIZE_SMALL3)
376  {
377 #ifdef DEBUG_FONT_COUNTERS
378  mDeleteCounter += 100;
379 #endif // DEBUG_FONT_COUNTERS
380 
381  cache->removeBack(100);
382 #ifdef DEBUG_FONT_COUNTERS
383  logger->log("delete3");
384 #endif // DEBUG_FONT_COUNTERS
385  }
386  else if (size > CACHE_SIZE_SMALL2)
387  {
388 #ifdef DEBUG_FONT_COUNTERS
389  mDeleteCounter += 20;
390 #endif // DEBUG_FONT_COUNTERS
391 
392  cache->removeBack(20);
393 #ifdef DEBUG_FONT_COUNTERS
394  logger->log("delete2");
395 #endif // DEBUG_FONT_COUNTERS
396  }
397  else if (size > CACHE_SIZE_SMALL1)
398  {
399 #ifdef DEBUG_FONT_COUNTERS
400  mDeleteCounter ++;
401 #endif // DEBUG_FONT_COUNTERS
402 
403  cache->removeBack();
404 #ifdef DEBUG_FONT_COUNTERS
405  logger->log("delete1");
406 #endif // DEBUG_FONT_COUNTERS
407  }
408  }
409 }
const unsigned int CACHE_SIZE_SMALL2
Definition: font.cpp:95
const unsigned int CACHE_SIZE_SMALL1
Definition: font.cpp:94
uint32_t size
Definition: textchunklist.h:55
TextChunkList mCache[CACHES_NUMBER]
Definition: font.h:151
Logger * logger
Definition: logger.cpp:95
const unsigned int CACHE_SIZE_SMALL3
Definition: font.cpp:96
unsigned int mDeleteCounter
Definition: font.h:147
const unsigned int CACHES_NUMBER
Definition: font.h:81
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ drawString()

void Font::drawString ( Graphics *const  graphics,
Color  col,
const Color col2,
const std::string &  text,
const int  x,
const int  y 
)
See also
Font::drawString

Definition at line 253 of file font.cpp.

References Color::a, BLOCK_END, BLOCK_START, Graphics::drawImage(), TextChunk::generate(), TextChunk::img, TextChunkList::insertFirst(), mCache, mCreateCounter, mDeleteCounter, mFont, TextChunkList::moveToFirst(), TextChunkList::removeBack(), TextChunkList::search, Image::setAlpha(), and TextChunkList::size.

Referenced by Game::addWatermark(), Actions::doSit(), ColorPage::draw(), AvatarListBox::draw(), TextParticle::draw(), ExtendedListBox::draw(), ServersListBox::draw(), EmoteShortcutContainer::draw(), SpellShortcutContainer::draw(), ItemShortcutContainer::draw(), VirtShortcutContainer::draw(), ShopListBox::draw(), EquipmentWindow::draw(), DropDown::draw(), FloorItem::draw(), ItemContainer::draw(), MapItem::draw(), SkillListBox::draw(), TextPreview::draw(), StaticBrowserBox::draw(), ListBox::draw(), TextBox::draw(), BrowserBox::draw(), SkillRectangleListBox::draw(), Gui::draw(), Viewport::drawPath(), Being::drawPortalSpriteAt(), TouchManager::drawText(), AvatarListBox::safeDraw(), SpellShortcutContainer::safeDraw(), ItemShortcutContainer::safeDraw(), EmoteShortcutContainer::safeDraw(), VirtShortcutContainer::safeDraw(), EquipmentWindow::safeDraw(), and ItemContainer::safeDraw().

258 {
259  BLOCK_START("Font::drawString")
260  if (text.empty())
261  {
262  BLOCK_END("Font::drawString")
263  return;
264  }
265 
266 // Color col = graphics->getColor();
267 // const Color &col2 = graphics->getColor2();
268  const float alpha = static_cast<float>(col.a) / 255.0F;
269 
270  /* The alpha value is ignored at string generation so avoid caching the
271  * same text with different alpha values.
272  */
273  col.a = 255;
274 
275  const unsigned char chr = text[0];
276  TextChunkList *const cache = &mCache[chr];
277 
278  std::map<TextChunkSmall, TextChunk*> &search = cache->search;
279  std::map<TextChunkSmall, TextChunk*>::iterator i
280  = search.find(TextChunkSmall(text, col, col2));
281  if (i != search.end())
282  {
283  TextChunk *const chunk2 = (*i).second;
284  cache->moveToFirst(chunk2);
285  Image *const image = chunk2->img;
286  if (image != nullptr)
287  {
288  image->setAlpha(alpha);
289  graphics->drawImage(image, x, y);
290  }
291  }
292  else
293  {
294  if (cache->size >= CACHE_SIZE)
295  {
296 #ifdef DEBUG_FONT_COUNTERS
297  mDeleteCounter ++;
298 #endif // DEBUG_FONT_COUNTERS
299 
300  cache->removeBack();
301  }
302 #ifdef DEBUG_FONT_COUNTERS
303  mCreateCounter ++;
304 #endif // DEBUG_FONT_COUNTERS
305 
306  TextChunk *chunk2 = new TextChunk(text, col, col2, this);
307 
308  chunk2->generate(mFont, alpha);
309  cache->insertFirst(chunk2);
310 
311  const Image *const image = chunk2->img;
312  if (image != nullptr)
313  graphics->drawImage(image, x, y);
314  }
315  BLOCK_END("Font::drawString")
316 }
void generate(TTF_Font *const font, const float alpha)
Definition: textchunk.cpp:96
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
const unsigned int CACHE_SIZE
Definition: font.cpp:93
TextChunkList mCache[CACHES_NUMBER]
Definition: font.h:151
bool find(const std::string &key)
virtual void setAlpha(const float alpha)
Definition: image.cpp:285
unsigned int mCreateCounter
Definition: font.h:146
TTF_Font * mFont
Definition: font.h:145
std::string empty
Definition: podict.cpp:25
Image * img
Definition: textchunk.h:62
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
unsigned int mDeleteCounter
Definition: font.h:147
Definition: image.h:61

◆ generate()

void Font::generate ( TextChunk chunk)

Definition at line 428 of file font.cpp.

References Color::a, TextChunk::color, TextChunk::color2, TextChunk::generate(), TextChunk::img, mCache, mCreateCounter, mDeleteCounter, mFont, TextChunkList::moveToFirst(), TextChunkList::remove(), TextChunkList::removeBack(), TextChunkList::search, TextChunkList::size, and TextChunk::text.

Referenced by ProgressBar::draw(), Text::draw(), CheckBox::draw(), Label::draw(), TextField::draw(), RadioButton::draw(), Window::draw(), Button::draw(), getDeleteCounter(), ProgressBar::safeDraw(), Window::safeDraw(), and Button::safeDraw().

429 {
430  const std::string &text = chunk.text;
431  if (text.empty())
432  return;
433 
434  const unsigned char chr = text[0];
435  TextChunkList *const cache = &mCache[chr];
436  Color &col = chunk.color;
437  Color &col2 = chunk.color2;
438  const int oldAlpha = col.a;
439  col.a = 255;
440 
441  TextChunkSmall key(text, col, col2);
442  std::map<TextChunkSmall, TextChunk*> &search = cache->search;
443  std::map<TextChunkSmall, TextChunk*>::iterator i = search.find(key);
444  if (i != search.end())
445  {
446  TextChunk *const chunk2 = (*i).second;
447  cache->moveToFirst(chunk2);
448 // search.erase(key);
449  cache->remove(chunk2);
450  chunk.img = chunk2->img;
451  chunk2->img = nullptr;
452  delete chunk2;
453 // logger->log("cached image: " + chunk.text);
454  }
455  else
456  {
457  if (cache->size >= CACHE_SIZE)
458  {
459 #ifdef DEBUG_FONT_COUNTERS
460  mDeleteCounter ++;
461 #endif // DEBUG_FONT_COUNTERS
462 
463  cache->removeBack();
464  }
465 #ifdef DEBUG_FONT_COUNTERS
466  mCreateCounter ++;
467 #endif // DEBUG_FONT_COUNTERS
468 
469  const float alpha = static_cast<float>(chunk.color.a) / 255.0F;
470  chunk.generate(mFont, alpha);
471 // logger->log("generate image: " + chunk.text);
472  }
473  col.a = oldAlpha;
474 }
std::string text
Definition: textchunk.h:64
void remove(const TextChunk *const item)
unsigned int a
Definition: color.h:250
void generate(TTF_Font *const font, const float alpha)
Definition: textchunk.cpp:96
uint32_t size
Definition: textchunklist.h:55
const unsigned int CACHE_SIZE
Definition: font.cpp:93
std::map< TextChunkSmall, TextChunk * > search
Definition: textchunklist.h:56
TextChunkList mCache[CACHES_NUMBER]
Definition: font.h:151
unsigned int mCreateCounter
Definition: font.h:146
TTF_Font * mFont
Definition: font.h:145
Image * img
Definition: textchunk.h:62
unsigned int mDeleteCounter
Definition: font.h:147
Color color
Definition: textchunk.h:65
Definition: color.h:74
Color color2
Definition: textchunk.h:66
void moveToFirst(TextChunk *const item)

◆ getCache()

const TextChunkList * Font::getCache ( ) const

Definition at line 423 of file font.cpp.

References mCache.

424 {
425  return mCache;
426 }
TextChunkList mCache[CACHES_NUMBER]
Definition: font.h:151

◆ getCreateCounter()

unsigned int Font::getCreateCounter ( ) const
inline

Definition at line 126 of file font.h.

References mCreateCounter.

127  { return mCreateCounter; }
unsigned int mCreateCounter
Definition: font.h:146

◆ getDeleteCounter()

unsigned int Font::getDeleteCounter ( ) const
inline

Definition at line 129 of file font.h.

References A_WARN_UNUSED, generate(), getStringIndexAt(), insertChunk(), mDeleteCounter, restrict, and restrict2.

130  { return mDeleteCounter; }
unsigned int mDeleteCounter
Definition: font.h:147

◆ getHeight()

int Font::getHeight ( ) const

◆ getStringIndexAt()

int Font::getStringIndexAt ( const std::string &  text,
const int  x 
) const

Definition at line 411 of file font.cpp.

References CAST_S32, and getWidth().

Referenced by getDeleteCounter(), TextField::mousePressed(), and TextBox::mousePressed().

412 {
413  const size_t sz = text.size();
414  for (size_t i = 0; i < sz; ++i)
415  {
416  if (getWidth(text.substr(0, i)) > x)
417  return CAST_S32(i);
418  }
419 
420  return CAST_S32(sz);
421 }
#define CAST_S32
Definition: cast.h:29
int getWidth(const std::string &text) const
Definition: font.cpp:333

◆ getWidth()

int Font::getWidth ( const std::string &  text) const

Definition at line 333 of file font.cpp.

References getSafeUtf8String(), Image::getWidth(), TextChunk::img, mCache, mFont, TextChunkList::moveToFirst(), TextChunkList::searchWidth, and strBuf.

Referenced by StaticBrowserBox::addRow(), BrowserBox::addRow(), Label::adjustSize(), RadioButton::adjustSize(), Button::adjustSize(), TextBox::adjustSize(), BrowserBox::calcHeight(), Actions::doSit(), ColorPage::draw(), ExtendedListBox::draw(), ServersListBox::draw(), ItemShortcutContainer::draw(), VirtShortcutContainer::draw(), EquipmentWindow::draw(), ItemContainer::draw(), ProgressBar::draw(), SkillListBox::draw(), TextPreview::draw(), ListBox::draw(), TextBox::draw(), Label::draw(), TextField::draw(), Window::draw(), SkillRectangleListBox::draw(), Gui::draw(), Button::draw(), Viewport::drawPath(), TouchManager::drawText(), TextField::fixScroll(), SliderList::getMaxLabelWidth(), SetupItemSlider2::getMaxWidth(), getStringIndexAt(), InventoryWindow::InventoryWindow(), Label::Label(), NpcDialog::NpcDialog(), OkDialog::OkDialog(), ConfirmDialog::postInit(), Label::resizeTo(), ItemShortcutContainer::safeDraw(), VirtShortcutContainer::safeDraw(), EquipmentWindow::safeDraw(), ItemContainer::safeDraw(), ProgressBar::safeDraw(), Window::safeDraw(), Button::safeDraw(), TextBox::scrollToCaret(), TextBox::setTextWrapped(), Setup_Colors::Setup_Colors(), ServersListModel::setVersionString(), SkillRectangleListBox::SkillRectangleListBox(), TextDialog::TextDialog(), TradeWindow::TradeWindow(), and StaticBrowserBox::updateHeight().

334 {
335  if (text.empty())
336  return 0;
337 
338  const unsigned char chr = text[0];
339  TextChunkList *const cache = &mCache[chr];
340 
341  std::map<std::string, TextChunk*> &search = cache->searchWidth;
342  std::map<std::string, TextChunk*>::iterator i = search.find(text);
343  if (i != search.end())
344  {
345  TextChunk *const chunk = (*i).second;
346  cache->moveToFirst(chunk);
347  const Image *const image = chunk->img;
348  if (image != nullptr)
349  return image->getWidth();
350  return 0;
351  }
352 
353  // if string was not drawed
354  int w, h;
355  getSafeUtf8String(text, strBuf);
356  TTF_SizeUTF8(mFont, strBuf, &w, &h);
357  return w;
358 }
TextChunkList mCache[CACHES_NUMBER]
Definition: font.h:151
const char * getSafeUtf8String(const std::string &text)
TTF_Font * mFont
Definition: font.h:145
char * strBuf
Definition: textchunk.cpp:45
std::map< std::string, TextChunk * > searchWidth
Definition: textchunklist.h:57
Image * img
Definition: textchunk.h:62
Definition: image.h:61
int getWidth() const A_INLINE
Definition: image.h:116
void moveToFirst(TextChunk *const item)

◆ insertChunk()

void Font::insertChunk ( TextChunk *const  chunk)

Definition at line 476 of file font.cpp.

References TextChunk::color, TextChunk::color2, delete2, TextChunk::img, TextChunkList::insertFirst(), mCache, TextChunkList::search, TextChunk::text, and TextChunk::textFont.

Referenced by TextChunk::deleteImage(), and getDeleteCounter().

477 {
478  if ((chunk == nullptr) || chunk->text.empty() || (chunk->img == nullptr))
479  return;
480 // logger->log("insert chunk: text=%s, color: %d,%d,%d",
481 // chunk->text.c_str(), chunk->color.r, chunk->color.g, chunk->color.b);
482  const unsigned char chr = chunk->text[0];
483  TextChunkList *const cache = &mCache[chr];
484 
485  std::map<TextChunkSmall, TextChunk*> &search = cache->search;
486  std::map<TextChunkSmall, TextChunk*>::iterator i
487  = search.find(TextChunkSmall(chunk->text,
488  chunk->color, chunk->color2));
489  if (i != search.end())
490  {
491  delete2(chunk->img);
492  return;
493  }
494 
495  TextChunk *const chunk2 = new TextChunk(chunk->text,
496  chunk->color, chunk->color2, chunk->textFont);
497  chunk2->img = chunk->img;
498  cache->insertFirst(chunk2);
499 }
std::string text
Definition: textchunk.h:64
#define delete2(var)
Definition: delete2.h:24
Font * textFont
Definition: textchunk.h:63
std::map< TextChunkSmall, TextChunk * > search
Definition: textchunklist.h:56
TextChunkList mCache[CACHES_NUMBER]
Definition: font.h:151
Image * img
Definition: textchunk.h:62
Color color
Definition: textchunk.h:65
void insertFirst(TextChunk *const item)
Color color2
Definition: textchunk.h:66

◆ loadFont()

void Font::loadFont ( std::string  filename,
const int  size,
const int  style 
)

Definition at line 218 of file font.cpp.

References clear(), fixDirSeparators(), ServerCommandType::font, fontCounter, Logger::log(), logger, mFont, openFont(), and ServerCommandType::size.

Referenced by Gui::updateFonts().

221 {
222  if (fontCounter == 0 && TTF_Init() == -1)
223  {
224  logger->log("Unable to initialize SDL_ttf: " +
225  std::string(SDL_GetError()));
226  return;
227  }
228 
229  fixDirSeparators(filename);
230  TTF_Font *const font = openFont(filename.c_str(), size);
231 
232  if (font == nullptr)
233  {
234  logger->log("Font::Font: " +
235  std::string(SDL_GetError()));
236  return;
237  }
238 
239  if (mFont != nullptr)
240  TTF_CloseFont(mFont);
241 
242  mFont = font;
243  TTF_SetFontStyle(mFont, style);
244  clear();
245 }
static int fontCounter
Definition: font.cpp:103
static TTF_Font * openFont(const char *const name, const int size)
Definition: font.cpp:190
void clear()
Definition: font.cpp:247
Logger * logger
Definition: logger.cpp:95
TTF_Font * mFont
Definition: font.h:145
std::string & fixDirSeparators(std::string &str)
Definition: paths.cpp:129
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ openFont()

TTF_Font * Font::openFont ( const char *const  name,
const int  size 
)
staticprivate

Definition at line 190 of file font.cpp.

References Files::existsLocal(), VirtFs::getPath(), Logger::log(), logger, reportAlways, VirtFs::rwopsOpenRead(), and ServerCommandType::size.

Referenced by Font(), and loadFont().

192 {
193 #ifdef USE_SDL2
194  SDL_RWops *const rw = VirtFs::rwopsOpenRead(name);
195  if (rw)
196  {
197  logger->log("Loading virtfs font file: %s",
198  name);
199  return TTF_OpenFontIndexRW(rw, 1, size, 0);
200  }
201 #endif
202  const std::string path = VirtFs::getPath(name);
203  if (Files::existsLocal(path) == false)
204  {
205 #ifndef UNITTESTS
206  // +++ in future need trigger assert in unit tests here too
207  reportAlways("Font::openFont font not exists: %s",
208  path.c_str());
209 #endif // UNITTESTS
210  return nullptr;
211  }
212  logger->log("Loading physical font file: %s",
213  path.c_str());
214  return TTF_OpenFontIndex(path.c_str(),
215  size, 0);
216 }
SDL_RWops * rwopsOpenRead(const std::string &fname)
Definition: rwops.cpp:104
Logger * logger
Definition: logger.cpp:95
std::string getPath(const std::string &file)
Definition: tools.cpp:96
bool existsLocal(const std::string &path)
Definition: files.cpp:207
void log(const char *const log_text,...)
Definition: logger.cpp:243
#define reportAlways(...)
Definition: checkutils.h:252

◆ slowLogic()

void Font::slowLogic ( const int  rnd)

Definition at line 318 of file font.cpp.

References BLOCK_END, BLOCK_START, cur_time, doClean(), and mCleanTime.

Referenced by Gui::slowLogic().

319 {
320  BLOCK_START("Font::slowLogic")
321  if (mCleanTime == 0)
322  {
323  mCleanTime = cur_time + CLEAN_TIME + rnd;
324  }
325  else if (mCleanTime < cur_time)
326  {
327  doClean();
328  mCleanTime = cur_time + CLEAN_TIME + rnd;
329  }
330  BLOCK_END("Font::slowLogic")
331 }
void doClean()
Definition: font.cpp:365
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
volatile time_t cur_time
Definition: timer.cpp:57
const unsigned int CLEAN_TIME
Definition: font.cpp:97
time_t mCleanTime
Definition: font.h:150

Field Documentation

◆ mCache

TextChunkList Font::mCache[CACHES_NUMBER]
mutableprivate

Definition at line 151 of file font.h.

Referenced by clear(), doClean(), drawString(), generate(), getCache(), getWidth(), and insertChunk().

◆ mCleanTime

time_t Font::mCleanTime
private

Definition at line 150 of file font.h.

Referenced by slowLogic().

◆ mCreateCounter

unsigned int Font::mCreateCounter
private

Definition at line 146 of file font.h.

Referenced by drawString(), generate(), and getCreateCounter().

◆ mDeleteCounter

unsigned int Font::mDeleteCounter
private

Definition at line 147 of file font.h.

Referenced by doClean(), drawString(), generate(), and getDeleteCounter().

◆ mFont

TTF_Font* Font::mFont
private

Definition at line 145 of file font.h.

Referenced by drawString(), Font(), generate(), getHeight(), getWidth(), loadFont(), and ~Font().

◆ mSoftMode

bool Font::mSoftMode
static

Definition at line 139 of file font.h.

Referenced by Font(), and TextChunkSmall::operator<().


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