Class: RotatedCell
- Inherits:
-
Prawn::Table::Cell::Text
- Object
- Prawn::Table::Cell::Text
- RotatedCell
- Defined in:
- lib/render_pdf.rb
Instance Method Summary collapse
- #draw_borders(pt) ⇒ 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.
5 6 7 8 9 10 11 12 |
# File 'lib/render_pdf.rb', line 5 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(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_content ⇒ Object
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_height ⇒ Object
27 28 29 30 |
# File 'lib/render_pdf.rb', line 27 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
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) = @text_options.reject { |k| k == :style } with_font { (@pdf.height_of(@content, ) + padding_top + padding_bottom) / tan_rotation } end |
#tan_rotation ⇒ Object
14 15 16 |
# File 'lib/render_pdf.rb', line 14 def tan_rotation Math.tan(Math::PI * @rotation / 180) end |