THotPDF.RegisterTensorProductPatchMesh Method

 

THotPDF.RegisterTensorProductPatchMesh

THotPDF

 

顶部

声明 PDF 1.3+ 张量积 patch mesh shading(ISO 32000-1 8.7.4.5.7,/ShadingType 7),并包装为页面 Resources/Pattern 字典中的内联 Pattern Type 2 条目。每个 patch 是完整的 4 x 4 双三次 Bezier 控制点网格 p[i][j](12 边界 + 4 内部),每个角带一个颜色。当 RegisterCoonsPatchMesh(Type 6)无法表达内部形状时使用——SVG mesh-gradient 往返,以及需要额外四个控制点弯曲 patch 内部的图稿。

 

Delphi 语法:

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

 

C++ 语法:

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

 

说明

该 shading 作为间接流输出,带有 /ShadingType 7、/BitsPerCoordinate 16、/BitsPerComponent 8 和 /BitsPerFlag 8。每个 patch 先是 1 个 flag 字节(独立 patch 时恒为 0),接着是 16 个控制点(每个 4 字节:2 字节大端 X + 2 字节大端 Y,按下文所述规范的流顺序),再接 4 个角点颜色(每个 NumComponents 字节),每个 patch 共 1 + 64 + 4 * NumComponents 字节

16 个控制点构成 4 x 4 网格 p[i][j],i 为行索引(0 = 视觉顶部 / YMax,3 = 视觉底部 / YMin),j 为列索引(0 = 左 / XMin,3 = 右 / XMax)。规范流顺序(Table 88)先顺时针遍历 12 个边界点(顶行从左到右、右列从上到下、底行从右到左、左列从下到上),然后从左上内部点开始按顺序列出 4 个内部点:p[1][1], p[1][2], p[2][2], p[2][1]。用户提供的 Patches 数组逐字遵循相同顺序。

当 16 个控制点全部位于规则的 1/3 / 2/3 格点上(边界点位于每条边的 1/3 / 2/3 处,内部点位于内侧 (1/3, 1/3) / (2/3, 1/3) / (2/3, 2/3) / (1/3, 2/3) 网格交点)时,双三次 Bezier 曲面退化为平面,颜色插值退化为双线性 - 视觉效果与使用直边的 RegisterCoonsPatchMesh,或使用四个角顶点的 RegisterFreeFormGouraudShading 完全相同

 

XMin, YMin, XMax, YMax - 限定编码坐标的用户空间矩形。这四个值成为 /Decode。请放在将要绘制的同一用户空间坐标中——对 HotPDF 中位于Rectangle 的屏幕坐标 (X, Y, W, H) Rectangle,对应的 PDF 用户空间矩形是(X, PageHeight - Y - H) 到 (X + W, PageHeight - Y)。

NumComponents - 每个角的颜色分量数量。DeviceGray 传 1,DeviceRGB 传 3,DeviceCMYK 传 4。其他值抛出异常。

Patches - Extended 值平面数组。每个 patch 贡献 32 + 4 * NumComponents 个值:16 个控制点的 32 个浮点数(X, Y, X, Y, ...,按规范流顺序的 16 对),后接角颜色的 4 * NumComponents 个浮点数(位于 p[0][0] / p[0][3] / p[3][3] / p[3][0],与 Coons 循环顺序一致)。数组长度必须是该 stride 的正倍数。所有输出的 patch 都带 flag = 0(独立 patch);本便捷重载不暴露连续 flag 1 / 2 / 3(与前一个 patch 共享边)。

 

返回值: 自动生成的 pattern 名称(Sh1、Sh2 等),注册在当前页面的 Resources/Pattern 字典。StrictVersionLock 开启且当前 Version 低于 PDF 1.3 时返回空字符串(否则文档版本自动提升到 1.3)。

 

代码示例

// 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;

 

另请参阅

RegisterCoonsPatchMesh, RegisterFreeFormGouraudShading, RegisterLatticeFormGouraudShading, Version, PDF 过滤器支持