add remove postscript name
add read windows names set post table to format 3
This commit is contained in:
parent
2a74b1977a
commit
9063239863
@ -57,6 +57,7 @@
|
||||
<li><a data-action="setting-name">字体信息</a></li>
|
||||
<li><a data-action="setting-metrics">字体度量</a></li>
|
||||
<li><a data-action="setting-glyf-name">生成字形名称</a></li>
|
||||
<li><a data-action="setting-glyf-clearname">清除字形名称</a></li>
|
||||
<li><a data-action="setting-editor">编辑器</a></li>
|
||||
<li><a data-action="setting-import-and-export">导入和导出</a></li>
|
||||
</ul>
|
||||
|
@ -259,6 +259,13 @@ define(
|
||||
}
|
||||
},
|
||||
|
||||
'setting-glyf-clearname': function () {
|
||||
var ttf = program.ttfManager.get();
|
||||
if (ttf) {
|
||||
program.ttfManager.clearGlyfName(program.viewer.getSelected());
|
||||
}
|
||||
},
|
||||
|
||||
'setting-editor': function () {
|
||||
var SettingEditor = settingSupport.editor;
|
||||
!new SettingEditor({
|
||||
|
@ -235,6 +235,25 @@ define(
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* 清除字形名称
|
||||
*
|
||||
* @param {Array} indexList 索引列表
|
||||
* @return {this}
|
||||
*/
|
||||
Manager.prototype.clearGlyfName = function (indexList) {
|
||||
|
||||
var list = this.ttf.clearGlyfName(indexList);
|
||||
if (list.length) {
|
||||
list.forEach(function (g) {
|
||||
g.modify = 'edit';
|
||||
});
|
||||
this.fireChange(true);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* 添加并体替换指定的glyf
|
||||
*
|
||||
|
@ -114,7 +114,7 @@ define(
|
||||
"maxMemType42": 0,
|
||||
"minMemType1": 0,
|
||||
"maxMemType1": 1,
|
||||
"format": 2
|
||||
"format": 3
|
||||
},
|
||||
"OS/2": {
|
||||
"version": 4,
|
||||
|
@ -54,14 +54,27 @@ define(
|
||||
|
||||
var names = {};
|
||||
|
||||
// 读取windows下的name records
|
||||
var platform = platformTbl.Microsoft;
|
||||
var encoding = encodingTbl.win.UCS2;
|
||||
// mac 下的english name
|
||||
var platform = platformTbl.Macintosh;
|
||||
var encoding = encodingTbl.mac.Default;
|
||||
var language = 0;
|
||||
|
||||
// 如果有windows 下的 english,则用windows下的 name
|
||||
if (nameRecordTbl.some(function (record) {
|
||||
return record.platform === platformTbl.Microsoft
|
||||
&& record.encoding === encodingTbl.win.UCS2
|
||||
&& record.language === 1033;
|
||||
})) {
|
||||
platform = platformTbl.Microsoft;
|
||||
encoding = encodingTbl.win.UCS2;
|
||||
language = 1033;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; ++i) {
|
||||
nameRecord = nameRecordTbl[i];
|
||||
if (nameRecord.platform === platform
|
||||
&& nameRecord.encoding === encoding
|
||||
&& nameRecord.language === language
|
||||
&& nameIdTbl[nameRecord.nameId]) {
|
||||
names[nameIdTbl[nameRecord.nameId]] = string.stringify(nameRecord.name);
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ define(
|
||||
['minMemType42', struct.Uint32],
|
||||
['maxMemType42', struct.Uint32],
|
||||
['minMemType1', struct.Uint32],
|
||||
['maxMemType1', struct.Uint32],
|
||||
['numberOfGlyphs', struct.Uint16]
|
||||
['maxMemType1', struct.Uint32]
|
||||
]
|
||||
);
|
||||
|
||||
@ -36,19 +35,15 @@ define(
|
||||
{
|
||||
|
||||
read: function (reader, ttf) {
|
||||
var tbl = null;
|
||||
var format = reader.readFixed(this.offset);
|
||||
// 读取表头
|
||||
var tbl = new Posthead(this.offset).read(reader, ttf);
|
||||
|
||||
// format2
|
||||
if (format === 2) {
|
||||
|
||||
// 读取表头
|
||||
tbl = new Posthead(this.offset).read(reader, ttf);
|
||||
tbl.format = format;
|
||||
|
||||
var numberOfGlyphs = ttf.maxp.numGlyphs;
|
||||
|
||||
var numberOfGlyphs = reader.readUint16();
|
||||
var glyphNameIndex = [];
|
||||
|
||||
for (var i = 0; i < numberOfGlyphs; ++i) {
|
||||
glyphNameIndex.push(reader.readUint16());
|
||||
}
|
||||
@ -60,10 +55,9 @@ define(
|
||||
tbl.glyphNameIndex = glyphNameIndex;
|
||||
tbl.names = string.readPascalString(pascalStringBytes);
|
||||
}
|
||||
else {
|
||||
tbl = {
|
||||
format: format
|
||||
};
|
||||
// deprecated
|
||||
else if (format === 2.5) {
|
||||
tbl.format = 3;
|
||||
}
|
||||
|
||||
return tbl;
|
||||
@ -71,11 +65,13 @@ define(
|
||||
|
||||
write: function (writer, ttf) {
|
||||
|
||||
var numberOfGlyphs = ttf.glyf.length;
|
||||
var post = ttf.post || {};
|
||||
|
||||
var post = ttf.post || {
|
||||
format: 3
|
||||
};
|
||||
|
||||
// write header
|
||||
writer.writeFixed(2); // format
|
||||
writer.writeFixed(post.format); // format
|
||||
writer.writeFixed(post.italicAngle || 0); // italicAngle
|
||||
writer.writeInt16(post.underlinePosition || 0); // underlinePosition
|
||||
writer.writeInt16(post.underlineThickness || 0); // underlineThickness
|
||||
@ -84,22 +80,37 @@ define(
|
||||
writer.writeUint32(post.maxMemType42 || 0); // maxMemType42
|
||||
writer.writeUint32(post.minMemType1 || 0); // minMemType1
|
||||
writer.writeUint32(post.maxMemType1 || 0); // maxMemType1
|
||||
writer.writeUint16(numberOfGlyphs); // numberOfGlyphs
|
||||
|
||||
// write glyphNameIndex
|
||||
var nameIndexs = ttf.support.post.nameIndexs;
|
||||
for (var i = 0, l = nameIndexs.length; i < l; i++) {
|
||||
writer.writeUint16(nameIndexs[i]);
|
||||
// version 3 不设置post信息
|
||||
if (post.format === 2) {
|
||||
var numberOfGlyphs = ttf.glyf.length;
|
||||
writer.writeUint16(numberOfGlyphs); // numberOfGlyphs
|
||||
// write glyphNameIndex
|
||||
var nameIndexs = ttf.support.post.nameIndexs;
|
||||
for (var i = 0, l = nameIndexs.length; i < l; i++) {
|
||||
writer.writeUint16(nameIndexs[i]);
|
||||
}
|
||||
|
||||
// write names
|
||||
ttf.support.post.glyphNames.forEach(function (name) {
|
||||
writer.writeBytes(name);
|
||||
});
|
||||
}
|
||||
|
||||
// write names
|
||||
ttf.support.post.glyphNames.forEach(function (name) {
|
||||
writer.writeBytes(name);
|
||||
});
|
||||
},
|
||||
|
||||
size: function (ttf) {
|
||||
|
||||
var numberOfGlyphs = ttf.glyf.length;
|
||||
ttf.post = ttf.post || {};
|
||||
ttf.post.format = ttf.post.format || 3;
|
||||
ttf.post.maxMemType1 = numberOfGlyphs;
|
||||
|
||||
// version 3 不设置post信息
|
||||
if (post.format === 3 || post.format === 1) {
|
||||
return 34;
|
||||
}
|
||||
|
||||
// version 2
|
||||
var glyphNames = [];
|
||||
var nameIndexs = [];
|
||||
var size = 34 + numberOfGlyphs * 2; // header + numberOfGlyphs * 2
|
||||
@ -122,21 +133,20 @@ define(
|
||||
// 这里需要注意,"" 有可能是"\3" length不为0,但是是空字符串
|
||||
var name = glyf.name;
|
||||
if (!name || name.charCodeAt(0) < 32) {
|
||||
name = string.getUnicodeName(unicode);
|
||||
nameIndexs.push(258 + nameIndex++);
|
||||
glyphNames.push([0]);
|
||||
size++;
|
||||
}
|
||||
else {
|
||||
nameIndexs.push(258 + nameIndex++);
|
||||
var bytes = string.getPascalStringBytes(name); // pascal string bytes
|
||||
glyphNames.push(bytes);
|
||||
size += bytes.length;
|
||||
}
|
||||
|
||||
nameIndexs.push(258 + nameIndex++);
|
||||
var bytes = string.getPascalStringBytes(name); // pascal string bytes
|
||||
glyphNames.push(bytes);
|
||||
size += bytes.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ttf.post = ttf.post || {};
|
||||
ttf.post.format = ttf.post.format || 0x2;
|
||||
ttf.post.maxMemType1 = numberOfGlyphs;
|
||||
|
||||
ttf.support.post = {
|
||||
nameIndexs: nameIndexs,
|
||||
glyphNames: glyphNames
|
||||
|
@ -401,6 +401,34 @@ define(
|
||||
return list;
|
||||
};
|
||||
|
||||
/**
|
||||
* 清除字形名称
|
||||
*
|
||||
* @param {Array} indexList 索引列表
|
||||
* @return {Array} 改变的glyf
|
||||
*/
|
||||
TTF.prototype.clearGlyfName = function (indexList) {
|
||||
var glyf = this.ttf.glyf;
|
||||
var list = [];
|
||||
if (indexList && indexList.length) {
|
||||
list = indexList.map(function (item) {
|
||||
return glyf[item];
|
||||
});
|
||||
}
|
||||
else {
|
||||
list = glyf;
|
||||
}
|
||||
|
||||
if (list.length) {
|
||||
|
||||
list.forEach(function (g) {
|
||||
delete g.name;
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
};
|
||||
|
||||
/**
|
||||
* 添加并体替换指定的glyf
|
||||
*
|
||||
|
@ -128,6 +128,8 @@ define(
|
||||
delete ttf.loca;
|
||||
delete ttf.post.glyphNameIndex;
|
||||
delete ttf.post.names;
|
||||
delete ttf.cmap;
|
||||
|
||||
if (!this.options.hinting) {
|
||||
delete ttf.fpgm;
|
||||
delete ttf.cvt;
|
||||
|
@ -104,6 +104,8 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
delete codes[65535];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user