Class: ODDB::FiPDF::Format

Inherits:
Object show all
Defined in:
ext/fipdf/src/format.rb,
ext/fipdf/test/format_test.rb

Constant Summary collapse

WRITER_CLASS =
PDF::Writer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFormat

Returns a new instance of Format.



14
15
16
17
18
# File 'ext/fipdf/src/format.rb', line 14

def initialize
	@writer = WRITER_CLASS.new
	@spacing_before = 0
	@spacing_after = 0
end

Instance Attribute Details

#differencesObject

Returns the value of attribute differences.



9
10
11
# File 'ext/fipdf/src/format.rb', line 9

def differences
  @differences
end

#fontObject

Returns the value of attribute font.



9
10
11
# File 'ext/fipdf/src/format.rb', line 9

def font
  @font
end

#fontsizeObject

Returns the value of attribute fontsize.



9
10
11
# File 'ext/fipdf/src/format.rb', line 9

def fontsize
  @fontsize
end

#justificationObject

Returns the value of attribute justification.



9
10
11
# File 'ext/fipdf/src/format.rb', line 9

def justification
  @justification
end

#marginObject

Returns the value of attribute margin.



9
10
11
# File 'ext/fipdf/src/format.rb', line 9

def margin
  @margin
end

#sizeObject

Returns the value of attribute size.



9
10
11
# File 'ext/fipdf/src/format.rb', line 9

def size
  @size
end

#spacing_after(text) ⇒ Object



43
44
45
# File 'ext/fipdf/src/format.rb', line 43

def spacing_after(text)
	(text.to_s.strip.empty?) ? 0 : @spacing_after
end

#spacing_before(text) ⇒ Object

Returns the value of attribute spacing_before.



9
10
11
# File 'ext/fipdf/src/format.rb', line 9

def spacing_before
  @spacing_before
end

#writerObject

Returns the value of attribute writer.



12
13
14
# File 'ext/fipdf/src/format.rb', line 12

def writer
  @writer
end

#yposObject

Returns the value of attribute ypos.



9
10
11
# File 'ext/fipdf/src/format.rb', line 9

def ypos
  @ypos
end

Instance Method Details

#font_height(font) ⇒ Object



40
41
42
# File 'ext/fipdf/src/format.rb', line 40

def font_height(font)
	@writer.font_height(font)
end

#get_height(text, width) ⇒ Object



35
36
37
38
39
# File 'ext/fipdf/src/format.rb', line 35

def get_height(text, width)
	line_count(text, width) \
		* @writer.font_height(@size) \
       - spacing_before(text) - spacing_after(text)
end

#line_count(text, width) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'ext/fipdf/src/format.rb', line 19

def line_count(text, width)
	return 0 if text.to_s.empty?
	@writer.select_font(@font, {
		:differences => @differences
	})
	text = text.dup
	line_count = 0
	text.each_line { |line|
		begin
			line_count += 1
			line = @writer.add_text_wrap(0, 0, width,\
				line, @size, @justification, 0, true)
		end while(!line.empty?)
	}
	line_count
end