Class: Prawn::Text::Formatted::Oval
- Inherits:
-
Box
- Object
- Box
- Prawn::Text::Formatted::Oval
- Defined in:
- lib/prawn_oval_text/formatted/oval.rb
Overview
Provides oval shaped text capacity
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_CROP_INCREMENT =
5
Instance Method Summary collapse
-
#available_width ⇒ Object
def height @vertical_radius * 2 end.
-
#initialize(formatted_text, options = {}) ⇒ Oval
constructor
A new instance of Oval.
- #render(flags = {}) ⇒ Object
- #valid_options ⇒ Object
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, ={}) super(formatted_text, ) @horizontal_radius = [:width] * 0.5 @vertical_radius = [:height] * 0.5 @height = [:height] @center = [@at[0] + @horizontal_radius, @at[1] - @vertical_radius] @center = [:center] if [:center] @at = [@center[0] - @horizontal_radius, @center[1] + @vertical_radius] @original_x = @at[0] @align = [: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 = [[:crop] || 0, @document.font.descender].max increase_crop(crop) end |
Instance Method Details
#available_width ⇒ Object
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_options ⇒ Object
23 24 25 |
# File 'lib/prawn_oval_text/formatted/oval.rb', line 23 def super.concat([:crop, :center]) end |