Fix support for Flash/HTML5 targets on older OpenFL releases
This commit is contained in:
@@ -191,7 +191,7 @@ class Assets {
|
|||||||
* @param id The ID or asset path for the font
|
* @param id The ID or asset path for the font
|
||||||
* @return A new Font object
|
* @return A new Font object
|
||||||
*/
|
*/
|
||||||
public static function getFont (id:String, useCache:Bool = true):Font {
|
public static function getFont (id:String, useCache:Bool = true):#if (openfl < "3.0.0") Dynamic #else Font #end {
|
||||||
|
|
||||||
initialize ();
|
initialize ();
|
||||||
|
|
||||||
@@ -1003,7 +1003,7 @@ class AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getFont (id:String):Font {
|
public function getFont (id:String):#if (openfl < "3.0.0") Dynamic #else Font #end {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -1091,7 +1091,7 @@ class AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function loadFont (id:String, handler:Font -> Void):Void {
|
public function loadFont (id:String, handler:#if (openfl < "3.0.0") Dynamic #else Font #end -> Void):Void {
|
||||||
|
|
||||||
handler (getFont (id));
|
handler (getFont (id));
|
||||||
|
|
||||||
|
|||||||
45
lime/graphics/Font.hx
Normal file
45
lime/graphics/Font.hx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package lime.graphics;
|
||||||
|
|
||||||
|
|
||||||
|
#if (openfl < "3.0.0")
|
||||||
|
|
||||||
|
|
||||||
|
class Font extends lime.text.Font {
|
||||||
|
|
||||||
|
|
||||||
|
public var fontName (get, set):String;
|
||||||
|
|
||||||
|
|
||||||
|
public function new (fontName:String = null) {
|
||||||
|
|
||||||
|
super (fontName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Get & Set Methods
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private function get_fontName ():String {
|
||||||
|
|
||||||
|
return name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function set_fontName (value:String):String {
|
||||||
|
|
||||||
|
return name = value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#end
|
||||||
@@ -256,19 +256,27 @@ class DefaultAssetLibrary extends AssetLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function getFont (id:String):Font {
|
public override function getFont (id:String):#if (openfl < "3.0.0") Dynamic #else Font #end {
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
|
|
||||||
var src = Type.createInstance (className.get (id), []);
|
var src = Type.createInstance (className.get (id), []);
|
||||||
|
#if (openfl < "3.0.0")
|
||||||
|
return src;
|
||||||
|
#else
|
||||||
var font = new Font (src.fontName);
|
var font = new Font (src.fontName);
|
||||||
font.src = src;
|
font.src = src;
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
|
#end
|
||||||
|
|
||||||
#elseif html5
|
#elseif html5
|
||||||
|
|
||||||
|
#if (openfl < "3.0.0")
|
||||||
|
var limeFont:Font = cast (Type.createInstance (className.get (id), []), Font);
|
||||||
|
return new openfl.text.Font (limeFont.name);
|
||||||
|
#else
|
||||||
return cast (Type.createInstance (className.get (id), []), Font);
|
return cast (Type.createInstance (className.get (id), []), Font);
|
||||||
|
#end
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user