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

- (Object) bottom_boundary

Alias for PDF::Writer#absolute_bottom_margin



345
346
347
# File 'lib/ruport/formatter/pdf.rb', line 345

def bottom_boundary
  pdf_writer.absolute_bottom_margin
end

- (Object) cursor

Alias for PDF::Writer#y



350
351
352
# File 'lib/ruport/formatter/pdf.rb', line 350

def cursor
  pdf_writer.y
end

- (Object) draw_text(text, text_opts)

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

All options to add_text are also supported.



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

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

- (Object) draw_text!(text, text_opts)

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.



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

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

- (Object) finalize



385
386
387
# File 'lib/ruport/formatter/pdf.rb', line 385

def finalize
  render_pdf
end

- (Object) horizontal_line(x1, x2)

Draws a horizontal line from x1 to x2



311
312
313
314
# File 'lib/ruport/formatter/pdf.rb', line 311

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

- (Object) horizontal_rule Also known as: hr

Draws a horizontal line from left_boundary to right_boundary



317
318
319
# File 'lib/ruport/formatter/pdf.rb', line 317

def horizontal_rule
  horizontal_line(left_boundary,right_boundary)
end

- (Object) left_boundary

Alias for PDF::Writer#absolute_left_margin



330
331
332
# File 'lib/ruport/formatter/pdf.rb', line 330

def left_boundary
  pdf_writer.absolute_left_margin
end

- (Object) right_boundary

Alias for PDF::Writer#absolute_right_margin



335
336
337
# File 'lib/ruport/formatter/pdf.rb', line 335

def right_boundary
  pdf_writer.absolute_right_margin
end

- (Object) top_boundary

Alias for PDF::Writer#absolute_top_margin



340
341
342
# File 'lib/ruport/formatter/pdf.rb', line 340

def top_boundary
  pdf_writer.absolute_top_margin
end

- (Object) vertical_line_at(x, y1, y2)

Draws a vertical line at x from y1 to y2



324
325
326
327
# File 'lib/ruport/formatter/pdf.rb', line 324

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