feature: long text is no longer rendered over other text that is aligned right

pull/6827/head
Jens Ulferts 14 years ago
parent f8c2c38b07
commit cf5be48904
  1. 87
      lib/taskboard_card/bottom_attributes.rb
  2. 24
      lib/taskboard_card/box.rb
  3. 5
      lib/taskboard_card/card.rb
  4. 12
      lib/taskboard_card/card_area.rb
  5. 53
      lib/taskboard_card/description.rb
  6. 15
      lib/taskboard_card/header.rb
  7. 61
      lib/taskboard_card/top_attributes.rb

@ -20,72 +20,73 @@ module TaskboardCard
def render(pdf, issue, options)
render_bounding_box(pdf, options.merge(:border => true, :margin => margin)) do
offset = [0, pdf.bounds.height]
category_box = render_category(pdf, issue, {:at => [0, pdf.bounds.height],
:align => :right})
render_assigned_to(pdf, issue, offset)
offset = render_category(pdf, issue, offset)
offset = render_empty_line(pdf, 12, offset)
render_sub_issues(pdf, issue, offset)
assigned_to_box = render_assigned_to(pdf, issue, {:at => [0, category_box.y],
:width => pdf.bounds.width - category_box.width})
offset = render_empty_line(pdf, 12, [0, category_box.y - category_box.height])
render_sub_issues(pdf, issue, {:at => offset})
end
end
def render_assigned_to(pdf, issue, offset)
pdf.font_size(12) do
assigned_to = "#{l(:field_assigned_to)}: #{issue.assigned_to ? issue.assigned_to : "-"}"
def render_assigned_to(pdf, issue, options)
offset = text_box(pdf,
assigned_to,
{:width => pdf.bounds.width,
:height => pdf.font.height,
:at => offset})
end
assigned_to = "#{l(:field_assigned_to)}: #{issue.assigned_to ? issue.assigned_to : "-"}"
offset
text_box(pdf,
assigned_to,
{:width => pdf.bounds.width,
:height => 12,
:size => 12}.merge(options))
end
def render_category(pdf, issue, offset)
pdf.font_size(12) do
category = "#{l(:field_category)}: #{issue.category ? issue.category : "-"}"
offset = text_box(pdf,
category,
{:width => pdf.bounds.width,
:height => pdf.font.height * 1,
:align => :right,
:at => offset})
end
def render_category(pdf, issue, options)
category = "#{l(:field_category)}: #{issue.category ? issue.category : "-"}"
text_box(pdf,
category,
{:width => pdf.bounds.width,
:height => 12}.merge(options))
offset
end
def render_sub_issues(pdf, issue, offset)
def render_sub_issues(pdf, issue, options)
at = options.delete(:at)
box = Box.new(at[0], at[1], 0, 0)
pdf.font_size(12) do
offset = text_box(pdf,
"#{l(:label_subtask_plural)}: #{issue.children.size == 0 ? "-" : ""}",
{:height => pdf.font.height,
:at => offset})
temp_box = text_box(pdf,
"#{l(:label_subtask_plural)}: #{issue.children.size == 0 ? "-" : ""}",
{:height => pdf.font.height,
:at => box.at})
box.height += temp_box.height
box.width = temp_box.width
issue.children.each_with_index do |child, i|
subtask_text = "#{child.tracker.name} ##{child.id}: #{child.subject}"
offset[0] = 10 #indentation
if offset[1] - pdf.font.height < pdf.font.height && issue.children.size - i != 1
offset = text_box(pdf,
if box.height + pdf.font.height > pdf.font.height || issue.children.size - i == 1
temp_box = text_box(pdf,
"#{child.tracker.name} ##{child.id}: #{child.subject}",
{:height => pdf.font.height,
:at => [10, at[1] - box.height]})
else
temp_box = text_box(pdf,
l('backlogs.x_more', :count => issue.children.size - i),
:height => pdf.font.height,
:at => offset)
:at => [10, at[1] - box.height])
break
else
offset = text_box(pdf,
"#{child.tracker.name} ##{child.id}: #{child.subject}",
{:height => pdf.font.height,
:at => offset})
end
box.height += temp_box.height
end
end
offset
box
end
end

@ -0,0 +1,24 @@
module TaskboardCard
class Box
attr_accessor :x
attr_accessor :y
attr_accessor :width
attr_accessor :height
def initialize(x,y,w,h)
@x = x
@y = y
@width = w
@height = h
end
def at
[x, y]
end
def at=(pos)
x = pos[0]
y = pos[1]
end
end
end

@ -30,7 +30,8 @@ module TaskboardCard
[TaskboardCard::Header,
TaskboardCard::TopAttributes,
TaskboardCard::Description,
TaskboardCard::BottomAttributes]
TaskboardCard::BottomAttributes
]
end
def margin
@ -44,7 +45,7 @@ module TaskboardCard
Card.areas.each do |card|
height = pdf.bounds.height * card.pref_size_percent[1]
card.render(pdf, issue, {:at => [0, y_offset],
:height => height})
:height => height})
y_offset -= height + pdf.bounds.height * 0.01
end
end

@ -7,11 +7,19 @@ module TaskboardCard
end
def self.text_box(pdf, text, options)
align = options.delete(:align)
if align == :right
options[:width] = pdf.width_of(text, options)
options[:at][0] = pdf.bounds.width - options[:width]
end
opts = {:width => pdf.bounds.width,
:overflow => :ellipses}
opts.merge!(options)
box = pdf.text_box(text, opts)
[0, opts[:at][1] - (opts[:height] + (opts[:size] || pdf.font_size) / 2)]
pdf.text_box(text, opts)
Box.new(options[:at][0], options[:at][1], options[:width], options[:height])
end
def self.render_bounding_box(pdf, options)

@ -20,35 +20,34 @@ module TaskboardCard
def render(pdf, issue, options)
render_bounding_box(pdf, options.merge(:border => true, :margin => margin)) do
offset = [0, pdf.bounds.height]
pdf.font_size(20) do
description = issue.description ? issue.description : ""
description.split("\n").each do |line|
r = RedCloth3.new(line)
line = r.to_html
line = Description.strip_tags(line)
height = pdf.height_of(line)
if offset[1] - height > pdf.font.height
offset = text_box(pdf,
line,
{:height => height,
:at => offset})
offset[1] += 10 #unfortunately I havent't found a way to reduce line spacing when placing
#the text line by line
else
offset = text_box(pdf,
"[...]",
{:height => pdf.font.height,
:at => [0, pdf.font.height]})
break
end
y_offset = pdf.bounds.height
description = issue.description ? issue.description : ""
description.split("\n").each do |line|
r = RedCloth3.new(line)
line = r.to_html
line = Description.strip_tags(line)
font_height = 20
if y_offset - font_height > font_height
box = text_box(pdf,
line,
{:height => pdf.height_of(line, :size => font_height),
:at => [0, y_offset],
:size => font_height})
y_offset -= box.height
else
text_box(pdf,
"[...]",
{:height => font_height,
:at => [0, y_offset],
:size => font_height})
break
end
end
offset
end
end

@ -15,16 +15,15 @@ module TaskboardCard
offset = [0, pdf.bounds.height]
pdf.font_size(20) do
issue_identification = "#{issue.tracker.name} ##{issue.id}"
issue_identification = "#{issue.tracker.name} ##{issue.id}"
offset = text_box(pdf,
issue_identification,
{:height => pdf.font.height,
:at => offset})
end
box = text_box(pdf,
issue_identification,
{:height => 20,
:at => offset,
:size => 20})
offset[1] += 10
offset[1] -= box.height
pdf.line offset, [pdf.bounds.width, offset[1]]
end

@ -19,62 +19,55 @@ module TaskboardCard
def render(pdf, issue, options)
render_bounding_box(pdf, options.merge(:border => true, :margin => margin)) do
offset = [0, pdf.bounds.height]
sprint_box = render_sprint(pdf, issue, {:at => [0, pdf.bounds.height],
:align => :right})
render_parent_issue(pdf, issue, offset)
offset = render_sprint(pdf, issue, offset)
render_subject(pdf, issue, offset)
render_effort(pdf, issue, offset)
render_parent_issue(pdf, issue, {:at => [0, sprint_box.y],
:width => pdf.bounds.width - sprint_box.width})
effort_box = render_effort(pdf, issue, {:at => [0, pdf.bounds.height - sprint_box.height],
:align => :right})
render_subject(pdf, issue, {:at => [0, effort_box.y],
:width => pdf.bounds.width - effort_box.width})
end
end
def render_parent_issue(pdf, issue, offset)
pdf.font_size(12) do
parent_name = issue.parent.present? ? "#{issue.parent.tracker.name} ##{issue.parent.id}: #{issue.parent.subject}" : ""
offset = text_box(pdf,
parent_name,
{:height => pdf.font.height,
:at => offset})
end
def render_parent_issue(pdf, issue, options)
parent_name = issue.parent.present? ? "#{issue.parent.tracker.name} ##{issue.parent.id}: #{issue.parent.subject}" : ""
offset
text_box(pdf,
parent_name,
{:height => 12,
:size => 12}.merge(options))
end
def render_sprint(pdf, issue, offset)
def render_sprint(pdf, issue, options)
name = issue.fixed_version ? issue.fixed_version.name : "-"
text_box(pdf,
name,
{:height => pdf.font.height,
:align => :right,
:at => offset,
:size => 12})
{:height => 12,
:size => 12}.merge(options))
end
def render_subject(pdf, issue, offset)
def render_subject(pdf, issue, options)
text_box(pdf,
issue.subject,
{:height => pdf.font.height * 2,
:at => offset,
:size => 20})
{:height => 20,
:size => 20}.merge(options))
end
def render_effort(pdf, issue, offset)
def render_effort(pdf, issue, options)
type = issue.is_task?
score = (type == :task ? issue.estimated_hours : issue.story_points)
score ||= '-'
score = "#{score} #{type == :task ? l(:label_hours) : l(:label_points)}"
pdf.font_size(20) do
offset = text_box(pdf,
score,
{:height => pdf.font.height,
:align => :right,
:at => offset})
end
offset
text_box(pdf,
score,
{:height => 20,
:size => 20}.merge(options))
end
end
end

Loading…
Cancel
Save