2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** filesystem.cpp
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** mkxp is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** mkxp is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "filesystem.h"
|
|
|
|
|
2014-07-23 20:57:39 +00:00
|
|
|
#include "rgssad.h"
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
#include "font.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "exception.h"
|
2014-08-29 01:33:46 +00:00
|
|
|
#include "sharedstate.h"
|
2013-12-11 19:46:54 +00:00
|
|
|
#include "boost-hash.h"
|
|
|
|
#include "debugwriter.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-12-04 16:48:37 +00:00
|
|
|
#include <physfs.h>
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-11-30 11:00:11 +00:00
|
|
|
#include <SDL_sound.h>
|
|
|
|
|
2013-12-04 16:48:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2013-12-08 12:19:22 +00:00
|
|
|
#include <algorithm>
|
2013-12-26 19:18:33 +00:00
|
|
|
#include <vector>
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-08-19 14:57:03 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <iconv.h>
|
|
|
|
#endif
|
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
static inline PHYSFS_File *sdlPHYS(SDL_RWops *ops)
|
|
|
|
{
|
|
|
|
return static_cast<PHYSFS_File*>(ops->hidden.unknown.data1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Sint64 SDL_RWopsSize(SDL_RWops *ops)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return PHYSFS_fileLength(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Sint64 SDL_RWopsSeek(SDL_RWops *ops, int64_t offset, int whence)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
int64_t base;
|
|
|
|
|
|
|
|
switch (whence)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case RW_SEEK_SET :
|
|
|
|
base = 0;
|
|
|
|
break;
|
|
|
|
case RW_SEEK_CUR :
|
|
|
|
base = PHYSFS_tell(f);
|
|
|
|
break;
|
|
|
|
case RW_SEEK_END :
|
|
|
|
base = PHYSFS_fileLength(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = PHYSFS_seek(f, base + offset);
|
|
|
|
|
|
|
|
return (result != 0) ? PHYSFS_tell(f) : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t SDL_RWopsRead(SDL_RWops *ops, void *buffer, size_t size, size_t maxnum)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
PHYSFS_sint64 result = PHYSFS_readBytes(f, buffer, size*maxnum);
|
|
|
|
|
|
|
|
return (result != -1) ? (result / size) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t SDL_RWopsWrite(SDL_RWops *ops, const void *buffer, size_t size, size_t num)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
PHYSFS_sint64 result = PHYSFS_writeBytes(f, buffer, size*num);
|
|
|
|
|
|
|
|
return (result != -1) ? (result / size) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SDL_RWopsClose(SDL_RWops *ops)
|
|
|
|
{
|
|
|
|
PHYSFS_File *f = sdlPHYS(ops);
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
int result = PHYSFS_close(f);
|
|
|
|
|
|
|
|
return (result != 0) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SDL_RWopsCloseFree(SDL_RWops *ops)
|
|
|
|
{
|
|
|
|
int result = SDL_RWopsClose(ops);
|
|
|
|
|
|
|
|
SDL_FreeRW(ops);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Uint32 SDL_RWOPS_PHYSFS = SDL_RWOPS_UNKNOWN+10;
|
|
|
|
|
2013-11-30 11:00:11 +00:00
|
|
|
struct FileSystemPrivate
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
/* Maps: lower case filename, To: actual (mixed case) filename.
|
|
|
|
* This is for compatibility with games that take Windows'
|
|
|
|
* case insensitivity for granted */
|
2013-12-11 19:46:54 +00:00
|
|
|
BoostHash<std::string, std::string> pathCache;
|
2014-01-16 03:19:22 +00:00
|
|
|
bool havePathCache;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-01-01 06:07:18 +00:00
|
|
|
std::vector<std::string> extensions[FileSystem::Undefined+1];
|
|
|
|
|
2013-11-30 11:00:11 +00:00
|
|
|
/* Attempt to locate an extension string in a filename.
|
|
|
|
* Either a pointer into the input string pointing at the
|
|
|
|
* extension, or null is returned */
|
|
|
|
const char *findExt(const char *filename)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
size_t len;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-11-30 11:00:11 +00:00
|
|
|
for (len = strlen(filename); len > 0; --len)
|
|
|
|
{
|
|
|
|
if (filename[len] == '/')
|
|
|
|
return 0;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-11-30 11:00:11 +00:00
|
|
|
if (filename[len] == '.')
|
|
|
|
return &filename[len+1];
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-11-30 11:00:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
/* Complete filename via regular physfs lookup */
|
|
|
|
bool completeFilenameReg(const char *filename,
|
|
|
|
FileSystem::FileType type,
|
|
|
|
char *outBuffer,
|
|
|
|
size_t outN,
|
|
|
|
const char **foundExt)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
/* Try supplementing extensions to find an existing path */
|
|
|
|
const std::vector<std::string> &extList = extensions[type];
|
|
|
|
|
|
|
|
for (size_t i = 0; i < extList.size(); ++i)
|
2014-01-01 06:07:18 +00:00
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
const char *ext = extList[i].c_str();
|
2014-01-01 06:07:18 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
snprintf(outBuffer, outN, "%s.%s", filename, ext);
|
2014-01-01 06:07:18 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
if (PHYSFS_exists(outBuffer))
|
2014-01-01 06:07:18 +00:00
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
if (foundExt)
|
|
|
|
*foundExt = ext;
|
2014-01-01 06:07:18 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
return true;
|
2014-01-01 06:07:18 +00:00
|
|
|
}
|
2014-01-16 03:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Doing the check without supplemented extension
|
|
|
|
* fits the usage pattern of RMXP games */
|
|
|
|
if (PHYSFS_exists(filename))
|
|
|
|
{
|
|
|
|
strncpy(outBuffer, filename, outN);
|
2014-01-01 06:07:18 +00:00
|
|
|
|
|
|
|
if (foundExt)
|
2014-01-16 03:19:22 +00:00
|
|
|
*foundExt = findExt(filename);
|
2014-01-01 06:07:18 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
return true;
|
2014-01-01 06:07:18 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Complete filename via path cache */
|
|
|
|
bool completeFilenamePC(const char *filename,
|
|
|
|
FileSystem::FileType type,
|
2014-05-21 16:10:14 +00:00
|
|
|
char *outBuffer,
|
|
|
|
size_t outN,
|
|
|
|
const char **foundExt)
|
2014-01-16 03:19:22 +00:00
|
|
|
{
|
2013-09-30 19:19:43 +00:00
|
|
|
size_t i;
|
2014-01-16 03:19:22 +00:00
|
|
|
char lowCase[512];
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
for (i = 0; i < sizeof(lowCase)-1 && filename[i]; ++i)
|
|
|
|
lowCase[i] = tolower(filename[i]);
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
lowCase[i] = '\0';
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
std::string key;
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
const std::vector<std::string> &extList = extensions[type];
|
|
|
|
|
|
|
|
for (size_t i = 0; i < extList.size(); ++i)
|
2013-11-30 11:00:11 +00:00
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
const char *ext = extList[i].c_str();
|
|
|
|
|
|
|
|
snprintf(outBuffer, outN, "%s.%s", lowCase, ext);
|
|
|
|
key = outBuffer;
|
2013-11-30 11:00:11 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
if (pathCache.contains(key))
|
|
|
|
{
|
|
|
|
strncpy(outBuffer, pathCache[key].c_str(), outN);
|
|
|
|
|
|
|
|
if (foundExt)
|
|
|
|
*foundExt = ext;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-11-30 11:00:11 +00:00
|
|
|
}
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
key = lowCase;
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
if (pathCache.contains(key))
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
strncpy(outBuffer, pathCache[key].c_str(), outN);
|
2013-11-30 11:00:11 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
if (foundExt)
|
|
|
|
*foundExt = findExt(filename);
|
2013-11-30 11:00:11 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
return true;
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-11-30 11:00:11 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
/* Try to complete 'filename' with file extensions
|
|
|
|
* based on 'type'. If no combination could be found,
|
|
|
|
* returns false, and 'foundExt' is untouched */
|
|
|
|
bool completeFileName(const char *filename,
|
|
|
|
FileSystem::FileType type,
|
2014-05-21 16:10:14 +00:00
|
|
|
char *outBuffer,
|
|
|
|
size_t outN,
|
|
|
|
const char **foundExt)
|
2014-01-16 03:19:22 +00:00
|
|
|
{
|
|
|
|
if (havePathCache)
|
|
|
|
return completeFilenamePC(filename, type, outBuffer, outN, foundExt);
|
|
|
|
else
|
|
|
|
return completeFilenameReg(filename, type, outBuffer, outN, foundExt);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
PHYSFS_File *openReadHandle(const char *filename,
|
|
|
|
FileSystem::FileType type,
|
|
|
|
const char **foundExt)
|
2013-09-30 19:19:43 +00:00
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
char found[512];
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
if (!completeFileName(filename, type, found, sizeof(found), foundExt))
|
2014-01-15 00:47:16 +00:00
|
|
|
throw Exception(Exception::NoFileError, "%s", filename);
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
PHYSFS_File *handle = PHYSFS_openRead(found);
|
|
|
|
|
2013-09-30 19:19:43 +00:00
|
|
|
if (!handle)
|
|
|
|
throw Exception(Exception::PHYSFSError, "PhysFS: %s", PHYSFS_getLastError());
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
|
|
|
|
void initReadOps(PHYSFS_File *handle,
|
|
|
|
SDL_RWops &ops,
|
|
|
|
bool freeOnClose)
|
|
|
|
{
|
|
|
|
ops.size = SDL_RWopsSize;
|
|
|
|
ops.seek = SDL_RWopsSeek;
|
|
|
|
ops.read = SDL_RWopsRead;
|
|
|
|
ops.write = SDL_RWopsWrite;
|
|
|
|
|
|
|
|
if (freeOnClose)
|
|
|
|
ops.close = SDL_RWopsCloseFree;
|
|
|
|
else
|
|
|
|
ops.close = SDL_RWopsClose;
|
|
|
|
|
|
|
|
ops.type = SDL_RWOPS_PHYSFS;
|
|
|
|
ops.hidden.unknown.data1 = handle;
|
|
|
|
}
|
2013-09-30 19:19:43 +00:00
|
|
|
};
|
|
|
|
|
2013-10-20 20:38:46 +00:00
|
|
|
FileSystem::FileSystem(const char *argv0,
|
|
|
|
bool allowSymlinks)
|
2013-09-30 19:19:43 +00:00
|
|
|
{
|
|
|
|
p = new FileSystemPrivate;
|
|
|
|
|
2014-01-01 06:07:18 +00:00
|
|
|
p->havePathCache = false;
|
|
|
|
|
2013-11-30 11:00:11 +00:00
|
|
|
/* Image extensions */
|
2013-12-26 19:18:33 +00:00
|
|
|
p->extensions[Image].push_back("jpg");
|
|
|
|
p->extensions[Image].push_back("png");
|
2013-11-30 11:00:11 +00:00
|
|
|
|
|
|
|
/* Audio extensions */
|
|
|
|
const Sound_DecoderInfo **di;
|
|
|
|
for (di = Sound_AvailableDecoders(); *di; ++di)
|
|
|
|
{
|
|
|
|
const char **ext;
|
|
|
|
for (ext = (*di)->extensions; *ext; ++ext)
|
|
|
|
{
|
2013-12-15 09:19:22 +00:00
|
|
|
/* All reported extensions are uppercase,
|
2013-11-30 11:00:11 +00:00
|
|
|
* so we need to hammer them down first */
|
|
|
|
char buf[16];
|
|
|
|
for (size_t i = 0; i < sizeof(buf); ++i)
|
|
|
|
{
|
|
|
|
buf[i] = tolower((*ext)[i]);
|
|
|
|
|
|
|
|
if (!buf[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-26 19:18:33 +00:00
|
|
|
p->extensions[Audio].push_back(buf);
|
2013-11-30 11:00:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-29 01:33:46 +00:00
|
|
|
if (rgssVer >= 2 && !contains(p->extensions[Audio], std::string("ogg")))
|
|
|
|
p->extensions[Audio].push_back("ogg");
|
|
|
|
|
2014-07-31 01:32:07 +00:00
|
|
|
p->extensions[Audio].push_back("mid");
|
|
|
|
p->extensions[Audio].push_back("midi");
|
|
|
|
|
2013-11-30 11:00:11 +00:00
|
|
|
/* Font extensions */
|
2013-12-26 19:18:33 +00:00
|
|
|
p->extensions[Font].push_back("ttf");
|
|
|
|
p->extensions[Font].push_back("otf");
|
2013-11-30 11:00:11 +00:00
|
|
|
|
2013-09-30 19:19:43 +00:00
|
|
|
PHYSFS_init(argv0);
|
2014-07-23 21:05:24 +00:00
|
|
|
|
|
|
|
PHYSFS_registerArchiver(&RGSS1_Archiver);
|
|
|
|
PHYSFS_registerArchiver(&RGSS2_Archiver);
|
2014-07-23 22:43:04 +00:00
|
|
|
PHYSFS_registerArchiver(&RGSS3_Archiver);
|
2013-10-20 20:38:46 +00:00
|
|
|
|
|
|
|
if (allowSymlinks)
|
|
|
|
PHYSFS_permitSymbolicLinks(1);
|
2013-09-30 19:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileSystem::~FileSystem()
|
|
|
|
{
|
|
|
|
delete p;
|
|
|
|
|
|
|
|
if (PHYSFS_deinit() == 0)
|
2013-12-11 19:46:54 +00:00
|
|
|
Debug() << "PhyFS failed to deinit.";
|
2013-09-30 19:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileSystem::addPath(const char *path)
|
|
|
|
{
|
|
|
|
PHYSFS_mount(path, 0, 1);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 14:57:03 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
struct CacheEnumCBData
|
|
|
|
{
|
|
|
|
FileSystemPrivate *p;
|
|
|
|
iconv_t nfd2nfc;
|
|
|
|
|
|
|
|
CacheEnumCBData(FileSystemPrivate *fsp)
|
|
|
|
{
|
|
|
|
p = fsp;
|
|
|
|
nfd2nfc = iconv_open("utf-8", "utf-8-mac");
|
|
|
|
}
|
|
|
|
|
|
|
|
~CacheEnumCBData()
|
|
|
|
{
|
|
|
|
iconv_close(nfd2nfc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nfcFromNfd(char *dst, const char *src, size_t dstSize)
|
|
|
|
{
|
|
|
|
size_t srcSize = strlen(src);
|
|
|
|
/* Reserve room for null terminator */
|
|
|
|
--dstSize;
|
|
|
|
/* iconv takes a char** instead of a const char**, even though
|
|
|
|
* the string data isn't written to. */
|
|
|
|
iconv(nfd2nfc,
|
|
|
|
const_cast<char**>(&src), &srcSize,
|
|
|
|
&dst, &dstSize);
|
|
|
|
/* Null-terminate */
|
|
|
|
*dst = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-09-30 19:19:43 +00:00
|
|
|
static void cacheEnumCB(void *d, const char *origdir,
|
|
|
|
const char *fname)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-08-19 14:57:03 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
CacheEnumCBData *data = static_cast<CacheEnumCBData*>(d);
|
|
|
|
FileSystemPrivate *p = data->p;
|
|
|
|
#else
|
2013-09-30 19:19:43 +00:00
|
|
|
FileSystemPrivate *p = static_cast<FileSystemPrivate*>(d);
|
2014-08-19 14:57:03 +00:00
|
|
|
#endif
|
2013-09-30 19:19:43 +00:00
|
|
|
|
|
|
|
char buf[512];
|
|
|
|
|
2014-01-15 00:51:56 +00:00
|
|
|
if (*origdir == '\0')
|
2013-09-30 19:19:43 +00:00
|
|
|
strncpy(buf, fname, sizeof(buf));
|
2014-01-15 00:51:56 +00:00
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", origdir, fname);
|
|
|
|
|
2014-08-19 14:57:03 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
char bufNfc[sizeof(buf)];
|
|
|
|
data->nfcFromNfd(bufNfc, buf, sizeof(bufNfc));
|
|
|
|
#else
|
|
|
|
char *const bufNfc = buf;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
char *ptr = bufNfc;
|
2014-01-15 00:51:56 +00:00
|
|
|
|
|
|
|
/* Trim leading slash */
|
|
|
|
if (*ptr == '/')
|
|
|
|
++ptr;
|
2013-09-30 19:19:43 +00:00
|
|
|
|
2014-01-15 00:51:56 +00:00
|
|
|
std::string mixedCase(ptr);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-08-19 14:57:03 +00:00
|
|
|
for (char *p = bufNfc; *p; ++p)
|
2013-09-30 19:19:43 +00:00
|
|
|
*p = tolower(*p);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-01-15 00:51:56 +00:00
|
|
|
std::string lowerCase(ptr);
|
2013-11-01 07:24:14 +00:00
|
|
|
|
2013-09-30 19:19:43 +00:00
|
|
|
p->pathCache.insert(lowerCase, mixedCase);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-08-19 14:57:03 +00:00
|
|
|
PHYSFS_enumerateFilesCallback(mixedCase.c_str(), cacheEnumCB, d);
|
2013-09-30 19:19:43 +00:00
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-30 19:19:43 +00:00
|
|
|
void FileSystem::createPathCache()
|
|
|
|
{
|
2014-08-19 14:57:03 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
CacheEnumCBData data(p);
|
|
|
|
PHYSFS_enumerateFilesCallback("", cacheEnumCB, &data);
|
|
|
|
#else
|
2014-01-15 00:51:56 +00:00
|
|
|
PHYSFS_enumerateFilesCallback("", cacheEnumCB, p);
|
2014-08-19 14:57:03 +00:00
|
|
|
#endif
|
2014-01-01 06:07:18 +00:00
|
|
|
|
|
|
|
p->havePathCache = true;
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
static void strToLower(std::string &str)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
for (size_t i = 0; i < str.size(); ++i)
|
|
|
|
str[i] = tolower(str[i]);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
struct FontSetsCBData
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
FileSystemPrivate *p;
|
|
|
|
SharedFontState *sfs;
|
|
|
|
};
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
static void fontSetEnumCB(void *data, const char *,
|
|
|
|
const char *fname)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
FontSetsCBData *d = static_cast<FontSetsCBData*>(data);
|
|
|
|
FileSystemPrivate *p = d->p;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
/* Only consider filenames with font extensions */
|
|
|
|
const char *ext = p->findExt(fname);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
if (!ext)
|
|
|
|
return;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
std::string lower(ext);
|
|
|
|
strToLower(lower);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
if (!contains(p->extensions[FileSystem::Font], lower))
|
|
|
|
return;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
std::string filename("Fonts/");
|
|
|
|
filename += fname;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
PHYSFS_File *handle = PHYSFS_openRead(filename.c_str());
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
if (!handle)
|
|
|
|
return;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
SDL_RWops ops;
|
|
|
|
p->initReadOps(handle, ops, false);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
d->sfs->initFontSetCB(ops, filename);
|
2013-09-04 11:32:11 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
SDL_RWclose(&ops);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
void FileSystem::initFontSets(SharedFontState &sfs)
|
2013-09-10 02:18:58 +00:00
|
|
|
{
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
FontSetsCBData d = { p, &sfs };
|
2013-09-10 02:18:58 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
PHYSFS_enumerateFilesCallback("Fonts", fontSetEnumCB, &d);
|
2013-09-10 02:18:58 +00:00
|
|
|
}
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
void FileSystem::openRead(SDL_RWops &ops,
|
|
|
|
const char *filename,
|
2013-09-10 02:18:58 +00:00
|
|
|
FileType type,
|
2013-11-30 11:00:11 +00:00
|
|
|
bool freeOnClose,
|
|
|
|
const char **foundExt)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
PHYSFS_File *handle = p->openReadHandle(filename, type, foundExt);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
p->initReadOps(handle, ops, freeOnClose);
|
|
|
|
}
|
2013-09-10 02:18:58 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
void FileSystem::openReadRaw(SDL_RWops &ops,
|
|
|
|
const char *filename,
|
|
|
|
bool freeOnClose)
|
|
|
|
{
|
|
|
|
PHYSFS_File *handle = PHYSFS_openRead(filename);
|
|
|
|
assert(handle);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.
Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.
Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add
fontSub=Arial>Open Sans
to the configuration file. Multiple such rules can be specified.
In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-11 11:37:14 +00:00
|
|
|
p->initReadOps(handle, ops, freeOnClose);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileSystem::exists(const char *filename, FileType type)
|
|
|
|
{
|
2014-01-16 03:19:22 +00:00
|
|
|
char found[512];
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-01-16 03:19:22 +00:00
|
|
|
return p->completeFileName(filename, type, found, sizeof(found), 0);
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|