Class: Prawn::Blank::Appearance
- Inherits:
-
Object
- Object
- Prawn::Blank::Appearance
- Defined in:
- lib/prawn/blank/appearance.rb
Defined Under Namespace
Classes: Item
Constant Summary collapse
- STYLE =
{ :border_color => '202020', :background_color => 'ffffff', :border_width => 1 }
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
- #button(element) ⇒ Object (also: #button_over, #button_down)
- #checkbox_off(element) ⇒ Object (also: #checkbox_off_over, #checkbox_off_down)
- #checkbox_on(element) ⇒ Object (also: #checkbox_on_over, #checkbox_on_down)
-
#initialize(document) ⇒ Appearance
constructor
A new instance of Appearance.
- #radio_off(element) ⇒ Object (also: #radio_off_over, #radio_off_down)
- #radio_on(element) ⇒ Object (also: #radio_on_over, #radio_on_down)
- #render(dict) ⇒ Object
- #text_field(element) ⇒ Object
Constructor Details
#initialize(document) ⇒ Appearance
Returns a new instance of Appearance.
30 31 32 33 34 |
# File 'lib/prawn/blank/appearance.rb', line 30 def initialize(document) @document = document @cache = {} #@style = STYLE.dup end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
20 21 22 |
# File 'lib/prawn/blank/appearance.rb', line 20 def document @document end |
Instance Method Details
#button(element) ⇒ Object Also known as: ,
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/prawn/blank/appearance.rb', line 48 def (element) if !element.width or element.width <= 0 element.width = 10 end if !element.height or element.height <= 0 element.height = 10 end width = element.width height = element.height style = element.style ||= Prawn::ColorStyle(@document,'ffffff','000000') border_style = element.border_style ||= Prawn::BorderStyle(@document,1) return cached(:checkbox_off, width, height, style, border_style) do render( :BBox => [0, 0, width, height] ) do document.canvas do # render background document.fill_color( *denormalize_color(style[:BG]) ) document.stroke_color( *denormalize_color(style[:BC]) ) document.line_width(border_style[:W]) bw = border_style[:W]/2.0 document.fill_and_stroke_rectangle( [bw, height - bw], width - border_style[:W], height - border_style[:W] ) end end end end |
#checkbox_off(element) ⇒ Object Also known as: checkbox_off_over, checkbox_off_down
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/prawn/blank/appearance.rb', line 76 def checkbox_off(element) if !element.width or element.width <= 0 element.width = 10 end if !element.height or element.height <= 0 element.height = 10 end width = element.width height = element.height style = element.style ||= Prawn::ColorStyle(@document,'ffffff','000000') border_style = element.border_style ||= Prawn::BorderStyle(@document,1) return cached(:checkbox_off, width, height, style, border_style) do render( :BBox => [0, 0, width, height] ) do document.canvas do # render background document.fill_color( *denormalize_color(style[:BG]) ) document.stroke_color( *denormalize_color(style[:BC]) ) document.line_width(border_style[:W]) bw = border_style[:W]/2.0 document.fill_and_stroke_rectangle( [bw, height - bw], width - border_style[:W], height - border_style[:W] ) end end end end |
#checkbox_on(element) ⇒ Object Also known as: checkbox_on_over, checkbox_on_down
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/prawn/blank/appearance.rb', line 104 def checkbox_on(element) if !element.width or element.width <= 0 element.width = 10 end if !element.height or element.height <= 0 element.height = 10 end width = element.width height = element.height style = element.style ||= Prawn::ColorStyle(@document,'ffffff','000000') border_style = element.border_style ||= Prawn::BorderStyle(@document,1) return cached(:checkbox_on, width, height, style, border_style) do render( :BBox => [0, 0, width, height] ) do document.canvas do # render background document.fill_color( *denormalize_color(style[:BG]) ) document.stroke_color( *denormalize_color(style[:BC]) ) document.line_width(border_style[:W]) bw = border_style[:W]/2.0 document.fill_and_stroke_rectangle( [bw, height - bw], width - border_style[:W], height - border_style[:W] ) document.stroke_line(0,0,width, height) document.stroke_line(width,0,0, height) end end end end |
#radio_off(element) ⇒ Object Also known as: radio_off_over, radio_off_down
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/prawn/blank/appearance.rb', line 134 def radio_off(element) if !element.width or element.width <= 0 element.width = 10 end if !element.height or element.height <= 0 element.height = 10 end width = element.width height = element.height style = element.style ||= Prawn::ColorStyle(@document,'ffffff','000000') border_style = element.border_style ||= Prawn::BorderStyle(@document,1) return cached(:radio_off, width, height, style, border_style) do render( :BBox => [0, 0, width, height] ) do document.canvas do # render background document.fill_color( *denormalize_color(style[:BG]) ) document.stroke_color( *denormalize_color(style[:BC]) ) document.line_width(border_style[:W]) rx = (width / 2.0) ry = (height / 2.0) document.fill_and_stroke_ellipse_at([rx,ry], rx-border_style[:W], ry-border_style[:W]) end end end end |
#radio_on(element) ⇒ Object Also known as: radio_on_over, radio_on_down
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/prawn/blank/appearance.rb', line 163 def radio_on(element) if !element.width or element.width <= 0 element.width = 10 end if !element.height or element.height <= 0 element.height = 10 end width = element.width height = element.height style = element.style ||= Prawn::ColorStyle(@document,'ffffff','000000') border_style = element.border_style ||= Prawn::BorderStyle(@document,1) return cached(:radio_on, width, height, style, border_style) do render( :BBox => [0, 0, width, height] ) do document.canvas do # render background document.fill_color( *denormalize_color(style[:BG]) ) document.stroke_color( *denormalize_color(style[:BC]) ) document.line_width(border_style[:W]) rx = (width / 2.0) ry = (height / 2.0) document.fill_and_stroke_ellipse_at([rx,ry], rx-border_style[:W], ry-border_style[:W]) document.fill_color( *denormalize_color(style[:BC]) ) document.fill_ellipse_at([rx,ry], rx-border_style[:W]-2, ry-border_style[:W]-2) end end end end |
#render(dict) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/prawn/blank/appearance.rb', line 36 def render(dict) dict = {:Subtype => :Form, :Resources => {:ProcSet => [:PDF, :ImageC, :ImageI, :ImageB]}}.merge(dict) result = @document.ref!(dict) @document.state.page.stamp_stream(result) do yield end @document.acroform.add_resources(result.data[:Resources]) return result end |
#text_field(element) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/prawn/blank/appearance.rb', line 195 def text_field(element) text_style = element.text_style ||= Prawn::TextStyle(@document,"Helvetica",9,'000000') border_style = element.border_style ||= Prawn::BorderStyle(@document,1) if !element.width or element.width <= 0 element.width = 100 end if !element.height or element.height <= 0 element.height = text_style.size + 6 + 2 * border_style[:W] end width = element.width height = element.height style = element.style ||= Prawn::ColorStyle(@document,'ffffff','000000') multiline = element.multiline value = element.value return cached(:text_field, width, height, style, border_style, text_style, multiline, value) do render( :BBox => [0, 0, width, height] ) do document.canvas do document.save_font do # render background document.fill_color( *denormalize_color(style[:BG]) ) document.stroke_color( *denormalize_color(style[:BC]) ) document.line_width(border_style[:W]) bw = border_style[:W]/2.0 document.fill_and_stroke_rectangle( [bw, height - bw], width - border_style[:W], height - border_style[:W]) if text_style document.font(text_style.font, :size=>text_style.size ) document.fill_color( *text_style.color ) end if value document.draw_text(value, :at =>[border_style[:W]+1, [1,height - document.font_size - border_style[:W]- 1.5].max ] ) end end end end end end |