Font: Open TTF font as late as possible
This reduces opened fonts that were never going to be used anyway.
This commit is contained in:
		
							parent
							
								
									857693d4a1
								
							
						
					
					
						commit
						d93c1280aa
					
				
					 1 changed files with 12 additions and 7 deletions
				
			
		
							
								
								
									
										19
									
								
								src/font.cpp
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								src/font.cpp
									
										
									
									
									
								
							| 
						 | 
					@ -146,6 +146,9 @@ struct FontPrivate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static Color defaultColorTmp;
 | 
						static Color defaultColorTmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* The actual font is opened as late as possible
 | 
				
			||||||
 | 
						 * (when it is queried by a Bitmap), prior it is
 | 
				
			||||||
 | 
						 * set to null */
 | 
				
			||||||
	TTF_Font *sdlFont;
 | 
						TTF_Font *sdlFont;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	FontPrivate(const char *name = 0,
 | 
						FontPrivate(const char *name = 0,
 | 
				
			||||||
| 
						 | 
					@ -155,11 +158,9 @@ struct FontPrivate
 | 
				
			||||||
	      bold(defaultBold),
 | 
						      bold(defaultBold),
 | 
				
			||||||
	      italic(defaultItalic),
 | 
						      italic(defaultItalic),
 | 
				
			||||||
	      color(&colorTmp),
 | 
						      color(&colorTmp),
 | 
				
			||||||
	      colorTmp(*defaultColor)
 | 
						      colorTmp(*defaultColor),
 | 
				
			||||||
	{
 | 
						      sdlFont(0)
 | 
				
			||||||
		sdlFont = shState->fontPool().request(this->name.c_str(),
 | 
						{}
 | 
				
			||||||
		                                      this->size);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	FontPrivate(const FontPrivate &other)
 | 
						FontPrivate(const FontPrivate &other)
 | 
				
			||||||
	    : name(other.name),
 | 
						    : name(other.name),
 | 
				
			||||||
| 
						 | 
					@ -214,7 +215,7 @@ void Font::setName(const char *value)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	p->name = value;
 | 
						p->name = value;
 | 
				
			||||||
	p->sdlFont = shState->fontPool().request(value, p->size);
 | 
						p->sdlFont = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Font::setSize(int value)
 | 
					void Font::setSize(int value)
 | 
				
			||||||
| 
						 | 
					@ -223,7 +224,7 @@ void Font::setSize(int value)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	p->size = value;
 | 
						p->size = value;
 | 
				
			||||||
	p->sdlFont = shState->fontPool().request(p->name.c_str(), value);
 | 
						p->sdlFont = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#undef CHK_DISP
 | 
					#undef CHK_DISP
 | 
				
			||||||
| 
						 | 
					@ -251,6 +252,10 @@ void Font::setDefaultName(const char *value)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_TTF_Font *Font::getSdlFont()
 | 
					_TTF_Font *Font::getSdlFont()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (!p->sdlFont)
 | 
				
			||||||
 | 
							p->sdlFont = shState->fontPool().request(p->name.c_str(),
 | 
				
			||||||
 | 
							                                         p->size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int style = TTF_STYLE_NORMAL;
 | 
						int style = TTF_STYLE_NORMAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (p->bold)
 | 
						if (p->bold)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue