mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
@@ -822,8 +822,8 @@ var game = {
|
||||
}
|
||||
|
||||
if (CC_WECHATGAME && cc.sys.browserType !== cc.sys.BROWSER_TYPE_WECHAT_GAME_SUB) {
|
||||
wx.onShow(onShown);
|
||||
wx.onHide(onHidden);
|
||||
wx.onShow && wx.onShow(onShown);
|
||||
wx.onHide && wx.onHide(onHidden);
|
||||
}
|
||||
|
||||
if ("onpageshow" in window && "onpagehide" in window) {
|
||||
|
||||
@@ -62,7 +62,14 @@ var SpriteAtlas = cc.Class({
|
||||
* @returns {SpriteFrame}
|
||||
*/
|
||||
getSpriteFrame: function (key) {
|
||||
return this._spriteFrames[key];
|
||||
let sf = this._spriteFrames[key];
|
||||
if (!sf) {
|
||||
return null;
|
||||
}
|
||||
if (!sf.name) {
|
||||
sf.name = key;
|
||||
}
|
||||
return sf;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -75,7 +82,7 @@ var SpriteAtlas = cc.Class({
|
||||
var spriteFrames = this._spriteFrames;
|
||||
|
||||
for (var key in spriteFrames) {
|
||||
frames.push(spriteFrames[key]);
|
||||
frames.push(this.getSpriteFrame(key));
|
||||
}
|
||||
|
||||
return frames;
|
||||
|
||||
@@ -640,7 +640,24 @@ proto.loadResDir = function (url, type, progressCallback, completeCallback) {
|
||||
|
||||
var urls = [];
|
||||
var uuids = resources.getUuidArray(url, type, urls);
|
||||
this._loadResUuids(uuids, progressCallback, completeCallback, urls);
|
||||
this._loadResUuids(uuids, progressCallback, function (errors, assetRes, urlRes) {
|
||||
// The spriteFrame url in spriteAtlas will be removed after build project
|
||||
// To show users the exact structure in asset panel, we need to return the spriteFrame assets in spriteAtlas
|
||||
let assetResLength = assetRes.length;
|
||||
for (let i = 0; i < assetResLength; ++i) {
|
||||
if (assetRes[i] instanceof cc.SpriteAtlas) {
|
||||
let spriteFrames = assetRes[i].getSpriteFrames();
|
||||
for (let k in spriteFrames) {
|
||||
let sf = spriteFrames[k];
|
||||
assetRes.push(sf);
|
||||
if (urlRes) {
|
||||
urlRes.push(`${urlRes[i]}/${sf.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
completeCallback(errors, assetRes, urlRes);
|
||||
}, urls);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -317,7 +317,7 @@ module.exports = {
|
||||
let canvasSizeX = 0;
|
||||
let canvasSizeY = 0;
|
||||
for (let i = 0; i < paragraphedStrings.length; ++i) {
|
||||
let paraLength = _context.measureText(paragraphedStrings[i]).width;
|
||||
let paraLength = TextUtils.safeMeasureText(_context, paragraphedStrings[i]);
|
||||
canvasSizeX = canvasSizeX > paraLength ? canvasSizeX : paraLength;
|
||||
}
|
||||
canvasSizeY = _splitedStrings.length * this._getLineHeight();
|
||||
@@ -369,7 +369,7 @@ module.exports = {
|
||||
_splitedStrings = [];
|
||||
let canvasWidthNoMargin = _canvasSize.width - 2 * _margin;
|
||||
for (let i = 0; i < paragraphedStrings.length; ++i) {
|
||||
let allWidth = _context.measureText(paragraphedStrings[i]).width;
|
||||
let allWidth = TextUtils.safeMeasureText(_context, paragraphedStrings[i]);
|
||||
let textFragment = TextUtils.fragmentText(paragraphedStrings[i],
|
||||
allWidth,
|
||||
canvasWidthNoMargin,
|
||||
@@ -408,8 +408,8 @@ module.exports = {
|
||||
let paragraphLength = [];
|
||||
|
||||
for (let i = 0; i < paragraphedStrings.length; ++i) {
|
||||
let textMetric = ctx.measureText(paragraphedStrings[i]);
|
||||
paragraphLength.push(textMetric.width);
|
||||
let width = TextUtils.safeMeasureText(ctx, paragraphedStrings[i]);
|
||||
paragraphLength.push(width);
|
||||
}
|
||||
|
||||
return paragraphLength;
|
||||
@@ -417,7 +417,7 @@ module.exports = {
|
||||
|
||||
_measureText (ctx) {
|
||||
return function (string) {
|
||||
return ctx.measureText(string).width;
|
||||
return TextUtils.safeMeasureText(ctx, string);
|
||||
};
|
||||
},
|
||||
|
||||
@@ -468,13 +468,13 @@ module.exports = {
|
||||
totalHeight = 0;
|
||||
for (i = 0; i < paragraphedStrings.length; ++i) {
|
||||
let j = 0;
|
||||
let allWidth = _context.measureText(paragraphedStrings[i]).width;
|
||||
let allWidth = TextUtils.safeMeasureText(_context, paragraphedStrings[i]);
|
||||
textFragment = TextUtils.fragmentText(paragraphedStrings[i],
|
||||
allWidth,
|
||||
canvasWidthNoMargin,
|
||||
this._measureText(_context));
|
||||
while (j < textFragment.length) {
|
||||
let measureWidth = _context.measureText(textFragment[j]).width;
|
||||
let measureWidth = TextUtils.safeMeasureText(_context, textFragment[j]);
|
||||
maxLength = measureWidth;
|
||||
totalHeight += this._getLineHeight();
|
||||
++j;
|
||||
|
||||
@@ -62,7 +62,7 @@ var CustomFontLoader = {
|
||||
|
||||
var md5Pipe = cc.loader.md5Pipe;
|
||||
if (md5Pipe) {
|
||||
url = md5Pipe.transformURL(url);
|
||||
url = md5Pipe.transformURL(url, true);
|
||||
}
|
||||
//these platforms support window.FontFace, but it sucks sometimes.
|
||||
var useFontFace = (cc.sys.browserType !== cc.sys.BROWSER_TYPE_BAIDU
|
||||
@@ -90,7 +90,7 @@ var CustomFontLoader = {
|
||||
}
|
||||
var oldWidth = this._fontWidthCache[k];
|
||||
this._canvasContext.font = '40px ' + k;
|
||||
var newWidth = this._canvasContext.measureText(this._testString).width;
|
||||
var newWidth = TextUtils.safeMeasureText(this._canvasContext, this._testString);
|
||||
if(oldWidth !== newWidth) {
|
||||
fontDescriptor.onLoaded();
|
||||
} else {
|
||||
@@ -169,7 +169,7 @@ var CustomFontLoader = {
|
||||
var fontDesc = '40px ' + fontFamilyName;
|
||||
this._canvasContext.font = fontDesc;
|
||||
|
||||
var width = this._canvasContext.measureText(this._testString).width;
|
||||
var width = TextUtils.safeMeasureText(this._canvasContext, this._testString);
|
||||
this._fontWidthCache[fontFamilyName] = width;
|
||||
|
||||
var self = this;
|
||||
@@ -227,6 +227,11 @@ var TextUtils = {
|
||||
return ((ch >= 9 && ch <= 13) || ch === 32 || ch === 133 || ch === 160 || ch === 5760 || (ch >= 8192 && ch <= 8202) || ch === 8232 || ch === 8233 || ch === 8239 || ch === 8287 || ch === 12288);
|
||||
},
|
||||
|
||||
safeMeasureText: function (ctx, string) {
|
||||
var metric = ctx.measureText(string);
|
||||
return metric && metric.width || 0;
|
||||
},
|
||||
|
||||
fragmentText: function (stringToken, allWidth, maxWidth, measureText) {
|
||||
//check the first character
|
||||
var wrappedWords = [];
|
||||
|
||||
@@ -109,7 +109,7 @@ exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, opt_macroF
|
||||
bundler.ignore(file);
|
||||
});
|
||||
|
||||
bundler.ignore('./DebugInfos.json');
|
||||
bundler.ignore(Path.resolve(__dirname, '../../DebugInfos.json'));
|
||||
|
||||
var Size = null;
|
||||
try {
|
||||
@@ -271,7 +271,7 @@ exports.buildJsbMin = function (sourceFile, outputFile, excludes, opt_macroFlags
|
||||
bundler.ignore(require.resolve(module));
|
||||
});
|
||||
|
||||
bundler.ignore('../../DebugInfos.json');
|
||||
bundler.ignore(Path.resolve(__dirname, '../../DebugInfos.json'));
|
||||
|
||||
bundler.bundle()
|
||||
.on('error', HandleErrors.handler)
|
||||
|
||||
Reference in New Issue
Block a user