设置元数据| JavaScript的API解决方案
如何将字体元数据设置为“名称”表?
您可以使用 AsposeFontSetInfo函数添加或更改元数据信息。
参数 nameId
定义记录的逻辑字符串类别。参数 platformId
、platformSpecificId
和 languageId
用于设置字符串的语言。最后一个参数 text
用于设置记录的字符串数据。
如果该记录与通过参数 platformID
、platformSpecificID
、languageID
和 nameID
添加的记录相符,则该方法不会添加新记录,而是使用参数 text
定义的值更新现有记录中的字符串数据。
设置元数据的示例
- 创建一个“ filereader”。
- 定义参数并运行 AsposeFontSetInfo函数。
使用Enum
ttfnametablenameId和
nameId和
platformId`,ttfnametableplatformid,
ttfnametablemacplatformspecificid,,
ttfnametablemsplatformspecificid或
ttfnametableabable deplatformspecificid用于platformSpecificid
和
ttfnametableMaclanguageId,或 ttfnametablemslanguageID用于`Leganagenagic id’参数。
- 接下来,如果
json.errorcode
为0,则可以获取结果数据。如果“ JSON.ERRORCODE”参数不等于0,因此您的文件中会有错误,则有关此类错误的信息将包含在json.erortext
中。 - 结果JSON对象包含“ FILENAMERESULT”字段,并在存储器文件系统中保存字体的文件名。使用下载文件函数获取它。
1 var fFontSetInfo = function (e) {
2 const file_reader = new FileReader();
3 file_reader.onload = (event) => {
4
5 const nameId = new Function("return Module.TtfNameTableNameId." + document.getElementById("NameId").value)();
6 const platformId = Module.TtfNameTablePlatformId.Microsoft;
7 const platformSpecificId = Module.TtfNameTableMSPlatformSpecificId.Unicode_BMP_UCS2.value;
8 const text = document.getElementById("textValue").value;
9 const langID = 1033;
10
11 const json = AsposeFontSetInfo(blob, file.name, nameId, platformId, platformSpecificId, langID, text);
12 if (json.errorCode == 0) {
13 DownloadFile(json.fileNameResult);
14 //DownloadFile(file.name);
15 }
16 else document.getElementById('output').textContent = json.errorText;
17 }
18 file_reader.readAsArrayBuffer(file);
或使用Web Worker:
1<script type="text/javascript">
2 /*Create Web Worker*/
3 const AsposeFontWebWorker = new Worker("AsposeFontforJS.js");
4 AsposeFontWebWorker.onerror = (evt) => console.log(`Error from Web Worker: ${evt.message}`);
5 AsposeFontWebWorker.onmessage = (evt) => document.getElementById("output").textContent =
6 (evt.data == 'ready') ? 'library loaded!' :
7 (evt.data.json.errorCode == 0) ? `Result:\n${DownloadFile(evt.data.json.fileNameResult, "font/ttf", evt.data.params[0])}` : `Error: ${evt.data.json.errorText}`;
8
9 /*Event handler*/
10 const ffileFontSetInfo = e => {
11 const file_reader = new FileReader();
12 file_reader.onload = event => {
13 const nameId = 'Module.TtfNameTableNameId.' + document.getElementById("NameId").value;
14 //Value will be changed for PlatformId = PlatformId.Microsoft, PlatformSpecificId = MSPlatformSpecificId.Unicode_BMP_UCS2 (1) and languageID = 1033 (English_United_States = 0x0409)
15 const platformId = 'Module.TtfNameTablePlatformId.Microsoft';
16 const platformSpecificId = 'Module.TtfNameTableMSPlatformSpecificId.Unicode_BMP_UCS2';
17 const langID = 'Module.TtfNameTableMSLanguageId.English_United_States';
18 const text = document.getElementById("textValue").value;
19 transfer = [event.target.result];
20 params = [event.target.result, e.target.files[0].name, nameId, platformId, platformSpecificId, langID, text];
21 AsposeFontWebWorker.postMessage({ "operation": 'AsposeFontSetInfo', "params": params }, transfer);
22 };
23 file_reader.readAsArrayBuffer(e.target.files[0]);
24 };
25</script>
如何获取解决方案?
如果您有兴趣获取图书馆,请转到 Java 版 Aspose.FontScript产品页面。在这里,您会发现解决方案给您的更多机会。您可以从那里下载免费试用版或在那里购买产品。
如果您剩下任何麻烦或问题,请随时在 aspose.font.product family 免费支持论坛的部分中发布它们,并在几个小时内我们的支持团队为您清除所有内容。