diff --git a/css/common/common.less b/css/common/common.less index cfd4399..694d0fb 100644 --- a/css/common/common.less +++ b/css/common/common.less @@ -132,11 +132,24 @@ body, html { span { display: inline-block; padding: 0 6px; - background: rgba(84, 114, 93, 0.8); + background: rgba(84, 114, 93, 0.9); color: #FFF; border: 1px solid #DDD; } +} +.loading[data-status="error"] { + span { + color: red; + background: rgba(236, 234, 69, 0.9); + } +} + +.loading[data-status="warn"] { + span { + color: #FF8722; + background: rgba(255, 255, 255, 0.9); + } } .editor { diff --git a/edp-build-config.js b/edp-build-config.js index 14c15ea..b0df4d3 100644 --- a/edp-build-config.js +++ b/edp-build-config.js @@ -61,7 +61,9 @@ exports.exclude = [ "output", ".DS_Store", ".gitignore", - "package.json" + "package.json", + "node", + "node_modules" ]; exports.injectProcessor = function ( processors ) { diff --git a/src/common/DOMParser.js b/src/common/DOMParser.js index 97b9d6f..6d15df4 100644 --- a/src/common/DOMParser.js +++ b/src/common/DOMParser.js @@ -3,8 +3,10 @@ * @author mengke01(kekee000@gmail.com) */ +/* eslint-disable no-undef */ + if (typeof exports !== 'undefined') { - module.exports = exports = require('xmldom').DOMParser; + module.exports = require('xmldom').DOMParser; } else { define( diff --git a/src/fonteditor/controller/default.js b/src/fonteditor/controller/default.js index 52cd909..ce0588d 100644 --- a/src/fonteditor/controller/default.js +++ b/src/fonteditor/controller/default.js @@ -241,14 +241,16 @@ define( var SettingFindGlyf = settingSupport['find-glyf']; !new SettingFindGlyf({ onChange: function (setting) { - var index = program.ttfManager.findGlyf(setting.unicode[0]); - if (-1 !== index) { + var glyfList = program.ttfManager.findGlyf(setting); + + if (glyfList.length) { var pageSize = program.setting.get('editor').viewer.pageSize; - var page = Math.ceil(index / pageSize); - showTTF(program.ttfManager.get(), page, [index]); + var page = Math.ceil(glyfList[0] / pageSize); + + showTTF(program.ttfManager.get(), page, glyfList); } else { - alert('未找到相关字形!'); + program.loading.warn('未找到相关字形!', 1000); } } }).show(); @@ -311,7 +313,7 @@ define( program.viewer.focus(); } }, function () { - console.warn('open project failed:' + e.projectId); + program.loading.error('打开项目失败!', 1000); }); }) @@ -326,7 +328,7 @@ define( program.data.projectId = null; } }, function () { - console.warn('remove project failed:' + e.projectId); + program.loading.warn('删除项目失败!', 1000); }); program.viewer.focus(); diff --git a/src/fonteditor/dialog/setting-find-glyf.js b/src/fonteditor/dialog/setting-find-glyf.js index 76db53c..bb99804 100644 --- a/src/fonteditor/dialog/setting-find-glyf.js +++ b/src/fonteditor/dialog/setting-find-glyf.js @@ -10,16 +10,16 @@ define( function (require) { - var unicodeREG = /^(?:\$[A-F0-9]+)$/gi; + var unicodeREG = /^(?:\$[A-F0-9]+)(?:\,\$[A-F0-9]+)*$/gi; var tpl = '' + '
' - + '
' - + 'unicode' - + '' - + '
' - + '  例如:"$21"' + + ' ' + + '' + + '

例如:代码点:"$21",名字: "uniE001"

' + '
'; @@ -32,14 +32,22 @@ define( }, validate: function () { + var condition = $('#setting-find-condition').val(); + var value = $('#setting-find-value').val(); - var unicode = $('#setting-glyf-unicode').val(); - if (unicode && !unicode.match(unicodeREG)) { - alert('unicode不正确!'); - return false; + if (condition === 'unicode') { + if (!value.match(unicodeREG)) { + alert('unicode不正确!'); + return false; + } + + value = value.split(','); } - return this.getFields(); + var setting = {}; + setting[condition] = value; + + return setting; } }); diff --git a/src/fonteditor/setting/ie.js b/src/fonteditor/setting/ie.js index 8a21cf4..ae744e7 100644 --- a/src/fonteditor/setting/ie.js +++ b/src/fonteditor/setting/ie.js @@ -15,7 +15,7 @@ define( // 导入 'import': { - combinePath: false // 导入svg文件时合并`path`标签 + combinePath: true // 导入svg文件时合并`path`标签 }, // 导出 diff --git a/src/fonteditor/widget/loading.js b/src/fonteditor/widget/loading.js index 976a926..9948d66 100644 --- a/src/fonteditor/widget/loading.js +++ b/src/fonteditor/widget/loading.js @@ -22,14 +22,17 @@ define( * * @param {string} text 显示文字 * @param {number} duration 显示时间 + * @param {string} status 显示的状态 * @return {this} */ - show: function (text, duration) { + show: function (text, duration, status) { clearTimeout(this.showtimer); - - $('#loading span').html(text || '正在加载...'); - $('#loading').show(); + var loading = $('#loading'); + loading.attr('data-status', status || '') + .find('span') + .html(text || '正在加载...'); + loading.show(); if (duration) { this.showtimer = setTimeout(this.hide, duration); @@ -38,6 +41,30 @@ define( return this; }, + /** + * 显示错误提示框 + * + * @param {string} text 显示文字 + * @param {number} duration 显示时间 + * @return {this} + */ + error: function (text, duration) { + this.show(text, duration, 'error'); + return this; + }, + + /** + * 显示警告提示框 + * + * @param {string} text 显示文字 + * @param {number} duration 显示时间 + * @return {this} + */ + warn: function (text, duration) { + this.show(text, duration, 'warn'); + return this; + }, + /** * 隐藏 */ diff --git a/src/fonteditor/widget/project.js b/src/fonteditor/widget/project.js index af769ba..54d84a5 100644 --- a/src/fonteditor/widget/project.js +++ b/src/fonteditor/widget/project.js @@ -89,7 +89,7 @@ define( if (projectDataStore) { var resolver = new Resolver(); - projectDataStore.update(id, ttf, function() { + projectDataStore.update(id, ttf, function () { resolver.resolve(id); }, function () { resolver.reject(id); @@ -120,7 +120,7 @@ define( if (projectDataStore) { var resolver = new Resolver(); - projectDataStore.remove(id, function() { + projectDataStore.remove(id, function () { storage.setItem('project-list', JSON.stringify(list)); resolver.resolve(list); }, function () { @@ -147,8 +147,8 @@ define( if (projectDataStore) { var resolver = new Resolver(); - - projectDataStore.get(id, function(data) { + /* eslint-disable no-loop-func */ + projectDataStore.get(id, function (data) { resolver.resolve(data); }, function () { resolver.reject(id); @@ -164,7 +164,7 @@ define( } } - return Resolver.rejected(id);; + return Resolver.rejected(id); }, /** diff --git a/src/fonteditor/widget/ttfmanager.js b/src/fonteditor/widget/ttfmanager.js index e4724ae..0ebc981 100644 --- a/src/fonteditor/widget/ttfmanager.js +++ b/src/fonteditor/widget/ttfmanager.js @@ -94,23 +94,12 @@ define( /** * 查找glyf * - * @param {number} unicode 编码 + * @param {Object} condition 查询条件 * - * @return {number} 没有找到返回 -1, 找到返回glyf索引 + * @return {Array} 找到返回glyf列表 */ - Manager.prototype.findGlyf = function (unicode) { - - var glyfList = this.ttf.getGlyf(); - - // 查找单个unicode - for (var i = 0, l = glyfList.length; i < l ; i++) { - var g = glyfList[i]; - if (g.unicode && g.unicode.length && g.unicode.indexOf(unicode) >= 0) { - return i; - } - } - - return -1; + Manager.prototype.findGlyf = function (condition) { + return this.ttf.findGlyf(condition); }; /** diff --git a/src/ttf/ttf.js b/src/ttf/ttf.js index b2ca1a0..a60c1cb 100644 --- a/src/ttf/ttf.js +++ b/src/ttf/ttf.js @@ -516,6 +516,75 @@ define( return glyf; }; + + /** + * 查找相关字形 + * + * @param {Object} condition 查询条件 + * @param {Array|number} condition.unicode unicode列表或者单个unicode编码 + * @param {Array} condition.name 名字列表 + * + * @return {Array} glyf字形列表 + */ + TTF.prototype.findGlyf = function (condition) { + if (!condition) { + return []; + } + + + var filters = []; + + // 按unicode数组查找 + if (condition.unicode) { + var unicodeList = lang.isArray(condition.unicode) ? condition.unicode : [condition.unicode]; + var unicodeHash = {}; + unicodeList.forEach(function (unicode) { + if (typeof unicode === 'string') { + unicode = Number('0x' + unicode.slice(1)); + } + unicodeHash[unicode] = true; + }); + + filters.push(function (glyf) { + if (!glyf.unicode || !glyf.unicode.length) { + return false; + } + + for (var i = 0, l = glyf.unicode.length; i < l; i++) { + if (unicodeHash[glyf.unicode[i]]) { + return true; + } + } + }); + } + + // 按名字查找 + if (condition.name) { + var name = condition.name; + filters.push(function (glyf) { + return glyf.name && glyf.name.indexOf(name) === 0; + }); + } + + // 按筛选函数查找 + if (typeof condition.filter === 'function') { + filters.push(condition.filter); + } + + var indexList = []; + this.ttf.glyf.forEach(function (glyf, index) { + for (var filterIndex = 0, filter; (filter = filters[filterIndex++]);) { + if (true === filter(glyf)) { + indexList.push(index); + break; + } + } + }); + + return indexList; + }; + + /** * 更新指定的glyf *