|
宣告 PDF 1.3+ lattice-form Gouraud-shaded triangle mesh shading (ISO 32000-1 8.7.4.5.5, /ShadingType 5),並將其包裝為頁面 Resources/Pattern 字典中的 inline Pattern Type 2 項目。轉譯器會將每一對相鄰列自動三角化為 triangle strip,因此呼叫端只需提供頂點格線;當來源資料本來就在規則取樣格線中時很有用,例如地形、FEA 結果、科學 heatmap。若三角化不規則且需要 per-triangle flags,請改用 RegisterFreeFormGouraudShading
Delphi 語法:
function RegisterLatticeFormGouraudShading(XMin, YMin, XMax, YMax: Single; NumComponents: Integer; VerticesPerRow: Integer; const Vertices: array of Extended): AnsiString;
C++ 語法:
AnsiString RegisterLatticeFormGouraudShading(float XMin, float YMin, float XMax, float YMax, int NumComponents, int VerticesPerRow, const Extended* Vertices, int VertexElementCount);
說明
此 shading 會輸出為 indirect stream,包含 /ShadingType 5、/BitsPerCoordinate 16、/BitsPerComponent 8 與 /VerticesPerRow N。不同於 Type 4,它沒有 per-vertex flag byte,shading 字典中也沒有 /BitsPerFlag;每個頂點佔用 4 + NumComponents 位元組,也就是 2 個 big-endian X、2 個 big-endian Y,加上 N 個色彩元件。/Decode 陣列會將 16 位元座標映射回提供的 [XMin, XMax] x [YMin, YMax] 使用者空間矩形,並將每個色彩元件映射回 [0, 1]
Vertices 以 row-major 排列:前 VerticesPerRow 個頂點形成第 0 列,接下來的 VerticesPerRow 個形成第 1 列,依此類推。轉譯器會將每一對相鄰列(row i 與 row i+1)連接為 triangle strip,沒有 flags,也沒有明確的 triangle list。傳入 Vertices 的 Extended 值數量必須是 的倍數,推導出的列數也必須至少為 2
XMin, YMin, XMax, YMax - 界定 lattice 的使用者空間矩形。這四個值會成為 /Decode 的前四個項目。請將它們放在你要繪製到的同一組使用者空間座標中;對於 HotPDF 螢幕座標 Rectangle at (X, Y, W, H),對應的 PDF 使用者空間矩形是 (X, PageHeight - Y - H) 到 (X + W, PageHeight - Y)
NumComponents - 每個頂點的色彩元件數。DeviceGray 傳入 1,DeviceRGB 傳入 3,DeviceCMYK 傳入 4。任何其他值都會擲回例外
VerticesPerRow - 每個 lattice 列的頂點數 N,N >= 2。字典項目 /VerticesPerRow 會逐字採用此值。列數 M 會由陣列長度推導為 VertexCount / VerticesPerRow,且必須至少為 2
Vertices - Extended 值的扁平陣列,每個頂點依 (X, Y, c1...cN) 順序排列,並以 row-major 重複(先 row 0,再 row 1,依此類推)。座標會限制在 [XMin, XMax] x [YMin, YMax] 並量化為 16 位元整數;色彩元件會限制在 [0, 1] 並量化為 8 位元整數
傳回值: 自動產生的 pattern name(Sh1、Sh2、...),會註冊到目前頁面的 Resources/Pattern 字典。當 StrictVersionLock 啟用且目前 Version 低於 PDF 1.3 時會傳回空字串;否則檔案版本會自動提升到 1.3
Code Example
// 3x3 lattice over a 200x200 quad. The renderer auto-triangulates
// adjacent rows into a triangle strip, giving 4 cells x 2 triangles
// = 8 triangles. Colour layout (visual):
//
// row 0 (top, Y=YMax): red yellow green
// row 1 (mid): magenta gray cyan
// row 2 (bot, Y=YMin): blue purple orange
var
Doc: THotPDF;
PatName: AnsiString;
Verts: array[0..44] of Extended; // 9 vertices x 5 floats each
H, XMin, YMin, XMax, YMax, XMid, YMid: 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;
XMid := (XMin + XMax) / 2;
YMid := (YMin + YMax) / 2;
// row 0 (Y=YMax): red - yellow - green
Verts[ 0] := XMin; Verts[ 1] := YMax; Verts[ 2] := 1.0; Verts[ 3] := 0.0; Verts[ 4] := 0.0;
Verts[ 5] := XMid; Verts[ 6] := YMax; Verts[ 7] := 1.0; Verts[ 8] := 1.0; Verts[ 9] := 0.0;
Verts[10] := XMax; Verts[11] := YMax; Verts[12] := 0.0; Verts[13] := 1.0; Verts[14] := 0.0;
// row 1 (Y mid): magenta - gray - cyan
Verts[15] := XMin; Verts[16] := YMid; Verts[17] := 1.0; Verts[18] := 0.0; Verts[19] := 1.0;
Verts[20] := XMid; Verts[21] := YMid; Verts[22] := 0.5; Verts[23] := 0.5; Verts[24] := 0.5;
Verts[25] := XMax; Verts[26] := YMid; Verts[27] := 0.0; Verts[28] := 1.0; Verts[29] := 1.0;
// row 2 (Y=YMin): blue - purple - orange
Verts[30] := XMin; Verts[31] := YMin; Verts[32] := 0.0; Verts[33] := 0.0; Verts[34] := 1.0;
Verts[35] := XMid; Verts[36] := YMin; Verts[37] := 0.5; Verts[38] := 0.0; Verts[39] := 0.5;
Verts[40] := XMax; Verts[41] := YMin; Verts[42] := 1.0; Verts[43] := 0.5; Verts[44] := 0.0;
PatName := Doc.RegisterLatticeFormGouraudShading(
XMin, YMin, XMax, YMax, 3, 3, Verts);
Doc.CurrentPage.SetFillPattern(PatName);
Doc.CurrentPage.Rectangle(0, 0, 200, 200);
Doc.CurrentPage.Fill;
Doc.EndDoc;
finally
Doc.Free;
end;
end;
請參閱
RegisterFreeFormGouraudShading, RegisterDeviceN, RegisterSeparation, RegisterLabColorSpace, Version, PDF 篩選器支援
|