2010-04-13 09:29:48 +02:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest Shared Library (www.glest.org)
|
|
|
|
//
|
2010-08-05 02:48:46 +02:00
|
|
|
// Copyright (C) 2001-2007 Martio Figueroa
|
2010-04-13 09:29:48 +02:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#include "font.h"
|
2010-08-05 02:48:46 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
#include "conversion.h"
|
2010-04-13 09:29:48 +02:00
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
2010-08-05 02:48:46 +02:00
|
|
|
using namespace std;
|
|
|
|
using namespace Shared::Util;
|
|
|
|
|
2010-04-13 09:29:48 +02:00
|
|
|
namespace Shared{ namespace Graphics{
|
|
|
|
|
2010-08-05 02:48:46 +02:00
|
|
|
int Font::charCount= 256;
|
|
|
|
std::string Font::fontTypeName = "Times New Roman";
|
|
|
|
|
2010-04-13 09:29:48 +02:00
|
|
|
// =====================================================
|
|
|
|
// class FontMetrics
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
FontMetrics::FontMetrics(){
|
|
|
|
widths= new float[Font::charCount];
|
|
|
|
height= 0;
|
|
|
|
|
|
|
|
for(int i=0; i<Font::charCount; ++i){
|
|
|
|
widths[i]= 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FontMetrics::~FontMetrics(){
|
|
|
|
delete [] widths;
|
2010-08-05 02:48:46 +02:00
|
|
|
widths = NULL;
|
2010-04-13 09:29:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
float FontMetrics::getTextWidth(const string &str) const{
|
|
|
|
float width= 0.f;
|
2010-10-21 09:20:17 +02:00
|
|
|
for(unsigned int i=0; i< str.size() && (int)i < Font::charCount; ++i){
|
2010-08-05 02:48:46 +02:00
|
|
|
if(str[i] >= Font::charCount) {
|
|
|
|
string sError = "str[i] >= Font::charCount, [" + str + "] i = " + intToStr(i);
|
|
|
|
throw runtime_error(sError);
|
|
|
|
}
|
2010-04-13 09:29:48 +02:00
|
|
|
width+= widths[str[i]];
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
float FontMetrics::getHeight() const{
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ===============================================
|
|
|
|
// class Font
|
|
|
|
// ===============================================
|
|
|
|
|
|
|
|
Font::Font(){
|
|
|
|
inited= false;
|
2010-05-03 08:16:32 +02:00
|
|
|
type= fontTypeName;
|
2010-04-13 09:29:48 +02:00
|
|
|
width= 400;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ===============================================
|
|
|
|
// class Font2D
|
|
|
|
// ===============================================
|
|
|
|
|
|
|
|
Font2D::Font2D(){
|
|
|
|
size= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ===============================================
|
|
|
|
// class Font3D
|
|
|
|
// ===============================================
|
|
|
|
|
|
|
|
Font3D::Font3D(){
|
|
|
|
depth= 10.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
}}//end namespace
|