Class: HexaPDF::Type::Resources
- Inherits:
-
Dictionary
- Object
- Object
- Dictionary
- HexaPDF::Type::Resources
- Defined in:
- lib/hexapdf/type/resources.rb
Overview
Represents the resources needed by a content stream.
See: PDF1.7 s7.8.3
Constant Summary
Constants included from DictionaryFields
DictionaryFields::Boolean, DictionaryFields::PDFByteString, DictionaryFields::PDFDate
Constants inherited from Object
Object::NOT_DUPLICATABLE_CLASSES
Instance Attribute Summary
Attributes inherited from Object
#data, #document, #must_be_indirect
Instance Method Summary collapse
-
#add_color_space(color_space) ⇒ Object
Adds the color space to the resources and returns the name under which it is stored.
-
#add_ext_gstate(object) ⇒ Object
Adds the graphics state parameter dictionary to the resources and returns the name under which it is stored.
-
#add_font(object) ⇒ Object
Adds the font dictionary to the resources and returns the name under which it is stored.
-
#add_xobject(object) ⇒ Object
Adds the XObject to the resources and returns the name under which it is stored.
-
#color_space(name) ⇒ Object
Returns the color space stored under the given name.
-
#ext_gstate(name) ⇒ Object
Returns the graphics state parameter dictionary (see Type::GraphicsStateParameter) stored under the given name.
-
#font(name) ⇒ Object
Returns the font dictionary stored under the given name.
-
#type ⇒ Object
Returns
:XXResources
. -
#xobject(name) ⇒ Object
Returns the XObject stored under the given name.
Methods inherited from Dictionary
#[], #[]=, define_field, #delete, #each, each_field, #empty?, field, #key?, #to_hash
Methods inherited from Object
#<=>, #==, deep_copy, #deep_copy, #document?, #eql?, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, #must_be_indirect?, #null?, #oid, #oid=, #validate, #value, #value=
Constructor Details
This class inherits a constructor from HexaPDF::Object
Instance Method Details
#add_color_space(color_space) ⇒ Object
Adds the color space to the resources and returns the name under which it is stored.
If there already exists a color space with the same definition, it is reused. The device color spaces :DeviceGray
, :DeviceRGB
and :DeviceCMYK
are never stored, their respective name is just returned.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/hexapdf/type/resources.rb', line 94 def add_color_space(color_space) family = color_space.family return family if family == :DeviceRGB || family == :DeviceGray || family == :DeviceCMYK definition = color_space.definition self[:ColorSpace] = {} unless key?(:ColorSpace) color_space_dict = self[:ColorSpace] name, _value = color_space_dict.value.find do |_k, v| v.map! {|item| document.deref(item)} v == definition end unless name name = create_resource_name(color_space_dict.value, 'CS') color_space_dict[name] = definition end name end |
#add_ext_gstate(object) ⇒ Object
Adds the graphics state parameter dictionary to the resources and returns the name under which it is stored.
If there already exists a name for the given dictionary, it is just returned.
139 140 141 |
# File 'lib/hexapdf/type/resources.rb', line 139 def add_ext_gstate(object) object_setter(:ExtGState, 'GS'.freeze, object) end |
#add_font(object) ⇒ Object
Adds the font dictionary to the resources and returns the name under which it is stored.
If there already exists a name for the given dictionary, it is just returned.
153 154 155 |
# File 'lib/hexapdf/type/resources.rb', line 153 def add_font(object) object_setter(:Font, 'F'.freeze, object) end |
#add_xobject(object) ⇒ Object
Adds the XObject to the resources and returns the name under which it is stored.
If there already exists a name for the given XObject, it is just returned.
123 124 125 |
# File 'lib/hexapdf/type/resources.rb', line 123 def add_xobject(object) object_setter(:XObject, 'XO'.freeze, object) end |
#color_space(name) ⇒ Object
Returns the color space stored under the given name.
If the color space is not found, an error is raised.
Note: The color spaces :DeviceGray, :DeviceRGB and :DeviceCMYK are returned without a lookup since they are fixed.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/hexapdf/type/resources.rb', line 67 def color_space(name) case name when :DeviceRGB, :DeviceGray, :DeviceCMYK GlobalConfiguration.constantize('color_space.map'.freeze, name).new else space_definition = self[:ColorSpace] && self[:ColorSpace][name] if space_definition.nil? raise HexaPDF::Error, "Color space '#{name}' not found in the resources" elsif space_definition.kind_of?(Array) space_definition.map! {|item| document.deref(item)} space_family = space_definition[0] else space_family = space_definition space_definition = [space_definition] end GlobalConfiguration.constantize('color_space.map'.freeze, space_family) do HexaPDF::Content::ColorSpace::Universal end.new(space_definition) end end |
#ext_gstate(name) ⇒ Object
Returns the graphics state parameter dictionary (see Type::GraphicsStateParameter) stored under the given name.
If the dictionary is not found, an error is raised.
131 132 133 |
# File 'lib/hexapdf/type/resources.rb', line 131 def ext_gstate(name) object_getter(:ExtGState, name) end |
#font(name) ⇒ Object
Returns the font dictionary stored under the given name.
If the dictionary is not found, an error is raised.
146 147 148 |
# File 'lib/hexapdf/type/resources.rb', line 146 def font(name) object_getter(:Font, name) end |
#type ⇒ Object
Returns :XXResources
.
57 58 59 |
# File 'lib/hexapdf/type/resources.rb', line 57 def type :XXResources end |
#xobject(name) ⇒ Object
Returns the XObject stored under the given name.
If the XObject is not found, an error is raised.
116 117 118 |
# File 'lib/hexapdf/type/resources.rb', line 116 def xobject(name) object_getter(:XObject, name) end |