add right side bearing
This commit is contained in:
parent
c1d46b61e2
commit
457ff27134
@ -16,6 +16,8 @@ function(require) {
|
||||
"xMax": 521,
|
||||
"yMin": -27,
|
||||
"yMax": 475,
|
||||
"advanceWidth": 520,
|
||||
|
||||
"contours": [
|
||||
[
|
||||
{
|
||||
|
@ -196,17 +196,28 @@ define(
|
||||
*/
|
||||
function initAxis(origin) {
|
||||
|
||||
var axisLayer = this.render.getLayer('axis');
|
||||
// 绘制轴线
|
||||
this.axis = {
|
||||
type: 'axis',
|
||||
this.axis = axisLayer.addShape('axis', {
|
||||
id: 'axis',
|
||||
x: origin.x,
|
||||
y: origin.y,
|
||||
width: 100,
|
||||
width: origin.axisWidth,
|
||||
unitsPerEm: this.options.unitsPerEm,
|
||||
metrics: this.options.metrics,
|
||||
selectable: false
|
||||
};
|
||||
this.render.getLayer('axis').addShape(this.axis);
|
||||
});
|
||||
|
||||
axisLayer.addShape('line', {
|
||||
id: 'rightSideBearing',
|
||||
p0: {
|
||||
x: origin.rightSideBearing
|
||||
},
|
||||
style: {
|
||||
strokeColor: 'blue'
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -293,7 +304,13 @@ define(
|
||||
// 重置形状
|
||||
this.render.reset();
|
||||
|
||||
initAxis.call(this, {x: offsetX, y: offsetY});
|
||||
var rightSideBearing = offsetX + font.advanceWidth + font.xMin;
|
||||
initAxis.call(this, {
|
||||
x: offsetX,
|
||||
y: offsetY,
|
||||
rightSideBearing: rightSideBearing,
|
||||
axisWidth: 100
|
||||
});
|
||||
|
||||
var fontLayer = this.render.painter.getLayer('font');
|
||||
|
||||
|
@ -27,10 +27,17 @@ define(
|
||||
var ratio = camera.ratio;
|
||||
var scale = camera.scale;
|
||||
|
||||
shape.p0.x = ratio * (shape.p0.x - center.x) + center.x;
|
||||
shape.p0.y = ratio * (shape.p0.y - center.y) + center.y;
|
||||
shape.p1.x = ratio * (shape.p1.x - center.x) + center.x;
|
||||
shape.p1.y = ratio * (shape.p1.y - center.y) + center.y;
|
||||
if(undefined !== shape.p0.x) {
|
||||
shape.p0.x = ratio * (shape.p0.x - center.x) + center.x;
|
||||
}
|
||||
else {
|
||||
shape.p0.y = ratio * (shape.p0.y - center.y) + center.y;
|
||||
}
|
||||
|
||||
if(undefined !== shape.p1) {
|
||||
shape.p1.x = ratio * (shape.p1.x - center.x) + center.x;
|
||||
shape.p1.y = ratio * (shape.p1.y - center.y) + center.y;
|
||||
}
|
||||
|
||||
return shape;
|
||||
},
|
||||
@ -41,10 +48,18 @@ define(
|
||||
* @return {Object} shape对象
|
||||
*/
|
||||
move: function(shape, mx, my) {
|
||||
shape.p0.x += mx;
|
||||
shape.p0.y += my;
|
||||
shape.p1.x += mx;
|
||||
shape.p1.y += my;
|
||||
|
||||
if(undefined !== shape.p0.x) {
|
||||
shape.p0.x += mx;
|
||||
}
|
||||
else {
|
||||
shape.p0.y += my;
|
||||
}
|
||||
|
||||
if(undefined !== shape.p1) {
|
||||
shape.p1.x += mx;
|
||||
shape.p1.y += my;
|
||||
}
|
||||
return shape;
|
||||
},
|
||||
|
||||
@ -56,7 +71,7 @@ define(
|
||||
* @param {Object} 矩形区域
|
||||
*/
|
||||
getRect: function(shape) {
|
||||
return computeBoundingBox.computeBounding([shape.p0, shape.p1]);
|
||||
return undefined === shape.p1 ? false : computeBoundingBox.computeBounding([shape.p0, shape.p1]);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -68,11 +83,19 @@ define(
|
||||
* @param {boolean} 是否
|
||||
*/
|
||||
isIn: function(shape, x, y) {
|
||||
var x0 = shape.p0.x;
|
||||
var y0 = shape.p0.y;
|
||||
var x1 = shape.p1.x;
|
||||
var y1 = shape.p1.y;
|
||||
return (y - y0) * (x - x1) == (y - y1) * (x - x0);
|
||||
|
||||
// 单点模式
|
||||
if(undefined === shape.p1) {
|
||||
return undefined !== shape.p0.x && Math.abs(shape.p0.x - x) < 2
|
||||
|| undefined !== shape.p0.y && Math.abs(shape.p0.y - y) < 2;
|
||||
}
|
||||
else {
|
||||
var x0 = shape.p0.x;
|
||||
var y0 = shape.p0.y;
|
||||
var x1 = shape.p1.x;
|
||||
var y1 = shape.p1.y;
|
||||
return (y - y0) * (x - x1) == (y - y1) * (x - x0);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -83,18 +106,37 @@ define(
|
||||
*/
|
||||
draw: function(ctx, shape) {
|
||||
|
||||
ctx.translate(0.5, 0.5);
|
||||
var x0 = Math.round(shape.p0.x);
|
||||
var y0 = Math.round(shape.p0.y);
|
||||
var x1 = Math.round(shape.p1.x);
|
||||
var y1 = Math.round(shape.p1.y);
|
||||
|
||||
if(shape.dashed) {
|
||||
dashedLineTo(ctx, x0, y0, x1, y1);
|
||||
ctx.translate(0.5, 0.5);
|
||||
|
||||
// 单点模式
|
||||
if(undefined === shape.p1) {
|
||||
|
||||
if(undefined !== shape.p0.x) {
|
||||
var x0 = Math.round(shape.p0.x);
|
||||
ctx.moveTo(x0, 0);
|
||||
ctx.lineTo(x0, ctx.canvas.height);
|
||||
}
|
||||
else {
|
||||
var y0 = Math.round(shape.p0.y);
|
||||
ctx.moveTo(0, y0);
|
||||
ctx.lineTo(ctx.canvas.width, y0);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
ctx.moveTo(x0, y0);
|
||||
ctx.lineTo(x1, y1);
|
||||
var x0 = Math.round(shape.p0.x);
|
||||
var y0 = Math.round(shape.p0.y);
|
||||
var x1 = Math.round(shape.p1.x);
|
||||
var y1 = Math.round(shape.p1.y);
|
||||
|
||||
if(shape.dashed) {
|
||||
dashedLineTo(ctx, x0, y0, x1, y1);
|
||||
}
|
||||
else {
|
||||
ctx.moveTo(x0, y0);
|
||||
ctx.lineTo(x1, y1);
|
||||
}
|
||||
}
|
||||
ctx.translate(-0.5, -0.5);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user