add svg glyf adjust
This commit is contained in:
parent
41f1322992
commit
626993ef80
@ -199,7 +199,7 @@ define(
|
|||||||
!new SettingAdjustPos({
|
!new SettingAdjustPos({
|
||||||
onChange: function (setting) {
|
onChange: function (setting) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
program.ttfManager.adjustGlyfPos(setting, selected);
|
program.ttfManager.adjustGlyfPos(selected, setting);
|
||||||
}, 20);
|
}, 20);
|
||||||
}
|
}
|
||||||
}).show(opt);
|
}).show(opt);
|
||||||
@ -211,7 +211,7 @@ define(
|
|||||||
!new SettingAdjustGlyf({
|
!new SettingAdjustGlyf({
|
||||||
onChange: function (setting) {
|
onChange: function (setting) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
program.ttfManager.adjustGlyf(setting, program.viewer.getSelected());
|
program.ttfManager.adjustGlyf(program.viewer.getSelected(), setting);
|
||||||
}, 20);
|
}, 20);
|
||||||
}
|
}
|
||||||
}).show();
|
}).show();
|
||||||
|
@ -275,13 +275,13 @@ define(
|
|||||||
/**
|
/**
|
||||||
* 调整glyf位置
|
* 调整glyf位置
|
||||||
*
|
*
|
||||||
* @param {Object} setting 选项
|
|
||||||
* @param {Array} indexList 索引列表
|
* @param {Array} indexList 索引列表
|
||||||
|
* @param {Object} setting 选项
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
Manager.prototype.adjustGlyfPos = function (setting, indexList) {
|
Manager.prototype.adjustGlyfPos = function (indexList, setting) {
|
||||||
|
|
||||||
var list = this.ttf.adjustGlyfPos(setting, indexList);
|
var list = this.ttf.adjustGlyfPos(indexList, setting);
|
||||||
if (list.length) {
|
if (list.length) {
|
||||||
list.forEach(function (g) {
|
list.forEach(function (g) {
|
||||||
g.modify = 'edit';
|
g.modify = 'edit';
|
||||||
@ -296,13 +296,13 @@ define(
|
|||||||
/**
|
/**
|
||||||
* 调整glyf
|
* 调整glyf
|
||||||
*
|
*
|
||||||
* @param {Object} setting 选项
|
|
||||||
* @param {Array} indexList 索引列表
|
* @param {Array} indexList 索引列表
|
||||||
|
* @param {Object} setting 选项
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
Manager.prototype.adjustGlyf = function (setting, indexList) {
|
Manager.prototype.adjustGlyf = function (indexList, setting) {
|
||||||
|
|
||||||
var list = this.ttf.adjustGlyf(setting, indexList);
|
var list = this.ttf.adjustGlyf(indexList, setting);
|
||||||
if (list.length) {
|
if (list.length) {
|
||||||
list.forEach(function (g) {
|
list.forEach(function (g) {
|
||||||
g.modify = 'edit';
|
g.modify = 'edit';
|
||||||
@ -343,7 +343,7 @@ define(
|
|||||||
|| (undefined !== setting.rightSideBearing
|
|| (undefined !== setting.rightSideBearing
|
||||||
&& setting.rightSideBearing + (glyf.xMax || 0) !== glyf.advanceWidth)
|
&& setting.rightSideBearing + (glyf.xMax || 0) !== glyf.advanceWidth)
|
||||||
) {
|
) {
|
||||||
var list = this.ttf.adjustGlyfPos(setting, [index]);
|
var list = this.ttf.adjustGlyfPos([index], setting);
|
||||||
if (list.length) {
|
if (list.length) {
|
||||||
list.forEach(function (g) {
|
list.forEach(function (g) {
|
||||||
g.modify = 'edit';
|
g.modify = 'edit';
|
||||||
|
107
src/ttf/ttf.js
107
src/ttf/ttf.js
@ -65,6 +65,58 @@ define(
|
|||||||
return glyfList;
|
return glyfList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调整字形位置
|
||||||
|
*
|
||||||
|
* @param {Array} glyfList 字形列表
|
||||||
|
* @param {number=} leftSideBearing 左边距
|
||||||
|
* @param {number=} rightSideBearing 右边距
|
||||||
|
* @param {number=} verticalAlign 垂直对齐
|
||||||
|
*
|
||||||
|
* @return {Array} 改变的列表
|
||||||
|
*/
|
||||||
|
function adjustPos(glyfList, leftSideBearing, rightSideBearing, verticalAlign) {
|
||||||
|
|
||||||
|
var changed = false;
|
||||||
|
|
||||||
|
// 左边轴
|
||||||
|
if (null != leftSideBearing) {
|
||||||
|
changed = true;
|
||||||
|
|
||||||
|
glyfList.forEach(function (g) {
|
||||||
|
if (g.leftSideBearing !== leftSideBearing) {
|
||||||
|
glyfAdjust(g, 1, 1, leftSideBearing - g.leftSideBearing);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 右边轴
|
||||||
|
if (null != rightSideBearing) {
|
||||||
|
changed = true;
|
||||||
|
|
||||||
|
glyfList.forEach(function (g) {
|
||||||
|
g.advanceWidth = g.xMax + rightSideBearing;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 基线高度
|
||||||
|
if (null != verticalAlign) {
|
||||||
|
changed = true;
|
||||||
|
var verticalAlign = verticalAlign || 0;
|
||||||
|
|
||||||
|
glyfList.forEach(function (g) {
|
||||||
|
if (g.contours && g.contours.length) {
|
||||||
|
var bound = computeBoundingBox.computePath.apply(this, g.contours);
|
||||||
|
var offset = verticalAlign - bound.y;
|
||||||
|
glyfAdjust(g, 1, 1, 0, offset);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed ? glyfList : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合并两个ttfObject,此处仅合并简单字形
|
* 合并两个ttfObject,此处仅合并简单字形
|
||||||
@ -91,7 +143,8 @@ define(
|
|||||||
if (options.adjustGlyf) {
|
if (options.adjustGlyf) {
|
||||||
var ascent = ttf.hhea.ascent;
|
var ascent = ttf.hhea.ascent;
|
||||||
var descent = ttf.hhea.descent;
|
var descent = ttf.hhea.descent;
|
||||||
var ajdustToEmPadding = 0;
|
var ajdustToEmPadding = 16;
|
||||||
|
adjustPos(list, 16, 16);
|
||||||
adjustToEmBox(list, ascent, descent, ajdustToEmPadding);
|
adjustToEmBox(list, ascent, descent, ajdustToEmPadding);
|
||||||
|
|
||||||
list.forEach(function (g) {
|
list.forEach(function (g) {
|
||||||
@ -376,63 +429,31 @@ define(
|
|||||||
/**
|
/**
|
||||||
* 调整glyf位置
|
* 调整glyf位置
|
||||||
*
|
*
|
||||||
* @param {Object} setting 选项
|
|
||||||
* @param {Array} indexList 索引列表
|
* @param {Array} indexList 索引列表
|
||||||
|
* @param {Object} setting 选项
|
||||||
* @return {Array} 改变的glyf
|
* @return {Array} 改变的glyf
|
||||||
*/
|
*/
|
||||||
TTF.prototype.adjustGlyfPos = function (setting, indexList) {
|
TTF.prototype.adjustGlyfPos = function (indexList, setting) {
|
||||||
|
|
||||||
var glyfList = this.getGlyf(indexList);
|
var glyfList = this.getGlyf(indexList);
|
||||||
var changed = false;
|
|
||||||
|
|
||||||
// 左边轴
|
return adjustPos(
|
||||||
if (undefined !== setting.leftSideBearing) {
|
glyfList,
|
||||||
|
setting.leftSideBearing,
|
||||||
changed = true;
|
setting.rightSideBearing,
|
||||||
|
setting.verticalAlign
|
||||||
glyfList.forEach(function (g) {
|
);
|
||||||
if (g.leftSideBearing !== setting.leftSideBearing) {
|
|
||||||
glyfAdjust(g, 1, 1, setting.leftSideBearing - g.leftSideBearing);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 右边轴
|
|
||||||
if (undefined !== setting.rightSideBearing) {
|
|
||||||
|
|
||||||
changed = true;
|
|
||||||
glyfList.forEach(function (g) {
|
|
||||||
g.advanceWidth = g.xMax + setting.rightSideBearing;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 基线高度
|
|
||||||
if (undefined !== setting.verticalAlign) {
|
|
||||||
changed = true;
|
|
||||||
|
|
||||||
var verticalAlign = setting.verticalAlign || 0;
|
|
||||||
glyfList.forEach(function (g) {
|
|
||||||
if (g.contours && g.contours.length) {
|
|
||||||
var bound = computeBoundingBox.computePath.apply(this, g.contours);
|
|
||||||
var offset = verticalAlign - bound.y;
|
|
||||||
glyfAdjust(g, 1, 1, 0, offset);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return changed ? glyfList : [];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调整glyf
|
* 调整glyf
|
||||||
*
|
*
|
||||||
* @param {Object} setting 选项
|
|
||||||
* @param {Array} indexList 索引列表
|
* @param {Array} indexList 索引列表
|
||||||
|
* @param {Object} setting 选项
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
TTF.prototype.adjustGlyf = function (setting, indexList) {
|
TTF.prototype.adjustGlyf = function (indexList, setting) {
|
||||||
|
|
||||||
var glyfList = this.getGlyf(indexList);
|
var glyfList = this.getGlyf(indexList);
|
||||||
var changed = false;
|
var changed = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user