Module: Ruport::Formatter::PDF::DrawingHelpers

Included in:
Ruport::Formatter::PDF
Defined in:
lib/ruport/formatter/pdf.rb

Overview

This module provides tools to simplify some common drawing operations. It is included by default in the PDF formatter.

Instance Method Summary collapse

Instance Method Details

#bottom_boundaryObject

Alias for PDF::Writer#absolute_bottom_margin



347
348
349
# File 'lib/ruport/formatter/pdf.rb', line 347

def bottom_boundary
  pdf_writer.absolute_bottom_margin
end

#cursorObject

Alias for PDF::Writer#y



352
353
354
# File 'lib/ruport/formatter/pdf.rb', line 352

def cursor
  pdf_writer.y
end

#draw_text(text, text_opts) ⇒ Object

Draws text at an absolute location, defined by :y, :x1|:left, :x2|:right

All options to add_text are also supported.



360
361
362
363
364
365
366
367
# File 'lib/ruport/formatter/pdf.rb', line 360

def draw_text(text,text_opts)
  ypos = cursor
  move_cursor_to(text_opts[:y]) if text_opts[:y]
  add_text(text,
    text_opts.merge(:absolute_left => text_opts[:x1] || text_opts[:left],
    :absolute_right => text_opts[:x2] || text_opts[:right]))
  move_cursor_to(ypos)
end

#draw_text!(text, text_opts) ⇒ Object

Draws text at an absolute location, defined by :y, :x1|:left

The x position defaults to the left margin and the y position defaults to the current cursor location.

Uses PDF::Writer#add_text, so it will ignore any options not supported by that method.



377
378
379
380
381
382
383
384
385
# File 'lib/ruport/formatter/pdf.rb', line 377

def draw_text!(text,text_opts)
  ypos = cursor
  pdf_writer.add_text(text_opts[:x1] || text_opts[:left] || left_boundary,
    text_opts[:y] || ypos,
    text,
    text_opts[:font_size],
    text_opts[:angle] || 0)
  move_cursor_to(ypos)
end

#finalizeObject



387
388
389
# File 'lib/ruport/formatter/pdf.rb', line 387

def finalize
  render_pdf
end

#horizontal_line(x1, x2) ⇒ Object

Draws a horizontal line from x1 to x2



313
314
315
316
# File 'lib/ruport/formatter/pdf.rb', line 313

def horizontal_line(x1,x2)
  pdf_writer.line(x1,cursor,x2,cursor)
  pdf_writer.stroke
end

#horizontal_ruleObject Also known as: hr

Draws a horizontal line from left_boundary to right_boundary



319
320
321
# File 'lib/ruport/formatter/pdf.rb', line 319

def horizontal_rule
  horizontal_line(left_boundary,right_boundary)                                            
end

#left_boundaryObject

Alias for PDF::Writer#absolute_left_margin



332
333
334
# File 'lib/ruport/formatter/pdf.rb', line 332

def left_boundary
  pdf_writer.absolute_left_margin
end

#right_boundaryObject

Alias for PDF::Writer#absolute_right_margin



337
338
339
# File 'lib/ruport/formatter/pdf.rb', line 337

def right_boundary
  pdf_writer.absolute_right_margin
end

#top_boundaryObject

Alias for PDF::Writer#absolute_top_margin



342
343
344
# File 'lib/ruport/formatter/pdf.rb', line 342

def top_boundary
  pdf_writer.absolute_top_margin
end

#vertical_line_at(x, y1, y2) ⇒ Object

Draws a vertical line at x from y1 to y2



326
327
328
329
# File 'lib/ruport/formatter/pdf.rb', line 326

def vertical_line_at(x,y1,y2)
  pdf_writer.line(x,y1,x,y2)
  pdf_writer.stroke 
end