Class: ODDB::FiPDF::Format

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

Constant Summary

WRITER_CLASS =
PDF::Writer

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Format) initialize

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

- (Object) differences

Returns the value of attribute differences



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

def differences
  @differences
end

- (Object) font

Returns the value of attribute font



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

def font
  @font
end

- (Object) fontsize

Returns the value of attribute fontsize



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

def fontsize
  @fontsize
end

- (Object) justification

Returns the value of attribute justification



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

def justification
  @justification
end

- (Object) margin

Returns the value of attribute margin



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

def margin
  @margin
end

- (Object) size

Returns the value of attribute size



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

def size
  @size
end

- (Object) spacing_after(text)



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

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

- (Object) spacing_before(text)

Returns the value of attribute spacing_before



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

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

- (Object) writer

Returns the value of attribute writer



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

def writer
  @writer
end

- (Object) ypos

Returns the value of attribute ypos



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

def ypos
  @ypos
end

Instance Method Details

- (Object) font_height(font)



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

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

- (Object) get_height(text, width)



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

- (Object) line_count(text, width)



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