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) και το τυλίγει σε inline Pattern Type 2 entry στο page Resources/Pattern dictionary. Ο renderer κάνει auto-triangulates κάθε ζεύγος adjacent rows σε triangle strip, οπότε ο καλών παρέχει μόνο το vertex grid - χρήσιμο όταν τα source data βρίσκονται ήδη σε regular sample grid (terrain, FEA results, scientific heatmaps). Χρησιμοποιήστε το RegisterFreeFormGouraudShading όταν το triangulation είναι irregular και χρειάζονται per-triangle flags

 

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 εκπέμπεται ως indirect stream με /ShadingType 5, /BitsPerCoordinate 16, /BitsPerComponent 8 και /VerticesPerRow N. Σε αντίθεση με 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 πίσω στο παρεχόμενο [XMin, XMax] x [YMin, YMax] user-space rectangle και κάθε color component πίσω στο [0, 1]

Τα Vertices ταξινομούνται row-major: τα πρώτα VerticesPerRow vertices σχηματίζουν row 0, τα επόμενα VerticesPerRow σχηματίζουν row 1 κ.ο.κ. Ο renderer συνδέει κάθε ζεύγος adjacent rows (row i και row i+1) σε triangle strip - χωρίς flags, χωρίς explicit triangle list. Ο αριθμός Extended values που περνάτε στο Vertices πρέπει να είναι multiple του (2 + NumComponents) * VerticesPerRow και το resulting row count πρέπει να είναι τουλάχιστον 2

 

XMin, YMin, XMax, YMax - το user-space rectangle που περικλείει το lattice. Αυτές οι τέσσερις values γίνονται οι πρώτες τέσσερις entries του /Decode. Τοποθετήστε τα στα ίδια user-space coordinates όπου θα ζωγραφίσετε - για Rectangle του HotPDF με screen-coordinate στο (X, Y, W, H), το αντίστοιχο PDF user-space rectangle είναι (X, PageHeight - Y - H) έως (X + W, PageHeight - Y)

NumComponents - αριθμός color components ανά vertex. Περάστε 1 για DeviceGray, 3 για DeviceRGB ή 4 για DeviceCMYK. Οποιαδήποτε άλλη τιμή προκαλεί exception

VerticesPerRow - αριθμός vertices N ανά lattice row, N >= 2. Το dictionary entry /VerticesPerRow λαμβάνει αυτή την τιμή verbatim. Ο αριθμός rows M συνάγεται από το array length ως VertexCount / VerticesPerRow και πρέπει να είναι τουλάχιστον 2

Vertices - flat array από Extended values σε σειρά (X, Y, c1...cN) ανά vertex, επαναλαμβανόμενη row-major (πρώτα row 0, έπειτα row 1, ...). Τα coordinates γίνονται clamped στο [XMin, XMax] x [YMin, YMax] και quantised σε 16-bit integers· τα color components γίνονται clamped στο [0, 1] και quantised σε 8-bit integers

 

Return value: auto-generated pattern name (Sh1, Sh2, ...) καταχωρημένο στο Resources/Pattern dictionary της τρέχουσας σελίδας. Επιστρέφει κενό string όταν το StrictVersionLock είναι on και το active Version είναι κάτω από PDF 1.3 (διαφορετικά το document version γίνεται auto-bump σε 1.3)

 

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;

 

See Also

RegisterFreeFormGouraudShading, RegisterDeviceN, RegisterSeparation, RegisterLabColorSpace, Version, PDF Filter Support