fixed #2151: Custom font can't be loaded correctly if using full path of filename.

This commit is contained in:
James Chen 2013-05-13 19:12:37 +08:00
parent 4e3ff65707
commit 8fa593a8fe
2 changed files with 10 additions and 2 deletions

View File

@ -72,7 +72,7 @@ public:
// If the path name returned includes the 'assets' dir then that needs to be removed, because the android.content.Context
// requires this portion of the path to be omitted for assets inside the app package.
if (fullPathOrFontName.find_first_of("assets/") == 0)
if (fullPathOrFontName.find("assets/") == 0)
{
fullPathOrFontName = fullPathOrFontName.substr(strlen("assets/")); // Chop out the 'assets/' portion of the path.
}

View File

@ -57,7 +57,15 @@ public class Cocos2dxTypefaces {
public static synchronized Typeface get(final Context pContext, final String pAssetName) {
if (!Cocos2dxTypefaces.sTypefaceCache.containsKey(pAssetName)) {
final Typeface typeface = Typeface.createFromAsset(pContext.getAssets(), pAssetName);
Typeface typeface = null;
if (pAssetName.startsWith("/"))
{
typeface = Typeface.createFromFile(pAssetName);
}
else
{
typeface = Typeface.createFromAsset(pContext.getAssets(), pAssetName);
}
Cocos2dxTypefaces.sTypefaceCache.put(pAssetName, typeface);
}