Skip to content

Commit 27cfa04

Browse files
committed
Add ttc loader and prevent the pure digital fonts is invalid
1 parent 5814b70 commit 27cfa04

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cocos2d/core/platform/CCLoaders.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,21 @@ cc._fontLoader = {
8282
TYPE : {
8383
".eot" : "embedded-opentype",
8484
".ttf" : "truetype",
85+
".ttc" : "truetype",
8586
".woff" : "woff",
8687
".svg" : "svg"
8788
},
8889
_loadFont : function(name, srcs, type){
8990
var doc = document, path = cc.path, TYPE = this.TYPE, fontStyle = cc.newElement("style");
91+
type = type.toLowerCase();
9092
fontStyle.type = "text/css";
9193
doc.body.appendChild(fontStyle);
9294

93-
var fontStr = "@font-face { font-family:" + name + "; src:";
95+
var fontStr = "";
96+
if(isNaN(name - 0))
97+
fontStr += "@font-face { font-family:" + name + "; src:";
98+
else
99+
fontStr += "@font-face { font-family:'" + name + "'; src:";
94100
if(srcs instanceof Array){
95101
for(var i = 0, li = srcs.length; i < li; i++){
96102
var src = srcs[i];
@@ -101,7 +107,7 @@ cc._fontLoader = {
101107
}else{
102108
fontStr += "url('" + srcs + "') format('" + TYPE[type] + "');";
103109
}
104-
fontStyle.textContent += fontStr + "};";
110+
fontStyle.textContent += fontStr + "}";
105111

106112
//<div style="font-family: PressStart;">.</div>
107113
var preloadDiv = cc.newElement("div");
@@ -126,7 +132,7 @@ cc._fontLoader = {
126132
cb(null, true);
127133
}
128134
};
129-
cc.loader.register(["font", "eot", "ttf", "woff", "svg"], cc._fontLoader);
135+
cc.loader.register(["font", "eot", "ttf", "woff", "svg", "ttc"], cc._fontLoader);
130136

131137
cc._binaryLoader = {
132138
load : function(realUrl, url, res, cb){

extensions/cocostudio/loader/parsers/timelineParser-2.x.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@
631631
if (cc.sys.isNative) {
632632
fontName = cc.path.join(cc.loader.resPath, resourcePath, path);
633633
} else {
634-
fontName = path.match(/([^\/]+)\.ttf/);
634+
fontName = path.match(/([^\/]+)\.(\S+)/);
635635
fontName = fontName ? fontName[1] : "";
636636
}
637637
widget.setTitleFontName(fontName);

0 commit comments

Comments
 (0)