Skip to content

Commit 7edcc89

Browse files
committed
Merge pull request cocos2d#2971 from VisualSJ/develop-20670
Add ttc loader and prevent the pure digital fonts is invalid
2 parents ae163f5 + aa6b57a commit 7edcc89

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,6 +82,7 @@ cc._fontLoader = {
8282
TYPE : {
8383
".eot" : "embedded-opentype",
8484
".ttf" : "truetype",
85+
".ttc" : "truetype",
8586
".woff" : "woff",
8687
".svg" : "svg"
8788
},
@@ -90,7 +91,11 @@ cc._fontLoader = {
9091
fontStyle.type = "text/css";
9192
doc.body.appendChild(fontStyle);
9293

93-
var fontStr = "@font-face { font-family:" + name + "; src:";
94+
var fontStr = "";
95+
if(isNaN(name - 0))
96+
fontStr += "@font-face { font-family:" + name + "; src:";
97+
else
98+
fontStr += "@font-face { font-family:'" + name + "'; src:";
9499
if(srcs instanceof Array){
95100
for(var i = 0, li = srcs.length; i < li; i++){
96101
var src = srcs[i];
@@ -99,9 +104,10 @@ cc._fontLoader = {
99104
fontStr += (i === li - 1) ? ";" : ",";
100105
}
101106
}else{
107+
type = type.toLowerCase();
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)