Date:2014-07-18 04:26:48 (2 months 12 days ago)
Author:Maarten ter Huurne
Commit:5c7ca19f4bbdd32d7c60b725510649805f74f10f
Message:Don't issue warnings when rendering empty string

Files: src/font.cpp (4 diffs)
src/font.h (1 diff)

Change Details

src/font.cpp
6767    }
6868
6969    if (text.find("\n", 0) == string::npos) {
70        writeLine(surface, text.c_str(), x, y, halign, valign);
70        writeLine(surface, text, x, y, halign, valign);
7171        return;
7272    }
7373
...... 
7575    split(v, text, "\n");
7676
7777    for (vector<string>::const_iterator it = v.begin(); it != v.end(); it++) {
78        writeLine(surface, it->c_str(), x, y, halign, valign);
78        writeLine(surface, *it, x, y, halign, valign);
7979        y += lineSpacing;
8080    }
8181}
8282
83void Font::writeLine(Surface *surface, const char *text,
83void Font::writeLine(Surface *surface, std::string const& text,
8484                int x, int y, HAlign halign, VAlign valign)
8585{
8686    if (!font) {
8787        return;
8888    }
89    if (text.empty()) {
90        // SDL_ttf will return a nullptr when rendering the empty string.
91        return;
92    }
8993
9094    switch (valign) {
9195    case VAlignTop:
...... 
99103    }
100104
101105    SDL_Color color = { 0, 0, 0, 0 };
102    SDL_Surface *s = TTF_RenderUTF8_Blended(font, text, color);
106    SDL_Surface *s = TTF_RenderUTF8_Blended(font, text.c_str(), color);
103107    if (!s) {
104        ERROR("Font rendering failed for text \"%s\"\n", text);
108        ERROR("Font rendering failed for text \"%s\"\n", text.c_str());
105109        return;
106110    }
107111
...... 
140144    color.g = 0xff;
141145    color.b = 0xff;
142146
143    s = TTF_RenderUTF8_Blended(font, text, color);
147    s = TTF_RenderUTF8_Blended(font, text.c_str(), color);
144148    if (!s) {
145        ERROR("Font rendering failed for text \"%s\"\n", text);
149        ERROR("Font rendering failed for text \"%s\"\n", text.c_str());
146150        return;
147151    }
148152    SDL_BlitSurface(s, NULL, surface->raw, &rect);
src/font.h
4141private:
4242    Font(TTF_Font *font);
4343
44    void writeLine(Surface *surface, const char *text,
44    void writeLine(Surface *surface, std::string const& text,
4545                int x, int y, HAlign halign, VAlign valign);
4646
4747    TTF_Font *font;

Archive Download the corresponding diff file



interactive