THotPDF.RegisterTensorProductPatchMesh Method

 

THotPDF.RegisterTensorProductPatchMesh

THotPDF

 

傳回頂部

宣告 PDF 1.3+ tensor product patch mesh shading (ISO 32000-1 8.7.4.5.7, /ShadingType 7),並將其包裝為頁面 Resources/Pattern 字典中的 inline Pattern Type 2 項目。每個 patch 都是完整的 4 x 4 bicubic Bezier 控制點格線 p[i][j](12 個邊界點 + 4 個內部點),再加上每個角落一個色彩。當 RegisterCoonsPatchMesh (Type 6) 無法表達內部形狀時使用此方法,例如 SVG mesh-gradient round-trip,以及任何需要額外四個控制點來彎曲 patch 內部的圖稿

 

Delphi 語法:

function RegisterTensorProductPatchMesh(XMin, YMin, XMax, YMax: Single; NumComponents: Integer; const Patches: array of Extended): AnsiString;

 

C++ 語法:

AnsiString RegisterTensorProductPatchMesh(float XMin, float YMin, float XMax, float YMax, int NumComponents, const Extended* Patches, int PatchesElementCount);

 

說明

此 shading 會輸出為 indirect stream,包含 /ShadingType 7、/BitsPerCoordinate 16、/BitsPerComponent 8 與 /BitsPerFlag 8。每個 patch 會封裝為 1 個 flag byte(獨立 patch 永遠為 0),後接 16 個控制點(每個 4 位元組:2 個 big-endian X + 2 個 big-endian Y,依下方說明的規格 stream order),以及 4 個角落色彩(每個 NumComponents 位元組),每個 patch 總計 1 + 64 + 4 * NumComponents 位元組

16 個控制點形成 4 x 4 格線 p[i][j],其中 i 是列索引(0 = 視覺頂端 / YMax,3 = 視覺底端 / YMin),j 是欄索引(0 = 左 / XMin,3 = 右 / XMax)。規格 stream order(Table 88)會先順時針走訪 12 個邊界點(top row LtoR、right column TtoB、bottom row RtoL、left column BtoT),接著從左上內部點開始,依順時針順序列出 4 個內部點:p[1][1], p[1][2], p[2][2], p[2][1]。使用者提供的 Patches 陣列會逐字遵循相同順序

當全部 16 個控制點位於規則的 1/3 / 2/3 lattice 上(邊界點位於每條邊的 1/3 / 2/3 位置,內部點位於內部 (1/3, 1/3) / (2/3, 1/3) / (2/3, 2/3) / (1/3, 2/3) 格線交點)時,bicubic Bezier 表面會退化為平面,色彩插值會退化為 bilinear;視覺上等同於使用直線邊的 RegisterCoonsPatchMesh,或具有四個角落頂點的 RegisterFreeFormGouraudShading

 

XMin, YMin, XMax, YMax - 界定已編碼座標的使用者空間矩形。這四個值會成為 /Decode 的前四個項目。請將它們放在你要繪製到的同一組使用者空間座標中;對於 HotPDF 螢幕座標 Rectangle at (X, Y, W, H),對應的 PDF 使用者空間矩形是 (X, PageHeight - Y - H) 到 (X + W, PageHeight - Y)

NumComponents - 每個角落的色彩元件數。DeviceGray 傳入 1,DeviceRGB 傳入 3,DeviceCMYK 傳入 4。任何其他值都會擲回例外

Patches - Extended 值的扁平陣列。每個 patch 提供 32 + 4 * NumComponents 個值:16 個控制點的 32 個 float(X, Y, X, Y, ...,依規格 stream order 的 16 組座標),後接角落色彩的 4 * NumComponents 個 float(位於 p[0][0] / p[0][3] / p[3][3] / p[3][0],符合 Coons cyclic order)。陣列長度必須是此 stride 的正倍數。所有輸出的 patch 都帶有 flag = 0(獨立 patch);continuation flags 1 / 2 / 3(與前一 patch 共用邊)不會在這個便利 overload 中暴露4 * NumComponents 個浮點數表示角落顏色(位於 p[0][0] / p[0][3] / p[3][3] / p[3][0])

 

傳回值: 自動產生的 pattern name(Sh1、Sh2、...),會註冊到目前頁面的 Resources/Pattern 字典。當 StrictVersionLock 啟用且目前 Version 低於 PDF 1.3 時會傳回空字串;否則檔案版本會自動提升到 1.3

 

Code Example

// Single bilinear-equivalent tensor-product patch covering a 200x200
// quad. All 16 control points sit on the 1/3 / 2/3 lattice =>
// bicubic surface degenerates to bilinear; four corner colours
// red / green / yellow / blue
var
  Doc: THotPDF;
  PatName: AnsiString;
  Patches: array[0..43] of Extended;   // 16 ctrl pts * 2 + 4 corners * 3 = 44
  H, XMin, YMin, XMax, YMax: Single;
  XThird, X2Third, YThird, Y2Third: Single;
begin
  Doc := THotPDF.Create(nil);
  try
    Doc.Version := pdf14;
    Doc.BeginDoc;
    H := Doc.CurrentPage.Height;
    XMin := 0; YMin := H - 200; XMax := 200; YMax := H;
    XThird  := XMin + 200 / 3;     X2Third := XMin + 2 * 200 / 3;
    YThird  := YMin + 200 / 3;     Y2Third := YMin + 2 * 200 / 3;
    // Spec stream order: top row LtoR, right column TtoB, bottom row RtoL,
    // left column BtoT, then interior 4 clockwise starting at p[1][1]
    Patches[ 0] := XMin;     Patches[ 1] := YMax;       // p[0][0] TL
    Patches[ 2] := XThird;   Patches[ 3] := YMax;       // p[0][1]
    Patches[ 4] := X2Third;  Patches[ 5] := YMax;       // p[0][2]
    Patches[ 6] := XMax;     Patches[ 7] := YMax;       // p[0][3] TR
    Patches[ 8] := XMax;     Patches[ 9] := Y2Third;    // p[1][3]
    Patches[10] := XMax;     Patches[11] := YThird;     // p[2][3]
    Patches[12] := XMax;     Patches[13] := YMin;       // p[3][3] BR
    Patches[14] := X2Third;  Patches[15] := YMin;       // p[3][2]
    Patches[16] := XThird;   Patches[17] := YMin;       // p[3][1]
    Patches[18] := XMin;     Patches[19] := YMin;       // p[3][0] BL
    Patches[20] := XMin;     Patches[21] := YThird;     // p[2][0]
    Patches[22] := XMin;     Patches[23] := Y2Third;    // p[1][0]
    Patches[24] := XThird;   Patches[25] := Y2Third;    // p[1][1]
    Patches[26] := X2Third;  Patches[27] := Y2Third;    // p[1][2]
    Patches[28] := X2Third;  Patches[29] := YThird;     // p[2][2]
    Patches[30] := XThird;   Patches[31] := YThird;     // p[2][1]
    // 4 corner colours at p[0][0] / p[0][3] / p[3][3] / p[3][0]
    Patches[32] := 1.0; Patches[33] := 0.0; Patches[34] := 0.0;  // red
    Patches[35] := 0.0; Patches[36] := 1.0; Patches[37] := 0.0;  // green
    Patches[38] := 1.0; Patches[39] := 1.0; Patches[40] := 0.0;  // yellow
    Patches[41] := 0.0; Patches[42] := 0.0; Patches[43] := 1.0;  // blue
    PatName := Doc.RegisterTensorProductPatchMesh(
      XMin, YMin, XMax, YMax, 3, Patches);
    Doc.CurrentPage.SetFillPattern(PatName);
    Doc.CurrentPage.Rectangle(0, 0, 200, 200);
    Doc.CurrentPage.Fill;
    Doc.EndDoc;
  finally
    Doc.Free;
  end;
end;

 

請參閱

RegisterCoonsPatchMesh, RegisterFreeFormGouraudShading, RegisterLatticeFormGouraudShading, Version, PDF 篩選器支援