wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src font.cpp


From: Jon Daniel
Subject: [Wesnoth-cvs-commits] wesnoth/src font.cpp
Date: Mon, 08 Aug 2005 07:54:37 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Jon Daniel <address@hidden>     05/08/08 11:54:36

Modified files:
        src            : font.cpp 

Log message:
        cleaned up font initialization may have fixed a memory leak.
        make zip-install doesn't zip the fonts dir so we don't need to care 
about zipios there.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.148&tr2=1.149&r1=text&r2=text

Patches:
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.148 wesnoth/src/font.cpp:1.149
--- wesnoth/src/font.cpp:1.148  Sun Aug  7 22:15:44 2005
+++ wesnoth/src/font.cpp        Mon Aug  8 11:54:36 2005
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.148 2005/08/07 22:15:44 j_daniel Exp $ */
+/* $Id: font.cpp,v 1.149 2005/08/08 11:54:36 j_daniel Exp $ */
 /* vim:set encoding=utf-8: */
 /*
    Copyright (C) 2003 by David White <address@hidden>
@@ -141,52 +141,29 @@
 TTF_Font* open_font(const std::string& fname, int size)
 {
        std::string name;
-
-       LOG_FT << "Opening font '" << fname << "' ...\n";
-#ifndef USE_ZIPIOS
-       if(game_config::path.empty() == false) {
+       if(!game_config::path.empty()) {
                name = game_config::path + "/fonts/" + fname;
-               LOG_FT << "Trying file '" << name << "' ...\n";
-
-               if (!file_exists(name)) {
-                       name = "fonts/" + fname;
-                       WRN_FT << "Failed opening '" << name << "'; now trying 
'" << name << "' ...\n";
-                       if (!file_exists(name)) {
-                               ERR_FT << "Failed opening font: " << fname << 
"\n";
-                               return NULL;
-                       }
+               if(!file_exists(name)) {
+                       ERR_FT << "Failed opening font: '" << name << "': No 
such file or directory\n";
+                       return NULL;
                }
        } else {
                name = "fonts/" + fname;
-               LOG_FT << "Trying file '" << name << "' ...\n";
-
                if(!file_exists(name)) {
-                       ERR_FT << "Failed opening font '" << fname << "'\n";
-                       return NULL;
+                       if(!file_exists(fname)) {
+                               ERR_FT << "Failed opening font: '" << name << 
"': No such file or directory\n";
+                               return NULL;
+                       }
+                       name = fname;
                }
        }
 
-       LOG_FT << "Opening font file '" << name << "', font size is " << size 
<< "\n";
-
        TTF_Font* font = TTF_OpenFont(name.c_str(),size);
-#else
-       std::string tmp = read_file("fonts/" + fname);
-       if (tmp.empty()) {
-               ERR_FT << "Failed opening font file '" << fname << "'\n";
-               return NULL;
-       }
-       // the following statement would leak memory if fonts were closed
-       std::string *s = new std::string(tmp);
-       SDL_RWops* ops = SDL_RWFromMem((void*)s->c_str(), s->size());
-       TTF_Font* font = TTF_OpenFontRW(ops, 0, size);
-#endif
        if(font == NULL) {
-               ERR_FT << "Failed opening font file '" << name << "'\n";
+               ERR_FT << "Failed opening font: TTF_OpenFont: " << 
TTF_GetError() << "\n";
                return NULL;
        }
 
-       LOG_FT << "Opened font okay\n";
-
        return font;
 }
 
@@ -293,27 +270,22 @@
 
        std::vector<subset_descriptor>::const_iterator itor;
        for(itor = fontlist.begin(); itor != fontlist.end(); ++itor) {
-               const subset_id subset = font_names.size();
                // Insert fonts only if the font file exists
-#ifndef USE_ZIPIOS
                if(game_config::path.empty() == false) {
-                       if(file_exists(game_config::path + "/fonts/" + 
itor->name)) {
-                               font_names.push_back(itor->name);
+                       if(!file_exists(game_config::path + "/fonts/" + 
itor->name)) {
+                               WRN_FT << "Failed opening font file '" << 
itor->name << "': No such file or directory\n";
+                               continue;
                        }
                } else {
-                       if(file_exists("fonts/" + itor->name)) {
-                               font_names.push_back(itor->name);
+                       if(!file_exists("fonts/" + itor->name)) {
+                               if(!file_exists(itor->name)) {
+                                       WRN_FT << "Failed opening font file '" 
<< itor->name << "': No such file or directory\n";
+                                       continue;
+                               }
                        }
                }
-#else
-               if (!read_file("fonts/" + itor->name).empty()) {
-                       font_names.push_back(itor->name);
-               }
-#endif
-               if(font_names.back() != itor->name) {
-                       WRN_FT << "Failed opening font file '" << itor->name << 
"'\n";
-                       continue;
-               }
+               const subset_id subset = font_names.size();
+               font_names.push_back(itor->name);
 
                std::vector<std::pair<size_t,size_t> >::const_iterator cp_range;
                for(cp_range = itor->present_codepoints.begin();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]