From 8fa593a8fed10563b4bfa5dc88f35d51d97e7396 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 13 May 2013 19:12:37 +0800 Subject: [PATCH] fixed #2151: Custom font can't be loaded correctly if using full path of filename. --- cocos2dx/platform/android/CCImage.cpp | 2 +- .../java/src/org/cocos2dx/lib/Cocos2dxTypefaces.java | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cocos2dx/platform/android/CCImage.cpp b/cocos2dx/platform/android/CCImage.cpp index 766f85d9dc..03955040e2 100644 --- a/cocos2dx/platform/android/CCImage.cpp +++ b/cocos2dx/platform/android/CCImage.cpp @@ -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. } diff --git a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxTypefaces.java b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxTypefaces.java index 901b38153b..b7495fba90 100644 --- a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxTypefaces.java +++ b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxTypefaces.java @@ -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); }