lib/prawn/text/formatted/box.rb in prawn-2.2.2 vs lib/prawn/text/formatted/box.rb in prawn-2.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
# text/formatted/rectangle.rb : Implements text boxes with formatted text
#
# Copyright February 2010, Daniel Nelson. All Rights Reserved.
#
# This is free software. Please see the LICENSE and COPYING files for details.
@@ -244,10 +246,11 @@
# The height actually used during the previous <tt>render</tt>
#
def height
return 0 if @baseline_y.nil? || @descender.nil?
+
(@baseline_y - @descender).abs
end
# <tt>fragment</tt> is a Prawn::Text::Formatted::Fragment object
#
@@ -265,10 +268,13 @@
x = if @direction == :ltr
@at[0]
else
@at[0] + @width - line_width
end
+ else
+ raise ArgumentError,
+ 'align must be one of :left, :right, :center or :justify symbols'
end
x += accumulated_width
y = @at[1] + @baseline_y
@@ -336,23 +342,23 @@
def self.inherited(base)
extensions.each { |e| base.extensions << e }
end
def valid_options
- PDF::Core::Text::VALID_OPTIONS + [
- :at,
- :height, :width,
- :align, :valign,
- :rotate, :rotate_around,
- :overflow, :min_font_size,
- :disable_wrap_by_char,
- :leading, :character_spacing,
- :mode, :single_line,
- :document,
- :direction,
- :fallback_fonts,
- :draw_text_callback
+ PDF::Core::Text::VALID_OPTIONS + %i[
+ at
+ height width
+ align valign
+ rotate rotate_around
+ overflow min_font_size
+ disable_wrap_by_char
+ leading character_spacing
+ mode single_line
+ document
+ direction
+ fallback_fonts
+ draw_text_callback
]
end
private
@@ -494,10 +500,11 @@
# only run once.
if defined?(@vertical_alignment_processed) &&
@vertical_alignment_processed
return
end
+
@vertical_alignment_processed = true
return if @vertical_align == :top
wrap(text)
@@ -585,10 +592,11 @@
end
end
def draw_fragment_overlay_link(fragment)
return unless fragment.link
+
box = fragment.absolute_bounding_box
@document.link_annotation(
box,
Border: [0, 0, 0],
A: {
@@ -599,19 +607,21 @@
)
end
def draw_fragment_overlay_anchor(fragment)
return unless fragment.anchor
+
box = fragment.absolute_bounding_box
@document.link_annotation(
box,
Border: [0, 0, 0],
Dest: fragment.anchor
)
end
def draw_fragment_overlay_local(fragment)
return unless fragment.local
+
box = fragment.absolute_bounding_box
@document.link_annotation(
box,
Border: [0, 0, 0],
A: {