lib/hexapdf/document/layout.rb in hexapdf-0.44.0 vs lib/hexapdf/document/layout.rb in hexapdf-0.45.0
- old
+ new
@@ -173,13 +173,10 @@
@children << self.class.collect(@layout, &block)
end
end
- # The mapping of style name (a Symbol) to Layout::Style instance.
- attr_reader :styles
-
# Creates a new Layout object for the given PDF document.
def initialize(document)
@document = document
@styles = {base: HexaPDF::Layout::Style.new}
end
@@ -215,9 +212,24 @@
# See: HexaPDF::Layout::Style
def style(name, base: :base, **properties)
style = @styles[name] ||= (@styles.key?(base) ? @styles[base].dup : HexaPDF::Layout::Style.new)
style.update(**properties) unless properties.empty?
style
+ end
+
+ # :call-seq:
+ # layout.styles -> styles
+ # layout.styles(**mapping) -> styles
+ #
+ # Returns the mapping of style names to Layout::Style instances. If +mapping+ is provided,
+ # also defines the given styles using #style.
+ #
+ # The argument +mapping+ needs to be a hash mapping a style name (a Symbol) to style
+ # properties. The special key +:base+ can be used to define the base style. For details see
+ # #style.
+ def styles(**mapping)
+ mapping.each {|name, properties| style(name, **properties) } unless mapping.empty?
+ @styles
end
# Creates an inline box for use together with text fragments.
#
# The +valign+ argument ist used to specify the vertical alignment of the box within the text