Merge pull request #2 from finnlabs/indented-labels

Indented labels
pull/6827/head
manwithtwowatches 11 years ago
commit ea48d9af7f
  1. 2
      README.md
  2. 2
      app/models/export_card_configuration.rb
  3. 90
      lib/open_project/pdf_export/export_card/column_element.rb

@ -97,6 +97,7 @@ group1:
columns:
status:
has_label: true
indented: true
font_size: 15
font_style: normal
minimum_lines: 1
@ -109,6 +110,7 @@ group2:
columns:
description:
has_label: true
indented: false
font_size: 15
font_style: normal
minimum_lines: 1

@ -47,7 +47,7 @@ class ExportCardConfiguration < ActiveRecord::Base
REQUIRED_COLUMN_KEYS = []
VALID_COLUMN_KEYS = ["has_label", "min_font_size", "max_font_size",
"font_size", "font_style", "text_align", "minimum_lines", "render_if_empty",
"width"]
"width", "indented"]
def assert_required_keys(hash, valid_keys, required_keys)
hash.assert_valid_keys valid_keys

@ -55,7 +55,8 @@ module OpenProject::PdfExport::ExportCard
private
def abbreviate_text(text, options)
def abbreviated_text(text, options)
options = options.merge!({ document: @pdf })
text_box = Prawn::Text::Box.new(text, options)
left_over = text_box.render(:dry_run => true)
@ -70,7 +71,6 @@ module OpenProject::PdfExport::ExportCard
end
def draw_value(value)
# Font size
if @config['font_size']
# Specific size given
@ -95,26 +95,78 @@ module OpenProject::PdfExport::ExportCard
font_style = (@config['font_style'] or "normal").to_sym
text_align = (@config['text_align'] or "left").to_sym
offset = [@orientation[:x_offset], @orientation[:height] - (@orientation[:text_padding] / 2)]
options = { :document => @pdf,
:height => @orientation[:height],
:width => @orientation[:width],
:at => offset,
:style => font_style,
:overflow => overflow,
:size => font_size,
:min_font_size => min_font_size,
:align => text_align}
# Draw on pdf
# Label and text
has_label = @config['has_label']
indented = @config['indented']
value = value.to_s if !value.is_a?(String)
text = ""
text = text + "#{@work_package.class.human_attribute_name(@property_name)}: " if has_label
text = abbreviate_text(text + value, options)
label_text = if has_label
"#{@work_package.class.human_attribute_name(@property_name)}: "
else
""
end
box = @pdf.text_box(text, options)
end
if has_label && indented
width_ratio = 0.2 # Note: I don't think it's worth having this in the config
# Label Textbox
offset = [@orientation[:x_offset], @orientation[:height] - (@orientation[:text_padding] / 2)]
box = @pdf.text_box(label_text,
{:height => @orientation[:height],
:width => @orientation[:width] * width_ratio,
:at => offset,
:style => :bold,
:overflow => overflow,
:size => font_size,
:min_font_size => min_font_size,
:align => :left})
# Get abbraviated text
options = {:height => @orientation[:height],
:width => @orientation[:width] * (1 - width_ratio),
:at => offset,
:style => font_style,
:overflow => overflow,
:size => font_size,
:min_font_size => min_font_size,
:align => text_align}
text = abbreviated_text(value, options)
offset = [@orientation[:x_offset] + (@orientation[:width] * width_ratio), @orientation[:height] - (@orientation[:text_padding] / 2)]
# Content Textbox
box = @pdf.text_box(text, {:height => @orientation[:height],
:width => @orientation[:width] * (1 - width_ratio),
:at => offset,
:style => font_style,
:overflow => overflow,
:size => font_size,
:min_font_size => min_font_size,
:align => text_align})
else
options = {:height => @orientation[:height],
:width => @orientation[:width],
:at => offset,
:style => font_style,
:overflow => overflow,
:min_font_size => min_font_size,
:align => text_align}
text = abbreviated_text(value, options)
label_text = if has_label
"#{@work_package.class.human_attribute_name(@property_name)}: "
else
""
end
texts = [{ text: label_text, styles: [:bold], :size => font_size }, { text: text, :size => font_size }]
# Label and Content Textbox
offset = [@orientation[:x_offset], @orientation[:height] - (@orientation[:text_padding] / 2)]
box = @pdf.formatted_text_box(texts, {:height => @orientation[:height],
:width => @orientation[:width],
:at => offset,
:style => font_style,
:overflow => overflow,
:min_font_size => min_font_size,
:align => text_align})
end
end
end
end
Loading…
Cancel
Save