Skip to content

Commit

Permalink
增加复合字形编辑支持
Browse files Browse the repository at this point in the history
  • Loading branch information
kekee000 committed Jan 5, 2016
1 parent c25d851 commit 9d3760c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/fonteditor/controller/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ define(
var settingSupport = require('../dialog/support');
var clipboard = require('editor/widget/clipboard');
var actions = require('./actions');
var glyfAdjust = require('fonteditor-core/ttf/util/glyfAdjust');
var program;

/**
Expand Down Expand Up @@ -53,14 +52,25 @@ define(
// 调整显示级别
program.editor.setAxis(getEditingOpt(ttf));

if (null == glyfIndex) {
return;
}
glyfIndex = +glyfIndex;
var font = ttf.glyf[glyfIndex];
if (font) {
if (font.compond) {
alert(i18n.lang.msg_not_support_compound_glyf);
}
else {
program.editor.setFont(lang.clone(font));
var clonedFont = lang.clone(font);
if (clonedFont.compound) {
if (!confirm(i18n.lang.msg_transform_compound_glyf)) {
return;
}

// 转换复合字形为简单字形,原始字形不变
var transformGlyfContours = require('fonteditor-core/ttf/util/transformGlyfContours');
var compound2simple = require('fonteditor-core/ttf/util/compound2simple');
clonedFont = compound2simple(clonedFont, transformGlyfContours(font, ttf));
}

program.editor.setFont(clonedFont);
}
}
}
Expand Down Expand Up @@ -221,7 +231,7 @@ define(
})
.on('copy', function (e) {

var list = program.ttfManager.getGlyf(e.list);
var list = program.ttfManager.getCopiedGlyf(e.list);
var clip = {
unitsPerEm: program.ttfManager.get().head.unitsPerEm,
glyf: list
Expand All @@ -245,6 +255,7 @@ define(
// 根据 unitsPerEm 调整形状
if (program.ttfManager.get().head.unitsPerEm !== clip.unitsPerEm) {
var scale = program.ttfManager.get().head.unitsPerEm / (clip.unitsPerEm || 1024);
var glyfAdjust = require('fonteditor-core/ttf/util/glyfAdjust');
clip.glyf.forEach(function (g) {
glyfAdjust(g, scale, scale);
});
Expand Down
1 change: 1 addition & 0 deletions src/fonteditor/i18n/en-us/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ define(
msg_input_proj_name: 'Please input project name:',
msg_confirm_gen_names: 'Glyph name will be rewrite by generated name, do you really want to regenerate?',
msg_not_support_compound_glyf: 'Not support compound glyph currently!',
msg_transform_compound_glyf: 'Do you want to transform compound glyf to simple glyf?',
msg_confirm_save_glyph: 'Do you want to cancel save current editing glyph?',
msg_no_related_glhph: 'Find no related glyph!',
msg_error_open_proj: 'Open project error, do you want to delete this project?',
Expand Down
1 change: 1 addition & 0 deletions src/fonteditor/i18n/zh-cn/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ define(
msg_input_proj_name: '请输入项目名称:',
msg_confirm_gen_names: '生成的字形名称会覆盖原来的名称,确定生成?',
msg_not_support_compound_glyf: '暂不支持复合字形!',
msg_transform_compound_glyf: '是否转换复合字形为简单字形?',
msg_confirm_save_glyph: '是否放弃保存当前编辑的字形?',
msg_no_related_glhph: '未找到相关字形!',
msg_error_open_proj: '打开项目失败,是否删除项目?',
Expand Down
26 changes: 26 additions & 0 deletions src/fonteditor/widget/TTFManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ define(
var History = require('editor/widget/History');
var TTF = require('fonteditor-core/ttf/ttf');
var string = require('fonteditor-core/ttf/util/string');
var transformGlyfContours = require('fonteditor-core/ttf/util/transformGlyfContours');
var compound2simple = require('fonteditor-core/ttf/util/compound2simple');

/**
* 清除glyf编辑状态
Expand Down Expand Up @@ -548,6 +550,30 @@ define(
return this;
};



/**
* 获取复制的glyf对象,这里会将复合字形转换成简单字形,以便于粘贴到其他地方
*
* @param {Array=} indexList 索引列表
* @return {Array} glyflist
*/
Manager.prototype.getCopiedGlyf = function (indexList) {
var list = [];
var ttf = this.ttf.get();
for (var i = 0, l = indexList.length; i < l; ++i) {
var index = indexList[i];
var cloned = lang.clone(ttf.glyf[index]);
if (ttf.glyf[index].compound) {
compound2simple(cloned, transformGlyfContours(ttf.glyf[index], ttf));
}
list.push(cloned);
}
return list;
};



Manager.prototype.clearGlyfTag = clearGlyfTag;

/**
Expand Down

0 comments on commit 9d3760c

Please sign in to comment.