summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-02-15 02:35:06 +0300
committerAndrei Karas <akaras@inbox.ru>2012-02-15 03:04:32 +0300
commit624b07bf0ee70794240135bb403e9dfb879749c4 (patch)
treedf6ced39a2cdd2f46c7d51747abdee168d29a146
parent99bc9d1fb4bccae0785d731711e3b1009de1b394 (diff)
downloadManaVerse-624b07bf0ee70794240135bb403e9dfb879749c4.tar.gz
ManaVerse-624b07bf0ee70794240135bb403e9dfb879749c4.tar.bz2
ManaVerse-624b07bf0ee70794240135bb403e9dfb879749c4.tar.xz
ManaVerse-624b07bf0ee70794240135bb403e9dfb879749c4.zip
Add function to fix dir separator.
-rw-r--r--src/gui/sdlfont.cpp11
-rw-r--r--src/gui/sdlfont.h4
-rw-r--r--src/utils/paths.cpp12
-rw-r--r--src/utils/paths.h2
4 files changed, 23 insertions, 6 deletions
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp
index 0e69db026..7e0114cb8 100644
--- a/src/gui/sdlfont.cpp
+++ b/src/gui/sdlfont.cpp
@@ -27,6 +27,7 @@
#include "graphics.h"
#include "logger.h"
#include "main.h"
+#include "utils/paths.h"
#include "resources/image.h"
#include "resources/resourcemanager.h"
@@ -98,7 +99,7 @@ typedef std::list<SDLTextChunk>::iterator CacheIterator;
static int fontCounter;
-SDLFont::SDLFont(const std::string &filename, int size, int style) :
+SDLFont::SDLFont(std::string filename, int size, int style) :
mCreateCounter(0),
mDeleteCounter(0)
{
@@ -117,13 +118,16 @@ SDLFont::SDLFont(const std::string &filename, int size, int style) :
}
++fontCounter;
+
+ fixDirSeparators(filename);
mFont = TTF_OpenFont(resman->getPath(filename).c_str(), size);
if (!mFont)
{
logger->log("Error finding font " + filename);
+ std::string backFile = "fonts/dejavusans.ttf";
mFont = TTF_OpenFont(resman->getPath(
- "fonts/dejavusans.ttf").c_str(), size);
+ fixDirSeparators(backFile)).c_str(), size);
if (!mFont)
{
throw GCN_EXCEPTION("SDLSDLFont::SDLSDLFont: " +
@@ -148,7 +152,7 @@ SDLFont::~SDLFont()
}
}
-void SDLFont::loadFont(const std::string &filename, int size, int style)
+void SDLFont::loadFont(std::string filename, int size, int style)
{
ResourceManager *resman = ResourceManager::getInstance();
@@ -159,6 +163,7 @@ void SDLFont::loadFont(const std::string &filename, int size, int style)
return;
}
+ fixDirSeparators(filename);
TTF_Font *font = TTF_OpenFont(resman->getPath(filename).c_str(), size);
if (!font)
diff --git a/src/gui/sdlfont.h b/src/gui/sdlfont.h
index 6fcad34d4..77e3761e7 100644
--- a/src/gui/sdlfont.h
+++ b/src/gui/sdlfont.h
@@ -53,14 +53,14 @@ class SDLFont : public gcn::Font
* @param filename Font filename.
* @param size Font size.
*/
- SDLFont(const std::string &filename, int size, int style = 0);
+ SDLFont(std::string filename, int size, int style = 0);
/**
* Destructor.
*/
~SDLFont();
- void loadFont(const std::string &filename, int size, int style = 0);
+ void loadFont(std::string filename, int size, int style = 0);
void createSDLTextChunk(SDLTextChunk *chunk);
diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp
index faa1882e6..04f553ca9 100644
--- a/src/utils/paths.cpp
+++ b/src/utils/paths.cpp
@@ -20,10 +20,12 @@
#include "utils/paths.h"
+#include "utils/stringutils.h"
+
#include <string.h>
#include <cstdarg>
#include <cstdio>
-
+#include <physfs.h>
#include <stdlib.h>
#ifdef WIN32
@@ -65,3 +67,11 @@ bool checkPath(std::string path)
&& path.find("/..") == std::string::npos
&& path.find("\\..") == std::string::npos;
}
+
+std::string &fixDirSeparators(std::string &str)
+{
+ if (*PHYSFS_getDirSeparator() == '/')
+ return str;
+
+ return replaceAll(str, "/", "\\");
+}
diff --git a/src/utils/paths.h b/src/utils/paths.h
index f92fcdcb5..b89671adc 100644
--- a/src/utils/paths.h
+++ b/src/utils/paths.h
@@ -29,4 +29,6 @@ bool isRealPath(const std::string &str);
bool checkPath(std::string path);
+std::string &fixDirSeparators(std::string &str);
+
#endif // UTILS_PATHS_H