Class: RotatedCell
- Inherits:
-
Prawn::Table::Cell::Text
- Object
- Prawn::Table::Cell::Text
- RotatedCell
- Defined in:
- app/lib/render_pdf.rb
Instance Method Summary collapse
- #draw_borders(point) ⇒ Object
- #draw_content ⇒ Object
-
#initialize(pdf, text, options = {}) ⇒ RotatedCell
constructor
A new instance of RotatedCell.
- #natural_content_height ⇒ Object
- #skew ⇒ Object
- #styled_width_of(_text) ⇒ Object
- #tan_rotation ⇒ Object
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, = {}) [:content] = text [:valign] = :center [:align] = :center [:rotate_around] = :center @rotation = -[:rotate] || 0 super(pdf, [0, pdf.cursor], ) 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_content ⇒ Object
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_height ⇒ Object
26 27 28 29 |
# File 'app/lib/render_pdf.rb', line 26 def natural_content_height = @text_options.reject { |k| k == :style } with_font { (@pdf.width_of(@content, ) + padding_top + padding_bottom) * tan_rotation } end |
#skew ⇒ Object
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) = @text_options.reject { |k| k == :style } with_font { (@pdf.height_of(@content, ) + padding_top + padding_bottom) / tan_rotation } end |
#tan_rotation ⇒ Object
13 14 15 |
# File 'app/lib/render_pdf.rb', line 13 def tan_rotation Math.tan(Math::PI * @rotation / 180) end |