THotPDF.RegisterLatticeFormGouraudShading Method

 

THotPDF.RegisterLatticeFormGouraudShading

THotPDF

 

الأعلى

يعلن shading لشبكة مثلثات Gouraud ذات lattice-form في PDF 1.3+ (ISO 32000-1 8.7.4.5.5, /ShadingType 5) ويلفه في Pattern Type 2 inline ضمن Resources/Pattern. يقوم renderer بتثليث كل زوج من الصفوف المتجاورة تلقائيًا إلى triangle strip، لذلك يمرر المستدعي شبكة الرؤوس فقط، وهو مفيد عندما تكون البيانات الأصلية على sample grid منتظمة

 

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. بخلاف Type 4 لا توجد flag byte لكل vertex ولا توجد /BitsPerFlag؛ ويشغل كل vertex ‏4 + NumComponents bytes. تربط /Decode الإحداثيات ومكونات اللون بالنطاقات المعطاة

ترتب Vertices حسب row-major: أول VerticesPerRow رؤوس تشكل row 0، ثم row 1، وهكذا. يربط renderer كل زوج من الصفوف المتجاورة في triangle strip دون flags أو قائمة مثلثات صريحة. يجب أن يكون طول Vertices من مضاعفات (2 + NumComponents) * VerticesPerRow وأن يكون عدد الصفوف الناتج 2 على الأقل

 

XMin وYMin وXMax وYMax - مستطيل user-space الذي يحد lattice. تصبح هذه القيم أول أربعة مداخل في /Decode، ويجب أن توضع في إحداثيات user-space نفسها التي سيجري الرسم فيها

NumComponents - عدد مكونات اللون لكل vertex. مرر 1 لـ DeviceGray أو 3 لـ DeviceRGB أو 4 لـ DeviceCMYK. أي قيمة أخرى ترفع exception

VerticesPerRow - عدد الرؤوس N في كل صف lattice، ويجب أن يكون N >= 2. يأخذ مدخل /VerticesPerRow هذه القيمة كما هي. يستنتج عدد الصفوف M من طول المصفوفة ويجب أن يكون 2 على الأقل

Vertices - مصفوفة مسطحة من قيم Extended بترتيب (X, Y, c1...cN) لكل vertex، مكررة حسب row-major. تقيد الإحداثيات إلى [XMin, XMax] x [YMin, YMax] وتكمم إلى 16-bit، وتقيد مكونات اللون إلى [0, 1] وتكمم إلى 8-bit

 

القيمة المعادة: اسم pattern مولد تلقائيًا (Sh1, Sh2, ...) ومسجل في قاموس Resources/Pattern للصفحة الحالية. يعيد سلسلة فارغة عندما يكون StrictVersionLock مفعّلًا وVersion النشطة أقل من PDF 1.3؛ وإلا يرفع إصدار المستند تلقائيًا إلى 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;

 

انظر أيضا

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