修改ttf接口

This commit is contained in:
kekee000 2015-01-30 00:01:12 +08:00
parent 9f1b650f88
commit 2f9a2890fc
3 changed files with 29 additions and 26 deletions

View File

@ -1,7 +1,7 @@
/**
* @file glyf.js
* @author mengke01
* @date
* @date
* @description
* glyf canvas 绘制
*/
@ -37,7 +37,7 @@ define(
codes.forEach(function(item) {
str += '<li data-code="'+ item +'">'
+ '<span class="i-font">'+ String.fromCharCode(item) +'</span>'
+ (item > 255 ? '\\u' + Number(item).toString(16) : item)
+ (item > 255 ? '\\u' + Number(item).toString(16) : item)
+'</li>';
});
$('#font-list').html(str);
@ -45,11 +45,11 @@ define(
}
function showGlyf(charcode) {
var glyf = lang.clone(ttf.getCodeGlyf(charcode));
var glyf = lang.clone(ttf.getGlyfByCode(charcode));
if (glyf.compound) {
glyf.glyfs.forEach(function(g){
g.glyf = ttf.getIndexGlyf(g.glyphIndex);
g.glyf = ttf.getGlyfByIndex(g.glyphIndex);
});
}

View File

@ -1,7 +1,7 @@
/**
* @file glyfsvg.js
* @author mengke01
* @date
* @date
* @description
* glyf 查看
*/
@ -39,7 +39,7 @@ define(
codes.forEach(function(item) {
str += '<li data-code="'+ item +'">'
+ '<span class="i-font">'+ String.fromCharCode(item) +'</span>'
+ (item > 255 ? '\\u' + Number(item).toString(16) : item)
+ (item > 255 ? '\\u' + Number(item).toString(16) : item)
+'</li>';
});
@ -57,12 +57,12 @@ define(
+ '</g>'
+ '</svg>';
var svg = $(tpl);
var glyf = lang.clone(ttf.getCodeGlyf(charcode));
var glyf = lang.clone(ttf.getGlyfByCode(charcode));
if (glyf.compound) {
return;
}
// 调整大小
var width = glyf.xMax;
var height = glyf.yMax - glyf.yMin;

View File

@ -191,39 +191,42 @@ define(
/**
* 根据编码获取字形索引
*
* @param {string} c 字符或者字符编码
*
* @return {?number} 返回glyf索引号
*/
TTF.prototype.getCodeGlyfIndex = function (c) {
TTF.prototype.getGlyfIndexByCode = function (c) {
var charCode = typeof c === 'number' ? c : c.charCodeAt(0);
var glyfIndex = this.ttf.cmap[charCode] || 0;
var glyfIndex = this.ttf.cmap[charCode] || -1;
return glyfIndex;
};
/**
* 根据编码获取字形
* @param {string} c 字符或者字符编码
*
* @return {?Object} 返回glyf对象
*/
TTF.prototype.getCodeGlyf = function (c) {
var glyfIndex = this.getCodeGlyfIndex(c);
return this.getIndexGlyf(glyfIndex);
};
/**
* 根据索引获取字形
*
* @param {number} glyfIndex glyf的索引
*
* @return {?Object} 返回glyf对象
*/
TTF.prototype.getIndexGlyf = function (glyfIndex) {
TTF.prototype.getGlyfByIndex = function (glyfIndex) {
var glyfList = this.ttf.glyf;
var glyf = glyfList[glyfIndex];
return glyf;
};
/**
* 根据编码获取字形
*
* @param {string} c 字符或者字符编码
*
* @return {?Object} 返回glyf对象
*/
TTF.prototype.getGlyfByCode = function (c) {
var glyfIndex = this.getGlyfIndexByCode(c);
return this.getGlyfByIndex(glyfIndex);
};
/**
* 设置ttf对象
*
@ -521,8 +524,8 @@ define(
* 查找相关字形
*
* @param {Object} condition 查询条件
* @param {Array|number} condition.unicode unicode列表或者单个unicode编码
* @param {Array} condition.name 名字列表
* @param {Array|number} condition.unicode unicode编码列表或者单个unicode编码
* @param {string} condition.name glyf名字例如`uniE001`, `uniE`
*
* @return {Array} glyf字形列表
*/