From c9b11848b6093b7ab4d2077ba5779620ce847487 Mon Sep 17 00:00:00 2001 From: kekee000 Date: Sun, 9 Aug 2015 18:32:47 +0800 Subject: [PATCH] add sort glyf --- build/i18n.en-us.js | 1 + build/i18n.zh-cn.js | 1 + index-en.html | 2 +- index.html | 2 +- index.tpl | 1 + src/fonteditor/controller/actions.js | 9 +++++++++ src/fonteditor/i18n/en-us/message.js | 3 ++- src/fonteditor/i18n/zh-cn/message.js | 2 ++ src/fonteditor/widget/TTFManager.js | 29 ++++++++++++++++++++++++++++ src/fonteditor/widget/ttfmanager.js | 29 ++++++++++++++++++++++++++++ src/graphics/computeBoundingBox.js | 2 +- src/graphics/pathAdjust.js | 2 +- src/graphics/pathCeil.js | 2 +- src/graphics/pathIterator.js | 2 +- src/graphics/pathRotate.js | 2 +- src/graphics/pathSkew.js | 2 +- src/graphics/pathTransform.js | 2 +- src/graphics/pathUtil.js | 2 +- src/graphics/pathsUtil.js | 2 +- src/graphics/reducePath.js | 2 +- src/graphics/util.js | 2 +- src/math/bezierCubic2Q2.js | 2 +- 22 files changed, 88 insertions(+), 15 deletions(-) diff --git a/build/i18n.en-us.js b/build/i18n.en-us.js index 0b45d0c..64db96c 100644 --- a/build/i18n.en-us.js +++ b/build/i18n.en-us.js @@ -20,6 +20,7 @@ module.exports = exports = { gen_glyph_name: 'Generate Glyph Name', clear_glyph_name: 'Clear Glyph Name', optimize_glyph: 'Optimize Glyph', + sort_glyf: 'Sort Glyph by Unicode', compound2simple: 'Composite Glyph to Simple Glyph', preview: 'Preview', preview_ttf: 'ttf Font', diff --git a/build/i18n.zh-cn.js b/build/i18n.zh-cn.js index 1310739..f04b273 100644 --- a/build/i18n.zh-cn.js +++ b/build/i18n.zh-cn.js @@ -20,6 +20,7 @@ module.exports = exports = { gen_glyph_name: '生成字形名称', clear_glyph_name: '清除字形名称', optimize_glyph: '优化字体', + sort_glyf: '按代码点进行排序', compound2simple: '复合字形转简单字形', preview: '预览', preview_ttf: 'ttf字体', diff --git a/index-en.html b/index-en.html index a31f4fa..2d3e1e5 100644 --- a/index-en.html +++ b/index-en.html @@ -1 +1 @@ - FontEditor
\ No newline at end of file + FontEditor
\ No newline at end of file diff --git a/index.html b/index.html index c1fba0b..002ef3b 100644 --- a/index.html +++ b/index.html @@ -1 +1 @@ - FontEditor
\ No newline at end of file + FontEditor
\ No newline at end of file diff --git a/index.tpl b/index.tpl index 53f0b19..4ba99ef 100644 --- a/index.tpl +++ b/index.tpl @@ -50,6 +50,7 @@
  • ${lang.gen_glyph_name}
  • ${lang.clear_glyph_name}
  • ${lang.optimize_glyph}
  • +
  • ${lang.sort_glyf}
  • ${lang.compound2simple}
  • diff --git a/src/fonteditor/controller/actions.js b/src/fonteditor/controller/actions.js index 5f0a01e..9586053 100644 --- a/src/fonteditor/controller/actions.js +++ b/src/fonteditor/controller/actions.js @@ -268,6 +268,15 @@ define( } }, + 'setting-sort': function () { + if (program.ttfManager.get()) { + var result = program.ttfManager.sortGlyf(); + if (true !== result) { + alert(result.message); + } + } + }, + 'setting-compound2simple': function () { if (program.ttfManager.get()) { program.ttfManager.compound2simple(program.viewer.getSelected()); diff --git a/src/fonteditor/i18n/en-us/message.js b/src/fonteditor/i18n/en-us/message.js index 7a975ba..9cddf6e 100644 --- a/src/fonteditor/i18n/en-us/message.js +++ b/src/fonteditor/i18n/en-us/message.js @@ -33,7 +33,8 @@ define( msg_no_related_glhph: 'Find no related glyph!', msg_error_open_proj: 'Open project error, do you want to delete this project?', msg_error_del_proj: 'Delete project error, please refresh this page and try delete again!', - + msg_no_sort_glyf: 'No glyph to sort!', + msg_has_compound_glyf_sort: 'Can\'t sort glyphs while contains compound glyph.', preview_title: 'Preview {%=fontFormat%} Format Font', preview_first_step: 'Step 1: Use `{%=fontFamily%}` as font-face.', diff --git a/src/fonteditor/i18n/zh-cn/message.js b/src/fonteditor/i18n/zh-cn/message.js index 21cabeb..90c26ae 100644 --- a/src/fonteditor/i18n/zh-cn/message.js +++ b/src/fonteditor/i18n/zh-cn/message.js @@ -33,6 +33,8 @@ define( msg_no_related_glhph: '未找到相关字形!', msg_error_open_proj: '打开项目失败,是否删除项目?', msg_error_del_proj: '删除项目失败,请刷新页面后删除!', + msg_no_sort_glyf: '没有要排序的字形!', + msg_has_compound_glyf_sort: '包含复合字形,无法进行排序', preview_title: '预览{%=fontFormat%}格式字体', diff --git a/src/fonteditor/widget/TTFManager.js b/src/fonteditor/widget/TTFManager.js index 3906d93..6f73b29 100644 --- a/src/fonteditor/widget/TTFManager.js +++ b/src/fonteditor/widget/TTFManager.js @@ -440,6 +440,35 @@ define( }; }; + /** + * 对字形按照unicode编码排序 + * + * @return {true|Object} 优化成功,或者错误信息 + */ + Manager.prototype.sortGlyf = function () { + + var result = this.ttf.sortGlyf(); + + if (result === -1) { + return { + message: i18n.lang.msg_no_sort_glyf + }; + } + else if (result === -2) { + return { + message: i18n.lang.msg_has_compound_glyf_sort + }; + } + + if (result.length) { + result.forEach(function (g) { + g.modify = 'edit'; + }); + this.fireChange(true); + } + return true; + }; + /** * 复合字形转简单字形 * @param {Array=} indexList 选中的字形索引 diff --git a/src/fonteditor/widget/ttfmanager.js b/src/fonteditor/widget/ttfmanager.js index 3906d93..6f73b29 100644 --- a/src/fonteditor/widget/ttfmanager.js +++ b/src/fonteditor/widget/ttfmanager.js @@ -440,6 +440,35 @@ define( }; }; + /** + * 对字形按照unicode编码排序 + * + * @return {true|Object} 优化成功,或者错误信息 + */ + Manager.prototype.sortGlyf = function () { + + var result = this.ttf.sortGlyf(); + + if (result === -1) { + return { + message: i18n.lang.msg_no_sort_glyf + }; + } + else if (result === -2) { + return { + message: i18n.lang.msg_has_compound_glyf_sort + }; + } + + if (result.length) { + result.forEach(function (g) { + g.modify = 'edit'; + }); + this.fireChange(true); + } + return true; + }; + /** * 复合字形转简单字形 * @param {Array=} indexList 选中的字形索引 diff --git a/src/graphics/computeBoundingBox.js b/src/graphics/computeBoundingBox.js index 0053924..8bcbe69 100644 --- a/src/graphics/computeBoundingBox.js +++ b/src/graphics/computeBoundingBox.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/graphics/computeBoundingBox');; + return require('fonteditor-core/graphics/computeBoundingBox'); } ); diff --git a/src/graphics/pathAdjust.js b/src/graphics/pathAdjust.js index ddcf853..200acb4 100644 --- a/src/graphics/pathAdjust.js +++ b/src/graphics/pathAdjust.js @@ -4,6 +4,6 @@ */ define( function (require) { - return require('fonteditor-core/graphics/pathAdjust');; + return require('fonteditor-core/graphics/pathAdjust'); } ); diff --git a/src/graphics/pathCeil.js b/src/graphics/pathCeil.js index 6092597..187bf15 100644 --- a/src/graphics/pathCeil.js +++ b/src/graphics/pathCeil.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/graphics/pathCeil');; + return require('fonteditor-core/graphics/pathCeil'); } ); diff --git a/src/graphics/pathIterator.js b/src/graphics/pathIterator.js index 3d3c23d..7277018 100644 --- a/src/graphics/pathIterator.js +++ b/src/graphics/pathIterator.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/graphics/pathIterator');; + return require('fonteditor-core/graphics/pathIterator'); } ); diff --git a/src/graphics/pathRotate.js b/src/graphics/pathRotate.js index 1c21b7e..8c32446 100644 --- a/src/graphics/pathRotate.js +++ b/src/graphics/pathRotate.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/graphics/pathRotate');; + return require('fonteditor-core/graphics/pathRotate'); } ); diff --git a/src/graphics/pathSkew.js b/src/graphics/pathSkew.js index 4830a3c..193a902 100644 --- a/src/graphics/pathSkew.js +++ b/src/graphics/pathSkew.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/graphics/pathSkew');; + return require('fonteditor-core/graphics/pathSkew'); } ); diff --git a/src/graphics/pathTransform.js b/src/graphics/pathTransform.js index c4c16db..4edf9bb 100644 --- a/src/graphics/pathTransform.js +++ b/src/graphics/pathTransform.js @@ -15,6 +15,6 @@ define( function (require) { - return require('fonteditor-core/graphics/pathTransform');; + return require('fonteditor-core/graphics/pathTransform'); } ); diff --git a/src/graphics/pathUtil.js b/src/graphics/pathUtil.js index d0d6cef..14b6bf6 100644 --- a/src/graphics/pathUtil.js +++ b/src/graphics/pathUtil.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/graphics/pathUtil');; + return require('fonteditor-core/graphics/pathUtil'); } ); diff --git a/src/graphics/pathsUtil.js b/src/graphics/pathsUtil.js index 88d7a86..f669a01 100644 --- a/src/graphics/pathsUtil.js +++ b/src/graphics/pathsUtil.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/graphics/pathsUtil');; + return require('fonteditor-core/graphics/pathsUtil'); } ); diff --git a/src/graphics/reducePath.js b/src/graphics/reducePath.js index 47249dd..8188cc7 100644 --- a/src/graphics/reducePath.js +++ b/src/graphics/reducePath.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/graphics/reducePath');; + return require('fonteditor-core/graphics/reducePath'); } ); diff --git a/src/graphics/util.js b/src/graphics/util.js index a132445..31fce10 100644 --- a/src/graphics/util.js +++ b/src/graphics/util.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/graphics/util');; + return require('fonteditor-core/graphics/util'); } ); diff --git a/src/math/bezierCubic2Q2.js b/src/math/bezierCubic2Q2.js index ec00c15..cee55b5 100644 --- a/src/math/bezierCubic2Q2.js +++ b/src/math/bezierCubic2Q2.js @@ -5,6 +5,6 @@ define( function (require) { - return require('fonteditor-core/math/bezierCubic2Q2');; + return require('fonteditor-core/math/bezierCubic2Q2'); } );