diff --git a/cocos2dx/platform/CCFileUtils.cpp b/cocos2dx/platform/CCFileUtils.cpp index 9107af53fc..0b5f7c74dd 100644 --- a/cocos2dx/platform/CCFileUtils.cpp +++ b/cocos2dx/platform/CCFileUtils.cpp @@ -636,8 +636,8 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName) } } - CCLOG("cocos2d: fullPathForFilename: No file found at %s. Possible missing file.", pszFileName); - + //CCLOG("cocos2d: fullPathForFilename: No file found at %s. Possible missing file.", pszFileName); + // The file wasn't found, return the file name passed in. return pszFileName; } diff --git a/cocos2dx/platform/android/CCImage.cpp b/cocos2dx/platform/android/CCImage.cpp index c02d72e419..03955040e2 100644 --- a/cocos2dx/platform/android/CCImage.cpp +++ b/cocos2dx/platform/android/CCImage.cpp @@ -28,6 +28,7 @@ THE SOFTWARE. #include "platform/CCImageCommon_cpp.h" #include "platform/CCPlatformMacros.h" #include "platform/CCImage.h" +#include "platform/CCFileUtils.h" #include "jni/JniHelper.h" #include @@ -65,6 +66,17 @@ public: return false; } + // Do a full lookup for the font path using CCFileUtils in case the given font name is a relative path to a font file asset, + // or the path has been mapped to a different location in the app package: + std::string fullPathOrFontName = CCFileUtils::sharedFileUtils()->fullPathForFilename(pFontName); + + // 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("assets/") == 0) + { + fullPathOrFontName = fullPathOrFontName.substr(strlen("assets/")); // Chop out the 'assets/' portion of the path. + } + /**create bitmap * this method call Cococs2dx.createBitmap()(java code) to create the bitmap, the java code * will call Java_org_cocos2dx_lib_Cocos2dxBitmap_nativeInitBitmapDC() to init the width, height @@ -72,7 +84,7 @@ public: * use this approach to decrease the jni call number */ jstring jstrText = methodInfo.env->NewStringUTF(text); - jstring jstrFont = methodInfo.env->NewStringUTF(pFontName); + jstring jstrFont = methodInfo.env->NewStringUTF(fullPathOrFontName.c_str()); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, jstrText, jstrFont, (int)fontSize, eAlignMask, nWidth, nHeight); 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); }