Class: RotatedCell

Inherits:
Prawn::Table::Cell::Text
  • Object
show all
Defined in:
app/lib/render_pdf.rb

Instance Method Summary collapse

Constructor Details

#initialize(pdf, text, options = {}) ⇒ RotatedCell

Returns a new instance of RotatedCell.



4
5
6
7
8
9
10
11
# File 'app/lib/render_pdf.rb', line 4

def initialize(pdf, text, options = {})
  options[:content] = text
  options[:valign] = :center
  options[:align] = :center
  options[:rotate_around] = :center
  @rotation = -options[:rotate] || 0
  super(pdf, [0, pdf.cursor], options)
end

Instance Method Details

#draw_borders(point) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/lib/render_pdf.rb', line 31

def draw_borders(point)
  @pdf.mask(:line_width, :stroke_color) do
    x, y = point
    from = [[x - skew, y + (border_top_width / 2.0)],
            to = [x, y - height - (border_bottom_width / 2.0)]]

    @pdf.line_width = @border_widths[3]
    @pdf.stroke_color = @border_colors[3]
    @pdf.stroke_line(from, to)
    @pdf.undash
  end
end

#draw_contentObject



44
45
46
47
48
49
50
51
52
# File 'app/lib/render_pdf.rb', line 44

def draw_content
  with_font do
    with_text_color do
      text_box(width: spanned_content_width + FPTolerance + skew,
               height: spanned_content_height + FPTolerance,
               at: [1 - skew, @pdf.cursor]).render
    end
  end
end

#natural_content_heightObject



26
27
28
29
# File 'app/lib/render_pdf.rb', line 26

def natural_content_height
  options = @text_options.reject { |k| k == :style }
  with_font { (@pdf.width_of(@content, options) + padding_top + padding_bottom) * tan_rotation }
end

#skewObject



17
18
19
# File 'app/lib/render_pdf.rb', line 17

def skew
  (height + (border_top_width / 2.0) + (border_bottom_width / 2.0)) / tan_rotation
end

#styled_width_of(_text) ⇒ Object



21
22
23
24
# File 'app/lib/render_pdf.rb', line 21

def styled_width_of(_text)
  options = @text_options.reject { |k| k == :style }
  with_font { (@pdf.height_of(@content, options) + padding_top + padding_bottom) / tan_rotation }
end

#tan_rotationObject



13
14
15
# File 'app/lib/render_pdf.rb', line 13

def tan_rotation
  Math.tan(Math::PI * @rotation / 180)
end