Class: Pdfrb::Content::Shading::Base
- Inherits:
-
Object
- Object
- Pdfrb::Content::Shading::Base
- Defined in:
- lib/pdfrb/content/shading/base.rb
Overview
Base shading builder. Subclasses set shading_type and
shading_fields. Creates a shading dict and registers it
in the page's /Resources /Shading sub-dict.
Instance Attribute Summary collapse
-
#color_space ⇒ Object
readonly
Returns the value of attribute color_space.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(color_space: :DeviceGray) ⇒ Base
constructor
A new instance of Base.
-
#register_on(document, page) ⇒ Symbol
Register this shading on a page and return the resource name.
-
#to_dict ⇒ Object
Build the shading dictionary value (a Hash).
Constructor Details
#initialize(color_space: :DeviceGray) ⇒ Base
Returns a new instance of Base.
18 19 20 |
# File 'lib/pdfrb/content/shading/base.rb', line 18 def initialize(color_space: :DeviceGray) @color_space = color_space end |
Instance Attribute Details
#color_space ⇒ Object (readonly)
Returns the value of attribute color_space.
10 11 12 |
# File 'lib/pdfrb/content/shading/base.rb', line 10 def color_space @color_space end |
Class Method Details
.shading_type ⇒ Object
13 14 15 |
# File 'lib/pdfrb/content/shading/base.rb', line 13 def shading_type raise NotImplementedError end |
Instance Method Details
#register_on(document, page) ⇒ Symbol
Register this shading on a page and return the resource name.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pdfrb/content/shading/base.rb', line 32 def register_on(document, page) shading_obj = document.add(to_dict, type: Pdfrb::Model::Cos::Dictionary) ref = Pdfrb::Model::Reference.new(shading_obj.oid, shading_obj.gen) resources = ensure_resources(document, page) shading_dict = resources.value[:Shading] if shading_dict.nil? shading_dict = {} resources.value[:Shading] = shading_dict end name = next_shading_name(shading_dict) shading_dict[name] = ref name end |
#to_dict ⇒ Object
Build the shading dictionary value (a Hash).
23 24 25 26 |
# File 'lib/pdfrb/content/shading/base.rb', line 23 def to_dict { ShadingType: self.class.shading_type, ColorSpace: @color_space }.merge!(shading_fields) end |