From 4189b9cfcb2577b6532028d594a4b32bffd46187 Mon Sep 17 00:00:00 2001 From: mkwiser Date: Sun, 19 Oct 2014 18:00:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E6=88=90=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- css/common/common.less | 6 + css/common/editor.less | 22 ++ css/common/ico.less | 22 +- css/main.less | 10 +- css/ttf.less | 3 +- index.html | 6 +- src/common/lang.js | 2 +- src/editor/Editor.js | 15 +- src/editor/controller/initAxis.js | 4 +- src/editor/controller/initBinder.js | 6 + src/editor/controller/initFont.js | 41 +++- src/editor/controller/initRender.js | 4 + src/editor/options.js | 6 +- src/fonteditor/controller/default.js | 207 ++++++++++++++++++ .../default.js => controller/ttf.js} | 19 +- src/fonteditor/main.js | 9 +- src/fonteditor/{ttf/main.js => ttf.js} | 20 +- src/fonteditor/widget/glyfeditor.js | 34 ++- src/fonteditor/widget/glyfviewer.js | 83 +++++-- src/fonteditor/widget/program.js | 5 + src/fonteditor/widget/ttfmanager.js | 18 +- src/ttf/ttf.js | 16 ++ ttf.html | 2 +- 23 files changed, 478 insertions(+), 82 deletions(-) create mode 100644 src/fonteditor/controller/default.js rename src/fonteditor/{widget/controller/default.js => controller/ttf.js} (85%) rename src/fonteditor/{ttf/main.js => ttf.js} (82%) diff --git a/css/common/common.less b/css/common/common.less index 07a92b6..e328a6f 100644 --- a/css/common/common.less +++ b/css/common/common.less @@ -99,6 +99,7 @@ body, html { margin-left: -100px; line-height: 24px; text-align: center; + z-index: 1000; display: none; span { @@ -119,6 +120,11 @@ body, html { z-index: 1; background: #FEFEFE; border-right: 1px solid #DDD; + display: none; +} + +.editor.editing { + display: block; } .selection-range { diff --git a/css/common/editor.less b/css/common/editor.less index ecf9a2f..f3e7fec 100644 --- a/css/common/editor.less +++ b/css/common/editor.less @@ -1,6 +1,22 @@ // 编辑器样式集合 +.close-editor { + .ico(); + .i-ico('\e611'); + + position: absolute; + right: 0; + top: 0; + z-index: 100; + padding: 0 3px; + z-index: 100; + font-size: 14px; + background: #FFF; + border-left: 1px solid #000; + display: none; +} + .glyf-editor { width: 100%; @@ -32,4 +48,10 @@ border-bottom: none; } } +} + +.editor:hover { + .close-editor { + display: block; + } } \ No newline at end of file diff --git a/css/common/ico.less b/css/common/ico.less index 00948e8..8b10974 100644 --- a/css/common/ico.less +++ b/css/common/ico.less @@ -6,8 +6,7 @@ src: url('../font/iconfont.ttf') format('truetype'); } -.i-edit, -.i-del { +.ico() { display: inline-block; font-family: 'fonteditor'; font-size: 12px; @@ -21,10 +20,21 @@ } } -.i-edit:before { - content: '\e605'; +.i-ico(@unicode) { + &:before { + content: @unicode; + } } -.i-del:before { - content: '\e611'; +.i-edit, +.i-del { + .ico(); +} + +.i-edit { + .i-ico('\e605'); +} + +.i-del { + .i-ico('\e611'); } \ No newline at end of file diff --git a/css/main.less b/css/main.less index f91fb4e..90fe836 100644 --- a/css/main.less +++ b/css/main.less @@ -2,5 +2,13 @@ @import './ttf.less'; +@import './common/editor.less'; -@import './common/editor.less'; \ No newline at end of file +.glyf-list { + + >.glyf-item:hover { + .i-edit { + display: block; + } + } +} \ No newline at end of file diff --git a/css/ttf.less b/css/ttf.less index 4c02554..96607f0 100644 --- a/css/ttf.less +++ b/css/ttf.less @@ -90,8 +90,7 @@ fill: darkgreen; } - .i-del, - .i-edit { + .i-del { display: block; } } diff --git a/index.html b/index.html index f3262d5..c8d94f4 100644 --- a/index.html +++ b/index.html @@ -70,12 +70,12 @@ -
-
-
+
+
+
diff --git a/src/common/lang.js b/src/common/lang.js index e3d648c..e86e8d9 100644 --- a/src/common/lang.js +++ b/src/common/lang.js @@ -137,9 +137,9 @@ define( else { thisObj[field] = thatObj[field]; } - } }); + return thisObj; } diff --git a/src/editor/Editor.js b/src/editor/Editor.js index c735052..15702c4 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -60,7 +60,7 @@ define( * @return {Editor} 本对象 */ Editor.prototype.setMode = function(modeName) { - console.log(modeName); + if (this.mode) { this.mode.end.call(this); } @@ -70,6 +70,17 @@ define( this.mode.begin.apply(this, args); }; + /** + * 重置编辑器组件 + */ + Editor.prototype.reset = function() { + this.fontLayer.clearShapes(); + this.coverLayer.clearShapes(); + this.font = null; + this.refresh(); + return this; + }; + /** * 刷新编辑器组件 */ @@ -149,7 +160,7 @@ define( * @return {boolean} */ Editor.prototype.isChanged = function() { - return !this.history.atFirst(); + return this.changed; }; /** diff --git a/src/editor/controller/initAxis.js b/src/editor/controller/initAxis.js index 338c4d2..a6b361b 100644 --- a/src/editor/controller/initAxis.js +++ b/src/editor/controller/initAxis.js @@ -24,7 +24,7 @@ define( // 坐标原点位置,基线原点 var originX = (width - options.unitsPerEm) / 2; - var origionY = (height + (options.unitsPerEm + options.axis.metrics.decent)) / 2; + var origionY = (height + (options.unitsPerEm + options.axis.metrics.descent)) / 2; // 绘制轴线 this.axis = this.axisLayer.addShape('axis', lang.extend(lang.clone(options.axis), { @@ -65,7 +65,7 @@ define( var oldUnitsPerEm = this.options.unitsPerEm; this.options.unitsPerEm = options.unitsPerEm; - lang.overwrite(this.options, options); + lang.overwrite(this.options.axis, options); // 设置gap this.options.axis.graduation.gap = options.graduation && options.graduation.gap diff --git a/src/editor/controller/initBinder.js b/src/editor/controller/initBinder.js index 4dedaef..f9fabee 100644 --- a/src/editor/controller/initBinder.js +++ b/src/editor/controller/initBinder.js @@ -17,8 +17,14 @@ define( var me = this; // 保存历史记录 this.on('change', function(e) { + me.changed = true; me.history.add(me.getShapes()); }); + + // 是否改变 + this.on('save', function(e) { + me.changed = false; + }); } return initBinder; diff --git a/src/editor/controller/initFont.js b/src/editor/controller/initFont.js index 00bafc1..2d89a73 100644 --- a/src/editor/controller/initFont.js +++ b/src/editor/controller/initFont.js @@ -22,7 +22,7 @@ define( */ function setFont(font) { - var contours = font.contours; + var contours = font.contours || []; var originX = this.axis.x; var originY = this.axis.y; @@ -47,6 +47,7 @@ define( }); // 重置历史 + this.changed = false; this.history.reset(); this.history.add(lang.clone(shapes)); @@ -100,6 +101,30 @@ define( return this; } + /** + * 设置编辑中的轮廓 + * + * @param {Array} contours 轮廓数组 + * @return {[type]} [return description] + */ + function addContours(contours) { + if (!contours || contours.length === 0) { + return this; + } + + this.setShapes(contours.map(function(contour){ + return { + id: guid('shape'), + type: 'path', + points: contour + }; + })); + + this.fire('change'); + + return this; + } + /** * 获取编辑中的shapes * @@ -126,14 +151,17 @@ define( */ function getFont() { var font = lang.clone(this.font || {}); - font.rightSideBearing = font.rightSideBearing || 0; font.unicode = font.unicode || []; font.name = font.name || ''; + var origin = this.axis; + var rightSideBearing = Math.round((this.rightSideBearing.p0.x - origin.x) / this.render.camera.scale); var shapes = this.getShapes(); - var contours = lang.clone(shapes.map(function(shape) { + var contours = shapes.map(function(shape) { return shape.points; - })).forEach(function(g) { + }); + + contours.forEach(function(g) { pathCeil(g); }); @@ -145,8 +173,8 @@ define( font.xMax = box.x + box.width; font.yMax = box.y + box.height; font.leftSideBearing = font.xMin; - font.advanceWidth = font.xMax + font.rightSideBearing; - delete font.advanceWidth; + font.advanceWidth = rightSideBearing || (font.xMax + font.rightSideBearing) || font.xMax; + delete font.rightSideBearing; font.contours = contours; @@ -212,6 +240,7 @@ define( this.setShapes = setShapes; this.getShapes = getShapes; + this.addContours = addContours; }; } ); diff --git a/src/editor/controller/initRender.js b/src/editor/controller/initRender.js index d3365ef..bb48507 100644 --- a/src/editor/controller/initRender.js +++ b/src/editor/controller/initRender.js @@ -176,6 +176,10 @@ define( if (e.key == 'esc' && !me.mode.keyup) { me.setMode(); } + // 保存 + else if (e.keyCode == 83 && e.ctrlKey) { + me.fire('save'); + } // 粘贴 else if (e.keyCode == 86 && e.ctrlKey) { var shapes = me.getClipBoard(); diff --git a/src/editor/options.js b/src/editor/options.js index 059f523..77f6740 100644 --- a/src/editor/options.js +++ b/src/editor/options.js @@ -45,9 +45,9 @@ define( // 字体测量规格 metrics: { ascent: 480, // 上升 - decent: -33, // 下降 - 'x-Height': 256, // x高度 - 'CapHeight': 358 // 大写字母高度 + descent: -33, // 下降 + xHeight: 256, // x高度 + capHeight: 358 // 大写字母高度 }, // 刻度 diff --git a/src/fonteditor/controller/default.js b/src/fonteditor/controller/default.js new file mode 100644 index 0000000..937b9f3 --- /dev/null +++ b/src/fonteditor/controller/default.js @@ -0,0 +1,207 @@ +/** + * @file default.js + * @author mengke01 + * @date + * @description + * 默认的页面控制器 + */ + + +define( + function(require) { + var lang = require('common/lang'); + var clipboard = require('../widget/clipboard'); + var string = require('common/string'); + + // 获取ttf的编辑选项 + function getEditingOpt(ttf) { + + var opt = { + unitsPerEm: ttf.head.unitsPerEm, + metrics: { + ascent: ttf.hhea.ascent, + descent: ttf.hhea.descent, + capHeight: ttf['OS/2'].sCapHeight || ttf.hhea.ascent * 0.8, + xHeight: ttf['OS/2'].sxHeight || ttf.head.unitsPerEm * 0.4 + } + }; + return opt; + } + + + return { + + /** + * 初始化控制器 + * + * @param {Object} program 项目组件 + */ + init: function(program) { + + // 显示editor + var showEditor = function(glyfIndex) { + + // 重置editor缩放 + var ttf = program.ttfManager.get(); + if (ttf) { + $('.main').addClass('editing'); + $('.editor').addClass('editing'); + + program.viewer.blur(); + program.editor.show(); + + // 调整显示级别 + program.editor.setAxis(getEditingOpt(ttf)); + + var font = ttf.glyf[glyfIndex]; + if (font) { + if (font.compond) { + alert('暂不支持复合字形!'); + } + else { + program.data.editingIndex = glyfIndex; + program.editor.setFont(lang.clone(font)); + } + } + } + }; + + // 隐藏editor + var hideEditor = function() { + $('.main').removeClass('editing'); + $('.editor').removeClass('editing'); + + program.data.editingIndex = -1; + program.editor && program.editor.hide(); + program.viewer.focus(); + }; + + + program.viewer.on('del', function(e) { + if (e.list) { + program.ttfManager.removeGlyf(e.list); + } + }).on('edit', function(e) { + + if (program.editor.isChanged() && !confirm('是否放弃保存编辑的字形?')) { + return; + } + + $('.main').addClass('editing'); + $('.editor').addClass('editing'); + showEditor(e.list[0]); + + }).on('copy', function(e) { + var list = program.ttfManager.getGlyf(e.list); + clipboard.set(list, 'glyf'); + }).on('cut', function(e) { + var list = program.ttfManager.getGlyf(e.list); + clipboard.set(list, 'glyf'); + program.ttfManager.removeGlyf(e.list); + }).on('undo', function(e) { + program.ttfManager.undo(); + }).on('redo', function(e) { + program.ttfManager.redo(); + }); + + program.projectViewer.on('open', function(e) { + var imported = program.project.get(e.projectName); + if (imported) { + if (program.ttfManager.isChanged() && !window.confirm('是否放弃保存当前项目?')) { + return; + } + program.ttfManager.set(imported); + program.data.projectName = e.projectName; + program.viewer.focus(); + } + }).on('del', function(e) { + if (e.projectName && window.confirm('是否删除项目?')) { + program.projectViewer.show(program.project.remove(e.projectName)); + } + program.viewer.focus(); + }); + + program.ttfManager.on('change', function(e) { + if (program.editor.isEditing() && program.data.editingIndex !== -1) { + program.viewer.refresh(e.ttf, [program.data.editingIndex]); + } + else { + program.viewer.show(e.ttf, program.viewer.getSelected()); + program.viewer.focus(); + } + }); + + + program.on('save', function(e) { + // 保存项目 + if (program.ttfManager.get()) { + + if (program.editor.isEditing()) { + // 如果是正在编辑的 + if (program.data.editingIndex !== -1) { + program.ttfManager.updateGlyf(program.editor.getFont(), program.data.editingIndex); + } + // 否则新建font + else { + program.ttfManager.insertGlyf(program.editor.getFont()); + } + } + + if (program.data.projectName) { + program.project.add(program.data.projectName, program.ttfManager.get()); + program.ttfManager.setState('new'); + program.loading.show('保存成功..', 400); + } + else { + var name = ''; + if ((name = window.prompt('请输入项目名称:'))) { + name = string.encodeHTML(name); + var list = program.project.add(name, program.ttfManager.get()); + program.projectViewer.show(list); + program.data.projectName = name; + program.ttfManager.setState('new'); + program.loading.show('保存成功..', 400); + } + } + + } + }).on('paste', function(e) { + var glyfList = clipboard.get('glyf'); + if (glyfList && glyfList.length) { + if (!program.editor.isEditing()) { + program.ttfManager.appendGlyf(glyfList, program.viewer.getSelected()); + } + else { + program.editor.addContours(glyfList[0].contours); + } + } + }).on('function', function(e) { + // F4 + if (e.keyCode === 113) { + if (!program.editor.isVisible()) { + showEditor(); + } + else { + hideEditor(); + } + } + }); + + $('.close-editor').click(function(e) { + hideEditor(); + }); + + program.init({ + viewer: program.viewer.main.get(0), + editor: program.editor.main.get(0) + }); + + window.onbeforeunload = function() { + if (program.ttfManager.isChanged()) { + return '是否放弃保存当前项目?'; + } + }; + } + }; + } +); diff --git a/src/fonteditor/widget/controller/default.js b/src/fonteditor/controller/ttf.js similarity index 85% rename from src/fonteditor/widget/controller/default.js rename to src/fonteditor/controller/ttf.js index a9d34f8..91eefb1 100644 --- a/src/fonteditor/widget/controller/default.js +++ b/src/fonteditor/controller/ttf.js @@ -3,14 +3,14 @@ * @author mengke01 * @date * @description - * 默认的页面控制器 + * ttf页面的页面控制器 */ define( function(require) { var lang = require('common/lang'); - var clipboard = require('../clipboard'); + var clipboard = require('../widget/clipboard'); var string = require('common/string'); return { @@ -26,17 +26,6 @@ define( if (e.list) { program.ttfManager.removeGlyf(e.list); } - }).on('edit', function(e) { - $('.main').addClass('editing'); - $('.editor').addClass('editing'); - var list = program.ttfManager.getGlyf(e.list); - if (list[0].compound) { - alert('暂不支持复合字形!'); - } - else { - program.editor.show(lang.clone(list[0])); - } - }).on('copy', function(e) { var list = program.ttfManager.getGlyf(e.list); clipboard.set(list, 'glyf'); @@ -102,12 +91,12 @@ define( program.init({ viewer: program.viewer.main.get(0), - editor: program.editor.main.get(0) + editor: null }); window.onbeforeunload = function() { if (program.ttfManager.isChanged()) { - return '是否放弃保存当前项目?'; + return '是否放弃保存当前项目?'; } }; } diff --git a/src/fonteditor/main.js b/src/fonteditor/main.js index fa0ec65..77a9303 100644 --- a/src/fonteditor/main.js +++ b/src/fonteditor/main.js @@ -14,7 +14,7 @@ define( var ProjectViewer = require('./widget/projectviewer'); var TTFManager = require('./widget/ttfmanager'); var program = require('./widget/program'); - var controller = require('./widget/controller/default'); + var controller = require('./controller/default'); var actions = require('./widget/actions'); // 打开文件 @@ -100,13 +100,6 @@ define( // 加载项目 program.projectViewer.show(program.project.items()); - - // for test - $.getJSON('./demo/js/baiduHealth.json', function(ttf) { - program.ttfManager.set(ttf); - program.viewer.focus(); - }); - } }; diff --git a/src/fonteditor/ttf/main.js b/src/fonteditor/ttf.js similarity index 82% rename from src/fonteditor/ttf/main.js rename to src/fonteditor/ttf.js index 4834cab..74de747 100644 --- a/src/fonteditor/ttf/main.js +++ b/src/fonteditor/ttf.js @@ -9,12 +9,12 @@ define( function(require) { - var GLYFViewer = require('../widget/glyfviewer'); - var ProjectViewer = require('../widget/projectviewer'); - var TTFManager = require('../widget/ttfmanager'); - var program = require('../widget/program'); - var controller = require('../widget/controller/default'); - var actions = require('../widget/actions'); + var GLYFViewer = require('./widget/glyfviewer'); + var ProjectViewer = require('./widget/projectviewer'); + var TTFManager = require('./widget/ttfmanager'); + var program = require('./widget/program'); + var controller = require('./controller/ttf'); + var actions = require('./widget/actions'); // 打开文件 function onUpFile(e) { @@ -78,18 +78,18 @@ define( program.viewer = new GLYFViewer($('#glyf-list')); // 项目管理 - program.project = require('../widget/project'); + program.project = require('./widget/project'); program.projectViewer = new ProjectViewer($('#project-list')); // ttf管理 program.ttfManager = new TTFManager(); // 导入导出器 - program.loader = require('../widget/loader'); - program.exporter = require('../widget/exporter'); + program.loader = require('./widget/loader'); + program.exporter = require('./widget/exporter'); // 预览器 - program.previewer = require('../widget/previewer'); + program.previewer = require('./widget/previewer'); controller.init(program); diff --git a/src/fonteditor/widget/glyfeditor.js b/src/fonteditor/widget/glyfeditor.js index f31e567..b471167 100644 --- a/src/fonteditor/widget/glyfeditor.js +++ b/src/fonteditor/widget/glyfeditor.js @@ -26,19 +26,27 @@ define( } GLYFEditor.prototype.show = function(font) { + // 这里注意显示顺序,否则editor创建的时候计算宽度会错误 + this.main.show(); + if (!this.editor) { this.editor = editor.create(this.main.get(0)); } - this.main.show(); + if (font) { this.editor.setFont(font); + } + else { + this.editor.reset(); + } + this.editor.focus(); this.editing = true; }; GLYFEditor.prototype.hide = function() { - this.editor.blur(); + this.editor && this.editor.blur(); this.main.hide(); this.editing = false; }; @@ -47,8 +55,28 @@ define( return this.editing; }; + GLYFEditor.prototype.isVisible = function() { + return this.main.get(0).style.display !== 'none'; + }; + + GLYFEditor.prototype.focus = function() { + this.editing = true; + this.editor && this.editor.focus(); + }; + + GLYFEditor.prototype.blur = function() { + this.editing = false; + this.editor && this.editor.blur(); + }; + + GLYFEditor.prototype.dispose = function() { + this.off(); + this.editor.dispose(); + this.main = this.options = this.editor = null; + }; + // 导出editor的函数 - ['focus', 'blur', 'setFont', 'getFont', 'setShapes', 'getShapes'].forEach(function(fn) { + ['reset','setFont', 'getFont', 'addContours', 'isChanged', 'setAxis', 'adjustFont'].forEach(function(fn) { GLYFEditor.prototype[fn] = function() { return this.editor ? this.editor[fn].apply(this.editor, arguments) : undefined; }; diff --git a/src/fonteditor/widget/glyfviewer.js b/src/fonteditor/widget/glyfviewer.js index ab66913..2e2cc95 100644 --- a/src/fonteditor/widget/glyfviewer.js +++ b/src/fonteditor/widget/glyfviewer.js @@ -31,6 +31,28 @@ define( 88: 'cut' }; + // 获取glyfhtml文本 + function getGlyfHTML(glyf, ttf, opt) { + var g = { + index: opt.index, + compound: glyf.compound ? 'compound' : '', + selected: opt.selected ? 'selected' : '', + modify: glyf.modify, + unitsPerEm: opt.unitsPerEm, + descent: opt.descent, + unicode: (glyf.unicode || []).map(function(u) { + return '$' + u.toString(16).toUpperCase(); + }).join(','), + name: glyf.name + }; + var d = ''; + if ((d = glyf2svg(glyf, ttf))) { + g.d = 'd="'+ d +'"'; + } + + return string.format(GLYF_ITEM_TPL, g); + } + // 显示glyf function showGLYF(ttf, selectedList) { var unitsPerEm = ttf.head.unitsPerEm; @@ -40,31 +62,43 @@ define( selectedHash[i] = true; }); - var glyfStr = '', d = ''; + var glyfStr = ''; ttf.glyf.forEach(function(glyf, index) { - var g = { + glyfStr += getGlyfHTML(glyf, ttf, { index: index, - compound: glyf.compound ? 'compound' : '', - selected: selectedHash[index] ? 'selected' : '', - modify: glyf.modify, unitsPerEm: unitsPerEm, descent: descent, - unicode: (glyf.unicode || []).map(function(u) { - return '$' + u.toString(16).toUpperCase(); - }).join(','), - name: glyf.name - }; - - if ((d = glyf2svg(glyf, ttf))) { - g.d = 'd="'+ d +'"'; - } - - glyfStr += string.format(GLYF_ITEM_TPL, g); + selected: selectedHash[index] + }); }); this.main.html(glyfStr); } + // 刷新glyf + function refreshGLYF(ttf, indexList) { + var unitsPerEm = ttf.head.unitsPerEm; + var descent = unitsPerEm + ttf.hhea.descent; + var selectedHash = {}; + var selectedList = this.getSelected(); + + selectedList.forEach(function(i) { + selectedHash[i] = true; + }); + + var main = this.main; + indexList.forEach(function (index) { + var glyfStr = getGlyfHTML(ttf.glyf[index], ttf, { + index: index, + unitsPerEm: unitsPerEm, + descent: descent, + selected: selectedHash[index] + }); + var before = main.find('[data-index="'+ index +'"]'); + $(glyfStr).insertBefore(before); + before.remove(); + }); + } // 点击item function clickItem(e) { @@ -123,8 +157,6 @@ define( if (me.listening) { // 阻止ctrl+A默认事件 if (65 === e.keyCode && e.ctrlKey) { - e.preventDefault(); - e.stopPropagation(); me.main.children().addClass('selected'); } // 撤销 @@ -256,6 +288,21 @@ define( showGLYF.call(this, ttf, selectedList); }; + /** + * 刷新ttf文档 + * + * @param {Object} ttf ttfObject + * @param {Array?} selectedList 选中的列表 + */ + GLYFViewer.prototype.refresh = function(ttf, indexList) { + if (!indexList || indexList.length === 0) { + showGLYF.call(this, ttf, indexList); + } + else { + refreshGLYF.call(this, ttf, indexList); + } + }; + /** * 获取选中的列表 * diff --git a/src/fonteditor/widget/program.js b/src/fonteditor/widget/program.js index 745bd56..1055605 100644 --- a/src/fonteditor/widget/program.js +++ b/src/fonteditor/widget/program.js @@ -47,6 +47,11 @@ define( document.body.addEventListener('keydown', function(e) { + // 全选 + if (65 === e.keyCode && e.ctrlKey) { + e.preventDefault(); + e.stopPropagation(); + } // 功能键 if (e.keyCode >= 112 && e.keyCode <= 119 && e.keyCode !== 116) { e.preventDefault(); diff --git a/src/fonteditor/widget/ttfmanager.js b/src/fonteditor/widget/ttfmanager.js index 9f74381..8dddb0c 100644 --- a/src/fonteditor/widget/ttfmanager.js +++ b/src/fonteditor/widget/ttfmanager.js @@ -167,7 +167,7 @@ define( * * @param {Array} glyfList 添加的列表 * @param {Array} indexList 需要替换的索引列表 - * @return {Array} glyflist + * @return {this} */ Manager.prototype.appendGlyf = function(glyfList, indexList) { @@ -182,6 +182,22 @@ define( return this; }; + /** + * 更新指定的glyf + * + * @param {Object} glyf glyfobject + * @param {string} index 需要替换的索引列表 + * @return {this} + */ + Manager.prototype.updateGlyf = function(glyf, index) { + var list = this.ttf.updateGlyf(glyf, index); + if (list.length) { + list[0].modify = 'edit'; + this.fireChange(true); + } + return this; + }; + /** * 调整glyf位置 * diff --git a/src/ttf/ttf.js b/src/ttf/ttf.js index 7c640ba..af54006 100644 --- a/src/ttf/ttf.js +++ b/src/ttf/ttf.js @@ -293,6 +293,22 @@ define( return result; }; + /** + * 更新指定的glyf + * + * @param {Object} glyf glyfobject + * @param {string} index 需要替换的索引列表 + * @return {Array} 改变的glyf + */ + TTF.prototype.updateGlyf = function(glyf, index) { + if (index >=0 && index < this.ttf.glyf.length) { + this.ttf.glyf[index] = glyf; + return [glyf]; + } + return []; + }; + + /** * 调整glyf位置 * diff --git a/ttf.html b/ttf.html index f908639..6a9ad2c 100644 --- a/ttf.html +++ b/ttf.html @@ -109,7 +109,7 @@ } }); define('jquery', $); - require(['fonteditor/ttf/main']) + require(['fonteditor/ttf'])