Class: Prawn::Text::Formatted::Oval

Inherits:
Box
  • Object
show all
Defined in:
lib/prawn_oval_text/formatted/oval.rb

Overview

Provides oval shaped text capacity

Direct Known Subclasses

Oval

Constant Summary collapse

DEFAULT_CROP_INCREMENT =
5

Instance Method Summary collapse

Constructor Details

#initialize(formatted_text, options = {}) ⇒ Oval

Returns a new instance of Oval.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/prawn_oval_text/formatted/oval.rb', line 27

def initialize(formatted_text, options={})

  super(formatted_text, options)

  @horizontal_radius = options[:width] * 0.5
  @vertical_radius   = options[:height] * 0.5
  @height            = options[:height]
  @center            = [@at[0] + @horizontal_radius,
                        @at[1] - @vertical_radius]
  @center            = options[:center] if options[:center]
  @at                = [@center[0] - @horizontal_radius,
                        @center[1] + @vertical_radius]
  @original_x        = @at[0]
  @align             = options[:align] || :center
  @vertical_align    = :top

  # the crop lets us start printing text some distance below the
  # top of the ellipse, otherwise, there may not be enough space
  # to display much text, which looks bad
  crop = [options[:crop] || 0, @document.font.descender].max
  increase_crop(crop)
end

Instance Method Details

#available_widthObject

def height

@vertical_radius * 2

end



54
55
56
57
58
# File 'lib/prawn_oval_text/formatted/oval.rb', line 54

def available_width
  @width = compute_max_line_width(@horizontal_radius, @vertical_radius, width_limiting_y)
  @at[0] = @original_x + @horizontal_radius - @width * 0.5
  [@width, @line_height].max
end

#render(flags = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/prawn_oval_text/formatted/oval.rb', line 60

def render(flags={})
  @oval_line_height = @document.font.height
  @oval_descender   = @document.font.descender
  @oval_ascender    = @document.font.ascender
  @oval_line_gap    = @document.font.line_gap
  #          begin
  #            results = super(flags)
  super(flags)
  # rescue Prawn::Errors::CannotFit
  #   if @baseline_y.abs < @height - @oval_line_height
  #     increase_crop
  #     retry
  #   end
  #   results = []
  # end
  # results
end

#valid_optionsObject



23
24
25
# File 'lib/prawn_oval_text/formatted/oval.rb', line 23

def valid_options
  super.concat([:crop, :center])
end