Skip to content

Commit c04618b

Browse files
committed
Merge pull request #2780 from VisualSJ/develop-1565
Issue #1565: TTF font haven't been set when parser Label
2 parents 2d00a32 + f821b69 commit c04618b

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Diff for: extensions/cocostudio/loader/parsers/uiParser-1.x.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@
458458
/**
459459
* Text parser (UIText)
460460
*/
461+
var regTTF = /\.ttf$/;
461462
parser.TextAttributes = function(widget, options, resourcePath){
462463
var touchScaleChangeAble = options["touchScaleEnable"];
463464
widget.setTouchScaleChangeEnabled(touchScaleChangeAble);
@@ -469,7 +470,15 @@
469470
}
470471
var fn = options["fontName"];
471472
if (fn != null){
472-
widget.setFontName(options["fontName"]);
473+
if(cc.sys.isNative){
474+
if(regTTF.test(fn)){
475+
widget.setFontName(cc.path.join(cc.loader.resPath, resourcePath, fn));
476+
}else{
477+
widget.setFontName(fn);
478+
}
479+
}else{
480+
widget.setFontName(fn.replace(regTTF, ''));
481+
}
473482
}
474483
var aw = options["areaWidth"];
475484
var ah = options["areaHeight"];
@@ -599,7 +608,7 @@
599608
/**
600609
* TextField parser (UITextField)
601610
*/
602-
parser.TextFieldAttributes = function(widget, options, resoutcePath){
611+
parser.TextFieldAttributes = function(widget, options, resourcePath){
603612
var ph = options["placeHolder"];
604613
if(ph)
605614
widget.setPlaceHolder(ph);
@@ -608,8 +617,17 @@
608617
if(fs)
609618
widget.setFontSize(fs);
610619
var fn = options["fontName"];
611-
if(fn)
612-
widget.setFontName(fn);
620+
if (fn != null){
621+
if(cc.sys.isNative){
622+
if(regTTF.test(fn)){
623+
widget.setFontName(cc.path.join(cc.loader.resPath, resourcePath, fn));
624+
}else{
625+
widget.setFontName(fn);
626+
}
627+
}else{
628+
widget.setFontName(fn.replace(regTTF, ''));
629+
}
630+
}
613631
var tsw = options["touchSizeWidth"];
614632
var tsh = options["touchSizeHeight"];
615633
if(tsw!=null && tsh!=null)

0 commit comments

Comments
 (0)