Class: RotatedCell

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RotatedCell.


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

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(pt) ⇒ Object


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

def draw_borders(pt)
  @pdf.mask(:line_width, :stroke_color) do
    x, y = pt
    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


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

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


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

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


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

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

#styled_width_of(text) ⇒ Object


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

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


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

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