Class: PREP::Core::ArcRectangle
- Defined in:
- lib/core/arc_rectangle.rb
Overview
角丸矩形描画構成要素クラス
Constant Summary
Constants inherited from Rectangle
Rectangle::FILL_PATTERNS, Rectangle::STYLES
Instance Attribute Summary collapse
-
#round_arc ⇒ Object
readonly
Returns the value of attribute round_arc.
Attributes inherited from Rectangle
#expand, #fill_color, #fill_pattern, #line_color, #line_style, #line_width, #region
Attributes inherited from Drawable
Instance Method Summary collapse
-
#draw(prep, region, values, stop_on_drawable = nil) ⇒ Object
角丸矩形の描画.
-
#initialize(identifier, values = { }) ⇒ ArcRectangle
constructor
A new instance of ArcRectangle.
Methods inherited from Rectangle
#calculate_region, #expand_region
Methods inherited from Drawable
#<=>, #calculate_pos, #calculate_region, #key_string_to_symbol, #rewind_current_page, #visible?
Constructor Details
#initialize(identifier, values = { }) ⇒ ArcRectangle
Returns a new instance of ArcRectangle.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/core/arc_rectangle.rb', line 21 def initialize(identifier, values = { }) values = @@default_values.merge(key_string_to_symbol(values)) @round_arc = values.delete(:round_arc) if @round_arc.nil? raise "round_arc must be specified for arc_rectangle." else @round_arc = @round_arc.mm2pixcel end super(identifier, values) end |
Instance Attribute Details
#round_arc ⇒ Object (readonly)
Returns the value of attribute round_arc.
19 20 21 |
# File 'lib/core/arc_rectangle.rb', line 19 def round_arc @round_arc end |
Instance Method Details
#draw(prep, region, values, stop_on_drawable = nil) ⇒ Object
角丸矩形の描画
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 130 131 132 133 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 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/core/arc_rectangle.rb', line 35 def draw(prep, region, values, stop_on_drawable = nil) if self === stop_on_drawable raise ReRenderJump.new(region) end STDERR.puts("Draw on #{self.class} #{self.identifier}") if ENV['DEBUG'] # 領域判定 calculate_region(prep, region, values) if visible?(values) # 円弧描画時は 5% 太さを上げる prep.current_page.set_line_width(@line_width.to_f * 1.05) unless @line_color.white? prep.current_page.set_rgb_stroke(@line_color.red.to_f, @line_color.green.to_f, @line_color.blue.to_f) end unless @fill_color.white? prep.current_page.set_rgb_fill(@fill_color.red.to_f, @fill_color.green.to_f, @fill_color.blue.to_f) end end region_backup = @region.dup if @expand_region @region = @expand_region.dup @expand_region = nil end pos_x, pos_y = calculate_pos(prep.current_page, region, @region.x, @region.y) if visible?(values) ### 塗り潰し描画 unless @fill_color.white? # 縦方向 prep.current_page.rectangle(pos_x + @round_arc, pos_y - @region.height, @region.width - (@round_arc * 2), @region.height) prep.current_page.fill # 横方向 prep.current_page.rectangle(pos_x, pos_y - @region.height + @round_arc, @region.width, @region.height - (@round_arc * 2)) prep.current_page.fill end # ここからが本番 ### 4角の円弧を描画 # 左上 unless @fill_color.white? prep.current_page.move_to(pos_x + @round_arc, pos_y - @round_arc) prep.current_page.line_to(pos_x, pos_y - @round_arc) prep.current_page.arc(pos_x + @round_arc, pos_y - @round_arc, @round_arc, 360 * 0.75, 360) prep.current_page.line_to(pos_x + @round_arc, pos_y - @round_arc) prep.current_page.fill end unless @line_color.white? prep.current_page.arc(pos_x + @round_arc, pos_y - @round_arc, @round_arc, 360 * 0.75, 360) prep.current_page.stroke end # 右上 unless @fill_color.white? prep.current_page.move_to(pos_x + @region.width - @round_arc, pos_y - @round_arc) prep.current_page.line_to(pos_x + @region.width - @round_arc, pos_y) prep.current_page.arc(pos_x + @region.width - @round_arc, pos_y - @round_arc, @round_arc, 0, 360 * 0.25) prep.current_page.line_to(pos_x + @region.width - @round_arc, pos_y - @round_arc) prep.current_page.fill end unless @line_color.white? prep.current_page.arc(pos_x + @region.width - @round_arc, pos_y - @round_arc, @round_arc, 0, 360 * 0.25) prep.current_page.stroke end # 左下 unless @fill_color.white? prep.current_page.move_to(pos_x + @round_arc, pos_y - @region.height + @round_arc) prep.current_page.line_to(pos_x + @round_arc, pos_y - @region.height) prep.current_page.arc(pos_x + @round_arc, pos_y - @region.height + @round_arc, @round_arc, 360 * 0.5, 360 * 0.75) prep.current_page.line_to(pos_x + @round_arc, pos_y - @region.height + @round_arc) prep.current_page.fill end unless @line_color.white? prep.current_page.arc(pos_x + @round_arc, pos_y - @region.height + @round_arc, @round_arc, 360 * 0.5, 360 * 0.75) prep.current_page.stroke end # 右下 unless @fill_color.white? prep.current_page.move_to(pos_x + @region.width - @round_arc, pos_y - @region.height + @round_arc) prep.current_page.line_to(pos_x + @region.width, pos_y - @region.height + @round_arc) prep.current_page.arc(pos_x + @region.width - @round_arc, pos_y - @region.height + @round_arc, @round_arc, 360 * 0.25, 360 * 0.5) prep.current_page.line_to(pos_x + @region.width - @round_arc, pos_y - @region.height + @round_arc) prep.current_page.fill end unless @line_color.white? prep.current_page.arc(pos_x + @region.width - @round_arc, pos_y - @region.height + @round_arc, @round_arc, 360 * 0.25, 360 * 0.5) prep.current_page.stroke end # 元の太さへ prep.current_page.set_line_width(@line_width.to_f) # ### 4辺描画 unless @line_color.white? # 上 prep.current_page.move_to(pos_x + @round_arc, pos_y) prep.current_page.line_to(pos_x + @region.width - @round_arc, pos_y) prep.current_page.stroke # 下 prep.current_page.move_to(pos_x + @round_arc, pos_y - @region.height) prep.current_page.line_to(pos_x + @region.width - @round_arc, pos_y - @region.height) prep.current_page.stroke # 左 prep.current_page.move_to(pos_x, pos_y - @region.height + @round_arc) prep.current_page.line_to(pos_x, pos_y - @round_arc) prep.current_page.stroke # 右 prep.current_page.move_to(pos_x + @region.width, pos_y - @region.height + @round_arc) prep.current_page.line_to(pos_x + @region.width, pos_y - @round_arc) prep.current_page.stroke end end @region = region_backup prep.current_page.drawed = true end |