Hpdf::Shading
Inherits Hpdf::Helper / Reference / Object
A shading object defines a smooth colour gradient using a Gouraud-shaded
triangle mesh. Create one with Doc#create_shading, add vertices with
#add_vertex, then paint it onto a page with Page#set_shading.
Each group of three NoConnection vertices forms one triangle. Additional
triangles can share an edge with the previous one via PreviousBC /
PreviousAC edge flags, building a connected mesh.
Currently only ShadingType::FreeFormTriangleMesh (type 4) is supported
by libharu.
sh = doc.create_shading(Hpdf::ShadingType::FreeFormTriangleMesh,
Hpdf::ColorSpace::DeviceRgb, 0, 400, 0, 500)
sh.add_vertex(edge: :no_connection, x: 0, y: 0, r: 255_u8, g: 0_u8, b: 0_u8)
sh.add_vertex(edge: :no_connection, x: 400, y: 0, r: 0_u8, g: 255_u8, b: 0_u8)
sh.add_vertex(edge: :no_connection, x: 200, y: 500, r: 0_u8, g: 0_u8, b: 255_u8)
page.set_shading(sh)
Constructors
new(shading : LibHaru::Shading, doc : Doc)
SourceInstance methods
add_vertex(*, edge : ShadingEdgeFlag | Symbol, x : Number, y : Number, r : UInt8, g : UInt8, b : UInt8)
adds a vertex to the shading mesh.
- edge connectivity to the previous triangle — accepts a
ShadingEdgeFlagor one of the symbols:no_connection,:previous_bc,:previous_ac - x, y coordinates of the vertex in user space
- r, g, b RGB colour components of the vertex (0–255 each)
to_unsafe
Source