add editor

This commit is contained in:
kekee000
2016-07-02 23:41:23 +08:00
parent 2f71564a22
commit 86dbd1a82f
13 changed files with 693 additions and 16 deletions

View File

@@ -17,10 +17,10 @@ define(
/**
* 重置缩放
*/
rescale: function () {
rescale: function (scale) {
this.coverLayer.clearShapes();
var size = this.render.getSize();
var scale = 512 / this.options.unitsPerEm;
scale = scale || (512 / this.options.unitsPerEm);
this.render.scaleTo(scale, {
x: size.width / 2,
@@ -130,14 +130,16 @@ define(
rightSideBearing = (this.rightSideBearing.p0.x - box.x - box.width) / scale;
}
this.fire('setting:font', {
setting: {
leftSideBearing: Math.round(leftSideBearing),
rightSideBearing: Math.round(rightSideBearing || 0),
unicode: this.font.unicode,
name: this.font.name
}
});
if (this.font) {
this.fire('setting:font', {
setting: {
leftSideBearing: Math.round(leftSideBearing),
rightSideBearing: Math.round(rightSideBearing || 0),
unicode: this.font.unicode,
name: this.font.name
}
});
}
}
};
}

View File

@@ -58,6 +58,7 @@ define(
* @return {boolean} `false`或者`undefined`
*/
rotateleft: function (shapes) {
shapes = shapes || (this.currentGroup && this.currentGroup.shapes);
return support.rotate.call(this, shapes, -Math.PI / 2);
},
@@ -68,6 +69,7 @@ define(
* @return {boolean} `false`或者`undefined`
*/
rotateright: function (shapes) {
shapes = shapes || (this.currentGroup && this.currentGroup.shapes);
return support.rotate.call(this, shapes, Math.PI / 2);
},
@@ -78,7 +80,7 @@ define(
* @return {boolean} `false`或者`undefined`
*/
flipshapes: function (shapes) {
shapes = shapes || (this.currentGroup && this.currentGroup.shapes);
if (!shapes || !shapes.length) {
return false;
}
@@ -97,7 +99,7 @@ define(
* @return {boolean} `false`或者`undefined`
*/
mirrorshapes: function (shapes) {
shapes = shapes || (this.currentGroup && this.currentGroup.shapes);
if (!shapes || !shapes.length) {
return false;
}

View File

@@ -43,7 +43,7 @@ define(
this.fire('save');
break;
default:
this.execCommand(e.command, e);
this.execCommand(e.command);
}
}

View File

@@ -69,7 +69,7 @@ define(
default:
// 是否编辑器支持
if (this.supportCommand(command)) {
this.execCommand(command, e);
this.execCommand(command);
}
}
}

88
src/fonteditor/editor.js Normal file
View File

@@ -0,0 +1,88 @@
/**
* @file 编辑器导出接口,用于编辑字形相关的矢量图形
* @author mengke01(kekee000@gmail.com)
*/
define(function (require) {
var editor = require('../editor/main');
var options = require('../editor/options');
var commandList = require('../editor/menu/commandList');
// 用来做跨域通信的密钥
var EDITOR_KEY = require('../common/lang').parseQuery(location.search.slice(1)).key || 'fonteditor';
/**
* 向引用方外部发送事件
* @param {string} name 名称
* @param {Object} data 数据
* @param {number} stamp 某次通信的信标,用以区分多次事件
*/
function fireEvent(name, data, stamp) {
parent.postMessage({
key: EDITOR_KEY,
name: name,
stamp: stamp,
data: data || null
}, '*');
return this;
}
function onMessage() {
window.addEventListener('message', function (e) {
if (!e.data.key === EDITOR_KEY) {
return;
}
var name = e.data.name;
var args = e.data.data;
if (typeof window.editor[name] === 'function') {
var data = window.editor[name].apply(window.editor, args);
if (e.data.stamp) {
fireEvent(name, data === window.editor ? null : data, e.data.stamp);
}
}
});
}
function removeCommandMenu(name, menu) {
for (var i = menu.length - 1; i >= 0; i--) {
if (menu[i].name === name) {
menu.splice(i, 1);
return true;
}
else if (menu[i].items) {
if (removeCommandMenu(name, menu[i].items)) {
return true
}
}
}
return false;
}
function initEditor() {
removeCommandMenu('fontsetting', commandList.editor)
removeCommandMenu('save', commandList.editor)
removeCommandMenu('moresetting', commandList.editor)
options.editor.unitsPerEm = 1024;
options.editor.axis.metrics = {
ascent: 812, // 上升
descent: -212, // 下降
xHeight: 400, // x高度
capHeight: 700 // 大写字母高度
};
var context = editor.create($('#editor-panel').get(0), options);
return context;
}
function main() {
onMessage();
var context = initEditor();
context.focus();
window.editor = context;
fireEvent('load');
}
main();
return {};
});