THotPDF.SetFormUnicodeFontDict Method

 

THotPDF.SetFormUnicodeFontDict

THotPDF

 

Atas

Mendaftarkan font Unicode yang disediakan pemanggil di dict sumber daya default AcroForm sehingga generator auto-appearance-stream HotPDF (PDF 1.7 ISO 32000-1 12.7.4.3) dapat merender nilai awal widget Tx non-ASCII langsung ke /AP, alih-alih mengeluarkan placeholder AP kosong v2.46.0. Pasangkan dengan CreateIndirectFontDict untuk mengalokasikan dict font tak langsung yang akan diisi

 

Delphi syntax:

procedure SetFormUnicodeFontDict(const LogicalName: AnsiString; FontDict: THPDFDictionaryObject);

 

C++ syntax:

void SetFormUnicodeFontDict(const AnsiString& LogicalName, THPDFDictionaryObject* FontDict);

 

Deskripsi

Once both LogicalName and FontDict are populated, three things change in subsequent emission: (a) the AcroForm-level /DA string switches from '/Helv 12 Tf 0 0 0 rg' to '/<LogicalName> 12 Tf 0 0 0 rg'; (b) the AcroForm /DR /Font sub-dict gains an entry /<LogicalName> <FontDict-indirect-ref> alongside the existing /Helv + /ZaDb; (c) every Tx widget added through AddTextField or AddRichTextField gets its per-field /DA set the same way. When AutoFormAppearances is on and the widget's initial value contains any byte >= 0x80, GenerateTextFieldAP emits a real /AP /N Form XObject whose content stream selects the registered font via Tf and renders the text as a CID hex-string Tj operator; the Form's /Resources/Font sub-dict references the same indirect font so the AP is self-contained.

Saat font yang didaftarkan berasal dari RegisterUnicodeTTF, karakter Unicode di supplementary plane (misalnya U+1F600) dikeluarkan melalui satu CID yang dialokasikan secara internal alih-alih memecah pasangan surrogate UTF-16 menjadi dua Identity-H CID. HotPDF menyegarkan stream /CIDToGIDMap, /W, dan /ToUnicode yang dihasilkan saat finalisasi sehingga CID internal memetakan glyph font yang sesungguhnya dan ekstraksi teks memetakan kembali ke pasangan surrogate UTF-16BE asli

Field Tx ASCII tetap memakai /Helv dan menghasilkan keluaran /AP yang identik byte demi byte untuk pemanggil v2.46.0. Berikan LogicalName kosong + nil FontDict untuk menghapus pendaftaran dan kembali ke perilaku hanya /Helv. Alur kerja tipikal: panggil SetFormUnicodeFontDict sekali segera setelah BeginDoc, sebelum AddTextField apa pun - widget yang dibuat sebelumnya tidak diperbarui secara retroaktif

 

LogicalName - Name PDF yang dipakai sebagai kunci di /DR/Font dan sebagai operand untuk Tf di dalam string /DA. Umumnya: 'F0'. Tidak boleh kosong saat mendaftar; nama kosong dengan FontDict non-nil akan memunculkan exception

FontDict - THPDFDictionaryObject tak langsung yang berisi resource Font PDF valid. Pemanggil bertanggung jawab membangun font dict dengan benar - biasanya font komposit Type 0 / CIDFontType2 + Identity-H + ToUnicode CMap; untuk tampilan sederhana atau hanya garis, subset Type 1 / TrueType juga bisa dipakai. HotPDF tidak memvalidasi isinya; ia hanya menserialisasi referensinya

 

Scope - v2.56.0 hanya mencakup widget Tx satu baris. Widget Tx multi-baris (ffMultiline) dan comb (ffComb) dengan nilai awal non-ASCII masih mengeluarkan placeholder AP kosong v2.46.0; ekstensi Unicode-AP untuk cabang tersebut dijadwalkan untuk v2.57.0+. Shaping bidi RTL (Arabic / Hebrew) memerlukan Unicode Bidi Algorithm (UAX #9) + penggabungan kontekstual Arabic; juga termasuk scope v2.57.0+

 

Contoh kode

// Register a Type 0 / CIDFontType2 + Identity-H composite font for
// AcroForm Tx widget AP rendering. (Real production code adds a
// /FontFile2 stream and a ToUnicode CMap so the glyphs actually
// render - omitted here for brevity.)
var
  F0, Descendant, FontDescriptor, CIDSysInfo: THPDFDictionaryObject;
  Descendants: THPDFArrayObject;
  R: TRect;
begin
  HPDF.BeginDoc;
  HPDF.AutoFormAppearances := True;

  F0 := HPDF.CreateIndirectFontDict;          // empty indirect dict
  F0.AddNameValue('Type', 'Font');
  F0.AddNameValue('Subtype', 'Type0');
  F0.AddNameValue('BaseFont', 'MyCJK');
  F0.AddNameValue('Encoding', 'Identity-H');

  CIDSysInfo := THPDFDictionaryObject.Create(nil);
  CIDSysInfo.AddStringValue('Registry', 'Adobe');
  CIDSysInfo.AddStringValue('Ordering', 'Identity');
  CIDSysInfo.AddNumericValue('Supplement', 0);

  FontDescriptor := THPDFDictionaryObject.Create(nil);
  FontDescriptor.AddNameValue('Type', 'FontDescriptor');
  // ... fill required Ascent / Descent / FontBBox / etc

  Descendant := THPDFDictionaryObject.Create(nil);
  Descendant.AddNameValue('Type', 'Font');
  Descendant.AddNameValue('Subtype', 'CIDFontType2');
  Descendant.AddNameValue('BaseFont', 'MyCJK');
  Descendant.AddValue('CIDSystemInfo', CIDSysInfo);
  Descendant.AddValue('FontDescriptor', FontDescriptor);
  Descendant.AddNumericValue('DW', 1000);

  Descendants := THPDFArrayObject.Create(nil);
  Descendants.AddObject(Descendant);
  F0.AddValue('DescendantFonts', Descendants);

  HPDF.SetFormUnicodeFontDict('F0', F0);

  R.Left := 60; R.Top := 60; R.Right := 280; R.Bottom := 100;
  HPDF.CurrentPage.AddTextField('Greeting', '你好世界', R);

  HPDF.EndDoc;
end;

 

See Also

CreateIndirectFontDict, AutoFormAppearances, AddTextField, AddRichTextField, Version