Class: Prawn::Core::Text::LineWrap
- Inherits:
-
Object
- Object
- Prawn::Core::Text::LineWrap
- Defined in:
- lib/prawn/core/text/line_wrap.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
-
#consumed_char_count ⇒ Object
The number of characters consumed from the last line passed into wrap_line.
-
#scan_pattern ⇒ Object
The pattern used to determine chunks of text to place on a given line.
-
#space_count ⇒ Object
The number of spaces in the last wrapped line.
-
#width ⇒ Object
The width of the last wrapped line.
-
#word_division_scan_pattern ⇒ Object
The pattern used to determine whether any word breaks exist on a current line, which in turn determines whether character level word breaking is needed.
-
#wrap_line(line, options) ⇒ Object
Take a single line and deterimine what part of it fits within the width defined by the :width option.
Instance Method Details
#consumed_char_count ⇒ Object
The number of characters consumed from the last line passed into wrap_line. This may differ from the number of characters in the returned line because trailing white spaces are removed
32 33 34 |
# File 'lib/prawn/core/text/line_wrap.rb', line 32 def consumed_char_count @consumed_char_count end |
#scan_pattern ⇒ Object
The pattern used to determine chunks of text to place on a given line
38 39 40 41 42 43 44 45 46 |
# File 'lib/prawn/core/text/line_wrap.rb', line 38 def scan_pattern pattern = "[^#{break_chars}]+#{soft_hyphen}|" + "[^#{break_chars}]+#{hyphen}+|" + "[^#{break_chars}]+|" + "[#{whitespace}]+|" + "#{hyphen}+[^#{break_chars}]*|" + "#{soft_hyphen}" new_regexp(pattern) end |
#space_count ⇒ Object
The number of spaces in the last wrapped line
24 25 26 |
# File 'lib/prawn/core/text/line_wrap.rb', line 24 def space_count @space_count end |
#width ⇒ Object
The width of the last wrapped line
18 19 20 |
# File 'lib/prawn/core/text/line_wrap.rb', line 18 def width @accumulated_width || 0 end |
#word_division_scan_pattern ⇒ Object
The pattern used to determine whether any word breaks exist on a current line, which in turn determines whether character level word breaking is needed
52 53 54 |
# File 'lib/prawn/core/text/line_wrap.rb', line 52 def word_division_scan_pattern new_regexp("\\s|[#{hyphen}#{soft_hyphen}]") end |
#wrap_line(line, options) ⇒ Object
Take a single line and deterimine what part of it fits within the width defined by the :width option
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/prawn/core/text/line_wrap.rb', line 59 def wrap_line(line, ) initialize_line() previous_segment = nil whitespace_pattern = new_regexp("[#{whitespace}]") line.scan(@scan_pattern).each do |segment| # Don't let leading white space count against available space if @output.empty? && segment =~ whitespace_pattern @discarded_char_count += segment.length next end segment_width = @document.width_of(segment, :kerning => @kerning) if @accumulated_width + segment_width <= @width @accumulated_width += segment_width @output += segment else end_of_the_line(segment) break end previous_segment = segment end raise Errors::CannotFit if @output.empty? && !line.strip.empty? finalize_line @space_count = @output.count(" ") @output end |