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