fix svg import bug
This commit is contained in:
parent
130880e471
commit
743831cf0c
@ -119,16 +119,16 @@ define(
|
||||
var fileReader = new FileReader();
|
||||
|
||||
fileReader.onload = function (e) {
|
||||
try {
|
||||
//try {
|
||||
var buffer = e.target.result;
|
||||
var imported = svg2ttf(buffer);
|
||||
fileReader = null;
|
||||
options.success && options.success(imported);
|
||||
}
|
||||
catch (exp) {
|
||||
alert(exp.message);
|
||||
throw exp;
|
||||
}
|
||||
// }
|
||||
// catch (exp) {
|
||||
// alert(exp.message);
|
||||
// throw exp;
|
||||
// }
|
||||
|
||||
loading.hide();
|
||||
};
|
||||
|
@ -18,6 +18,7 @@ define(
|
||||
var glyfAdjust = require('./util/glyfAdjust');
|
||||
var error = require('./error');
|
||||
var getEmptyttfObject = require('./getEmptyttfObject');
|
||||
var reduceGlyf = require('./util/reduceGlyf');
|
||||
|
||||
/**
|
||||
* 加载xml字符串
|
||||
@ -112,9 +113,13 @@ define(
|
||||
|
||||
|
||||
// 如果是svg格式字体,则去小数
|
||||
// 由于svg格式导入时候会出现字形重复问题,这里进行优化
|
||||
if (ttf.from === 'svgfont' && ttf.head.unitsPerEm > 128) {
|
||||
ttf.glyf.forEach(function (g) {
|
||||
glyfAdjust(g);
|
||||
if (g.contours) {
|
||||
reduceGlyf(g);
|
||||
glyfAdjust(g);
|
||||
}
|
||||
});
|
||||
}
|
||||
// 否则重新计算字形大小,缩放到1024的em
|
||||
@ -126,6 +131,7 @@ define(
|
||||
|
||||
ttf.glyf.forEach(function (g) {
|
||||
if (g.contours) {
|
||||
reduceGlyf(g);
|
||||
var bound = computeBoundingBox.computePathBox.apply(null, g.contours);
|
||||
if (bound) {
|
||||
xMin = Math.min(xMin, bound.x);
|
||||
|
@ -24,12 +24,10 @@ define(
|
||||
var contour;
|
||||
var length;
|
||||
for (var j = contours.length - 1; j >= 0; j--) {
|
||||
contour = contours[j];
|
||||
reducePath(contour);
|
||||
length = contour.length;
|
||||
contour = reducePath(contours[j]);
|
||||
|
||||
// 空轮廓
|
||||
if (0 === length || 2 === length) {
|
||||
if (contour.length <= 2) {
|
||||
contours.splice(j, 1);
|
||||
continue;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user