Skip to content

Commit

Permalink
Fix for android font name decoding. Get project banners from banners.
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed May 25, 2015
1 parent 38c474d commit 4be5fe5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 23 deletions.
5 changes: 3 additions & 2 deletions nme/system/System.hx
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,16 @@ class System
return func();
}

#if android
public static function restart() : Void
{
#if android
var restart = JNI.createStaticMethod("org/haxe/nme/GameActivity", "restartProcess", "()V");
if (restart==null)
throw "Could not find restart function";
restart();
#end
Sys.exit(0);
}
#end

public static function getLocalIpAddress() : String
{
Expand Down
5 changes: 5 additions & 0 deletions project/src/common/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define NEKO_COMPATIBLE
#endif
#include <nme/NmeCffi.h>
#include <Utils.h>


namespace nme
Expand Down Expand Up @@ -326,8 +327,11 @@ Font *Font::Create(TextFormat &inFormat,double inScale,bool inNative,bool inInit

AutoGCRoot *bytes = 0;
FontBytesMap::iterator fbit = sgRegisteredFonts.find(WideToUTF8(inFormat.font).c_str());

ELOG("Create font %s\n", WideToUTF8(inFormat.font).c_str());
if (fbit!=sgRegisteredFonts.end())
{
ELOG("Registered!\n");
bytes = fbit->second;
}

Expand Down Expand Up @@ -376,6 +380,7 @@ Font *Font::Create(TextFormat &inFormat,double inScale,bool inNative,bool inInit
value nme_font_register_font(value inFontName, value inBytes)
{
AutoGCRoot *bytes = new AutoGCRoot(inBytes);
ELOG("nme_font_register_font %s!\n", val_string(inFontName) );
sgRegisteredFonts[std::string(val_string(inFontName))] = bytes;
return alloc_null();
}
Expand Down
21 changes: 11 additions & 10 deletions project/src/common/FreeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <Utils.h>
#include <map>

#include <Utils.h>

#ifdef HX_WINRT
#define generic userGeneric
#endif
Expand Down Expand Up @@ -698,7 +700,7 @@ int outline_cubic_to(FVecPtr, FVecPtr , FVecPtr , void *user) {
return 1;
}

wchar_t *get_familyname_from_sfnt_name(FT_Face face)
value get_familyname_from_sfnt_name(FT_Face face)
{
wchar_t *family_name = NULL;
FT_SfntName sfnt_name;
Expand All @@ -716,10 +718,7 @@ wchar_t *get_familyname_from_sfnt_name(FT_Face face)
if (sfnt_name.platform_id == TT_PLATFORM_MACINTOSH)
{
len = sfnt_name.string_len;
family_name = new wchar_t[len + 1];
mbstowcs(&family_name[0], &reinterpret_cast<const char*>(sfnt_name.string)[0], len);
family_name[len] = L'\0';
return family_name;
return alloc_string_len((const char *)sfnt_name.string, sfnt_name.string_len);
}
else if ((sfnt_name.platform_id == TT_PLATFORM_MICROSOFT) && (sfnt_name.encoding_id == TT_MS_ID_UNICODE_CS))
{
Expand All @@ -745,13 +744,15 @@ wchar_t *get_familyname_from_sfnt_name(FT_Face face)
family_name[i] = ((wchar_t)sfnt_name.string[i*2 + 1]) | (((wchar_t)sfnt_name.string[i*2]) << 8);
}
family_name[len] = L'\0';
return family_name;
value result = alloc_wstring(family_name);
free(family_name);
return result;
}
}
}
}

return NULL;
return 0;
}

} // end namespace
Expand Down Expand Up @@ -898,8 +899,8 @@ value freetype_import_font(value font_file, value char_vector, value em_size, va
}
}

int num_glyphs = glyphs.size();
wchar_t* family_name = get_familyname_from_sfnt_name(face);
int num_glyphs = glyphs.size();
value family_name = get_familyname_from_sfnt_name(face);

value ret = alloc_empty_object();
alloc_field(ret, val_id("has_kerning"), alloc_bool(FT_HAS_KERNING(face)));
Expand All @@ -908,7 +909,7 @@ value freetype_import_font(value font_file, value char_vector, value em_size, va
alloc_field(ret, val_id("is_italic"), alloc_bool(face->style_flags & FT_STYLE_FLAG_ITALIC));
alloc_field(ret, val_id("is_bold"), alloc_bool(face->style_flags & FT_STYLE_FLAG_BOLD));
alloc_field(ret, val_id("num_glyphs"), alloc_int(num_glyphs));
alloc_field(ret, val_id("family_name"), family_name == NULL ? alloc_string(face->family_name) : alloc_wstring(family_name));
alloc_field(ret, val_id("family_name"), family_name == 0 ? alloc_string(face->family_name) : family_name);
alloc_field(ret, val_id("style_name"), alloc_string(face->style_name));
alloc_field(ret, val_id("em_size"), alloc_int(face->units_per_EM));
alloc_field(ret, val_id("ascend"), alloc_int(face->ascender));
Expand Down
25 changes: 17 additions & 8 deletions samples/HerokuShaders/Source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ import shaders.VertexShader;
class Main extends Sprite {


private static var fragmentShaders:Array<Dynamic> =
private static var desktopShaders:Array<Dynamic> =
[
#if !mobile
FragmentShader_6286,
FragmentShader_6288_1,
FragmentShader_6284_1,
Expand All @@ -57,16 +56,21 @@ class Main extends Sprite {
FragmentShader_5359_8,
FragmentShader_5398_8,
FragmentShader_4278_1
#else
];


private static var mobileShaders:Array<Dynamic> =
[
FragmentShader_6284_1,
FragmentShader_6238,
FragmentShader_6147_1,
FragmentShader_5891_5,
FragmentShader_5805_18,
FragmentShader_5492,
FragmentShader_5398_8
#end
];

private static var fragmentShaders:Array<Dynamic>;

private static var maxTime = 7000;

Expand All @@ -93,6 +97,12 @@ class Main extends Sprite {
{
super();

switch( nme.system.System.systemName())
{
case "android", "ios" : fragmentShaders = mobileShaders;
default: fragmentShaders = desktopShaders.concat(mobileShaders);
}

bump = false;
mx = 0.1;
my = 0.1;
Expand Down Expand Up @@ -157,11 +167,10 @@ class Main extends Sprite {
var program = GL.createProgram ();
var vertex = VertexShader.source;

#if desktop
var fragment = "";
#else
var fragment = "precision mediump float;";
#end
var sys = nme.system.System.systemName();
if (sys=="android" || sys=="ios")
fragment = "precision mediump float;";

fragment += fragmentShaders[currentIndex].source;

Expand Down
24 changes: 22 additions & 2 deletions templates/android/PROJ/src/org/haxe/nme/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void release() {
}
}

public class Sound
public class Sound implements SoundPool.OnLoadCompleteListener
{
private static Context mContext;
private static Sound instance;
Expand All @@ -128,20 +128,29 @@ public class Sound
private static HashMap<Integer, Integer> mSoundId;
private static HashMap<Integer, Long> mSoundProgress;
private static HashMap<Integer, Long> mSoundDuration;
private static HashMap<Integer, Boolean> mSoundLoaded;

public Sound(Context context)
{
if (instance == null) {
mSoundId = new HashMap<Integer, Integer>();
mSoundProgress = new HashMap<Integer, Long>();
mSoundDuration = new HashMap<Integer, Long>();
mSoundLoaded = new HashMap<Integer, Boolean>();
mTimeStamp = System.currentTimeMillis();
mSoundPool = new SoundPool(8, AudioManager.STREAM_MUSIC, 0);
mSoundPool.setOnLoadCompleteListener(this);
}

instance = this;
mContext = context;
}

public void onLoadComplete(SoundPool soundPool,int sampleId,int status)
{
Log.v("Sound","onLoadComplete " + sampleId + "=" + status);
mSoundLoaded.put(sampleId,true);
}

public void doPause()
{
Expand Down Expand Up @@ -184,6 +193,7 @@ public static int getSoundHandle(String inFilename)
} else {
Log.v("Sound", "Resource not found: " + (-id));
index = mSoundPool.load(inFilename, 1);
mSoundLoaded.put(index,false);
Log.v("Sound", "Loaded index from path: " + index);
}

Expand Down Expand Up @@ -235,6 +245,16 @@ public static int playSound(int inResourceID, double inVolLeft, double inVolRigh
mSoundProgress.remove(a);
mSoundId.remove(inResourceID);
}

int tries = 0;
while( !mSoundLoaded.get(inResourceID) )
{
Log.v("Sound", "wait loaded...");
try { java.lang.Thread.sleep(5); } catch (InterruptedException e) { break; }
tries++;
if (tries>50)
break;
}

int streamId = mSoundPool.play(inResourceID, (float)inVolLeft, (float)inVolRight, 1, inLoop, 1.0f);
mSoundId.put(inResourceID, streamId);
Expand Down Expand Up @@ -420,4 +440,4 @@ public static void setMusicTransform(String inPath, double inVolLeft, double inV
}
}
}


2 changes: 1 addition & 1 deletion tools/nme/src/platforms/AndroidPlatform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class AndroidPlatform extends Platform
if (project.banners.length>0)
{
// TV banner icon
if (IconHelper.createIcon(project.icons, 320, 180, destination + "/res/drawable-xhdpi/banner.png"))
if (IconHelper.createIcon(project.banners, 320, 180, destination + "/res/drawable-xhdpi/banner.png"))
context.HAS_BANNER = true;
}

Expand Down

0 comments on commit 4be5fe5

Please sign in to comment.