Class: ODDB::FiPDF::ParagraphWrapper
- Defined in:
- ext/fipdf/src/paragraph_wrapper.rb,
ext/fipdf/test/paragraph_wrapper_test.rb
Instance Attribute Summary collapse
-
#hyphenator ⇒ Object
Returns the value of attribute hyphenator.
-
#wrapper_class ⇒ Object
Returns the value of attribute wrapper_class.
-
#writer ⇒ Object
Returns the value of attribute writer.
Instance Method Summary collapse
- #enforce_page_break?(first_height, column_height, width, format) ⇒ Boolean
- #format_text ⇒ Object
- #image? ⇒ Boolean
-
#initialize(paragraph) ⇒ ParagraphWrapper
constructor
A new instance of ParagraphWrapper.
- #lines_per_height(height, format) ⇒ Object
- #need_new_page?(height, width, formats) ⇒ Boolean
- #preformatted? ⇒ Boolean
- #text ⇒ Object
Constructor Details
#initialize(paragraph) ⇒ ParagraphWrapper
Returns a new instance of ParagraphWrapper.
11 12 13 14 |
# File 'ext/fipdf/src/paragraph_wrapper.rb', line 11 def initialize(paragraph) @paragraph = paragraph super end |
Instance Attribute Details
#hyphenator ⇒ Object
Returns the value of attribute hyphenator.
10 11 12 |
# File 'ext/fipdf/src/paragraph_wrapper.rb', line 10 def hyphenator @hyphenator end |
#wrapper_class ⇒ Object
Returns the value of attribute wrapper_class.
14 15 16 |
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 14 def wrapper_class @wrapper_class end |
#writer ⇒ Object
Returns the value of attribute writer.
14 15 16 |
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 14 def writer @writer end |
Instance Method Details
#enforce_page_break?(first_height, column_height, width, format) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 |
# File 'ext/fipdf/src/paragraph_wrapper.rb', line 44 def enforce_page_break?(first_height, column_height, width, format) total_lines = format.line_count(text(), width) first_lines = lines_per_height(first_height, format) column_lines = lines_per_height(column_height, format) if((total_lines - first_lines) % column_lines == 1) total_lines - 2 else false end end |
#format_text ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'ext/fipdf/src/paragraph_wrapper.rb', line 54 def format_text return '' unless(@paragraph.respond_to?(:text) \ && @paragraph.respond_to?(:formats)) txt = @paragraph.text text = "" @paragraph.formats.each { |format| str = txt[format.range].to_s if(format.italic?) str = "<i>" + str + "</i>" end if(format.bold?) str = "<b>" + str + "</b>" end if(format.symbol?) body = str.dup head = body.slice!(/^\s*/u) tail = body.slice!(/\s*$/u) str = head << '<f:Symbol>' << body << '</f>' << tail end text << str } unless(@paragraph.preformatted?) text = text.sub(/^-/u, "") end text end |
#image? ⇒ Boolean
41 42 43 |
# File 'ext/fipdf/src/paragraph_wrapper.rb', line 41 def image? @paragraph.is_a?(Text::ImageLink) end |
#lines_per_height(height, format) ⇒ Object
80 81 82 83 |
# File 'ext/fipdf/src/paragraph_wrapper.rb', line 80 def lines_per_height(height, format) font_size = format.size (height / format.font_height(font_size)).floor end |
#need_new_page?(height, width, formats) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'ext/fipdf/src/paragraph_wrapper.rb', line 15 def need_new_page?(height, width, formats) if image? path = File.join(PROJECT_ROOT, 'doc', @paragraph.src) if File.exist?(path) info = PDF::Writer::Graphics::ImageInfo.new(File.read(path)) width * info.height / info.width > height end else format = if(preformatted?) formats[:preformatted] else formats[:paragraph] end paragraph_height = format.get_height(text(), width) num_lines = format.line_count(text(), width) available_height = height + format.spacing_before(text()) lines_on_page = lines_per_height(available_height, format) if(num_lines <= 3 && paragraph_height > height) true elsif(num_lines > 3 && lines_on_page < 2) true else false end end end |
#preformatted? ⇒ Boolean
84 85 86 87 88 89 90 |
# File 'ext/fipdf/src/paragraph_wrapper.rb', line 84 def preformatted? if(@paragraph.respond_to? :preformatted?) @paragraph.preformatted? else false end end |