From 03d4fcde8bee117787f46bf4cddc0d6c57d0b700 Mon Sep 17 00:00:00 2001 From: mkwiser Date: Tue, 7 Oct 2014 17:04:55 +0800 Subject: [PATCH] add name setting --- css/bootstrap.css | 35 +++++++++++++ css/bootstrap.less | 4 ++ css/common.css | 3 ++ css/ttf.css | 5 ++ css/ttf.less | 3 +- src/fonteditor/dialog/setting-name.js | 64 +++++++++++++++++++++++ src/fonteditor/dialog/setting-unicode.js | 9 ++-- src/fonteditor/dialog/setting.js | 66 +++++++++++++++++------- src/fonteditor/ttf/main.js | 31 +++++++---- src/fonteditor/widget/glyfviewer.js | 2 +- src/fonteditor/widget/ttfmanager.js | 15 +++++- ttf.html | 8 +-- 12 files changed, 206 insertions(+), 39 deletions(-) create mode 100644 css/bootstrap.css create mode 100644 src/fonteditor/dialog/setting-name.js diff --git a/css/bootstrap.css b/css/bootstrap.css new file mode 100644 index 0000000..5d54196 --- /dev/null +++ b/css/bootstrap.css @@ -0,0 +1,35 @@ +.modal-dialog { + margin-top: 100px; +} +.modal-header { + padding-top: 6px; + padding-bottom: 6px; + background: #327EC0; + color: #FFF; +} +.modal-header .close { + margin-top: 3px; +} +.modal-header .modal-title { + font-size: 14px; + line-height: 25px; +} +.modal-footer { + padding-top: 10px; + padding-bottom: 10px; +} +.modal-body { + min-height: 100px; +} +.modal-content { + border-color: rgba(0, 0, 0, 0.5); + -webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); + overflow: hidden; +} +.dropdown-menu a { + cursor: pointer; +} +.input-group { + margin-bottom: 10px; +} diff --git a/css/bootstrap.less b/css/bootstrap.less index 1811d91..eb0857f 100644 --- a/css/bootstrap.less +++ b/css/bootstrap.less @@ -41,4 +41,8 @@ a { cursor: pointer; } +} + +.input-group { + margin-bottom: 10px; } \ No newline at end of file diff --git a/css/common.css b/css/common.css index dbee717..b7bd2a4 100644 --- a/css/common.css +++ b/css/common.css @@ -30,6 +30,9 @@ .dropdown-menu a { cursor: pointer; } +.input-group { + margin-bottom: 10px; +} body, html { margin: 0; diff --git a/css/ttf.css b/css/ttf.css index 320a849..4ae9669 100644 --- a/css/ttf.css +++ b/css/ttf.css @@ -30,6 +30,9 @@ .dropdown-menu a { cursor: pointer; } +.input-group { + margin-bottom: 10px; +} body, html { margin: 0; @@ -161,6 +164,8 @@ html { display: none; } .glyf-list { + padding-bottom: 1000000px; + margin-bottom: -1000000px; overflow: hidden; } .glyf-list > .glyf-item { diff --git a/css/ttf.less b/css/ttf.less index 67aa8d5..a368762 100644 --- a/css/ttf.less +++ b/css/ttf.less @@ -35,7 +35,8 @@ .glyf-list { - + padding-bottom: 1000000px; + margin-bottom: -1000000px; overflow: hidden; >.glyf-item { diff --git a/src/fonteditor/dialog/setting-name.js b/src/fonteditor/dialog/setting-name.js new file mode 100644 index 0000000..f78177c --- /dev/null +++ b/src/fonteditor/dialog/setting-name.js @@ -0,0 +1,64 @@ +/** + * @file setting-unicode.js + * @author mengke01 + * @date + * @description + * 设置字体命名信息 + */ + +define( + function(require) { + + var tpl = '' + + '
' + + '字体家族' + + '' + + '
' + + '
' + + '字体子家族' + + '' + + '
' + + '
' + + '完整字体名' + + '' + + '
' + + '
' + + '版本' + + '' + + '
' + + '
' + + 'PostScript名称' + + '' + + '
'; + + + return require('./setting').derive({ + + title: '命名信息', + + getTpl: function() { + return tpl; + }, + + set: function(setting) { + this.getDialog().find('[data-field]').each(function(i, item) { + item = $(item); + item.val(setting[item.attr('data-field')] || ''); + }); + }, + + validate: function() { + var name = {}; + this.getDialog().find('[data-field]').each(function(i, item) { + item = $(item); + var val = item.val().trim(); + if (val) { + name[item.attr('data-field')] = val; + } + }); + return name; + } + + }); + } +); diff --git a/src/fonteditor/dialog/setting-unicode.js b/src/fonteditor/dialog/setting-unicode.js index 0c340d1..8f08a4b 100644 --- a/src/fonteditor/dialog/setting-unicode.js +++ b/src/fonteditor/dialog/setting-unicode.js @@ -25,15 +25,16 @@ define( return require('./setting').derive({ + title: '设置代码点', + getTpl: function() { return tpl; }, - onConfirm: function() { + + validate: function() { var unicode = $('#setting-text-unicode').val(); if (unicode.match(/^\$[A-E0-9]+$/i)) { - this.fire('change', { - unicode: unicode - }); + return this.setting = unicode; } else { alert('代码点设置不正确'); diff --git a/src/fonteditor/dialog/setting.js b/src/fonteditor/dialog/setting.js index 5fc0359..68f1a0f 100644 --- a/src/fonteditor/dialog/setting.js +++ b/src/fonteditor/dialog/setting.js @@ -17,20 +17,17 @@ define( * * @constructor */ - function Setting() { - } + function Setting(options) { + + this.options = options || {}; - /** - * 初始化绑定事件 - */ - Setting.prototype.preInit = function() { var dlg = $('#model-dialog'); - dlg.find('.modal-title').html(this.title); + dlg.find('.modal-title').html(this.title || '设置'); dlg.find('.modal-body').html(this.getTpl()); dlg.on('hidden.bs.modal', lang.bind(function (e) { if (dlg) { - this.un(); + delete this.options; dlg.off('hidden.bs.modal'); dlg.find('.btn-confirm').off('click'); dlg = null; @@ -38,11 +35,14 @@ define( }, this)); dlg.find('.btn-confirm').on('click', lang.bind(function() { - if (false !== this.onConfirm()) { + var setting = this.validate(); + if (false !== setting) { + this.options.onChange && this.options.onChange.call(this, setting); dlg.modal('hide'); } }, this)); - }; + } + /** * 获取模板 @@ -54,21 +54,53 @@ define( }; /** - * 确定事件 + * 获取dialog对象 * - * @return {boolean=} 是否关闭对话框 + * @return {Object} dialog对象 */ - Setting.prototype.onConfirm = function() { + Setting.prototype.getDialog = function() { + return $('#model-dialog'); + }; + + /** + * 验证设置 + * + * @return {boolean} + */ + Setting.prototype.validate = function() { + return true; }; /** * 显示 + * @param {Object} setting 设置选项 */ - Setting.prototype.show = function() { + Setting.prototype.show = function(setting) { $('#model-dialog').modal('show'); + this.set(setting); return this; }; + + /** + * 设置设置选项 + * + * @return {this} + */ + Setting.prototype.set = function(setting) { + this.setting = setting; + }; + + /** + * 获取设置选项 + * + * @return {Object} 设置选项 + */ + Setting.prototype.get = function() { + return this.setting; + }; + + /** * 注销 */ @@ -76,7 +108,6 @@ define( $('#model-dialog').modal('hide'); }; - /** * 派生一个setting * @@ -87,14 +118,11 @@ define( function Class() { Setting.apply(this, arguments); - this.preInit(); this.initialize && this.initialize(); } - Class.prototype = new Setting(); + lang.extend(Class.prototype, Setting.prototype, proto); Class.prototype.constructor = Setting; - lang.extend(Class.prototype, proto); - observable.mixin(Class.prototype); return Class; }; diff --git a/src/fonteditor/ttf/main.js b/src/fonteditor/ttf/main.js index b12de29..4b0e4f4 100644 --- a/src/fonteditor/ttf/main.js +++ b/src/fonteditor/ttf/main.js @@ -21,7 +21,8 @@ define( var setting = { - 'unicode': require('../dialog/setting-unicode') + 'unicode': require('../dialog/setting-unicode'), + 'name': require('../dialog/setting-name') } var actions = { @@ -53,17 +54,29 @@ define( }); }, - 'setting-unicode': function(e) { - var dlg = new setting.unicode(); - - dlg.on('change', function(e) { - // 此处延迟处理 - setTimeout(function(){ - setUnicode(e.unicode); - }, 20); + 'setting-unicode': function() { + var dlg = new setting.unicode({ + onChange: function(unicode) { + // 此处延迟处理 + setTimeout(function(){ + setUnicode(unicode); + }, 20); + } }); dlg.show(); + }, + + 'setting-name': function() { + var ttf = program.ttfmanager.get(); + if (ttf) { + var dlg = new setting.name({ + onChange: function(setting) { + program.ttfmanager.setName(setting); + } + }); + dlg.show(ttf.name); + } } }; diff --git a/src/fonteditor/widget/glyfviewer.js b/src/fonteditor/widget/glyfviewer.js index 30dfcc4..4124996 100644 --- a/src/fonteditor/widget/glyfviewer.js +++ b/src/fonteditor/widget/glyfviewer.js @@ -161,7 +161,7 @@ define( } - me.capture = new MouseCapture(me.main.parent().get(0), { + me.capture = new MouseCapture(me.main.get(0), { events: { dblclick: false, mousewheel: false, diff --git a/src/fonteditor/widget/ttfmanager.js b/src/fonteditor/widget/ttfmanager.js index 6c9cae8..2f601b9 100644 --- a/src/fonteditor/widget/ttfmanager.js +++ b/src/fonteditor/widget/ttfmanager.js @@ -184,7 +184,7 @@ define( } list = list.filter(function(g) { - return g.name != '.notdef'; + return g.name != '.notdef' && g.name != '.null' && g.name != 'nonmarkingreturn'; }); if (list.length) { @@ -239,6 +239,19 @@ define( }); }; + /** + * 撤销 + * @return {this} + */ + Manager.prototype.setName = function(name) { + if (name) { + name.fontFamily = name.fontFamily || 'fonteditor'; + name.fontSubFamily = name.fontSubFamily || 'Medium'; + name.fullName = name.fontFamily; + this.ttf.name = name; + } + }; + /** * 撤销 * @return {this} diff --git a/ttf.html b/ttf.html index 6f30d26..7a3810e 100644 --- a/ttf.html +++ b/ttf.html @@ -21,7 +21,7 @@ @@ -40,8 +40,8 @@ @@ -68,7 +68,7 @@