Class: Pdfrb::Document::Shadings
- Inherits:
-
Object
- Object
- Pdfrb::Document::Shadings
- Defined in:
- lib/pdfrb/document/shadings.rb
Overview
Gradient shading patterns facade. Creates Type 2 (axial) and Type 3 (radial) shading dictionaries and registers them in page /Resources /Shading.
For 2-stop gradients, uses a Type 2 ExponentialInterpolation function (/FunctionType 2). For multi-stop, chains Type 3 StitchingFunction.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#add_axial(from:, to:, stops:, extend: [true, true]) ⇒ Symbol
Add an axial (linear) gradient.
-
#add_radial(from:, to:, stops:, extend: [true, true]) ⇒ Symbol
Add a radial gradient.
- #each(&block) ⇒ Object
-
#initialize(document) ⇒ Shadings
constructor
A new instance of Shadings.
Constructor Details
#initialize(document) ⇒ Shadings
Returns a new instance of Shadings.
15 16 17 18 19 |
# File 'lib/pdfrb/document/shadings.rb', line 15 def initialize(document) @document = document @registry = {} @next_id = 1 end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
13 14 15 |
# File 'lib/pdfrb/document/shadings.rb', line 13 def document @document end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
13 14 15 |
# File 'lib/pdfrb/document/shadings.rb', line 13 def registry @registry end |
Instance Method Details
#[](name) ⇒ Object
74 75 76 |
# File 'lib/pdfrb/document/shadings.rb', line 74 def [](name) @registry[name] end |
#add_axial(from:, to:, stops:, extend: [true, true]) ⇒ Symbol
Add an axial (linear) gradient.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pdfrb/document/shadings.rb', line 28 def add_axial(from:, to:, stops:, extend: [true, true]) color_space = stops_to_color_values(stops.first || [0, [:gray, 0]])[0] name = next_name function = build_gradient_function(stops, color_space) shading = document.add( { ShadingType: 2, ColorSpace: color_space, Coords: Pdfrb::Model::PdfArray.new([*from, *to]), Function: function, Extend: Pdfrb::Model::PdfArray.new(extend), }, type: Pdfrb::Model::Cos::Dictionary ) register(name, shading) name end |
#add_radial(from:, to:, stops:, extend: [true, true]) ⇒ Symbol
Add a radial gradient.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pdfrb/document/shadings.rb', line 54 def add_radial(from:, to:, stops:, extend: [true, true]) color_space = stops_to_color_values(stops.first || [0, [:gray, 0]])[0] name = next_name function = build_gradient_function(stops, color_space) shading = document.add( { ShadingType: 3, ColorSpace: color_space, Coords: Pdfrb::Model::PdfArray.new([*from, *to]), Function: function, Extend: Pdfrb::Model::PdfArray.new(extend), }, type: Pdfrb::Model::Cos::Dictionary ) register(name, shading) name end |
#each(&block) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/pdfrb/document/shadings.rb', line 78 def each(&block) return enum_for(:each) unless block @registry.each(&block) self end |