Removed more unnecessary tabs in blank lines

This commit is contained in:
Alexander Szpakowski
2013-01-07 07:11:40 -04:00
parent eb98e8cc48
commit e5388ff73b
7 changed files with 90 additions and 98 deletions
+50 -58
View File
@@ -49,12 +49,10 @@ Font::Font(love::font::Rasterizer *r, const Image::Filter &filter)
, mSpacing(1)
, filter(filter)
{
r->retain();
love::font::GlyphData *gd = r->getGlyphData(32);
type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
delete gd;
// try to find the best texture size match for the font size
// default to the largest texture size if no rough match is found
texture_size_index = NUM_TEXTURE_SIZES - 1;
@@ -68,19 +66,13 @@ Font::Font(love::font::Rasterizer *r, const Image::Filter &filter)
break;
}
}
texture_width = TEXTURE_WIDTHS[texture_size_index];
texture_height = TEXTURE_HEIGHTS[texture_size_index];
try
{
createTexture();
}
catch (love::Exception &e)
{
r->release();
throw;
}
createTexture();
r->retain();
}
Font::~Font()
@@ -92,10 +84,10 @@ Font::~Font()
bool Font::initializeTexture(GLint format)
{
GLint internalformat = (format == GL_LUMINANCE_ALPHA) ? GL_LUMINANCE8_ALPHA8 : GL_RGBA8;
// clear errors before initializing
while (glGetError() != GL_NO_ERROR);
glTexImage2D(GL_TEXTURE_2D,
0,
internalformat,
@@ -105,49 +97,49 @@ bool Font::initializeTexture(GLint format)
format,
GL_UNSIGNED_BYTE,
NULL);
return glGetError() == GL_NO_ERROR;
}
void Font::createTexture()
{
texture_x = texture_y = rowHeight = TEXTURE_PADDING;
GLuint t;
glGenTextures(1, &t);
textures.push_back(t);
bindTexture(t);
setTextureFilter(filter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GLint format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
// try to initialize the texture, attempting smaller sizes if initialization fails
bool initialized = false;
while (texture_size_index >= 0)
{
texture_width = TEXTURE_WIDTHS[texture_size_index];
texture_height = TEXTURE_HEIGHTS[texture_size_index];
initialized = initializeTexture(format);
if (initialized || texture_size_index <= 0)
break;
--texture_size_index;
}
if (!initialized)
{
// cleanup before throwing
deleteTexture(t);
bindTexture(0);
textures.pop_back();
throw love::Exception("Could not create font texture!");
}
@@ -183,17 +175,17 @@ Font::Glyph *Font::addGlyph(const int glyph)
}
Glyph *g = new Glyph;
g->texture = 0;
g->spacing = gd->getAdvance();
memset(&g->quad, 0, sizeof(GlyphQuad));
// don't waste space for empty glyphs. also fixes a division by zero bug with ati drivers
if (w > 0 && h > 0)
{
const GLuint t = textures.back();
bindTexture(t);
glTexSubImage2D(GL_TEXTURE_2D,
0,
@@ -211,10 +203,10 @@ Font::Glyph *Font::addGlyph(const int glyph)
v.y = (float) texture_y;
v.w = (float) w;
v.h = (float) h;
Quad q = Quad(v, (const float) texture_width, (const float) texture_height);
const vertex *verts = q.getVertices();
// copy vertex data to the glyph and set proper bearing
for (int i = 0; i < 4; i++)
{
@@ -230,9 +222,9 @@ Font::Glyph *Font::addGlyph(const int glyph)
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
delete gd;
glyphs[glyph] = g;
return g;
}
@@ -241,7 +233,7 @@ Font::Glyph *Font::findGlyph(const int glyph)
Glyph *g = glyphs[glyph];
if (!g)
g = addGlyph(glyph);
return g;
}
@@ -254,15 +246,15 @@ void Font::print(const std::string &text, float x, float y, float letter_spacing
{
float dx = 0.0f; // spacing counter for newline handling
float dy = 0.0f;
// keeps track of when we need to switch textures in our vertex array
std::vector<GlyphArrayDrawInfo> glyphinfolist;
std::vector<GlyphQuad> glyphquads;
glyphquads.reserve(text.size()); // pre-allocate space for the maximum possible number of quads
int quadindex = 0;
glPushMatrix();
Matrix t;
@@ -273,11 +265,11 @@ void Font::print(const std::string &text, float x, float y, float letter_spacing
{
utf8::iterator<std::string::const_iterator> i(text.begin(), text.begin(), text.end());
utf8::iterator<std::string::const_iterator> end(text.end(), text.begin(), text.end());
while (i != end)
{
int g = *i++;
if (g == '\n')
{
// wrap newline, but do not print it
@@ -285,27 +277,27 @@ void Font::print(const std::string &text, float x, float y, float letter_spacing
dx = 0.0f;
continue;
}
Glyph *glyph = findGlyph(g);
// we only care about the vertices of glyphs which have a texture
if (glyph->texture != 0)
{
// copy glyphquad (4 vertices) from original glyph to our current quad list
glyphquads.push_back(glyph->quad);
// 1.25 is magic line height for true type fonts
float lineheight = (type == FONT_TRUETYPE) ? floor(getHeight() / 1.25f + 0.5f) : 0.0f;
// set proper relative position
for (int i = 0; i < 4; i++)
{
glyphquads[quadindex].vertices[i].x += dx;
glyphquads[quadindex].vertices[i].y += dy + lineheight;
}
size_t listsize = glyphinfolist.size();
// check if current glyph texture has changed since the previous iteration
if (listsize == 0 || glyphinfolist[listsize-1].texture != glyph->texture)
{
@@ -316,11 +308,11 @@ void Font::print(const std::string &text, float x, float y, float letter_spacing
glyphdrawinfo.texture = glyph->texture;
glyphinfolist.push_back(glyphdrawinfo);
}
++quadindex;
++glyphinfolist[glyphinfolist.size()-1].numquads;
}
// advance the x position for the next glyph
dx += glyph->spacing + letter_spacing;
}
@@ -337,32 +329,32 @@ void Font::print(const std::string &text, float x, float y, float letter_spacing
}
if (quadindex > 0 && glyphinfolist.size() > 0)
{
{
// sort glyph draw info list by texture first, and quad position in memory second (using the struct's < operator)
std::sort(glyphinfolist.begin(), glyphinfolist.end());
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&glyphquads[0].vertices[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&glyphquads[0].vertices[0].s);
// we need to draw a new vertex array for every section of the string that uses a different texture than the previous section
std::vector<GlyphArrayDrawInfo>::const_iterator it;
for (it = glyphinfolist.begin(); it != glyphinfolist.end(); ++it)
{
bindTexture(it->texture);
int startvertex = it->startquad * 4;
int numvertices = it->numquads * 4;
glDrawArrays(GL_QUADS, startvertex, numvertices);
}
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
glPopMatrix();
}
@@ -510,7 +502,7 @@ Image::Filter Font::getFilter()
bindTexture(*it);
return getTextureFilter();
}
return Image::getDefaultFilter();
}