|
PDF 1.3+ の Coons patch mesh shading (ISO 32000-1 8.7.4.5.6, /ShadingType 6) を宣言し、page Resources/Pattern dictionary 上の inline Pattern Type 2 entry に wrap します。各 patch は 4 本の cubic Bezier curves で囲まれ、corner ごとに 1 つの color を持ちます。renderer は 4 辺の間に Coons surface を fit し、任意に curved な color-bearing quad を生成します。straight-edge triangle meshes (RegisterFreeFormGouraudShading、RegisterLatticeFormGouraudShading) では curved boundaries を近似するために多数の triangles が必要になる場合に使用してください。bent paths 上の foil / metallic gradients、SVG-derived gradient meshes、curved edges を持つ任意の quad に向いています
Delphi syntax:
function RegisterCoonsPatchMesh(XMin, YMin, XMax, YMax: Single; NumComponents: Integer; const Patches: array of Extended): AnsiString;
C++ syntax:
AnsiString RegisterCoonsPatchMesh(float XMin, float YMin, float XMax, float YMax, int NumComponents, const Extended* Patches, int PatchesElementCount);
説明
shading は /ShadingType 6、/BitsPerCoordinate 16、/BitsPerComponent 8、/BitsPerFlag 8 を持つ indirect stream として出力されます。各 patch は 1 flag byte (independent patches では常に 0)、12 control points (各 4 bytes: 2 big-endian X + 2 big-endian Y)、4 corner colors (各 NumComponents bytes) の順で pack され、patch ごとに合計 1 + 48 + 4 * NumComponents bytes になります。/Decode array は 16-bit coordinates を supplied [XMin, XMax] x [YMin, YMax] user-space rectangle に戻し、各 color component を [0, 1] に戻します
12 個の control points は corner 1 から patch boundary を時計回りに c1..c12 と番号付けされます。4 つの corners は c1 / c4 / c7 / c10 で、残り 8 個 (c1 と c4 の間の c2, c3、c4 と c7 の間の c5, c6、c7 と c10 の間の c8, c9、c10 と c1 の間の c11, c12) は各 cubic edge の inner Bezier handles です。inner handles が adjacent corners 間の straight line 上の 1/3 と 2/3 にある場合、Coons surface は bilinear interpolation に退化し、視覚的には 4-vertex Type 4 mesh と同等になります
XMin、YMin、XMax、YMax - encoded coordinates を囲む user-space rectangle です。これら 4 つの values は /Decode の最初の 4 entries になります。この rectangle の外側にある control points は encoding time に clamp されます。描画先と同じ user-space coordinates で指定してください。HotPDF の screen-coordinate Rectangle が (X, Y, W, H) の場合、対応する PDF user-space rectangle は (X, PageHeight - Y - H) から (X + W, PageHeight - Y) です
NumComponents - corner ごとの color component count です。DeviceGray には 1、DeviceRGB には 3、DeviceCMYK には 4 を渡します。それ以外の値は exception を発生させます
Patches - flat Extended array です。各 patch は 24 + 4 * NumComponents values を提供します。12 control points 用の 24 floats (X, Y, X, Y, ...、c1..c12 clockwise order の 12 pairs) に続き、corner colors 用の 4 * NumComponents floats (corner 1 / 2 / 3 / 4 = cyclic order の c1 / c4 / c7 / c10) が入ります。array length はこの stride の正の倍数でなければなりません。出力されるすべての patches は flag = 0 (independent patch) を持ちます。continuation flags 1 / 2 / 3 (previous patch との edge sharing) はこの convenience overload では公開されません
戻り値: current page の Resources/Pattern dictionary に登録される auto-generated pattern name (Sh1、Sh2、...) です。StrictVersionLock が on で active Version が PDF 1.3 未満の場合は empty string を返します (それ以外では document version は 1.3 に auto-bump されます)
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 Filter Support
|