- patch from Nebososo for 2 byte characters and font widths

This commit is contained in:
Mark Vejvoda 2011-01-11 19:03:41 +00:00
parent a7f6a592ff
commit 9acbfb9d19

View File

@ -3,9 +3,9 @@
// //
// Copyright (C) 2001-2007 Martio Figueroa // Copyright (C) 2001-2007 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the // by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version // License, or (at your option) any later version
// ============================================================== // ==============================================================
@ -26,28 +26,35 @@ std::string Font::fontTypeName = "Times New Roman";
// class FontMetrics // class FontMetrics
// ===================================================== // =====================================================
FontMetrics::FontMetrics(){ FontMetrics::FontMetrics() {
widths= new float[Font::charCount]; widths= new float[Font::charCount];
height= 0; height= 0;
for(int i=0; i<Font::charCount; ++i){ for(int i=0; i < Font::charCount; ++i) {
widths[i]= 0; widths[i]= 0;
} }
} }
FontMetrics::~FontMetrics(){ FontMetrics::~FontMetrics() {
delete [] widths; delete [] widths;
widths = NULL; widths = NULL;
} }
float FontMetrics::getTextWidth(const string &str) const{ float FontMetrics::getTextWidth(const string &str) const {
float width= 0.f; float width= 0.f;
for(unsigned int i=0; i< str.size() && (int)i < Font::charCount; ++i){ for(unsigned int i=0; i< str.size() && (int)i < Font::charCount; ++i){
if(str[i] >= Font::charCount) { if(str[i] >= Font::charCount) {
string sError = "str[i] >= Font::charCount, [" + str + "] i = " + intToStr(i); string sError = "str[i] >= Font::charCount, [" + str + "] i = " + intToStr(i);
throw runtime_error(sError); throw runtime_error(sError);
} }
width+= widths[str[i]]; //Treat 2 byte characters as spaces
if(str[i] < 0) {
width+= widths[32];
i++;
}
else {
width+= widths[str[i]];
}
} }
return width; return width;
} }