support referenceline text
This commit is contained in:
parent
8b8a8a0291
commit
f86275cb3b
@ -15,6 +15,7 @@
|
||||
],
|
||||
"description": "ttf to woff, woff2, svg, eot convert, ttf adjust",
|
||||
"scripts": {
|
||||
"start": "npm run dev",
|
||||
"dev": "webpack-dev-server --open --config ./config/webpack.dev.js",
|
||||
"demo": "webpack-dev-server --open --config ./config/webpack.demo.js",
|
||||
"prod": "webpack --production --config ./config/webpack.prod.js",
|
||||
|
@ -56,13 +56,13 @@ export default function () {
|
||||
|
||||
// 坐标原点位置,基线原点
|
||||
let originX = (width - options.unitsPerEm) / 2;
|
||||
let origionY = (height + (options.unitsPerEm + options.axis.metrics.descent)) / 2;
|
||||
let originY = (height + (options.unitsPerEm + options.axis.metrics.descent)) / 2;
|
||||
|
||||
// 绘制轴线
|
||||
this.axis = this.axisLayer.addShape('axis', Object.assign(lang.clone(options.axis), {
|
||||
id: 'axis',
|
||||
x: originX,
|
||||
y: origionY,
|
||||
y: originY,
|
||||
unitsPerEm: options.unitsPerEm,
|
||||
selectable: false
|
||||
}));
|
||||
@ -76,6 +76,8 @@ export default function () {
|
||||
arrow: {
|
||||
y: 22
|
||||
},
|
||||
axis: this.axis,
|
||||
drawAxisText: true,
|
||||
style: {
|
||||
fill: true,
|
||||
stroke: true,
|
||||
|
@ -31,6 +31,8 @@ const mode = {
|
||||
p0: {
|
||||
x: e.x
|
||||
},
|
||||
axis: this.axis,
|
||||
drawAxisText: true,
|
||||
style: this.options.referenceline.style
|
||||
});
|
||||
this._dragMode = mode.dragLine;
|
||||
@ -41,6 +43,8 @@ const mode = {
|
||||
p0: {
|
||||
y: e.y
|
||||
},
|
||||
axis: this.axis,
|
||||
drawAxisText: true,
|
||||
style: this.options.referenceline.style
|
||||
});
|
||||
this._dragMode = mode.dragLine;
|
||||
|
@ -270,11 +270,11 @@ export default class GLYFEditor {
|
||||
/**
|
||||
* 执行指定命令
|
||||
*
|
||||
* @param {string} command 命令名
|
||||
* @param {...Array} args 命令参数
|
||||
*/
|
||||
execCommand() {
|
||||
execCommand(...args) {
|
||||
if (this.editor) {
|
||||
this.editor.execCommand.apply(this.editor, arguments);
|
||||
this.editor.execCommand.apply(this.editor, args);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ function svg2ttf(buffer) {
|
||||
function readttf(buffer, options) {
|
||||
// 暂不支持otf直接编辑,这里需要将otf转换成ttf
|
||||
if (options.type === 'woff') {
|
||||
options.inflate = inflate;
|
||||
options.inflate = inflate.inflate;
|
||||
}
|
||||
let ttf = font.create(buffer, options).data;
|
||||
delete options.inflate;
|
||||
|
@ -116,8 +116,8 @@ export default class Render {
|
||||
let size = me.painter.getSize();
|
||||
|
||||
me.fire('resize', {
|
||||
size: size,
|
||||
prevSize: prevSize
|
||||
size,
|
||||
prevSize
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ export default shape.derive({
|
||||
|
||||
isIn(shape, x, y) {
|
||||
// 单点模式
|
||||
return undefined !== shape.p0.x && Math.abs(shape.p0.x - x) < 4
|
||||
return undefined !== shape.p0.x && Math.abs(shape.p0.x - x) < 4
|
||||
|| undefined !== shape.p0.y && Math.abs(shape.p0.y - y) < 4;
|
||||
},
|
||||
|
||||
@ -55,7 +55,7 @@ export default shape.derive({
|
||||
* @param {number} shape.p0.y y坐标位置
|
||||
* @param {Object} shape.arrow 箭头配置数据
|
||||
*/
|
||||
draw(ctx, shape) {
|
||||
draw(ctx, shape, camera) {
|
||||
if (undefined !== shape.p0.x) {
|
||||
let x0 = Math.round(shape.p0.x);
|
||||
ctx.moveTo(x0, 0);
|
||||
@ -78,5 +78,22 @@ export default shape.derive({
|
||||
ctx.lineTo(shape.arrow.x, y0);
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制axis的坐标
|
||||
if (shape.axis && shape.drawAxisText) {
|
||||
ctx.save();
|
||||
ctx.scale(0.8, 0.8);
|
||||
let axis = shape.axis;
|
||||
let thickness = (axis.graduation.thickness || 22) + 18;
|
||||
if (undefined !== shape.p0.x) {
|
||||
let px = Math.round((shape.p0.x - shape.axis.x) / camera.scale);
|
||||
ctx.fillText(px, (shape.p0.x + 2) * 1.25, thickness * 1.25);
|
||||
}
|
||||
else {
|
||||
let py = Math.round((shape.axis.y - shape.p0.y) / camera.scale);
|
||||
ctx.fillText(py, thickness * 1.25, (shape.p0.y - 2) * 1.25);
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user