diff --git a/css/common/bootstrap.less b/css/common/bootstrap.less index 80e02f9..4620b89 100644 --- a/css/common/bootstrap.less +++ b/css/common/bootstrap.less @@ -51,4 +51,18 @@ .from { float: right; } -} \ No newline at end of file +} + +hr { + margin-top: 10px; + margin-bottom: 10px; +} + +// 自定义宽度 +.form-inline { + + .form-group { + margin-right: 10px; + width: 30%; + } +} diff --git a/css/common/common.less b/css/common/common.less index ee78395..5695b48 100644 --- a/css/common/common.less +++ b/css/common/common.less @@ -40,6 +40,7 @@ body, html { position: fixed; z-index: 10; width: 100%; + min-width: 1024px; top: 0; .btn { diff --git a/src/common/lang.js b/src/common/lang.js index 65111ec..99176c0 100644 --- a/src/common/lang.js +++ b/src/common/lang.js @@ -110,6 +110,28 @@ define( return target; } + /** + * 设置覆盖相关的属性值 + * + * @param {Object} thisObj 覆盖对象 + * @param {Object} thatObj 值对象 + * @param {Array.} fields 字段 + * @return {Object} thisObj + */ + function overwrite(thisObj, thatObj, fields) { + if(!thatObj) { + return thisObj; + } + + fields = fields || Object.keys(thatObj); + fields.forEach(function(field) { + if (thisObj.hasOwnProperty(field)) { + thisObj[field] = thatObj[field] + } + }); + } + + var hasOwnProperty = Object.prototype.hasOwnProperty; /** @@ -201,6 +223,7 @@ define( var exports = { extend: extend, + overwrite: overwrite, bind: bind, inherits: inherits, curry: curry, diff --git a/src/fonteditor/dialog/setting-metrics.js b/src/fonteditor/dialog/setting-metrics.js new file mode 100644 index 0000000..9cc2d9a --- /dev/null +++ b/src/fonteditor/dialog/setting-metrics.js @@ -0,0 +1,192 @@ +/** + * @file setting-name.js + * @author mengke01 + * @date + * @description + * 设置字体上标,下标信息 + */ + +define( + function(require) { + + var tpl = '' + + '
' + + '
' + + '
' + + '上升' + + '' + + '
' + + '
' + + '
' + + '
' + + '下降' + + '' + + '
' + + '
' + + '
' + + '
' + + '行间距' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + 'win上升' + + '' + + '
' + + '
' + + '
' + + '
' + + 'win下降' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '错字上升' + + '' + + '
' + + '
' + + '
' + + '
' + + '错字下降' + + '' + + '
' + + '
' + + '
' + + '
' + + '错字间距' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + 'x高度' + + '' + + '
' + + '
' + + '
' + + '
' + + '大写H高度' + + '' + + '
' + + '
' + + '
' + + + '
' + + + '
' + + '
' + + '
' + + '删除线位置' + + '' + + '
' + + '
' + + '
' + + '
' + + '删除线厚度' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '下划线位置' + + '' + + '
' + + '
' + + '
' + + '
' + + '下划线厚度' + + '' + + '
' + + '
' + + '
' + + + '
' + + + '
' + + '
' + + '
' + + '下标水平' + + '' + + '
' + + '
' + + '
' + + '
' + + '下标垂直' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '下标X偏移' + + '' + + '
' + + '
' + + '
' + + '
' + + '下标Y偏移' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '上标水平' + + '' + + '
' + + '
' + + '
' + + '
' + + '上标垂直' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '上标X偏移' + + '' + + '
' + + '
' + + '
' + + '
' + + '上标Y偏移' + + '' + + '
' + + '
' + + '
'; + + + return require('./setting').derive({ + + title: '字体度量', + + getTpl: function() { + return tpl; + }, + + set: function(setting) { + this.setFields(setting); + }, + + validate: function() { + var setting = this.getFields(); + return setting; + } + + }); + } +); diff --git a/src/fonteditor/ttf/main.js b/src/fonteditor/ttf/main.js index cf60747..d86f89d 100644 --- a/src/fonteditor/ttf/main.js +++ b/src/fonteditor/ttf/main.js @@ -27,6 +27,7 @@ define( 'name': require('../dialog/setting-name'), //'adjust-pos': require('../dialog/setting-adjust-pos'), //'adjust-glyf': require('../dialog/setting-adjust-glyf'), + 'metrics': require('../dialog/setting-metrics'), 'online': require('../dialog/font-online') } @@ -146,19 +147,6 @@ define( dlg.show(); }, - // 设置字体名称 - 'setting-name': function() { - var ttf = program.ttfmanager.get(); - if (ttf) { - var dlg = new setting.name({ - onChange: function(setting) { - program.ttfmanager.setInfo(setting); - } - }); - dlg.show($.extend({}, ttf.head, ttf.name)); - } - }, - // 调整字形位置 'setting-adjust-pos': function() { var ttf = program.ttfmanager.get(); @@ -200,6 +188,33 @@ define( dlg.show(); } + }, + + // 设置字体名称 + 'setting-name': function() { + var ttf = program.ttfmanager.get(); + if (ttf) { + var dlg = new setting.name({ + onChange: function(setting) { + program.ttfmanager.setInfo(setting); + } + }); + dlg.show($.extend({}, ttf.head, ttf.name)); + } + }, + + // 调整规格 + 'setting-metrics': function() { + var ttf = program.ttfmanager.get(); + if (ttf) { + var dlg = new setting['metrics']({ + onChange: function(setting) { + program.ttfmanager.setMetrics(setting); + } + }); + + dlg.show($.extend({}, ttf['OS/2'], ttf.hhea, ttf.post)); + } } }; diff --git a/src/fonteditor/widget/ttfmanager.js b/src/fonteditor/widget/ttfmanager.js index 59fcd90..4b532d8 100644 --- a/src/fonteditor/widget/ttfmanager.js +++ b/src/fonteditor/widget/ttfmanager.js @@ -245,6 +245,26 @@ define( this.ttf.setName(info); this.ttf.setHead(info); + if (changed) { + this.fireChange(false); + } + + return this; + }; + + /** + * 设置度量信息 + * @return {this} + */ + Manager.prototype.setMetrics = function(info) { + var changed = false; + if (this.ttf.get().hhea.descent != info.descent) { + changed = true; + } + this.ttf.setHhea(info); + this.ttf.setOS2(info); + this.ttf.setPost(info); + if (changed) { this.fireChange(false); } diff --git a/src/ttf/ttf.js b/src/ttf/ttf.js index 17ef4fc..28bdb0a 100644 --- a/src/ttf/ttf.js +++ b/src/ttf/ttf.js @@ -57,7 +57,6 @@ define( return list; } - /** * ttf读取函数 * @@ -433,11 +432,11 @@ define( /** * 设置head信息 * + * @param {Object} head 头部信息 * @return {Object} 头对象 */ TTF.prototype.setHead = function(head) { if (head) { - // unitsperem if (head.unitsPerEm && head.unitsPerEm >= 64 && head.unitsPerEm <= 16384) { this.ttf.head.unitsPerEm = head.unitsPerEm; @@ -446,10 +445,61 @@ define( // lowestrecppem if (head.lowestRecPPEM && head.lowestRecPPEM >= 8 && head.lowestRecPPEM <= 16384) { this.ttf.head.lowestRecPPEM = head.lowestRecPPEM; - } } + } + // created + if (head.created) { + this.ttf.head.created = head.created; + } + } return this.ttf.head; }; + /** + * 设置hhea信息 + * + * @param {Object} fields 字段值 + * @return {Object} 头对象 + */ + TTF.prototype.setHhea = function(fields) { + lang.overwrite(this.ttf.hhea, fields, ['ascent', 'descent', 'lineGap']); + return this.ttf.hhea; + }; + + /** + * 设置OS2信息 + * + * @param {Object} fields 字段值 + * @return {Object} 头对象 + */ + TTF.prototype.setOS2 = function(fields) { + lang.overwrite( + this.ttf['OS/2'], fields, + [ + 'usWinAscent', 'usWinDescent', + 'sTypoAscender', 'sTypoDescender', 'sTypoLineGap', + 'sxHeight', 'bXHeight', + 'yStrikeoutPosition', 'yStrikeoutSize' + ] + ); + return this.ttf['OS/2']; + }; + + /** + * 设置post信息 + * + * @param {Object} fields 字段值 + * @return {Object} 头对象 + */ + TTF.prototype.setPost = function(fields) { + lang.overwrite( + this.ttf.post, fields, + [ + 'underlinePosition', 'underlineThickness' + ] + ); + return this.ttf.post; + }; + return TTF; } ); diff --git a/src/ttf/ttfwriter.js b/src/ttf/ttfwriter.js index 1f3d0db..4a1607c 100644 --- a/src/ttf/ttfwriter.js +++ b/src/ttf/ttfwriter.js @@ -47,10 +47,11 @@ define( // 重置校验码 ttf.head.checkSumAdjustment = 0; ttf.head.magickNumber = 0x5F0F3CF5; + if (typeof(ttf.head.created) == 'string') { ttf.head.created = /^\d+$/.test(ttf.head.created) ? +ttf.head.created : Date.parse(ttf.head.created); } - ttf.head.created = Date.now(); + ttf.head.modified = Date.now(); // 将glyf的代码点按小到大排序 diff --git a/ttf.html b/ttf.html index c6f9dc2..ae3da10 100644 --- a/ttf.html +++ b/ttf.html @@ -43,6 +43,7 @@
  • 字体信息
  • 调整位置
  • 调整字形
  • +
  • 调整字体度量