|
PDF 1.3+ free-form Gouraud-shaded triangle mesh shading(ISO 32000-1 8.7.4.5.4, /ShadingType 4)을 선언하고 page Resources/Pattern dictionary의 inline Pattern Type 2 entry로 감쌉니다. 반환된 pattern name을 THPDFPage.SetFillPattern 또는 THPDFPage.SetStrokePattern과 함께 사용하여 각 triangle 전체에서 color가 부드럽게 변하는 vector gradient를 paint할 수 있습니다
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은 /ShadingType 4, /BitsPerCoordinate 16, /BitsPerComponent 8, /BitsPerFlag 8을 가진 단일 indirect stream으로 emit됩니다. 각 vertex는 stream order에서 8 + NumComponents - 3 byte로 pack됩니다. 즉 1-byte flag(independent triangle이므로 항상 0), X coordinate용 2 big-endian byte, Y coordinate용 2 big-endian byte, NumComponents개의 8-bit color component입니다. /Decode array는 16-bit coordinate를 제공된 [XMin, XMax] x [YMin, YMax] user-space rectangle로, 각 color component를 [0, 1]로 다시 map합니다
Vertex는 세 개씩 independent triangle로 소비됩니다. Vertices에 전달하는 Extended value 수는 정확히 (2 + NumComponents) * 3 * TriangleCount여야 합니다. Array length가 stride의 배수가 아니거나 vertex count가 3의 배수가 아니면 helper가 exception을 raise합니다
XMin, YMin, XMax, YMax - mesh를 둘러싸는 user-space rectangle입니다. 이 네 값은 /Decode의 처음 네 entry가 되어 16-bit-encoded vertex coordinate를 PDF user space로 다시 map합니다. 실제로 paint할 동일한 user-space coordinate에 배치하십시오. HotPDF screen-coordinate Rectangle의 (X, Y, W, H)에 대응하는 PDF user-space rectangle은 (X, PageHeight - Y - H)부터 (X + W, PageHeight - Y)까지입니다
NumComponents - vertex당 color component 수입니다. DeviceGray는 1, DeviceRGB는 3, DeviceCMYK는 4를 전달하십시오. 다른 값은 exception을 raise합니다. 결과 shading의 /ColorSpace entry는 이에 맞게 설정됩니다
Vertices - 각 vertex마다 (X, Y, c1...cN) 순서로 반복되는 Extended value의 flat array입니다. Coordinate는 [XMin, XMax] x [YMin, YMax] box로 clamp되고 16-bit integer로 quantise됩니다. Color component는 [0, 1]로 clamp되고 8-bit integer로 quantise됩니다. Registered shading은 모든 vertex에 flag 0(independent triangle)을 사용하므로 edge를 공유해야 하는 adjacent triangle은 shared vertex를 그대로 반복해야 합니다
반환 값: current page의 Resources/Pattern dictionary에 등록된 auto-generated pattern name(Sh1, Sh2, ...)입니다. StrictVersionLock이 켜져 있고 active Version이 PDF 1.3보다 낮으면 빈 string을 반환합니다. 그렇지 않으면 document version이 1.3으로 auto-bump됩니다
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;
See Also
RegisterDeviceN, RegisterSeparation, RegisterLabColorSpace, Version, PDF Filter Support
|