lib/hexapdf/layout/column_box.rb in hexapdf-0.32.2 vs lib/hexapdf/layout/column_box.rb in hexapdf-0.33.0

- old
+ new

@@ -60,12 +60,13 @@ # The child boxes of this ColumnBox. They need to be finalized before #fit is called. attr_reader :children # The columns definition. # - # This is an array containing the widths of the columns. The size of the array is the number - # of columns. + # If the value is an array, it needs to contain the widths of the columns. The size of the + # array determines the number of columns. Otherwise, if the value is an integer, the value + # defines the number of equally sized columns, i.e. a value of +N+ is equal to [-1]*N. # # If a negative integer is used for the width, the column is auto-sized. Such columns split # the remaining width (after substracting the widths of the fixed columns) proportionally # among them. For example, if the definition is [-1, -2, -2], the first column is a fifth of # the width and the other columns are each two fifth of the width. @@ -130,10 +131,15 @@ # Returns +true+ as the 'position' style property value :flow is supported. def supports_position_flow? true end + # Returns +true+ if no box was fitted into the columns. + def empty? + super && (!@box_fitter || @box_fitter.fit_results.empty?) + end + # Fits the column box into the available space. # # If the style property 'position' is set to :flow, the columns might not be rectangles but # arbitrary (sets of) polygons since the +frame+s shape is taken into account. def fit(available_width, available_height, frame) @@ -197,10 +203,12 @@ tries += 1 end @width = columns[-1].sum + reserved_width @height = @box_fitter.content_heights.max + reserved_height + @draw_pos_x = frame.x + reserved_width_left + @draw_pos_y = frame.y - @height + reserved_height_bottom @box_fitter.fit_successful? end private @@ -235,11 +243,17 @@ box.instance_variable_set(:@children, @box_fitter.remaining_boxes) [self, box] end # Draws the child boxes onto the canvas at position [x, y]. - def draw_content(canvas, _x, _y) - @box_fitter.fit_results.each {|result| result.draw(canvas) } + def draw_content(canvas, x, y) + if style.position != :flow && (x != @draw_pos_x || y != @draw_pos_y) + canvas.translate(x - @draw_pos_x, y - @draw_pos_y) do + @box_fitter.fit_results.each {|result| result.draw(canvas) } + end + else + @box_fitter.fit_results.each {|result| result.draw(canvas) } + end end end end