add find glyf
This commit is contained in:
parent
1da142e333
commit
08b999a0d5
@ -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 {
|
||||
|
@ -61,7 +61,9 @@ exports.exclude = [
|
||||
"output",
|
||||
".DS_Store",
|
||||
".gitignore",
|
||||
"package.json"
|
||||
"package.json",
|
||||
"node",
|
||||
"node_modules"
|
||||
];
|
||||
|
||||
exports.injectProcessor = function ( processors ) {
|
||||
|
@ -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(
|
||||
|
@ -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();
|
||||
|
@ -10,16 +10,16 @@
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var unicodeREG = /^(?:\$[A-F0-9]+)$/gi;
|
||||
var unicodeREG = /^(?:\$[A-F0-9]+)(?:\,\$[A-F0-9]+)*$/gi;
|
||||
|
||||
var tpl = ''
|
||||
+ '<div class="form-inline">'
|
||||
+ '<div class="input-group input-group-sm">'
|
||||
+ '<span class="input-group-addon">unicode</span>'
|
||||
+ '<input value="$" data-field="unicode" data-type="unicode"'
|
||||
+ ' id="setting-glyf-unicode" class="form-control">'
|
||||
+ '</div>'
|
||||
+ ' <span>例如:"$21"</span>'
|
||||
+ '<select id="setting-find-condition" class="form-control">'
|
||||
+ '<option value="unicode" selected>按代码点查找字形</option>'
|
||||
+ '<option value="name">按名字查找字形</option>'
|
||||
+ '</select> '
|
||||
+ '<input value="" id="setting-find-value" class="form-control">'
|
||||
+ '<p>例如:代码点:"$21",名字: "uniE001"</p>'
|
||||
+ '</div>';
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ define(
|
||||
|
||||
// 导入
|
||||
'import': {
|
||||
combinePath: false // 导入svg文件时合并`path`标签
|
||||
combinePath: true // 导入svg文件时合并`path`标签
|
||||
},
|
||||
|
||||
// 导出
|
||||
|
@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
* 隐藏
|
||||
*/
|
||||
|
@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user