Merge branch 'develop'
This commit is contained in:
commit
9e1a50c342
@ -11,7 +11,7 @@ define(
|
||||
|
||||
var lang = require('common/lang');
|
||||
var editor = require('editor/main');
|
||||
var shape_baidu = require('./contours-2');
|
||||
var shape_baidu = require('demo/../data/contours-2');
|
||||
var isPathCross = require('graphics/isPathCross');
|
||||
var pathJoin = require('graphics/pathJoin');
|
||||
var util = require('graphics/util');
|
||||
|
@ -10,7 +10,7 @@ define(
|
||||
function(require) {
|
||||
|
||||
var editor = require('editor/main');
|
||||
var compound = require('./compound-glyf');
|
||||
var compound = require('demo/../data/compound-glyf');
|
||||
|
||||
var currentEditor;
|
||||
|
||||
|
@ -10,7 +10,7 @@ define(
|
||||
function(require) {
|
||||
|
||||
var editor = require('editor/main');
|
||||
var shape_baidu = require('./shape-baidu');
|
||||
var shape_baidu = require('demo/../data/shape-baidu');
|
||||
|
||||
var currentEditor;
|
||||
|
||||
|
@ -20,7 +20,7 @@ define(
|
||||
* 初始化
|
||||
*/
|
||||
init: function () {
|
||||
$.getJSON('./js/baiduHealth.json', function(ttf) {
|
||||
$.getJSON('./data/baiduHealth.json', function(ttf) {
|
||||
ttfObject = ttf;
|
||||
var str = '';
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var drawContour = require('./drawContour');
|
||||
var drawPath = require('render/util/drawPath');
|
||||
|
||||
/**
|
||||
* glyf canvas绘制
|
||||
@ -55,7 +55,7 @@ define(
|
||||
|
||||
contours = glyf.contours;
|
||||
for (i = 0, l = contours.length; i < l; i++) {
|
||||
drawContour(ctx, contours[i]);
|
||||
drawPath(ctx, contours[i]);
|
||||
}
|
||||
}
|
||||
// 复合图元绘制
|
||||
@ -76,7 +76,7 @@ define(
|
||||
|
||||
contours = g.glyf.contours;
|
||||
for (i = 0, l = contours.length; i < l; i++) {
|
||||
drawContour(ctx, contours[i]);
|
||||
drawPath(ctx, contours[i]);
|
||||
}
|
||||
|
||||
ctx.restore();
|
@ -14,7 +14,7 @@ define(
|
||||
var ttf2base64 = require('ttf/ttf2base64');
|
||||
var ajaxFile = require('common/ajaxFile');
|
||||
var setFontface = require('./setFontface');
|
||||
var glyf2canvas = require('ttf/util/glyf2canvas');
|
||||
var glyf2canvas = require('./glyf2canvas');
|
||||
var lang = require('common/lang');
|
||||
|
||||
var ttf = null;
|
||||
|
@ -10,8 +10,8 @@ define(
|
||||
function(require) {
|
||||
|
||||
var render = require('render/main');
|
||||
var shape_baidu = require('./shape-baidu');
|
||||
var shape_bdjk = require('./shape-bdjk');
|
||||
var shape_baidu = require('demo/../data/shape-baidu');
|
||||
var shape_bdjk = require('demo/../data/shape-bdjk');
|
||||
var lang = require('common/lang');
|
||||
|
||||
var currentRender;
|
||||
|
@ -97,7 +97,7 @@ define(
|
||||
}
|
||||
|
||||
function readAndWrite() {
|
||||
$.getJSON('./js/iconfont.json', function(ttf) {
|
||||
$.getJSON('./data/iconfont.json', function(ttf) {
|
||||
|
||||
var reader = new TTFReader();
|
||||
var writer = new TTFWriter();
|
||||
|
@ -181,7 +181,7 @@ define(
|
||||
|
||||
init: function () {
|
||||
|
||||
$.getJSON('./js/baiduHealth.json', function(ttf) {
|
||||
$.getJSON('./data/baiduHealth.json', function(ttf) {
|
||||
resolve(ttf);
|
||||
write(ttf);
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ define(
|
||||
* 初始化
|
||||
*/
|
||||
init: function () {
|
||||
$.getJSON('./js/iconfont.json', function(ttf) {
|
||||
$.getJSON('./data/iconfont.json', function(ttf) {
|
||||
|
||||
var reader = new TTFReader();
|
||||
var writer = new TTFWriter();
|
||||
|
@ -73,8 +73,8 @@
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a data-format="ttf" data-action="preview">ttf字体</a></li>
|
||||
<li><a data-format="woff" data-action="preview">woff字体</a></li>
|
||||
<li><a data-format="svg" data-action="preview" title="仅支持Safari">svg字体</a></li>
|
||||
<li><a data-format="eot" data-action="preview" title="仅支持IE">eot字体</a></li>
|
||||
<li><a data-format="svg" data-action="preview" title="仅支持Safari">svg字体(仅safari)</a></li>
|
||||
<li><a data-format="eot" data-action="preview" title="仅支持IE">eot字体(仅IE)</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -21,27 +21,52 @@ define(
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'circle',
|
||||
title: '添加圆'
|
||||
title: '圆'
|
||||
},
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'rect',
|
||||
title: '添加矩形'
|
||||
title: '矩形'
|
||||
},
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'roundrect',
|
||||
title: '添加圆角矩形'
|
||||
title: '圆角矩形'
|
||||
},
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'star',
|
||||
title: '添加五角星'
|
||||
title: '五角星'
|
||||
},
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'arrow',
|
||||
title: '添加箭头'
|
||||
title: '箭头'
|
||||
},
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'triangle',
|
||||
title: '三角形'
|
||||
},
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'heart',
|
||||
title: '心形'
|
||||
},
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'tel',
|
||||
title: '电话'
|
||||
},
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'drop',
|
||||
title: '水滴'
|
||||
},
|
||||
{
|
||||
name: 'addsupportshapes',
|
||||
type: 'du',
|
||||
title: '度图标'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
6
src/editor/shapes/drop.js
Normal file
6
src/editor/shapes/drop.js
Normal file
@ -0,0 +1,6 @@
|
||||
/* eslint-disable*/
|
||||
define(
|
||||
function (require) {
|
||||
return [[{"x":731,"y":526},{"x":674,"y":443,"onCurve":true},{"x":669,"y":437},{"x":589,"y":332},{"x":525,"y":242},{"x":446,"y":102},{"x":426,"y":41,"onCurve":true},{"x":421,"y":22},{"x":384,"y":0},{"x":347,"y":0},{"x":311,"y":22},{"x":305,"y":41,"onCurve":true},{"x":285,"y":102},{"x":206,"y":242},{"x":142,"y":332},{"x":62,"y":437},{"x":57,"y":443,"onCurve":true},{"x":0,"y":528},{"x":0,"y":621,"onCurve":true},{"x":0,"y":759},{"x":214,"y":953},{"x":517,"y":953},{"x":731,"y":759},{"x":731,"y":621,"onCurve":true}]];
|
||||
}
|
||||
);
|
6
src/editor/shapes/du.js
Normal file
6
src/editor/shapes/du.js
Normal file
@ -0,0 +1,6 @@
|
||||
/* eslint-disable*/
|
||||
define(
|
||||
function (require) {
|
||||
return [[{"x":373,"y":0,"onCurve":true},{"x":439,"y":0},{"x":477,"y":88,"onCurve":true},{"x":485,"y":107},{"x":489,"y":152,"onCurve":true},{"x":489,"y":245},{"x":415,"y":293,"onCurve":true},{"x":392,"y":304},{"x":371,"y":304,"onCurve":true},{"x":283,"y":304},{"x":255,"y":181,"onCurve":true},{"x":253,"y":162},{"x":253,"y":152,"onCurve":true},{"x":253,"y":51},{"x":335,"y":6,"onCurve":true},{"x":354,"y":0}],[{"x":687,"y":23,"onCurve":true},{"x":732,"y":23},{"x":780,"y":82,"onCurve":true},{"x":807,"y":122},{"x":807,"y":160,"onCurve":true},{"x":807,"y":223},{"x":742,"y":287,"onCurve":true},{"x":706,"y":316},{"x":666,"y":316,"onCurve":true},{"x":662,"y":316,"onCurve":true},{"x":586,"y":316},{"x":557,"y":242,"onCurve":true},{"x":550,"y":215},{"x":550,"y":190,"onCurve":true},{"x":550,"y":91},{"x":654,"y":30,"onCurve":true},{"x":666,"y":27}],[{"x":120,"y":224,"onCurve":true},{"x":200,"y":224},{"x":249,"y":325,"onCurve":true},{"x":253,"y":352},{"x":255,"y":380,"onCurve":true},{"x":255,"y":481},{"x":173,"y":512,"onCurve":true},{"x":152,"y":521},{"x":120,"y":521,"onCurve":true},{"x":27,"y":521},{"x":0,"y":396,"onCurve":true},{"x":0,"y":382,"onCurve":true},{"x":0,"y":325},{"x":40,"y":268,"onCurve":true},{"x":74,"y":224}],[{"x":862,"y":299,"onCurve":true},{"x":866,"y":299,"onCurve":true},{"x":955,"y":299},{"x":987,"y":386,"onCurve":true},{"x":997,"y":403},{"x":997,"y":428,"onCurve":true},{"x":997,"y":449,"onCurve":true},{"x":997,"y":586},{"x":871,"y":586,"onCurve":true},{"x":784,"y":586},{"x":755,"y":521,"onCurve":true},{"x":746,"y":485},{"x":746,"y":447,"onCurve":true},{"x":746,"y":299}],[{"x":479,"y":396,"onCurve":true},{"x":491,"y":396,"onCurve":true},{"x":586,"y":396},{"x":662,"y":508,"onCurve":true},{"x":765,"y":614},{"x":867,"y":689,"onCurve":true},{"x":919,"y":738},{"x":919,"y":797,"onCurve":true},{"x":919,"y":808,"onCurve":true},{"x":919,"y":888},{"x":852,"y":944,"onCurve":true},{"x":803,"y":974},{"x":734,"y":974,"onCurve":true},{"x":725,"y":974,"onCurve":true},{"x":662,"y":974},{"x":555,"y":949,"onCurve":true},{"x":517,"y":944},{"x":489,"y":944,"onCurve":true},{"x":464,"y":944},{"x":318,"y":963,"onCurve":true},{"x":291,"y":964},{"x":259,"y":964,"onCurve":true},{"x":255,"y":964,"onCurve":true},{"x":143,"y":964},{"x":103,"y":906,"onCurve":true},{"x":61,"y":856},{"x":61,"y":793,"onCurve":true},{"x":61,"y":694},{"x":194,"y":613,"onCurve":true},{"x":302,"y":525},{"x":331,"y":483,"onCurve":true},{"x":360,"y":428},{"x":445,"y":399,"onCurve":true},{"x":472,"y":396}],[{"x":379,"y":552,"onCurve":true},{"x":379,"y":639,"onCurve":true},{"x":379,"y":641},{"x":375,"y":641,"onCurve":true},{"x":306,"y":641,"onCurve":true},{"x":240,"y":641},{"x":198,"y":721,"onCurve":true},{"x":192,"y":738},{"x":192,"y":759,"onCurve":true},{"x":192,"y":776,"onCurve":true},{"x":198,"y":854},{"x":213,"y":854,"onCurve":true},{"x":266,"y":885},{"x":304,"y":885,"onCurve":true},{"x":453,"y":885,"onCurve":true},{"x":453,"y":555,"onCurve":true},{"x":453,"y":552},{"x":449,"y":552,"onCurve":true}],[{"x":500,"y":664,"onCurve":true},{"x":500,"y":822,"onCurve":true},{"x":500,"y":871},{"x":573,"y":885,"onCurve":true},{"x":746,"y":885,"onCurve":true},{"x":746,"y":664,"onCurve":true},{"x":672,"y":664,"onCurve":true},{"x":672,"y":837,"onCurve":true},{"x":672,"y":841},{"x":666,"y":841,"onCurve":true},{"x":605,"y":841,"onCurve":true},{"x":578,"y":841},{"x":575,"y":814,"onCurve":true},{"x":575,"y":662,"onCurve":true},{"x":512,"y":662,"onCurve":true}],[{"x":316,"y":702,"onCurve":true},{"x":377,"y":702,"onCurve":true},{"x":380,"y":702},{"x":380,"y":704,"onCurve":true},{"x":380,"y":837,"onCurve":true},{"x":380,"y":841},{"x":377,"y":841,"onCurve":true},{"x":314,"y":841,"onCurve":true},{"x":270,"y":841},{"x":257,"y":778,"onCurve":true},{"x":257,"y":727},{"x":308,"y":702,"onCurve":true},{"x":312,"y":702}]];
|
||||
}
|
||||
);
|
6
src/editor/shapes/heart.js
Normal file
6
src/editor/shapes/heart.js
Normal file
@ -0,0 +1,6 @@
|
||||
/* eslint-disable*/
|
||||
define(
|
||||
function (require) {
|
||||
return [[{"x":578,"y":965},{"x":546,"y":965},{"x":535,"y":953,"onCurve":true},{"x":143,"y":576,"onCurve":true},{"x":137,"y":570},{"x":116,"y":549},{"x":68,"y":488},{"x":29,"y":425},{"x":0,"y":337},{"x":0,"y":295,"onCurve":true},{"x":0,"y":156},{"x":159,"y":0},{"x":300,"y":0,"onCurve":true},{"x":340,"y":0},{"x":419,"y":27},{"x":490,"y":74},{"x":539,"y":114},{"x":562,"y":137,"onCurve":true},{"x":585,"y":114},{"x":634,"y":74},{"x":705,"y":27},{"x":786,"y":0},{"x":824,"y":0,"onCurve":true},{"x":965,"y":0},{"x":1124,"y":156},{"x":1124,"y":295,"onCurve":true},{"x":1124,"y":433},{"x":981,"y":576,"onCurve":true},{"x":589,"y":953,"onCurve":true}]];
|
||||
}
|
||||
);
|
@ -1,6 +1,6 @@
|
||||
/* eslint-disable*/
|
||||
define(
|
||||
function(require) {
|
||||
return [[{"x":994,"y":426,"onCurve":true},{"x":1008,"y":411},{"x":1025,"y":390},{"x":1025,"y":375,"onCurve":true},{"x":1025,"y":360},{"x":1009,"y":346},{"x":988,"y":341,"onCurve":true},{"x":673,"y":311,"onCurve":true},{"x":559,"y":38,"onCurve":true},{"x":557,"y":34},{"x":550,"y":21},{"x":539,"y":9},{"x":524,"y":0},{"x":514,"y":0,"onCurve":true},{"x":495,"y":0},{"x":472,"y":23},{"x":466,"y":40,"onCurve":true},{"x":349,"y":313,"onCurve":true},{"x":34,"y":342,"onCurve":true},{"x":22,"y":344},{"x":4,"y":360},{"x":0,"y":389},{"x":17,"y":416},{"x":29,"y":427,"onCurve":true},{"x":30,"y":428},{"x":51,"y":446},{"x":83,"y":473},{"x":122,"y":507},{"x":143,"y":524,"onCurve":true},{"x":191,"y":565},{"x":251,"y":617,"onCurve":true},{"x":231,"y":697},{"x":216,"y":760,"onCurve":true},{"x":209,"y":787},{"x":196,"y":840},{"x":186,"y":884},{"x":177,"y":916},{"x":176,"y":920,"onCurve":true},{"x":174,"y":929},{"x":182,"y":946},{"x":200,"y":959},{"x":221,"y":962},{"x":231,"y":957,"onCurve":true},{"x":237,"y":955},{"x":266,"y":938},{"x":307,"y":914},{"x":357,"y":885},{"x":382,"y":871,"onCurve":true},{"x":442,"y":837},{"x":514,"y":795,"onCurve":true},{"x":780,"y":950,"onCurve":true},{"x":785,"y":952},{"x":805,"y":959},{"x":810,"y":959,"onCurve":true},{"x":825,"y":959},{"x":849,"y":945},{"x":846,"y":925,"onCurve":true},{"x":845,"y":921},{"x":839,"y":889},{"x":830,"y":844},{"x":820,"y":789},{"x":814,"y":762,"onCurve":true},{"x":801,"y":697},{"x":783,"y":616,"onCurve":true}]];
|
||||
return [[{"x":756,"y":610,"onCurve":true},{"x":1009,"y":364,"onCurve":true},{"x":660,"y":315,"onCurve":true},{"x":504,"y":0,"onCurve":true},{"x":348,"y":315,"onCurve":true},{"x":0,"y":364,"onCurve":true},{"x":252,"y":610,"onCurve":true},{"x":193,"y":958,"onCurve":true},{"x":504,"y":793,"onCurve":true},{"x":815,"y":958,"onCurve":true}]];
|
||||
}
|
||||
);
|
||||
|
@ -12,7 +12,12 @@ define(
|
||||
rect: require('./rect'),
|
||||
roundrect: require('./roundrect'),
|
||||
arrow: require('./arrow'),
|
||||
star: require('./star')
|
||||
star: require('./star'),
|
||||
triangle: require('./triangle'),
|
||||
heart: require('./heart'),
|
||||
tel: require('./tel'),
|
||||
du: require('./du'),
|
||||
drop: require('./drop')
|
||||
};
|
||||
}
|
||||
);
|
||||
|
6
src/editor/shapes/tel.js
Normal file
6
src/editor/shapes/tel.js
Normal file
@ -0,0 +1,6 @@
|
||||
/* eslint-disable*/
|
||||
define(
|
||||
function (require) {
|
||||
return [[{"x":91,"y":42,"onCurve":true},{"x":116,"y":26},{"x":154,"y":14,"onCurve":true},{"x":191,"y":0},{"x":200,"y":0,"onCurve":true},{"x":209,"y":7},{"x":225,"y":56,"onCurve":true},{"x":244,"y":102},{"x":258,"y":139,"onCurve":true},{"x":279,"y":193},{"x":323,"y":269},{"x":318,"y":285},{"x":297,"y":309,"onCurve":true},{"x":277,"y":332},{"x":232,"y":362},{"x":230,"y":385,"onCurve":true},{"x":223,"y":413},{"x":258,"y":480,"onCurve":true},{"x":293,"y":545},{"x":355,"y":610,"onCurve":true},{"x":423,"y":668},{"x":478,"y":694,"onCurve":true},{"x":536,"y":717},{"x":569,"y":719,"onCurve":true},{"x":580,"y":719},{"x":634,"y":663},{"x":655,"y":636,"onCurve":true},{"x":657,"y":631},{"x":692,"y":647,"onCurve":true},{"x":722,"y":666},{"x":782,"y":701,"onCurve":true},{"x":843,"y":738},{"x":887,"y":768,"onCurve":true},{"x":928,"y":796},{"x":933,"y":803,"onCurve":true},{"x":931,"y":835},{"x":882,"y":877,"onCurve":true},{"x":831,"y":921},{"x":780,"y":942,"onCurve":true},{"x":736,"y":960},{"x":634,"y":949},{"x":546,"y":916,"onCurve":true},{"x":441,"y":882},{"x":121,"y":612},{"x":45,"y":422,"onCurve":true},{"x":-11,"y":258},{"x":3,"y":186,"onCurve":true},{"x":14,"y":111},{"x":45,"y":84,"onCurve":true},{"x":56,"y":67},{"x":68,"y":58,"onCurve":true},{"x":77,"y":46}]];
|
||||
}
|
||||
);
|
6
src/editor/shapes/triangle.js
Normal file
6
src/editor/shapes/triangle.js
Normal file
@ -0,0 +1,6 @@
|
||||
/* eslint-disable*/
|
||||
define(
|
||||
function (require) {
|
||||
return [[{"x":25,"y":871,"onCurve":true},{"x":431,"y":465,"onCurve":true},{"x":442,"y":454},{"x":442,"y":425},{"x":431,"y":414,"onCurve":true},{"x":25,"y":8,"onCurve":true},{"x":14,"y":-3},{"x":0,"y":4},{"x":0,"y":19,"onCurve":true},{"x":0,"y":860,"onCurve":true},{"x":0,"y":875},{"x":14,"y":882}]];
|
||||
}
|
||||
);
|
@ -13,7 +13,7 @@ define(
|
||||
var program = require('../widget/program');
|
||||
var ajaxFile = require('common/ajaxFile');
|
||||
var string = require('common/string');
|
||||
|
||||
var lang = require('common/lang');
|
||||
|
||||
/**
|
||||
* 读取在线字体
|
||||
@ -51,7 +51,7 @@ define(
|
||||
}
|
||||
|
||||
// 延迟focus editor
|
||||
var editorDelayFocus = setTimeout(function () {
|
||||
var editorDelayFocus = lang.debounce(function () {
|
||||
program.editor.focus();
|
||||
}, 20);
|
||||
|
||||
|
@ -366,8 +366,8 @@ define(
|
||||
program.on('save', function (e) {
|
||||
// 保存项目
|
||||
if (program.ttfManager.get()) {
|
||||
var type = e.type;
|
||||
if (type === 'editor' || program.editor.isEditing()) {
|
||||
var saveType = e.saveType;
|
||||
if (saveType === 'editor' || program.editor.isEditing()) {
|
||||
|
||||
// 如果是正在编辑的
|
||||
var editingIndex = program.viewer.getEditing();
|
||||
|
@ -72,12 +72,6 @@ define(
|
||||
});
|
||||
});
|
||||
|
||||
editor.on('save', function () {
|
||||
program.fire('save', {
|
||||
type: 'editor'
|
||||
});
|
||||
});
|
||||
|
||||
var commandMenu = this.commandMenu;
|
||||
if (commandMenu) {
|
||||
|
||||
@ -106,7 +100,7 @@ define(
|
||||
|
||||
if (command === 'save') {
|
||||
program.fire('save', {
|
||||
type: 'editor'
|
||||
saveType: 'editor'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -68,31 +68,19 @@ define(
|
||||
|
||||
// 待选集合
|
||||
var selectedPaths = [];
|
||||
// 重叠部分只需要一条路径
|
||||
var overlapHash = {};
|
||||
|
||||
[splitedPaths0, splitedPaths1].forEach(function (splitedPaths) {
|
||||
for (var i = 0, l = splitedPaths.length; i < l ; i++) {
|
||||
var splitedPath = splitedPaths[i];
|
||||
|
||||
// 重叠部分
|
||||
if (splitedPaths[i].cross === 2) {
|
||||
var hash = getPathHash(splitedPaths[i].path);
|
||||
if (!overlapHash[hash]) {
|
||||
selectedPaths.push(splitedPaths[i]);
|
||||
overlapHash[hash] = 1;
|
||||
overlapHash[getPathHash(splitedPaths[i].path.reverse())] = 1;
|
||||
}
|
||||
if (relation === Relation.join && splitedPaths[i].cross !== 1) {
|
||||
selectedPaths.push(splitedPath);
|
||||
}
|
||||
else {
|
||||
if (relation === Relation.join && splitedPaths[i].cross === 0) {
|
||||
selectedPaths.push(splitedPaths[i]);
|
||||
}
|
||||
else if (relation === Relation.intersect && splitedPaths[i].cross === 1) {
|
||||
selectedPaths.push(splitedPaths[i]);
|
||||
}
|
||||
else if (relation === Relation.tangency) {
|
||||
selectedPaths.push(splitedPaths[i]);
|
||||
}
|
||||
else if (relation === Relation.intersect && splitedPath.cross !== 0) {
|
||||
selectedPaths.push(splitedPath);
|
||||
}
|
||||
else if (relation === Relation.tangency) {
|
||||
selectedPaths.push(splitedPath);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -125,16 +113,18 @@ define(
|
||||
}
|
||||
};
|
||||
|
||||
for (var pathIndex = 0; pathIndex < startPaths.length; pathIndex++) {
|
||||
var curPath = startPaths[pathIndex];
|
||||
var combinedPath = curPath.path.slice(0, curPath.path.length - 1);
|
||||
var curPath;
|
||||
// 从起始待选路径中取一个开始路径,查找闭合轮廓
|
||||
while ((curPath = startPaths.shift())) {
|
||||
var start = curPath.path[0];
|
||||
var end = curPath.path[curPath.path.length - 1];
|
||||
var combinedPath = curPath.path.slice(0, curPath.path.length - 1);
|
||||
|
||||
// 防止找不到可组合的轮廓,最多组合MAX_COMBINE_PATHS个路径段
|
||||
var loops = 0;
|
||||
var paths;
|
||||
|
||||
// 查找闭合轮廓
|
||||
while (
|
||||
++loops < MAX_COMBINE_PATHS
|
||||
&& (Math.abs(start.x - end.x) > 0.001 || Math.abs(start.y - end.y) > 0.001)
|
||||
@ -142,7 +132,7 @@ define(
|
||||
|
||||
paths = pathStartHash[hashcode(end)];
|
||||
|
||||
if (!paths.length) {
|
||||
if (!paths || !paths.length) {
|
||||
throw 'can\'t find paths to combine.';
|
||||
}
|
||||
|
||||
@ -159,7 +149,7 @@ define(
|
||||
var overlapPath;
|
||||
for (var i = 0, l = paths.length; i < l ; i++) {
|
||||
if (paths[i] !== curPath) {
|
||||
if (paths[i].cross === 2) {
|
||||
if (paths[i].cross === 2 && curPath.origin !== paths[i].origin) {
|
||||
overlapPath = paths[i];
|
||||
}
|
||||
// 相切的情况需要优先寻找与当前相交性质相反并且不在同一路径上的路径段
|
||||
@ -183,9 +173,6 @@ define(
|
||||
// 如果找不到,则使用重叠的路径
|
||||
if (!path) {
|
||||
if (overlapPath) {
|
||||
// 这里由于相切需要取另一路径上的路径段,
|
||||
// 因此这里需要重新设置origin
|
||||
overlapPath.origin = curPath.origin;
|
||||
path = overlapPath;
|
||||
}
|
||||
else {
|
||||
@ -201,12 +188,9 @@ define(
|
||||
pathPoints = pathPoints.reverse();
|
||||
}
|
||||
|
||||
splice.apply(
|
||||
combinedPath,
|
||||
[combinedPath.length, 0].concat(pathPoints.slice(0, pathPoints.length - 1))
|
||||
);
|
||||
end = path.path[path.path.length - 1];
|
||||
curPath = path;
|
||||
for (var ppIndex = 0, ppLength = pathPoints.length; ppIndex < ppLength; ppIndex++) {
|
||||
combinedPath.push(pathPoints[ppIndex]);
|
||||
}
|
||||
|
||||
// 有一种边缘重叠的情况,没有相交区域,不应该移除相切路径段
|
||||
// 否则会导致组合错误
|
||||
@ -226,6 +210,10 @@ define(
|
||||
startPaths.splice(index, 1);
|
||||
}
|
||||
|
||||
// 寻找下一个待选路径
|
||||
end = pathPoints[path.path.length - 1];
|
||||
curPath = path;
|
||||
|
||||
}
|
||||
|
||||
if (loops >= MAX_COMBINE_PATHS) {
|
||||
|
@ -23,14 +23,20 @@ define(
|
||||
*/
|
||||
function cubic2Points(cubicList, contour) {
|
||||
|
||||
var i;
|
||||
var l;
|
||||
var q2List = [];
|
||||
|
||||
cubicList.forEach(function (c) {
|
||||
q2List = q2List.concat(bezierCubic2Q2(c[0], c[1], c[2], c[3]));
|
||||
var list = bezierCubic2Q2(c[0], c[1], c[2], c[3]);
|
||||
for (i = 0, l = list.length; i < l; i++) {
|
||||
q2List.push(list[i]);
|
||||
}
|
||||
});
|
||||
|
||||
var q2;
|
||||
var prevq2;
|
||||
for (var i = 0, l = q2List.length; i < l; i++) {
|
||||
for (i = 0, l = q2List.length; i < l; i++) {
|
||||
q2 = q2List[i];
|
||||
if (i === 0) {
|
||||
contour.push({
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* @file DSIG.js
|
||||
* @author mengke01
|
||||
* @date
|
||||
* @description
|
||||
* DSIG表
|
||||
* Digital Signature Table
|
||||
*
|
||||
* 暂不支持数字签名解析
|
||||
* http://www.microsoft.com/typography/otspec/dsig.htm
|
||||
*/
|
||||
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
var table = require('./table');
|
||||
var struct = require('./struct');
|
||||
var DSIG = table.create(
|
||||
'DSIG',
|
||||
[
|
||||
['ulVersion', struct.Uint32],
|
||||
['usNumSigs', struct.Uint16],
|
||||
['usFlag', struct.Uint16]
|
||||
]
|
||||
);
|
||||
|
||||
return DSIG;
|
||||
}
|
||||
);
|
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* @file GDEF.js
|
||||
* @author mengke01
|
||||
* @date
|
||||
* @description
|
||||
* GDEF表
|
||||
* The Glyph Definition Table
|
||||
* 暂不支持解析子表,因此四个offset为0
|
||||
* http://www.microsoft.com/typography/otspec/gdef.htm
|
||||
*/
|
||||
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
var table = require('./table');
|
||||
var struct = require('./struct');
|
||||
var GDEF = table.create(
|
||||
'GDEF',
|
||||
[
|
||||
['Version', struct.Uint32],
|
||||
['GlyphClassDef', struct.Uint16],
|
||||
['AttachList', struct.Uint16],
|
||||
['LigCaretList', struct.Uint16],
|
||||
['MarkAttachClassDef', struct.Uint16]
|
||||
]
|
||||
);
|
||||
|
||||
return GDEF;
|
||||
}
|
||||
);
|
@ -1,49 +0,0 @@
|
||||
/**
|
||||
* @file GPOS.js
|
||||
* @author mengke01
|
||||
* @date
|
||||
* @description
|
||||
* GPOS表
|
||||
* The Glyph Positioning Table
|
||||
* 暂不支持解析 ScriptList,FeatureList,LookupList 表
|
||||
*
|
||||
* http://www.microsoft.com/typography/otspec/gpos.htm
|
||||
* http://www.microsoft.com/typography/otspec/chapter2.htm
|
||||
*/
|
||||
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var table = require('./table');
|
||||
|
||||
var GPOS = table.create(
|
||||
'GPOS',
|
||||
[],
|
||||
{
|
||||
|
||||
read: function (reader) {
|
||||
reader.seek(this.offset);
|
||||
var gpos = {};
|
||||
gpos.Version = reader.readFixed();
|
||||
gpos.ScriptList = reader.readUint16();
|
||||
gpos.FeatureList = reader.readUint16();
|
||||
gpos.LookupList = reader.readUint16();
|
||||
// 脚本表
|
||||
gpos.ScriptTbl = {
|
||||
ScriptCount: reader.readUint16(this.offset + gpos.ScriptList)
|
||||
};
|
||||
|
||||
// 特征表
|
||||
gpos.FeatureTbl = false;
|
||||
// 查找表
|
||||
gpos.LookupTbl = false;
|
||||
|
||||
return gpos;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return GPOS;
|
||||
}
|
||||
);
|
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* @file GSUB.js
|
||||
* @author mengke01
|
||||
* @date
|
||||
* @description
|
||||
* GSUB表
|
||||
* The Glyph Substitution Table
|
||||
* 暂不支持解析 ScriptList,FeatureList,LookupList 表
|
||||
*
|
||||
* http://www.microsoft.com/typography/otspec/gsub.htm
|
||||
* http://www.microsoft.com/typography/otspec/chapter2.htm
|
||||
*/
|
||||
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
var table = require('./table');
|
||||
var ScriptList = require('./ScriptList');
|
||||
var GSUB = table.create(
|
||||
'GSUB',
|
||||
[],
|
||||
{
|
||||
|
||||
read: function (reader) {
|
||||
reader.seek(this.offset);
|
||||
var gsub = {};
|
||||
gsub.Version = reader.readFixed();
|
||||
gsub.ScriptList = reader.readUint16();
|
||||
gsub.FeatureList = reader.readUint16();
|
||||
gsub.LookupList = reader.readUint16();
|
||||
|
||||
// 读取脚本表
|
||||
var scriptList = new ScriptList(this.offset + gsub.ScriptList);
|
||||
gsub.ScriptTbl = scriptList.read(reader, {
|
||||
gsub: gsub
|
||||
});
|
||||
|
||||
// 特征表
|
||||
gsub.FeatureTbl = false;
|
||||
|
||||
// 查找表
|
||||
gsub.LookupTbl = false;
|
||||
|
||||
return gsub;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return GSUB;
|
||||
}
|
||||
);
|
@ -1,66 +0,0 @@
|
||||
/**
|
||||
* @file ScriptList.js
|
||||
* @author mengke01
|
||||
* @date
|
||||
* @description
|
||||
* 脚本表
|
||||
* 仅完成语言系统解析
|
||||
* http://www.microsoft.com/typography/otspec/chapter2.htm
|
||||
*/
|
||||
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
var table = require('./table');
|
||||
|
||||
var scriptList = table.create(
|
||||
'ScriptList',
|
||||
[],
|
||||
{
|
||||
|
||||
read: function (reader) {
|
||||
reader.seek(this.offset);
|
||||
var ScriptCount = reader.readUint16();
|
||||
|
||||
// script records
|
||||
var records = [];
|
||||
var record;
|
||||
var i;
|
||||
var j;
|
||||
var l;
|
||||
|
||||
for (i = 0, l = ScriptCount; i < l; i++) {
|
||||
record = {
|
||||
ScriptTag: reader.readUint32(),
|
||||
Offset: reader.readUint16()
|
||||
};
|
||||
records.push(record);
|
||||
}
|
||||
|
||||
// script table
|
||||
var offset = this.offset;
|
||||
for (i = 0, l = records.length; i < l; i++) {
|
||||
record = records[i];
|
||||
reader.seek(offset + record.Offset);
|
||||
record.DefaultLangSys = reader.readUint16();
|
||||
var LangSysCount = reader.readUint16();
|
||||
record.LangSysRecord = [];
|
||||
|
||||
// 此处解析语言系统
|
||||
for (j = 0, l = LangSysCount; j < l; j++) {
|
||||
var langSysRecord = {
|
||||
LangSysTag: reader.readUint32(),
|
||||
LangSys: reader.readUint16()
|
||||
};
|
||||
record.LangSysRecord.push(langSysRecord);
|
||||
}
|
||||
}
|
||||
|
||||
return records;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return scriptList;
|
||||
}
|
||||
);
|
@ -4,6 +4,8 @@
|
||||
* @date
|
||||
* @description
|
||||
* directory 表, 读取ttf表索引
|
||||
*
|
||||
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html
|
||||
*/
|
||||
|
||||
|
||||
@ -13,8 +15,7 @@ define(
|
||||
|
||||
var directory = table.create(
|
||||
'directory',
|
||||
[
|
||||
],
|
||||
[],
|
||||
{
|
||||
read: function (reader, ttf) {
|
||||
var tables = {};
|
||||
|
@ -1,44 +0,0 @@
|
||||
/**
|
||||
* @file gasp.js
|
||||
* @author mengke01
|
||||
* @date
|
||||
* @description
|
||||
* gasp表
|
||||
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6gasp.html
|
||||
*/
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
var table = require('./table');
|
||||
|
||||
var gasp = table.create(
|
||||
'gasp',
|
||||
[],
|
||||
{
|
||||
|
||||
read: function (reader) {
|
||||
var offset = this.offset;
|
||||
var gasp = {};
|
||||
|
||||
reader.seek(offset);
|
||||
|
||||
gasp.version = reader.readUint16();
|
||||
gasp.numRanges = reader.readUint16();
|
||||
|
||||
var GASPRangeTbl = [];
|
||||
for (var i = 0; i < gasp.numRanges; ++i) {
|
||||
var GASPRange = {};
|
||||
GASPRange.rangeMaxPPEM = reader.readUint16();
|
||||
GASPRange.rangeGaspBehavior = reader.readUint16();
|
||||
GASPRangeTbl.push(GASPRange);
|
||||
}
|
||||
|
||||
gasp.GASPRangeTbl = GASPRangeTbl;
|
||||
return gasp;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return gasp;
|
||||
}
|
||||
);
|
@ -27,10 +27,8 @@ define(
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fixed header + instructions + endPtsOfContours
|
||||
var result = 10
|
||||
+ 2
|
||||
// + (glyf.instructions ? glyf.instructions.length : 0)
|
||||
// fixed header + endPtsOfContours
|
||||
var result = 12
|
||||
+ glyf.contours.length * 2
|
||||
+ glyfSupport.flags.length;
|
||||
|
||||
@ -81,9 +79,6 @@ define(
|
||||
|
||||
});
|
||||
|
||||
// if (glyf.instructions) {
|
||||
// size += 2 + glyf.instructions.length;
|
||||
// }
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -267,8 +262,6 @@ define(
|
||||
|
||||
var g = glyf.glyfs[i];
|
||||
|
||||
// instructions
|
||||
// flags += glyf.instructions ? componentFlag.WE_HAVE_INSTRUCTIONS : 0;
|
||||
// use my metrics
|
||||
flags += g.useMyMetrics ? componentFlag.USE_MY_METRICS : 0;
|
||||
// overlap compound
|
||||
@ -328,14 +321,6 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
// if (glyf.instructions) {
|
||||
// var instructions = glyf.instructions;
|
||||
// writer.writeUint16(instructions.length);
|
||||
// for (var i = 0, l = instructions.length; i < l; i++) {
|
||||
// writer.writeUint8(instructions[i] & 0xFF);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@ -346,16 +331,7 @@ define(
|
||||
});
|
||||
|
||||
// not support instruction
|
||||
// if (glyf.instructions) {
|
||||
// var instructions = glyf.instructions;
|
||||
// writer.writeUint16(instructions.length);
|
||||
// for (var i = 0, l = instructions.length; i < l; i++) {
|
||||
// writer.writeUint8(instructions[i] & 0xFF);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
writer.writeUint16(0);
|
||||
// }
|
||||
|
||||
// 获取暂存中的flags
|
||||
flags = ttf.support.glyf[index].flags;
|
||||
|
@ -4,6 +4,8 @@
|
||||
* @date
|
||||
* @description
|
||||
* 基本数据结构
|
||||
*
|
||||
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html
|
||||
*/
|
||||
|
||||
|
||||
@ -19,22 +21,19 @@ define(
|
||||
Uint32: 6,
|
||||
Fixed: 7, // 32-bit signed fixed-point number (16.16)
|
||||
FUnit: 8, // Smallest measurable distance in the em space
|
||||
// 16-bit signed integer (SHORT) that describes a quantity in FUnits.
|
||||
// FWord: 9,
|
||||
// Unsigned 16-bit integer (USHORT) that describes a quantity in FUnits
|
||||
// UFWord: 10,
|
||||
// 16-bit signed fixed number with the low 14 bits of fraction
|
||||
F2Dot14: 11,
|
||||
// The long internal format of a date in seconds since 12:00 midnight,
|
||||
// January 1, 1904. It is represented as a signed 64-bit integer.
|
||||
LongDateTime: 12,
|
||||
|
||||
// extend data type
|
||||
Char: 13,
|
||||
String: 14,
|
||||
Bytes: 15
|
||||
};
|
||||
|
||||
// 翻转名字查找
|
||||
// 反转名字查找
|
||||
var names = {};
|
||||
Object.keys(struct).forEach(function (key) {
|
||||
names[struct[key]] = key;
|
||||
|
@ -1,67 +0,0 @@
|
||||
/**
|
||||
* @file drawContour.js
|
||||
* @author mengke01
|
||||
* @date
|
||||
* @description
|
||||
* 绘制contour曲线
|
||||
*/
|
||||
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
/**
|
||||
* ctx绘制轮廓
|
||||
*
|
||||
* @param {CanvasRenderingContext2D} ctx canvas会话
|
||||
* @param {Array} contour 轮廓序列
|
||||
*/
|
||||
function drawContour(ctx, contour) {
|
||||
|
||||
var curPoint;
|
||||
var prevPoint;
|
||||
var nextPoint;
|
||||
|
||||
for (var i = 0, l = contour.length; i < l; i++) {
|
||||
curPoint = contour[i];
|
||||
prevPoint = i === 0 ? contour[l - 1] : contour[i - 1];
|
||||
nextPoint = i === l - 1 ? contour[0] : contour[i + 1];
|
||||
|
||||
// 起始坐标
|
||||
if (i === 0) {
|
||||
if (curPoint.onCurve) {
|
||||
ctx.moveTo(curPoint.x, curPoint.y);
|
||||
}
|
||||
else {
|
||||
if (prevPoint.onCurve) {
|
||||
ctx.moveTo(prevPoint.x, prevPoint.y);
|
||||
}
|
||||
else {
|
||||
ctx.moveTo((prevPoint.x + curPoint.x) / 2, (prevPoint.y + curPoint.y) / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 直线
|
||||
if (curPoint.onCurve && nextPoint.onCurve) {
|
||||
ctx.lineTo(nextPoint.x, nextPoint.y);
|
||||
}
|
||||
else if (!curPoint.onCurve) {
|
||||
if (nextPoint.onCurve) {
|
||||
ctx.quadraticCurveTo(curPoint.x, curPoint.y, nextPoint.x, nextPoint.y);
|
||||
}
|
||||
else {
|
||||
ctx.quadraticCurveTo(
|
||||
curPoint.x,
|
||||
curPoint.y,
|
||||
(curPoint.x + nextPoint.x) / 2,
|
||||
(curPoint.y + nextPoint.y) / 2
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return drawContour;
|
||||
}
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user