THotPDF.RegisterCoonsPatchMesh Method

 

THotPDF.RegisterCoonsPatchMesh

THotPDF

 

傳回頂部

宣告 PDF 1.3+ Coons patch mesh shading (ISO 32000-1 8.7.4.5.6, /ShadingType 6),並將其包裝為頁面 Resources/Pattern 字典中的 inline Pattern Type 2 項目。每個 patch 由四條 cubic Bezier curves 圍成,並在每個角落帶有一個色彩;轉譯器會在四條邊之間擬合 Coons surface,形成可任意彎曲且帶有色彩的 quad。當 straight-edge triangle meshes(RegisterFreeFormGouraudShading、RegisterLatticeFormGouraudShading)需要大量三角形才能近似彎曲邊界時使用此方法,例如彎曲路徑上的 foil 與 metallic gradients、SVG-derived gradient meshes,以及任何具有彎曲邊的 quad

 

Delphi 語法:

XMin, YMin, XMax, YMax - 界定已編碼座標的使用者空間矩形。這四個值會成為

 

C++ 語法:

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

 

說明

此 shading 會輸出為 indirect stream,包含 /ShadingType 6、/BitsPerCoordinate 16、/BitsPerComponent 8 與 /BitsPerFlag 8。每個 patch 會封裝為 1 個 flag byte(獨立 patch 永遠為 0),後接 12 個控制點(每個 4 位元組:2 個 big-endian X + 2 個 big-endian Y)以及 4 個角落色彩(每個 NumComponents 位元組),每個 patch 總計 1 + 48 + 4 * NumComponents 位元組。/Decode 陣列會將 16 位元座標映射回提供的 [XMin, XMax] x [YMin, YMax] 使用者空間矩形,並將每個色彩元件映射回 [0, 1]

The 12 control points are numbered c1..c12 in clockwise order around the patch boundary starting from corner 1. The four corners are c1 / c4 / c7 / c10, and the remaining eight (c2, c3 between c1 and c4; c5, c6 between c4 and c7; c8, c9 between c7 and c10; c11, c12 between c10 and c1) are the inner Bezier handles of each cubic edge. When the inner handles sit at 1/3 and 2/3 along the straight line between adjacent corners, the Coons surface degenerates to bilinear interpolation - visually equivalent to a 4-vertex Type 4 mesh.

 

XMin, YMin, XMax, YMax - 界定已編碼座標的使用者空間矩形。這四個值會成為 /Decode 的前四個項目。此矩形外的控制點會在編碼時被 clamp。請將它們放在你要繪製到的同一組使用者空間座標中;對於 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 提供 24 + 4 * NumComponents 個值:12 個控制點的 24 個 float(X, Y, X, Y, ...,依 c1..c12 clockwise order 的 12 組座標),後接角落色彩的 4 * NumComponents 個 float(corner 1 / 2 / 3 / 4 = c1 / c4 / c7 / c10,依 cyclic order)。陣列長度必須是此 stride 的正倍數。所有輸出的 patches 都帶有 flag = 0(獨立 patch);continuation flags 1 / 2 / 3(與前一 patch 共用邊)不會在這個便利 overload 中暴露

 

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

 

Code Example

// Single straight-edge Coons patch covering a 200x200 quad. Inner
// control points placed at 1/3 / 2/3 along each edge => bilinear
// surface. Four corner colours = red / green / yellow / blue
var
  Doc: THotPDF;
  PatName: AnsiString;
  Patches: array[0..35] of Extended;   // 12 ctrl pts * 2 + 4 corners * 3 = 36
  H, XMin, YMin, XMax, YMax, W: 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;
    W := 200;
    // c1..c12 clockwise. Inner handles at 1/3 / 2/3 => straight edges
    Patches[ 0] := XMin;            Patches[ 1] := YMax;             // c1  TL
    Patches[ 2] := XMin + W / 3;    Patches[ 3] := YMax;             // c2
    Patches[ 4] := XMin + 2*W / 3;  Patches[ 5] := YMax;             // c3
    Patches[ 6] := XMax;            Patches[ 7] := YMax;             // c4  TR
    Patches[ 8] := XMax;            Patches[ 9] := YMax - W / 3;     // c5
    Patches[10] := XMax;            Patches[11] := YMax - 2*W / 3;   // c6
    Patches[12] := XMax;            Patches[13] := YMin;             // c7  BR
    Patches[14] := XMax - W / 3;    Patches[15] := YMin;             // c8
    Patches[16] := XMax - 2*W / 3;  Patches[17] := YMin;             // c9
    Patches[18] := XMin;            Patches[19] := YMin;             // c10 BL
    Patches[20] := XMin;            Patches[21] := YMin + W / 3;     // c11
    Patches[22] := XMin;            Patches[23] := YMin + 2*W / 3;   // c12
    // 4 corner colours (c1 / c4 / c7 / c10)
    Patches[24] := 1.0; Patches[25] := 0.0; Patches[26] := 0.0;  // red
    Patches[27] := 0.0; Patches[28] := 1.0; Patches[29] := 0.0;  // green
    Patches[30] := 1.0; Patches[31] := 1.0; Patches[32] := 0.0;  // yellow
    Patches[33] := 0.0; Patches[34] := 0.0; Patches[35] := 1.0;  // blue
    PatName := Doc.RegisterCoonsPatchMesh(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;

 

請參閱

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