mirror of
https://github.com/glest/glest-source.git
synced 2025-08-26 17:34:24 +02:00
- fixing crash on client connect screen
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2007 Marti<EFBFBD>o Figueroa
|
||||
// Copyright (C) 2001-2007 Martio Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
@@ -10,11 +10,18 @@
|
||||
// ==============================================================
|
||||
|
||||
#include "font.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include "conversion.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Shared::Util;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
int Font::charCount= 256;
|
||||
std::string Font::fontTypeName = "Times New Roman";
|
||||
|
||||
// =====================================================
|
||||
// class FontMetrics
|
||||
// =====================================================
|
||||
@@ -30,11 +37,16 @@ FontMetrics::FontMetrics(){
|
||||
|
||||
FontMetrics::~FontMetrics(){
|
||||
delete [] widths;
|
||||
widths = NULL;
|
||||
}
|
||||
|
||||
float FontMetrics::getTextWidth(const string &str) const{
|
||||
float width= 0.f;
|
||||
for(unsigned int i=0; i<str.size(); ++i){
|
||||
for(unsigned int i=0; i< str.size() && i < Font::charCount; ++i){
|
||||
if(str[i] >= Font::charCount) {
|
||||
string sError = "str[i] >= Font::charCount, [" + str + "] i = " + intToStr(i);
|
||||
throw runtime_error(sError);
|
||||
}
|
||||
width+= widths[str[i]];
|
||||
}
|
||||
return width;
|
||||
@@ -48,9 +60,6 @@ float FontMetrics::getHeight() const{
|
||||
// class Font
|
||||
// ===============================================
|
||||
|
||||
int Font::charCount= 256;
|
||||
std::string Font::fontTypeName = "Times New Roman";
|
||||
|
||||
Font::Font(){
|
||||
inited= false;
|
||||
type= fontTypeName;
|
||||
|
Reference in New Issue
Block a user