THotPDF.RegisterFreeFormGouraudShading Method

 

THotPDF.RegisterFreeFormGouraudShading

THotPDF

 

傳回頂部

宣告 PDF 1.3+ free-form Gouraud-shaded triangle mesh shading (ISO 32000-1 8.7.4.5.4, /ShadingType 4),並將其包裝為頁面 Resources/Pattern 字典中的 inline Pattern Type 2 項目。請將傳回的 pattern name 搭配 THPDFPage.SetFillPattern 或 THPDFPage.SetStrokePattern 使用,以繪製色彩在每個三角形內平滑變化的向量漸層

 

Delphi 語法:

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

 

C++ 語法:

AnsiString RegisterFreeFormGouraudShading(float XMin, float YMin, float XMax, float YMax, int NumComponents, const Extended* Vertices, int VertexElementCount);

 

說明

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

Vertices 會每次取三個作為獨立三角形使用。傳入 Vertices 的 Extended 值數量必須精確等於 ;若陣列長度不是 stride 的倍數,或頂點數不是三的倍數,helper 會擲回例外

 

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

NumComponents - 每個頂點的色彩元件數。DeviceGray 傳入 1,DeviceRGB 傳入 3,DeviceCMYK 傳入 4。任何其他值都會擲回例外。產生的 shading 會據此設定 /ColorSpace 項目

Vertices - Extended 值的扁平陣列,依 (X, Y, c1...cN) 順序排列,並對每個頂點重複。座標會限制在 [XMin, XMax] x [YMin, YMax] 方框內並量化為 16 位元整數;色彩元件會限制在 [0, 1] 並量化為 8 位元整數。需要共用邊的相鄰三角形必須逐字重複共用頂點,因為註冊的 shading 對每個頂點都使用 flag 0(獨立三角形)

 

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

 

Code Example

// Four-corner colour quad split into two independent triangles
// along the top-left -> bot-right diagonal. The colours blend
// smoothly across the mesh; the diagonal is the ridge where the
// two triangles meet
//
//   top-left red    -- top-right green
//        |                  |
//   bot-left blue   -- bot-right yellow
var
  Doc: THotPDF;
  PatName: AnsiString;
  Verts: array[0..29] of Extended;
  H, XMin, YMin, XMax, YMax: 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;
    // triangle A: top-left red, top-right green, bot-right yellow
    Verts[ 0] := XMin; Verts[ 1] := YMax; Verts[ 2] := 1.0; Verts[ 3] := 0.0; Verts[ 4] := 0.0;
    Verts[ 5] := XMax; Verts[ 6] := YMax; Verts[ 7] := 0.0; Verts[ 8] := 1.0; Verts[ 9] := 0.0;
    Verts[10] := XMax; Verts[11] := YMin; Verts[12] := 1.0; Verts[13] := 1.0; Verts[14] := 0.0;
    // triangle B: top-left red, bot-right yellow, bot-left blue
    Verts[15] := XMin; Verts[16] := YMax; Verts[17] := 1.0; Verts[18] := 0.0; Verts[19] := 0.0;
    Verts[20] := XMax; Verts[21] := YMin; Verts[22] := 1.0; Verts[23] := 1.0; Verts[24] := 0.0;
    Verts[25] := XMin; Verts[26] := YMin; Verts[27] := 0.0; Verts[28] := 0.0; Verts[29] := 1.0;
    PatName := Doc.RegisterFreeFormGouraudShading(
      XMin, YMin, XMax, YMax, 3, Verts);
    Doc.CurrentPage.SetFillPattern(PatName);
    Doc.CurrentPage.Rectangle(0, 0, 200, 200);
    Doc.CurrentPage.Fill;
    Doc.EndDoc;
  finally
    Doc.Free;
  end;
end;

 

請參閱

RegisterDeviceN, RegisterSeparation, RegisterLabColorSpace, Version, PDF 篩選器支援