Class: Pdfrb::Document::Colors
- Inherits:
-
Object
- Object
- Pdfrb::Document::Colors
- Defined in:
- lib/pdfrb/document/colors.rb
Overview
Facade for color space management. Embeds ICC profiles, registers named color spaces in page Resources, and provides lookup.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#embed_icc_profile(icc_bytes, alternate: nil) ⇒ Pdfrb::Model::PdfArray
Embed an ICC profile as a stream and return the color space array [/ICCBased ] for use in Resources.
-
#initialize(document) ⇒ Colors
constructor
A new instance of Colors.
-
#register(page, color_space) ⇒ Symbol
Register a color space in a page's Resources /ColorSpace dict and return the name (e.g. :CS1) for use in content streams.
Constructor Details
#initialize(document) ⇒ Colors
Returns a new instance of Colors.
10 11 12 13 |
# File 'lib/pdfrb/document/colors.rb', line 10 def initialize(document) @document = document @next_cs_number = 1 end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
8 9 10 |
# File 'lib/pdfrb/document/colors.rb', line 8 def document @document end |
Instance Method Details
#embed_icc_profile(icc_bytes, alternate: nil) ⇒ Pdfrb::Model::PdfArray
Embed an ICC profile as a stream and return the color space array [/ICCBased ] for use in Resources.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pdfrb/document/colors.rb', line 23 def (icc_bytes, alternate: nil) profile = Pdfrb::Color::ICCProfile.new(icc_bytes, alternate: alternate) stream = document.add( { **profile.stream_dictionary_fields, Length: profile.raw_data.bytesize }, type: Pdfrb::Model::Cos::Stream ) stream.stream = profile.raw_data Pdfrb::Model::PdfArray.new([ :ICCBased, Pdfrb::Model::Reference.new(stream.oid, stream.gen), ]) end |
#register(page, color_space) ⇒ Symbol
Register a color space in a page's Resources /ColorSpace dict and return the name (e.g. :CS1) for use in content streams.
43 44 45 46 47 48 49 50 51 |
# File 'lib/pdfrb/document/colors.rb', line 43 def register(page, color_space) resources = ensure_resources(page) cs_dict = resources.value[:ColorSpace] cs_dict = ensure_color_space_dict(resources, cs_dict) name = cs_name cs_dict[name] = color_space name end |