Skip to content

Commit

Permalink
Corrected valign: :bottom|:center spacing bug (Issue prawnpdf#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
derek-watson committed Jan 24, 2014
1 parent eaf19c1 commit b3a3880
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/prawn/text/formatted/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Prawn
module Text
module Formatted
# @group Stable API

# Draws the requested formatted text into a box. When the text overflows
# the rectangle shrink to fit or truncate the text. Text boxes are
# independent of the document y position.
Expand Down Expand Up @@ -293,7 +293,7 @@ def draw_fragment(fragment, accumulated_width=0, line_width=0, word_spacing=0) #
end

# @group Extension API

# Example (see Prawn::Text::Core::Formatted::Wrap for what is required
# of the wrap method if you want to override the default wrapping
# algorithm):
Expand Down Expand Up @@ -466,17 +466,20 @@ def process_vertical_alignment(text)
# we need to wait until render() is called so that the fonts are set
# up properly for wrapping. So guard with a boolean to ensure this is
# only run once.
return if defined?(@vertical_alignment_processed) && @vertical_alignment_processed
return if @vertical_alignment_processed
@vertical_alignment_processed = true

return if @vertical_align == :top
wrap(text)

line_padding = @line_height - (@ascender + @descender)
h = height - line_padding

case @vertical_align
when :center
@at[1] = @at[1] - (@height - height) * 0.5
@at[1] = @at[1] - (@height - h) * 0.5
when :bottom
@at[1] = @at[1] - (@height - height) + @descender
@at[1] = @at[1] - (@height - h)
end
@height = height
end
Expand Down

0 comments on commit b3a3880

Please sign in to comment.