From 4e028434771673b81647f17b72c14d830e6c7a7d Mon Sep 17 00:00:00 2001 From: mkwiser Date: Tue, 7 Oct 2014 02:52:48 +0800 Subject: [PATCH] modify change option --- src/fonteditor/ttf/main.js | 9 ++++--- src/fonteditor/widget/ttfmanager.js | 38 +++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/fonteditor/ttf/main.js b/src/fonteditor/ttf/main.js index c366af5..065d81f 100644 --- a/src/fonteditor/ttf/main.js +++ b/src/fonteditor/ttf/main.js @@ -24,7 +24,7 @@ define( var actions = { 'new': function() { - if (program.ttfmanager.get() && !window.confirm('是否放弃保存当前项目?')) { + if (program.ttfmanager.isChanged() && !window.confirm('是否放弃保存当前项目?')) { return; } newEmpty(); @@ -79,8 +79,10 @@ define( if (program.ttfmanager.get()) { var name = ''; if(name = window.prompt('请输入项目名称:')) { - var list = project.add(string.encodeHTML(name), program.ttfmanager.get()); + name = string.encodeHTML(name); + var list = project.add(name, program.ttfmanager.get()); program.projectViewer.show(list); + program.data.projectName = name; } } } @@ -172,10 +174,11 @@ define( program.projectViewer.on('open', function(e) { var imported = project.get(e.projectName); if (imported) { - if (program.ttfmanager.get() && !window.confirm('是否放弃保存当前项目?')) { + if (program.ttfmanager.isChanged() && !window.confirm('是否放弃保存当前项目?')) { return; } program.ttfmanager.set(imported); + program.data.projectName = e.projectName; } }); program.projectViewer.on('del', function(e) { diff --git a/src/fonteditor/widget/ttfmanager.js b/src/fonteditor/widget/ttfmanager.js index 5d84e80..0311890 100644 --- a/src/fonteditor/widget/ttfmanager.js +++ b/src/fonteditor/widget/ttfmanager.js @@ -35,11 +35,13 @@ define( scale = ttf.head.unitsPerEm / imported.head.unitsPerEm; } - imported.glyf.filter(function(g, index) { + var list = imported.glyf.filter(function(g, index) { return g.contours && g.contours.length //简单轮廓 && g.name != '.notdef' && g.name != '.null' && g.name != 'nonmarkingreturn'; // 非预定义字形 - }).forEach(function(g) { + }); + + list.forEach(function(g) { if (scale !== 1) { g.contours.forEach(function(contour) { pathAdjust(contour, scale, scale); @@ -49,7 +51,7 @@ define( ttf.glyf.push(g); }); - return ttf; + return list.length; } /** @@ -60,6 +62,7 @@ define( */ function Manager(ttf) { this.ttf = ttf; + this.changed = false; // ttf是否被改过 } /** @@ -69,9 +72,9 @@ define( * @return {this} */ Manager.prototype.set = function(ttf) { - if (this.ttf !== ttf) { this.ttf = ttf; + this.changed = false; this.fire('change', { ttf: this.ttf }); @@ -98,6 +101,7 @@ define( */ Manager.prototype.addglyf = function(glyf) { this.ttf.glyf.push(glyf); + this.changed = true; this.fire('change', { ttf: this.ttf }); @@ -114,10 +118,13 @@ define( * @return {this} */ Manager.prototype.combine = function(imported, options) { - combine(this.ttf, imported, options); - this.fire('change', { - ttf: this.ttf - }); + var count = combine(this.ttf, imported, options); + if (count) { + this.changed = true; + this.fire('change', { + ttf: this.ttf + }); + } return this; }; @@ -131,13 +138,14 @@ define( Manager.prototype.delglyf = function(indexList) { var glyf = this.ttf.glyf, count = 0; for(var i = glyf.length - 1; i >= 0; i--) { - if (indexList.indexOf(i) >= 0) { + if (indexList.indexOf(i) >= 0 && glyf[i].name != '.notdef') { glyf.splice(i, 1); count++; } } if (count) { + this.changed = true; this.fire('change', { ttf: this.ttf }); @@ -166,7 +174,7 @@ define( } list = list.filter(function(g) { - return g.name != '.notdef' && g.name != '.null' && g.name != 'nonmarkingreturn'; + return g.name != '.notdef'; }); if (list.length) { @@ -179,6 +187,7 @@ define( unicode++; }); + this.changed = true; this.fire('change', { ttf: this.ttf }); @@ -187,6 +196,15 @@ define( return this; }; + + /** + * ttf是否被改变 + * @return {boolean} + */ + Manager.prototype.isChanged = function() { + return !!this.changed; + }; + /** * 注销 */