Commit 8939b245 authored by 张博's avatar 张博

solved the compatibility of browsers

parent 6452c694
...@@ -7,10 +7,109 @@ define(function(require, exports, module) { ...@@ -7,10 +7,109 @@ define(function(require, exports, module) {
var Command = require('../core/command'); var Command = require('../core/command');
var Module = require('../core/module'); var Module = require('../core/module');
var Renderer = require('../core/render'); var Renderer = require('../core/render');
/**
* 针对不同系统、不同浏览器、不同字体做居中兼容性处理
* 暂时未增加Linux的处理
*/
var FONT_ADJUST = { var FONT_ADJUST = {
'微软雅黑,Microsoft YaHei': -0.15, 'safari': {
'arial black,avant garde': -0.17, '微软雅黑,Microsoft YaHei': -0.17,
'default': -0.15 '楷体,楷体_GB2312,SimKai': -0.1,
'隶书, SimLi': -0.1,
'comic sans ms': -0.23,
'impact,chicago': -0.15,
'times new roman': -0.1,
'arial black,avant garde': -0.17,
'default': -0.15
},
'ie': {
10: {
'微软雅黑,Microsoft YaHei': -0.17,
'comic sans ms': -0.17,
'impact,chicago': -0.08,
'times new roman': 0.04,
'arial black,avant garde': -0.17,
'default': -0.15
},
11: {
'微软雅黑,Microsoft YaHei': -0.17,
'arial,helvetica,sans-serif': -0.17,
'comic sans ms': -0.17,
'impact,chicago': -0.08,
'times new roman': 0.04,
'sans-serif': -0.16,
'arial black,avant garde': -0.17,
'default': -0.15
}
},
'edge': {
'微软雅黑,Microsoft YaHei': -0.15,
'arial,helvetica,sans-serif': -0.17,
'comic sans ms': -0.17,
'impact,chicago': -0.08,
'sans-serif': -0.16,
'arial black,avant garde': -0.17,
'default': -0.15
},
'sg': {
'微软雅黑,Microsoft YaHei': -0.15,
'arial,helvetica,sans-serif': -0.05,
'comic sans ms': -0.22,
'impact,chicago': -0.16,
'times new roman': -0.03,
'arial black,avant garde': -0.22,
'default': -0.15
},
'chrome': {
'Mac': {
'andale mono': -0.05,
'comic sans ms': -0.3,
'impact,chicago': -0.13,
'times new roman': -0.1,
'arial black,avant garde': -0.17,
'default': 0
},
'Win': {
'微软雅黑,Microsoft YaHei': -0.15,
'arial,helvetica,sans-serif': -0.02,
'arial black,avant garde': -0.2,
'comic sans ms': -0.2,
'impact,chicago': -0.12,
'times new roman': -0.02,
'default': -0.15
},
'Lux': {
'微软雅黑,Microsoft YaHei': -0.15,
'arial black,avant garde': -0.17,
'default': -0.15
}
},
'firefox': {
'Mac': {
'微软雅黑,Microsoft YaHei': -0.2,
'宋体,SimSun': -0.15,
'comic sans ms': -0.2,
'impact,chicago': -0.15,
'arial black,avant garde': -0.17,
'default': -0.15
},
'Win': {
'微软雅黑,Microsoft YaHei': -0.16,
'andale mono': -0.17,
'arial,helvetica,sans-serif': -0.17,
'comic sans ms': -0.22,
'impact,chicago': -0.23,
'times new roman': -0.22,
'sans-serif': -0.22,
'arial black,avant garde': -0.17,
'default': -0.16
},
'Lux': {
'微软雅黑,Microsoft YaHei': -0.15,
'arial black,avant garde': -0.17,
'default': -0.15
}
}
}; };
var TextRenderer = kity.createClass('TextRenderer', { var TextRenderer = kity.createClass('TextRenderer', {
...@@ -36,12 +135,28 @@ define(function(require, exports, module) { ...@@ -36,12 +135,28 @@ define(function(require, exports, module) {
var height = (lineHeight * fontSize) * textArr.length - (lineHeight - 1) * fontSize; var height = (lineHeight * fontSize) * textArr.length - (lineHeight - 1) * fontSize;
var yStart = -height / 2; var yStart = -height / 2;
var Browser = kity.Browser;
if (kity.Browser.ie) { var adjust;
var adjust = FONT_ADJUST[fontFamily] || 0;
textGroup.setTranslate(0, adjust * fontSize); if (Browser.chrome || Browser.opera || Browser.bd ||Browser.lb === "chrome") {
adjust = FONT_ADJUST['chrome'][Browser.platform][fontFamily];
} else if (Browser.gecko) {
adjust = FONT_ADJUST['firefox'][Browser.platform][fontFamily];
} else if (Browser.sg) {
adjust = FONT_ADJUST['sg'][fontFamily];
} else if (Browser.safari) {
adjust = FONT_ADJUST['safari'][fontFamily];
} else if (Browser.ie) {
adjust = FONT_ADJUST['ie'][Browser.version][fontFamily];
} else if (Browser.edge) {
adjust = FONT_ADJUST['edge'][fontFamily];
} else if (Browser.lb) {
// 猎豹浏览器的ie内核兼容性模式下
adjust = 0.9;
} }
textGroup.setTranslate(0, (adjust || 0) * fontSize);
var rBox = new kity.Box(), var rBox = new kity.Box(),
r = Math.round; r = Math.round;
...@@ -62,7 +177,7 @@ define(function(require, exports, module) { ...@@ -62,7 +177,7 @@ define(function(require, exports, module) {
while (growth--) { while (growth--) {
textShape = new kity.Text() textShape = new kity.Text()
.setAttr('text-rendering', 'inherit'); .setAttr('text-rendering', 'inherit');
if (kity.Browser.ie) { if (kity.Browser.ie || kity.Browser.edge) {
textShape.setVerticalAlign('top'); textShape.setVerticalAlign('top');
} else { } else {
textShape.setAttr('dominant-baseline', 'text-before-edge'); textShape.setAttr('dominant-baseline', 'text-before-edge');
...@@ -72,9 +187,9 @@ define(function(require, exports, module) { ...@@ -72,9 +187,9 @@ define(function(require, exports, module) {
} }
for (i = 0, text, textShape; for (i = 0, text, textShape;
(text = textArr[i], textShape = textGroup.getItem(i)); i++) { (text = textArr[i], textShape = textGroup.getItem(i)); i++) {
textShape.setContent(text); textShape.setContent(text);
if (kity.Browser.ie) { if (kity.Browser.ie || kity.Browser.edge) {
textShape.fixPosition(); textShape.fixPosition();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment