Last active
August 18, 2017 05:10
-
-
Save heineiuo/8d8662adc34534b7fdcdfbdad0cac4d0 to your computer and use it in GitHub Desktop.
百度脑图对文字居中兼容处理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* source: https://github.com/fex-team/kityminder-core/blob/dev/src/module/text.js#L10-L127 | |
*/ | |
/** | |
* 针对不同系统、不同浏览器、不同字体做居中兼容性处理 | |
* 暂时未增加Linux的处理 | |
*/ | |
var FONT_ADJUST = { | |
'safari': { | |
'微软雅黑,Microsoft YaHei': -0.17, | |
'楷体,楷体_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 | |
}, | |
'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': { | |
'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 | |
} | |
}, | |
'firefox': { | |
'Mac': { | |
'微软雅黑,Microsoft YaHei': -0.2, | |
'宋体,SimSun': 0.05, | |
'comic sans ms': -0.2, | |
'impact,chicago': -0.15, | |
'arial black,avant garde': -0.17, | |
'times new roman': -0.1, | |
'default': 0.05 | |
}, | |
'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': { | |
"宋体,SimSun": -0.2, | |
"微软雅黑,Microsoft YaHei": -0.2, | |
"黑体, SimHei": -0.2, | |
"隶书, SimLi": -0.2, | |
"楷体,楷体_GB2312,SimKai": -0.2, | |
"andale mono": -0.2, | |
"arial,helvetica,sans-serif": -0.2, | |
"comic sans ms": -0.2, | |
"impact,chicago": -0.2, | |
"times new roman": -0.2, | |
"sans-serif": -0.2, | |
"arial black,avant garde": -0.2, | |
"default": -0.16 | |
} | |
}, | |
}; | |
var Browser = kity.Browser; | |
var adjust; | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment