lib/thinreports/generator/pdf/document/draw_shape.rb in thinreports-0.11.0 vs lib/thinreports/generator/pdf/document/draw_shape.rb in thinreports-0.12.0

- old
+ new

@@ -3,24 +3,30 @@ module Thinreports module Generator class PDF module DrawShape # @param [Thinreports::Core::Shape::TextBlock::Internal] shape - def draw_shape_tblock(shape) - x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height') + # @param [Numeric] height (nil) It will be used as rendering height if present. + # Otherwise, the rendering height is the height of schema. + # @param [:truncate, :shrink_to_fit, :expand] overflow (nil) It will be set the overflow attribute if present. + def draw_shape_tblock(shape, height: nil, overflow: nil, &block) + x, y, w = shape.format.attributes.values_at('x', 'y', 'width') + h = height || shape.format.attributes['height'] + content = shape.real_value.to_s return if content.empty? attrs = build_text_attributes(shape.style.finalized_styles) + attrs[:overflow] = overflow if overflow unless shape.multiple? content = content.tr("\n", ' ') attrs[:single] = true end - text_box(content, x, y, w, h, attrs) + text_box(content, x, y, w, h, attrs, &block) end def draw_shape_pageno(shape, page_no, page_count) x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height') @@ -44,19 +50,34 @@ style = shape.style.finalized_styles image_box( shape.src, x, y, w, h, position_x: image_position_x(style['position-x']), + position_y: image_position_y(style['position-y']), + offset_x: style['offset-x'], + offset_y: style['offset-y'] + ) + end + + def shape_iblock_dimenions(shape) + return nil if blank_value?(shape.src) + + x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height') + style = shape.style.finalized_styles + + image_dimensions( + shape.src, x, y, w, h, + position_x: image_position_x(style['position-x']), position_y: image_position_y(style['position-y']) ) end # @param [Thinreports::Core::Shape::Text::Internal] shape - def draw_shape_text(shape) + def draw_shape_text(shape, dheight = 0) x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height') text( - shape.texts.join("\n"), x, y, w, h, + shape.texts.join("\n"), x, y, w, h + dheight, build_text_attributes(shape.style.finalized_styles) ) end # @param [Thinreports::Core::Shape::Basic::Internal] shape @@ -64,21 +85,21 @@ cx, cy, rx, ry = shape.format.attributes.values_at('cx', 'cy', 'rx', 'ry') ellipse(cx, cy, rx, ry, build_graphic_attributes(shape.style.finalized_styles)) end # @param [Thinreports::Core::Shape::Basic::Internal] shape - def draw_shape_line(shape) + def draw_shape_line(shape, dy1 = 0, dy2 = 0) x1, y1, x2, y2 = shape.format.attributes.values_at('x1', 'y1', 'x2', 'y2') - line(x1, y1, x2, y2, build_graphic_attributes(shape.style.finalized_styles)) + line(x1, y1 + dy1, x2, y2 + dy2, build_graphic_attributes(shape.style.finalized_styles)) end # @param [Thinreports::Core::Shape::Basic::Internal] shape - def draw_shape_rect(shape) + def draw_shape_rect(shape, dheight = 0) x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height') rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs| attrs[:radius] = shape.format.attributes['border-radius'] end - rect(x, y, w, h, rect_attributes) + rect(x, y, w, h + dheight, rect_attributes) end end end end end