Skip to content

Instantly share code, notes, and snippets.

@gmgent
Created April 23, 2011 06:49
Show Gist options
  • Save gmgent/938422 to your computer and use it in GitHub Desktop.
Save gmgent/938422 to your computer and use it in GitHub Desktop.
require "rubygems"
require "prawn"
require "prawn/layout"
require "prawn/measurement_extensions"
module DataGrid
#colors
TEXT_COLOR = "000000"
DEFAULT_BG_COLOR = "ffffff"
DEFAULT_BORDER_COLOR = "d9d9d9"
DARK_BORDER_COLOR = "a6a6a6"
CONCENTRATION_HEADER_BG = "dce6f1"
DOSING_HEADER_BG = "f2dcdb"
DURATION_HEADER_BG = "ebf1de"
BOLUS_HEADER_BG = "fde9d9"
ALTERNATING_ROW_BG = "f2f2f2"
#grid properties
ONE_BY_ONE_FIELD_LENGTH = 7 # 1 x 1 grid text length for font Monaco size 7
#data grid
DATA_GRID_SIGNAL = ""
TOTAL_ROWS_PER_PAGE = 37
DATA_ROW_HEIGHT = 3
DATA_HEADER_HEIGHT = 3 #{care_area} header plus section headers
#starts
DOSING_START = 2
CONCENTRATION_START = DOSING_START+7
DURATION_START = CONCENTRATION_START+4
BOLUS_START = DURATION_START+5
#headers
DATA_SECTION_HEADER_HEIGHT = 2
ALIAS_TITLE = "Record Label"
PRINTED_FIRST_HALF_WIDTH = 2
BOLUS_WIDTH = 5
#legend
LEGEND_SIGNAL = "legend_"
LEGEND_ALIAS_WIDTH = 3
LEGEND_DRUG_NAME_WIDTH = 2
LEGEND_DELIVERY_METHOD_WIDTH = 4
LEGEND_CONCENTRATION_START=LEGEND_ALIAS_WIDTH+LEGEND_DRUG_NAME_WIDTH
LEGEND_INDICATION_START = LEGEND_CONCENTRATION_START+4
LEGEND_DELIVERY_METHOD_START = LEGEND_INDICATION_START+5
LEGEND_SECTION_HEADER_HEIGHT = 1
LEGEND_ROW_HEIGHT = 3
LEGEND_HEADER_HEIGHT = 2 #{care_area} header plus section headers
FONT_PATH = "#{Rails.root}/lib/data_grid"
LOGO_PATH = "#{Rails.root}/public/images/logo"
def set_data_font
font "#{FONT_PATH}/Monaco.dfont", :size => 7
end
def set_bold_font
font "#{FONT_PATH}/Arial Bold.ttf", :size => 7
end
def set_header_font
font "#{FONT_PATH}/Arial.ttf", :size => 7
end
def primer_logo_file_name
"#{LOGO_PATH}/primer_logo.png"
end
def zynx_logo_file_name
"#{LOGO_PATH}/zynx_logo.png"
end
def data_row_height
(@legend_state == LEGEND_SIGNAL)? LEGEND_ROW_HEIGHT : DATA_ROW_HEIGHT
end
def data_header_height
(@legend_state==LEGEND_SIGNAL)? LEGEND_HEADER_HEIGHT: DATA_HEADER_HEIGHT
end
def group_by_care_area(drug_records)
drug_records.group_by{ |dr| dr.care_area }.sort_by{ |care_area, drs| care_area.name}
end
def order_by_population_and_label(records)
records.group_by { |dr| dr.patient_population }.sort_by { |pat_pop, drs| [pat_pop.name, drs.sort!{ |dr1, dr2| dr1.record_label <=> dr2.record_label } ] }
end
class Document
include DataGrid
attr_reader :pages, :print_date
def initialize(drug_records)
@pages = []
grouped_drug_records = group_by_care_area(drug_records)
@print_date = "#{Time.now.strftime('%B %d %Y %H:%M')}"
@current_page_num = 0
@legend_state = DATA_GRID_SIGNAL
start_page(false)
@rows_remaining = TOTAL_ROWS_PER_PAGE
grouped_drug_records.each do |care_area, records|
grouped_records = order_by_population_and_label(records)
add_care_area_group(grouped_records, care_area)
start_page(true)
add_care_area_group(grouped_records, care_area)
if grouped_drug_records.last[0].id != care_area.id
start_page(true)
end
end
end
def total_pages
@pages.size
end
protected
def add_page
@current_page = Page.new(@current_page_num, @legend_state)
@pages << @current_page
end
def start_page(alternate)
alternate_legend_state if alternate
@rows_remaining = TOTAL_ROWS_PER_PAGE - 1 #subtract 1 for page header
@current_page_num += 1
add_page
end
def add_care_area_group(grouped_records, care_area)
grouped_records.each do |patient_population, drug_records_for_population|
add_population_records(drug_records_for_population, care_area, patient_population)
end
end
def add_population_records(drug_records_for_population, care_area, patient_population)
total_records = drug_records_for_population.size
num_rows = (@rows_remaining - data_header_height) / data_row_height
if (num_rows >= total_records)
add_section(care_area, patient_population, total_records, drug_records_for_population)
else
add_section(care_area, patient_population, num_rows, drug_records_for_population[0..(num_rows-1)]) if num_rows > 0
drug_records_for_population[num_rows..(total_records-1)].each_slice((TOTAL_ROWS_PER_PAGE-1-data_header_height)/data_row_height) do |slice|
start_page(false)
add_section(care_area, patient_population, slice.size, slice)
end
end
end #Document
def add_section(care_area, patient_population, total_records, drug_records_for_population)
@current_page.add_section(care_area, patient_population, total_records, drug_records_for_population)
@rows_remaining = @rows_remaining - data_header_height - drug_records_for_population.size*data_row_height
end
def alternate_legend_state
@legend_state = ( (@legend_state==LEGEND_SIGNAL) ? DATA_GRID_SIGNAL : LEGEND_SIGNAL)
end
end
class DocumentView < Prawn::Document
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::TextHelper
include DrugQuantityHelper
include DataGrid
def initialize(data_grid_doc)
super :page_layout => :landscape, :margin => 14.mm
set_data_font
define_grid :columns => 23, :rows => TOTAL_ROWS_PER_PAGE
@data_grid_doc = data_grid_doc
end
def render
@data_grid_doc.pages.each do |page|
generate_page_header(page, @data_grid_doc, page.data_grid?)
@starting_row = 1
page.sections.each do |section|
page.data_grid? ? generate_data_grid(section) : generate_legend_data_grid(section)
end
start_new_page unless page.page_no == @data_grid_doc.total_pages
end
super
end
protected
def generate_page_header(page, doc, grid)
set_header_font
text_box([0,0], [0,PRINTED_FIRST_HALF_WIDTH-1], :no_border => true) { text "Printed on ", :align => :center, :valign => :center}
text_box([0,PRINTED_FIRST_HALF_WIDTH], [0,4], :no_border => true) {
set_bold_font
text "#{doc.print_date}", :align => :left, :valign => :center
}
text_box([0,5], [0,7], :no_border => true) { text "Drug Record " + (grid ? "Grid" : "Key"), :align => :left, :valign => :center}
text_box([0,8], [0,11], :no_border => true) { |box| image primer_logo_file_name, :height => box.height, :position => :right }
text_box([0,13], [0,16], :no_border => true) { |box| image zynx_logo_file_name, :height => box.height, :position => :left }
text_box([0,17], [0,22], :no_border => true) { text "Page #{page.page_no} of #{doc.total_pages}", :align => :right }
end
def generate_section_header(section)
set_bold_font
text_box([@starting_row,0], [@starting_row,19], :no_border => true) {
text "#{section.care_area.name} - #{section.patient_population.name}", :align => :left
}
set_header_font
text_box([@starting_row, 20], [@starting_row, 22], :no_border => true) { text "#{pluralize(section.total_records, 'Drug Record')}", :align => :right }
@starting_row += 1
end
def generate_header(section)
generate_section_header(section)
set_header_font
#ALIAS_TITLE
text_box([@starting_row,0], [@starting_row+1, DOSING_START-1]) { text ALIAS_TITLE }
#Dosing
text_box([@starting_row,DOSING_START], [@starting_row,DOSING_START+6],
:color => DOSING_HEADER_BG) { text "Dosing" }
text_box([@starting_row+1,DOSING_START], [@starting_row+1,DOSING_START]) { text "hard min"}
text_box([@starting_row+1,DOSING_START+1], [@starting_row+1,DOSING_START+1]) { text "soft min"}
text_box([@starting_row+1,DOSING_START+2], [@starting_row+1,DOSING_START+2]) { text "soft max"}
text_box([@starting_row+1,DOSING_START+3], [@starting_row+1,DOSING_START+3]) { text "hard max"}
text_box([@starting_row+1,DOSING_START+4], [@starting_row+1,DOSING_START+4]) { text "initial" }
text_box([@starting_row+1,DOSING_START+5], [@starting_row+1,DOSING_START+6]) { text "cumulative max" }
#Concentration
text_box([@starting_row, CONCENTRATION_START], [@starting_row,CONCENTRATION_START+3],
:color => CONCENTRATION_HEADER_BG) { text "Concentration" }
text_box([@starting_row+1,CONCENTRATION_START], [@starting_row+1,CONCENTRATION_START]) { text "hard min"}
text_box([@starting_row+1,CONCENTRATION_START+1], [@starting_row+1,CONCENTRATION_START+1]) { text "soft min"}
text_box([@starting_row+1,CONCENTRATION_START+2], [@starting_row+1,CONCENTRATION_START+2]) { text "soft max"}
text_box([@starting_row+1,CONCENTRATION_START+3], [@starting_row+1,CONCENTRATION_START+3]) { text "hard max"}
#Duration
text_box([@starting_row,DURATION_START], [@starting_row,DURATION_START+4],
:color => DURATION_HEADER_BG ) { text "Duration" }
text_box([@starting_row+1,DURATION_START], [@starting_row+1,DURATION_START]) { text "hard min"}
text_box([@starting_row+1,DURATION_START+1], [@starting_row+1,DURATION_START+1]) { text "soft min"}
text_box([@starting_row+1,DURATION_START+2], [@starting_row+1,DURATION_START+2]) { text "soft max"}
text_box([@starting_row+1,DURATION_START+3], [@starting_row+1,DURATION_START+3]) { text "hard max"}
text_box([@starting_row+1,DURATION_START+4], [@starting_row+1,DURATION_START+4]) { text "initial" }
#Bolus
text_box([@starting_row,BOLUS_START], [@starting_row,BOLUS_START+4],
:color => BOLUS_HEADER_BG) { text "Bolus Administration Rate" }
text_box([@starting_row+1,BOLUS_START], [@starting_row+1,BOLUS_START]) { text "hard min" }
text_box([@starting_row+1,BOLUS_START+1], [@starting_row+1,BOLUS_START+1]) { text "soft min" }
text_box([@starting_row+1,BOLUS_START+2], [@starting_row+1,BOLUS_START+2]) { text "soft max" }
text_box([@starting_row+1,BOLUS_START+3], [@starting_row+1,BOLUS_START+3]) { text "hard max" }
text_box([@starting_row+1,BOLUS_START+4], [@starting_row+1,BOLUS_START+4]) { text "initial" }
@starting_row += DATA_SECTION_HEADER_HEIGHT
end
def generate_legend_header(section)
generate_section_header(section)
set_bold_font
text_box([@starting_row,0],
[@starting_row,LEGEND_ALIAS_WIDTH-1]) { text ALIAS_TITLE, :align => :center }
text_box([@starting_row,LEGEND_ALIAS_WIDTH],
[@starting_row,LEGEND_ALIAS_WIDTH+LEGEND_DRUG_NAME_WIDTH-1]) { text "Drug name", :align => :left }
text_box([@starting_row,LEGEND_CONCENTRATION_START],
[@starting_row,LEGEND_CONCENTRATION_START+1]) { text "Concentration", :align => :left }
text_box([@starting_row,LEGEND_CONCENTRATION_START+2],
[@starting_row,LEGEND_CONCENTRATION_START+3]) { text "Population", :align => :left }
text_box([@starting_row,LEGEND_INDICATION_START],
[@starting_row,LEGEND_INDICATION_START+2]) { text "Indication", :align => :left }
text_box([@starting_row,LEGEND_INDICATION_START+3],
[@starting_row,LEGEND_INDICATION_START+4]) { text "Care Area", :align => :left }
text_box([@starting_row,LEGEND_DELIVERY_METHOD_START],
[@starting_row,LEGEND_DELIVERY_METHOD_START+LEGEND_DELIVERY_METHOD_WIDTH-1]) { text "Delivery Method", :align => :left }
text_box([@starting_row,LEGEND_DELIVERY_METHOD_START+LEGEND_DELIVERY_METHOD_WIDTH],
[@starting_row,LEGEND_DELIVERY_METHOD_START+LEGEND_DELIVERY_METHOD_WIDTH+2]) { text "Clinical Advisory", :align => :left }
text_box([@starting_row,21],
[@starting_row,21]) { text "Version", :align => :left }
text_box([@starting_row,22],
[@starting_row,22]) { text "Status", :align => :left }
@starting_row += LEGEND_SECTION_HEADER_HEIGHT
end
#data grid section by care area, population
def generate_data_grid(section)
generate_header(section)
row_bg_color = DEFAULT_BG_COLOR
set_data_font
section.data_section.inject(@starting_row) do |row_index, record|
text_box([row_index,0],
[row_index+2,DOSING_START-1],
:color => row_bg_color) { text((record.record_label || "NONE"), :text_length => ONE_BY_ONE_FIELD_LENGTH*4-1) }
# Dosing
text_box([row_index, DOSING_START],
[row_index, DOSING_START],
:color => row_bg_color) { text(format_drug_quantity(record.dosing_hard_min_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index, DOSING_START+1],
[row_index, DOSING_START+1],
:color => row_bg_color) { text(format_drug_quantity(record.dosing_soft_min_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index, DOSING_START+2],
[row_index, DOSING_START+2],
:color => row_bg_color) { text(format_drug_quantity(record.dosing_soft_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index, DOSING_START+3],
[row_index, DOSING_START+3],
:color => row_bg_color) { text(format_drug_quantity(record.dosing_hard_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index, DOSING_START+4],
[row_index, DOSING_START+4],
:color => row_bg_color) { text(format_drug_quantity(record.dosing_initial_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH ) }
text_box([row_index+1, DOSING_START],
[row_index+2, DOSING_START+4],
:color => row_bg_color) { text(record.dosing_unit.try(:abbreviation)) }
text_box([row_index, DOSING_START+5],
[row_index, DOSING_START+6],
:color => row_bg_color) { text(format_drug_quantity(record.dosing_cumulative_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH*2 ) }
text_box([row_index+1, DOSING_START+5],
[row_index+2, DOSING_START+6],
:color => row_bg_color) { text(record.dosing_cumulative_max_unit.try(:abbreviation), :text_length => ONE_BY_ONE_FIELD_LENGTH*4) }
# Concentration
text_box([row_index, CONCENTRATION_START],
[row_index, CONCENTRATION_START],
:color => row_bg_color) { text(format_drug_quantity(record.concentration_hard_min_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index, CONCENTRATION_START+1],
[row_index, CONCENTRATION_START+1],
:color => row_bg_color) { text(format_drug_quantity(record.concentration_soft_min_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index, CONCENTRATION_START+2],
[row_index, CONCENTRATION_START+2],
:color => row_bg_color) { text(format_drug_quantity(record.concentration_soft_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index, CONCENTRATION_START+3],
[row_index, CONCENTRATION_START+3],
:color => row_bg_color) { text(format_drug_quantity(record.concentration_hard_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index+1, CONCENTRATION_START],
[row_index+2, CONCENTRATION_START+3],
:color => row_bg_color) { text(record.concentration_unit.try(:abbreviation)) }
# Duration
text_box([row_index,DURATION_START],
[row_index,DURATION_START],
:color => row_bg_color) { text(format_drug_quantity(record.duration_hard_min_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index,DURATION_START+1],
[row_index,DURATION_START+1],
:color => row_bg_color) { text(format_drug_quantity(record.duration_soft_min_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index,DURATION_START+2],
[row_index,DURATION_START+2],
:color => row_bg_color) { text(format_drug_quantity(record.duration_soft_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index,DURATION_START+3],
[row_index,DURATION_START+3],
:color => row_bg_color) { text(format_drug_quantity(record.duration_hard_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index,DURATION_START+4],
[row_index,DURATION_START+4],
:color => row_bg_color) { text(format_drug_quantity(record.duration_hard_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index + 1,DURATION_START],
[row_index + 2,DURATION_START+4],
:color => row_bg_color) { text(record.duration_unit.try(:abbreviation)) }
# Bolus Administration Rate
text_box([row_index,BOLUS_START],
[row_index,BOLUS_START],
:color => row_bg_color) { text(format_drug_quantity(record.bolus_administration_rate_hard_min_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index,BOLUS_START+1],
[row_index,BOLUS_START+1],
:color => row_bg_color) { text(format_drug_quantity(record.bolus_administration_rate_soft_min_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index,BOLUS_START+2],
[row_index,BOLUS_START+2],
:color => row_bg_color) { text(format_drug_quantity(record.bolus_administration_rate_soft_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index,BOLUS_START+3],
[row_index,BOLUS_START+3],
:color => row_bg_color) { text(format_drug_quantity(record.bolus_administration_rate_hard_max_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index,BOLUS_START+4],
[row_index,BOLUS_START+4],
:color => row_bg_color) { text(format_drug_quantity(record.bolus_administration_rate_initial_quantity), :text_length => ONE_BY_ONE_FIELD_LENGTH) }
text_box([row_index + 1,BOLUS_START],
[row_index + 2,BOLUS_START+4],
:color => row_bg_color) { text(record.bolus_administration_rate_unit.try(:abbreviation)) }
row_bg_color = alternate_row_color(row_bg_color)
row_index + DATA_ROW_HEIGHT
end
start = @starting_row - DATA_SECTION_HEADER_HEIGHT
draw_borders([DOSING_START,
CONCENTRATION_START,
DURATION_START,
BOLUS_START,
BOLUS_START+BOLUS_WIDTH],
start, (DATA_SECTION_HEADER_HEIGHT + DATA_ROW_HEIGHT*section.data_section.size))
@starting_row += DATA_ROW_HEIGHT * section.data_section.size
end
#legend grid section by care area, population
def generate_legend_data_grid(section)
generate_legend_header(section)
row_bg_color = ALTERNATING_ROW_BG
set_data_font
#NOTE: if valign of text is top, you get twice as much text
section.data_section.inject(@starting_row) do |row_index, record|
text_box([row_index,0],
[row_index+LEGEND_ROW_HEIGHT-1,LEGEND_ALIAS_WIDTH-1],
:color => row_bg_color) { text((record.record_label || "NONE"), :text_length => 88, :valign => :top, :align => :center ) }
text_box([row_index,LEGEND_ALIAS_WIDTH],
[row_index+LEGEND_ROW_HEIGHT-1,LEGEND_ALIAS_WIDTH+LEGEND_DRUG_NAME_WIDTH-1],
:color => row_bg_color) { text(record.full_drug_name, :text_length => ONE_BY_ONE_FIELD_LENGTH*8, :valign => :top, :align => :left) }
text_box([row_index,LEGEND_CONCENTRATION_START],
[row_index+LEGEND_ROW_HEIGHT-1,LEGEND_CONCENTRATION_START+1],
:color => row_bg_color) { text(record.concentration.name, :text_length => ONE_BY_ONE_FIELD_LENGTH*4, :align => :left, :valign => :top) }
text_box([row_index,LEGEND_CONCENTRATION_START+2],
[row_index+LEGEND_ROW_HEIGHT-1,LEGEND_CONCENTRATION_START+3],
:color => row_bg_color) { text(section.patient_population.name, :text_length => ONE_BY_ONE_FIELD_LENGTH*4, :align => :left, :valign => :top) }
text_box([row_index,LEGEND_INDICATION_START],
[row_index+LEGEND_ROW_HEIGHT-1,LEGEND_INDICATION_START+2],
:color => row_bg_color) { text(record.indication.name, :text_length => ONE_BY_ONE_FIELD_LENGTH*6, :align => :left, :valign => :top) }
text_box([row_index,LEGEND_INDICATION_START+3],
[row_index+LEGEND_ROW_HEIGHT-1,LEGEND_INDICATION_START+4],
:color => row_bg_color) { text(section.care_area.name, :text_length => ONE_BY_ONE_FIELD_LENGTH*4, :align => :left, :valign => :top) }
text_box([row_index,LEGEND_DELIVERY_METHOD_START],
[row_index+LEGEND_ROW_HEIGHT-1,LEGEND_DELIVERY_METHOD_START+LEGEND_DELIVERY_METHOD_WIDTH-1],
:color => row_bg_color) { text(record.delivery_method.name, :text_length => ONE_BY_ONE_FIELD_LENGTH*8, :align => :left, :valign => :top) }
text_box([row_index,LEGEND_DELIVERY_METHOD_START+LEGEND_DELIVERY_METHOD_WIDTH],
[row_index+LEGEND_ROW_HEIGHT-1,LEGEND_DELIVERY_METHOD_START+LEGEND_DELIVERY_METHOD_WIDTH+2],
:color => row_bg_color) { text((record.clinical_advisory || ""), :text_length => ONE_BY_ONE_FIELD_LENGTH*12, :valign => :top, :align => :left, :valign => :top) }
text_box([row_index,21],
[row_index+LEGEND_ROW_HEIGHT-1,21],
:color => row_bg_color) { text((record.version || "").to_s, :text_length => ONE_BY_ONE_FIELD_LENGTH*2, :align => :left, :valign => :top) }
text_box([row_index,22],
[row_index+LEGEND_ROW_HEIGHT-1,22],
:color => row_bg_color) { text(record.approval_status.name, :text_length => ONE_BY_ONE_FIELD_LENGTH*2, :align => :left, :valign => :top) }
row_bg_color = alternate_row_color(row_bg_color)
row_index + LEGEND_ROW_HEIGHT
end
@starting_row += LEGEND_ROW_HEIGHT * section.data_section.size
end
def alternate_row_color(current_color)
(current_color==DEFAULT_BG_COLOR) ? ALTERNATING_ROW_BG : DEFAULT_BG_COLOR
end
def draw_borders(x_array, start, drug_rows)
x_array.each do |x|
stroke_color DARK_BORDER_COLOR
stroke do
vertical_line(@page_height - start*@box_height, @page_height - (start+drug_rows)*@box_height, :at => x*@box_width)
end
end
end
def set_grid_dims(box)
@page_height = box.height * TOTAL_ROWS_PER_PAGE if @page_height.blank?
@box_height = box.height if @box_height.blank?
@box_width = box.width/PRINTED_FIRST_HALF_WIDTH if @box_width.blank?
end
def text(text, options={})
text ||= ""
fill_color TEXT_COLOR
valign = (options[:valign] || :center)
if (options[:text_length].blank?)
super text, { :align => :center, :valign => valign }.merge(options)
else
super truncate(text, :length => options[:text_length]), { :align => :center, :valign => valign }.merge(options)
end
end
def text_box(top_left, lower_right, options = {})
box = grid top_left, lower_right
set_grid_dims(box)
bounding_box box.top_left, :width => box.width, :height => box.height do
fill_color (options[:color] || DEFAULT_BG_COLOR)
stroke_color (options[:border_color] || DEFAULT_BORDER_COLOR)
fill_and_stroke do
rectangle(bounds.top_left, box.width, box.height)
end unless options[:no_border]
yield box
end
box.top_left[1]
end
end #DocumentView
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment