THotPDF.RegisterTensorProductPatchMesh Method

 

THotPDF.RegisterTensorProductPatchMesh

THotPDF

 

Top

Declares a PDF 1.3+ tensor product patch mesh shading (ISO 32000-1 8.7.4.5.7, /ShadingType 7) and wraps it in an inline Pattern Type 2 entry on the page Resources/Pattern dictionary. Each patch is a full 4 x 4 grid of bicubic Bezier control points p[i][j] (12 boundary + 4 interior) plus one colour per corner. Use this when RegisterCoonsPatchMesh (Type 6) cannot express the interior shape - SVG mesh-gradient round-trips and any artwork that needs the extra four control points to bend the patch interior.

 

Delphi syntax:

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

 

C++ syntax:

AnsiString RegisterTensorProductPatchMesh(float XMin, float YMin, float XMax, float YMax, int NumComponents, const Extended* Patches, int PatchesElementCount);

 

Description

The shading is emitted as an indirect stream with /ShadingType 7, /BitsPerCoordinate 16, /BitsPerComponent 8 and /BitsPerFlag 8. Each patch is packed as 1 flag byte (always 0 for independent patches) followed by 16 control points (each 4 bytes: 2 big-endian X + 2 big-endian Y, in the spec's stream order described below) and 4 corner colours (each NumComponents bytes), totalling 1 + 64 + 4 * NumComponents bytes per patch.

The 16 control points form a 4 x 4 grid p[i][j] with i = row index (0 = visual top / YMax, 3 = visual bottom / YMin) and j = column index (0 = left / XMin, 3 = right / XMax). The spec stream order (Table 88) traverses the 12 boundary points clockwise first (top row LtoR, right column TtoB, bottom row RtoL, left column BtoT), then lists the 4 interior points in clockwise order starting at the top-left interior point: p[1][1], p[1][2], p[2][2], p[2][1]. The user-supplied Patches array follows this same order verbatim.

When all 16 control points sit on a regular 1/3 / 2/3 lattice (boundary points at 1/3 / 2/3 along each edge, interior points at the inner (1/3, 1/3) / (2/3, 1/3) / (2/3, 2/3) / (1/3, 2/3) grid intersections), the bicubic Bezier surface degenerates to a flat plane and the colour interpolation degenerates to bilinear - visually identical to RegisterCoonsPatchMesh with straight edges or RegisterFreeFormGouraudShading with four corner vertices.

 

XMin, YMin, XMax, YMax - the user-space rectangle that bounds the encoded coordinates. These four values become the first four entries of /Decode. Place them in the same user-space coordinates you will paint into - for HotPDF's screen-coordinate Rectangle at (X, Y, W, H) the matching PDF user-space rectangle is (X, PageHeight - Y - H) to (X + W, PageHeight - Y).

NumComponents - number of colour components per corner. Pass 1 for DeviceGray, 3 for DeviceRGB or 4 for DeviceCMYK. Any other value raises an exception.

Patches - flat array of Extended values. Each patch contributes 32 + 4 * NumComponents values: 32 floats for the 16 control points (X, Y, X, Y, ..., 16 pairs in the spec stream order) followed by 4 * NumComponents floats for the corner colours (at p[0][0] / p[0][3] / p[3][3] / p[3][0], matching the Coons cyclic order). Array length must be a positive multiple of this stride. All emitted patches carry flag = 0 (independent patch); continuation flags 1 / 2 / 3 (edge sharing with the previous patch) are not exposed in this convenience overload.

 

Return value: an auto-generated pattern name (Sh1, Sh2, ...) registered on the current page's Resources/Pattern dictionary. Returns an empty string when StrictVersionLock is on and the active Version is below PDF 1.3 (otherwise the document version auto-bumps to 1.3).

 

Code Example

// Single bilinear-equivalent tensor-product patch covering a 200x200
// quad. All 16 control points sit on the 1/3 / 2/3 lattice =>
// bicubic surface degenerates to bilinear; four corner colours
// red / green / yellow / blue.
var
  Doc: THotPDF;
  PatName: AnsiString;
  Patches: array[0..43] of Extended;   // 16 ctrl pts * 2 + 4 corners * 3 = 44
  H, XMin, YMin, XMax, YMax: Single;
  XThird, X2Third, YThird, Y2Third: 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;
    XThird  := XMin + 200 / 3;     X2Third := XMin + 2 * 200 / 3;
    YThird  := YMin + 200 / 3;     Y2Third := YMin + 2 * 200 / 3;
    // Spec stream order: top row LtoR, right column TtoB, bottom row RtoL,
    // left column BtoT, then interior 4 clockwise starting at p[1][1].
    Patches[ 0] := XMin;     Patches[ 1] := YMax;       // p[0][0] TL
    Patches[ 2] := XThird;   Patches[ 3] := YMax;       // p[0][1]
    Patches[ 4] := X2Third;  Patches[ 5] := YMax;       // p[0][2]
    Patches[ 6] := XMax;     Patches[ 7] := YMax;       // p[0][3] TR
    Patches[ 8] := XMax;     Patches[ 9] := Y2Third;    // p[1][3]
    Patches[10] := XMax;     Patches[11] := YThird;     // p[2][3]
    Patches[12] := XMax;     Patches[13] := YMin;       // p[3][3] BR
    Patches[14] := X2Third;  Patches[15] := YMin;       // p[3][2]
    Patches[16] := XThird;   Patches[17] := YMin;       // p[3][1]
    Patches[18] := XMin;     Patches[19] := YMin;       // p[3][0] BL
    Patches[20] := XMin;     Patches[21] := YThird;     // p[2][0]
    Patches[22] := XMin;     Patches[23] := Y2Third;    // p[1][0]
    Patches[24] := XThird;   Patches[25] := Y2Third;    // p[1][1]
    Patches[26] := X2Third;  Patches[27] := Y2Third;    // p[1][2]
    Patches[28] := X2Third;  Patches[29] := YThird;     // p[2][2]
    Patches[30] := XThird;   Patches[31] := YThird;     // p[2][1]
    // 4 corner colours at p[0][0] / p[0][3] / p[3][3] / p[3][0].
    Patches[32] := 1.0; Patches[33] := 0.0; Patches[34] := 0.0;  // red
    Patches[35] := 0.0; Patches[36] := 1.0; Patches[37] := 0.0;  // green
    Patches[38] := 1.0; Patches[39] := 1.0; Patches[40] := 0.0;  // yellow
    Patches[41] := 0.0; Patches[42] := 0.0; Patches[43] := 1.0;  // blue
    PatName := Doc.RegisterTensorProductPatchMesh(
      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;

 

See Also

RegisterCoonsPatchMesh, RegisterFreeFormGouraudShading, RegisterLatticeFormGouraudShading, Version, PDF Filter Support