THotPDF.RegisterLatticeFormGouraudShading Method

 

THotPDF.RegisterLatticeFormGouraudShading

THotPDF

 

先頭

PDF 1.3+ の lattice-form Gouraud-shaded triangle mesh shading (ISO 32000-1 8.7.4.5.5, /ShadingType 5) を宣言し、page Resources/Pattern dictionary 上の inline Pattern Type 2 entry に wrap します。renderer は adjacent rows の各 pair を triangle strip に自動 triangulate するため、caller は vertex grid だけを渡します。source data が regular sample grid (terrain、FEA results、scientific heatmaps など) にすでにある場合に有用です。triangulation が irregular で per-triangle flags が必要な場合は、代わりに RegisterFreeFormGouraudShading を使用してください

 

Delphi syntax:

function RegisterLatticeFormGouraudShading(XMin, YMin, XMax, YMax: Single; NumComponents: Integer; VerticesPerRow: Integer; const Vertices: array of Extended): AnsiString;

 

C++ syntax:

AnsiString RegisterLatticeFormGouraudShading(float XMin, float YMin, float XMax, float YMax, int NumComponents, int VerticesPerRow, const Extended* Vertices, int VertexElementCount);

 

説明

shading は /ShadingType 5/BitsPerCoordinate 16/BitsPerComponent 8/VerticesPerRow N を持つ indirect stream として出力されます。Type 4 と異なり per-vertex flag byte はなく、/BitsPerFlag は shading dictionary に存在しません。各 vertex は 4 + NumComponents bytes (2 big-endian X + 2 big-endian Y + N color components) を占めます。/Decode array は 16-bit coordinates を supplied [XMin, XMax] x [YMin, YMax] user-space rectangle に戻し、各 color component を [0, 1] に戻します

vertices は row-major order です。最初の VerticesPerRow vertices が row 0、次の VerticesPerRow vertices が row 1、以降も同様です。renderer は adjacent rows (row i と row i+1) の各 pair を triangle strip に接続します。flags も explicit triangle list もありません。Vertices に渡す Extended values の数は (2 + NumComponents) * VerticesPerRow の倍数でなければならず、結果の row count は少なくとも 2 でなければなりません

 

XMinYMinXMaxYMax - lattice を囲む user-space rectangle です。これら 4 つの values は /Decode の最初の 4 entries になります。描画先と同じ user-space coordinates で指定してください。HotPDF の screen-coordinate Rectangle(X, Y, W, H) の場合、対応する PDF user-space rectangle は (X, PageHeight - Y - H) から (X + W, PageHeight - Y) です

NumComponents - vertex ごとの color component count です。DeviceGray には 1、DeviceRGB には 3、DeviceCMYK には 4 を渡します。それ以外の値は exception を発生させます。結果の shading の /ColorSpace entry はこれに応じて設定されます

VerticesPerRow - lattice row ごとの vertex count N で、N >= 2 です。dictionary entry /VerticesPerRow はこの値をそのまま取ります。row count M は array length から VertexCount / VerticesPerRow として推定され、少なくとも 2 でなければなりません

Vertices - vertex ごとの (X, Y, c1...cN) order の flat Extended array で、row-major (row 0、次に row 1、...) に繰り返されます。coordinates は [XMin, XMax] x [YMin, YMax] に clamp され 16-bit integers に quantise されます。color components は [0, 1] に clamp され 8-bit integers に quantise されます

 

戻り値: current page の Resources/Pattern dictionary に登録される auto-generated pattern name (Sh1Sh2、...) です。StrictVersionLock が on で active Version が PDF 1.3 未満の場合は empty string を返します (それ以外では document version は 1.3 に auto-bump されます)

 

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 Filter Support