lib/hexapdf/layout/box.rb in hexapdf-0.44.0 vs lib/hexapdf/layout/box.rb in hexapdf-0.45.0
- old
+ new
@@ -321,25 +321,40 @@
#
# The arguments +available_width+ and +available_height+ are the width and height of the
# current region of the frame, adjusted for this box. The frame itself is provided as third
# argument.
#
- # The default implementation uses the given available width and height for the box width and
- # height if they were initially set to 0. Otherwise the intially specified dimensions are
- # used. The method returns early if the thus configured box already doesn't fit. Otherwise,
- # the #fit_content method is called which allows sub-classes to fit their content.
+ # If the box uses flow positioning, the width is set to the frame's width and the height to
+ # the remaining height in the frame. Otherwise the given available width and height are used
+ # for the width and height if they were initially set to 0. Otherwise the intially specified
+ # dimensions are used. The method returns early if the thus configured box already doesn't
+ # fit. Otherwise, the #fit_content method is called which allows sub-classes to fit their
+ # content.
#
# The following variables are set that may later be used during splitting or drawing:
#
# * (@fit_x, @fit_y): The lower-left corner of the content box where fitting was done. Can be
# used to adjust the drawing position in #draw_content if necessary.
def fit(available_width, available_height, frame)
@fit_result.reset(frame)
- @width = (@initial_width > 0 ? @initial_width : available_width)
- @height = (@initial_height > 0 ? @initial_height : available_height)
- return @fit_result if style.position != :flow && (float_compare(@width, available_width) > 0 ||
- float_compare(@height, available_height) > 0)
+ position_flow = supports_position_flow? && style.position == :flow
+ @width = if @initial_width > 0
+ @initial_width
+ elsif position_flow
+ frame.width
+ else
+ available_width
+ end
+ @height = if @initial_height > 0
+ @initial_height
+ elsif position_flow
+ frame.y - frame.bottom
+ else
+ available_height
+ end
+ return @fit_result if !position_flow && (float_compare(@width, available_width) > 0 ||
+ float_compare(@height, available_height) > 0)
fit_content(available_width, available_height, frame)
@fit_x = frame.x + reserved_width_left
@fit_y = frame.y - @height + reserved_height_bottom
@@ -377,10 +392,10 @@
#
# When +@draw_block+ is used (the block specified when creating the box), the coordinate
# system is translated so that the origin is at the bottom left corner of the **content box**.
#
# Subclasses should not rely on the +@draw_block+ but implement the #draw_content method. The
- # coordinates passed to it are also modified to represent the bottom left corner of the
+ # coordinates passed to it are also modified to represent the bottom-left corner of the
# content box but the coordinate system is not translated.
def draw(canvas, x, y)
if @fit_result.overflow? && @initial_height > 0 && style.overflow == :error
raise HexaPDF::Error, "Box with limited height doesn't completely fit and " \
"style property overflow is set to :error"