modify change option

This commit is contained in:
mkwiser 2014-10-07 02:52:48 +08:00
parent 168984c777
commit 4e02843477
2 changed files with 34 additions and 13 deletions

View File

@ -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) {

View File

@ -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;
};
/**
* 注销
*/