メタデータの設定| JavaScript用のAPIソリューション

フォントメタデータを「名前」テーブルに設定する方法は?

AsposeFontsetInfo関数を使用して、メタデータ情報を追加または変更できます。

パラメーター nameIdレコードの論理文字列カテゴリを定義します。パラメーターPlatformIdPlatformspecifid、およびLanguageIDは、文字列の言語を設定するために使用されます。最後のパラメーター「テキスト」は、レコードの文字列データを設定するために使用されます。

レコードがパラメーターPlatformIdPlatformspecifidLanguageID、およびnameIdによって追加されたものと一致する場合、メソッドは新しいレコードを追加しませんが、パラメーター「テキスト」で定義された値を使用して既存のレコードの文字列データを更新します。

メタデータの設定の例

  1. filreaderを作成します。
  2. パラメーターを定義し、 Asposefontsetinfo関数を実行します。

enum ttfnameTableNameidを使用します ttfnameTablePlatFormidnameIdおよび `platformid’の場合

TTFNAMETABLEMACPLATFORMSPICIDttfnameTablemsplatformspecid、または TTFNAMETABLEUNICODEPLATFORMSPICID PlatformSpecificId、および

ttfnameTablemaclanguageid、または TTFNAMETABLEMSLANGUAGEIDLanguageIDパラメーターの場合。

  1. 次に、json.errorcodeが0の場合、結果データを取得できます。 json.errorcodeパラメーターが0に等しくなく、したがってファイルにエラーが発生する場合、そのようなエラーに関する情報は json.errortextに含まれます。
  2. 結果のJSONオブジェクトには、メモリファイルシステムに保存されたフォントのファイル名を持つfilenameresultフィールドが含まれています。 downloadfile関数を使用して取得します。
 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ワーカーの使用:

 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>

解決策を取得する方法は?

ライブラリの入手に興味がある場合は、 aspose.font for javascript product pageにアクセスしてください。そこでは、ソリューションが提供する機会が増えます。無料トライアルをダウンロードしたり、そこで製品を購入したりできます。

問題や質問が残っている場合は、 aspose.font.productファミリー free support forumのセクションに投稿してください。

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.