class CTioga2::Graphics::Types::MarginsBox
A box defined by its margins
Attributes
bottom[RW]
Margin specifications. These are Dimension
objects.
left[RW]
Margin specifications. These are Dimension
objects.
right[RW]
Margin specifications. These are Dimension
objects.
top[RW]
Margin specifications. These are Dimension
objects.
Public Class Methods
new(left, right, top, bottom)
click to toggle source
Creates a new MarginsBox
object with the specified margins, as String
(passed on to Dimension::to_text), float (defaults to frame coordinates) or directly as Dimension
objects.
The Dimension's orientation is automatically tweaked.
# File lib/ctioga2/graphics/types/boxes.rb, line 79 def initialize(left, right, top, bottom) # First, convert any float into Dimension: a = [left, right, top, bottom] a.each_index do |i| if ! a[i].is_a? Dimension a[i] = Dimension::from_text(a[i].to_s, :x, :frame) end end left, right, top, bottom = a # Then assign to the appropriate stuff: @left = left @left.orientation = :x @right = right @right.orientation = :x @top = top @top.orientation = :y @bottom = bottom @bottom.orientation = :y end
Public Instance Methods
expand_to!(t, other)
click to toggle source
Augments the margins so that they also encompass those given in other. Based on the current interpretation of the measures as bp.
# File lib/ctioga2/graphics/types/boxes.rb, line 128 def expand_to!(t, other) for w in %w(left right top bottom) mine = self.send(w) theirs = other.send(w) if mine.to_bp(t) < theirs.to_bp(t) self.send("#{w}=", theirs) end end end
margins()
click to toggle source
Returns the dimensions composing the MarginsBox
, in the order left, right, top, bottom, suitable for feeding to MarginsBox.new
.
# File lib/ctioga2/graphics/types/boxes.rb, line 121 def margins return [@left, @right, @top, @bottom] end
to_frame_coordinates(t)
click to toggle source
# File lib/ctioga2/graphics/types/boxes.rb, line 100 def to_frame_coordinates(t) return [@left.to_frame(t), 1 - @top.to_frame(t), 1 - @right.to_frame(t), @bottom.to_frame(t)] end
to_output(t, fact = 1.0)
click to toggle source
Converts to output coordinates
# File lib/ctioga2/graphics/types/boxes.rb, line 106 def to_output(t, fact = 1.0) a = to_frame_coordinates(t) 4.times do |i| a[i] = if (i % 2 == 0) fact * t.convert_page_to_output_x(t.convert_frame_to_page_x(a[i])) else fact * t.convert_page_to_output_y(t.convert_frame_to_page_y(a[i])) end end return a end