Class: PREP::Core::Loop
Overview
ループ読み込みクラスの定義
Constant Summary collapse
- DIRECTIONS =
{ :horizontal => 'horizontal', :vertical => 'vertical' }
- @@default_values =
{ :direction => DIRECTIONS[:vertical], :gap => 0, :page_break => false, :layer => 4, }
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#footer_group ⇒ Object
readonly
Returns the value of attribute footer_group.
-
#gap ⇒ Object
readonly
Returns the value of attribute gap.
-
#header_group ⇒ Object
readonly
Returns the value of attribute header_group.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#iterator_group ⇒ Object
readonly
Returns the value of attribute iterator_group.
-
#page_break ⇒ Object
readonly
Returns the value of attribute page_break.
-
#point ⇒ Object
readonly
Returns the value of attribute point.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes inherited from Drawable
Instance Method Summary collapse
-
#calculate_region(prep, region, values, stop_on_drawable = nil) ⇒ Object
データに依存してサイズが変化する可能性がある.
-
#draw(prep, region, values, stop_on_drawable = nil) ⇒ Object
実際の描画を実施.
-
#fit_region(region) ⇒ Object
リージョン補正.
-
#generate_sample_dataset(prep) ⇒ Object
データセット雛形を生成.
-
#initialize(identifier, values = { }) ⇒ Loop
constructor
A new instance of Loop.
Methods inherited from Drawable
#<=>, #calculate_pos, #key_string_to_symbol, #rewind_current_page
Constructor Details
#initialize(identifier, values = { }) ⇒ Loop
Returns a new instance of Loop.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/core/loop.rb', line 27 def initialize(identifier, values = { }) values = @@default_values.merge(key_string_to_symbol(values)) super(identifier, values[:layer]) self.direction = values[:direction] @header_group = values[:header] @iterator_group = values[:iterator] @gap = values[:gap].mm2pixcel @footer_group = values[:footer] @point = Point.new(values[:x].mm2pixcel, values[:y].mm2pixcel) @page_break = values[:page_break] end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
25 26 27 |
# File 'lib/core/loop.rb', line 25 def direction @direction end |
#footer_group ⇒ Object (readonly)
Returns the value of attribute footer_group.
25 26 27 |
# File 'lib/core/loop.rb', line 25 def @footer_group end |
#gap ⇒ Object (readonly)
Returns the value of attribute gap.
25 26 27 |
# File 'lib/core/loop.rb', line 25 def gap @gap end |
#header_group ⇒ Object (readonly)
Returns the value of attribute header_group.
25 26 27 |
# File 'lib/core/loop.rb', line 25 def header_group @header_group end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
25 26 27 |
# File 'lib/core/loop.rb', line 25 def height @height end |
#iterator_group ⇒ Object (readonly)
Returns the value of attribute iterator_group.
25 26 27 |
# File 'lib/core/loop.rb', line 25 def iterator_group @iterator_group end |
#page_break ⇒ Object (readonly)
Returns the value of attribute page_break.
25 26 27 |
# File 'lib/core/loop.rb', line 25 def page_break @page_break end |
#point ⇒ Object (readonly)
Returns the value of attribute point.
25 26 27 |
# File 'lib/core/loop.rb', line 25 def point @point end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
25 26 27 |
# File 'lib/core/loop.rb', line 25 def width @width end |
Instance Method Details
#calculate_region(prep, region, values, stop_on_drawable = nil) ⇒ Object
データに依存してサイズが変化する可能性がある
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 |
# File 'lib/core/loop.rb', line 68 def calculate_region(prep, region, values, stop_on_drawable = nil) if self === stop_on_drawable puts "STOPPING on #{stop_on_drawable.identifier}" if ENV["DEBUG"] gets if ENV["DEBUG"] raise ReRenderJump.new(region) end puts "Calculate region for #{self.class}: #{self.identifier} region: #{region}" if ENV["DEBUG"] # リージョン補正 current_region = fit_region(region) # 描画計算の初期位置を保持 @initial_calculate_region = current_region.dup # ヘッダの領域サイズを計算 current_region = calculate_header_region(prep, current_region, values, stop_on_drawable) puts "Header:\t#{current_region}" if ENV["DEBUG"] # 繰り返し部分の領域サイズを計算 current_region = calculate_iterator_region(prep, current_region, values, stop_on_drawable) puts "Iterator:\t#{current_region}" if ENV["DEBUG"] # フッタの領域サイズを計算 current_region = (prep, current_region, values, stop_on_drawable) puts "Footer:\t#{current_region}" if ENV["DEBUG"] begin # 最終的にリージョン補正位置から必要な領域を計算 # 元のリージョン範囲から最終的に残っているリージョン範囲を減算すればよい ret_region = Region.new(0, 0, region.width - current_region.width, region.height - current_region.height) # 進行方向じゃない方向に対しての差分は別途取得 if @direction == DIRECTIONS[:horizontal] ret_region.height = @height else # if @direction == DIRECTIONS[:vertical] ret_region.width = @width end return ret_region.width, ret_region.height rescue RegionWidthOverflowError, RegionHeightOverflowError => e # これは負の数を返却してやれば上位では単純な加算しか起きない w, h = region.width - current_region.width, region.height - current_region.height if @direction == DIRECTIONS[:horizontal] h = @height else # if @direction == DIRECTIONS[:vertical] w = @width end puts "Inner page break!! width: #{w}, height: #{h}" if ENV["DEBUG"] gets if ENV["DEBUG"] return w, h end end |
#draw(prep, region, values, stop_on_drawable = nil) ⇒ Object
実際の描画を実施
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/core/loop.rb', line 137 def draw(prep, region, values, stop_on_drawable = nil) if self === stop_on_drawable puts "STOPPING on #{stop_on_drawable.identifier}" if ENV["DEBUG"] gets if ENV["DEBUG"] raise ReRenderJump.new(region) end STDERR.puts("Draw on #{self.class} #{self.identifier}") if ENV['DEBUG'] # リージョン補正 current_region = fit_region(region) # 描画計算の初期位置を保持 @initial_draw_region = current_region.dup # 領域に関する情報を取得 = { } if !@page_break # 描画に先立ち領域拡張設定を実施 # ループ要素の描画領域を算出(事前計算) rewind_current_page(prep) do calculate_region(prep, region.dup, values) end if @direction == DIRECTIONS[:horizontal] [:height] = @height else # if @direction == DIRECTIONS[:vertical] [:width] = @width end end # ヘッダおよびフッタの子に関してワンタイム設定を実施 unless @header_group.nil? header = prep.group(@header_group) header.drawable_items.each do |drawable| if Label === drawable || Rectangle === drawable if drawable. drawable.() end end end end unless @footer_group.nil? = prep.group(@footer_group) .drawable_items.each do |drawable| if Label === drawable || Rectangle === drawable if drawable. drawable.() end end end end # ヘッダブロック描画 current_region = draw_header(prep, current_region, values, stop_on_drawable) # 繰り返しブロック描画 current_region = draw_iterator(prep, current_region, values, stop_on_drawable) # フッタブロック描画 current_region = (prep, current_region, values, stop_on_drawable) end |
#fit_region(region) ⇒ Object
リージョン補正
相対位置情報を元にリージョンを補正して返却
126 127 128 129 130 131 132 133 134 |
# File 'lib/core/loop.rb', line 126 def fit_region(region) current_region = region.dup current_region.x += point.x current_region.y += point.y current_region.width -= point.x current_region.height -= point.y return current_region end |
#generate_sample_dataset(prep) ⇒ Object
データセット雛形を生成
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/core/loop.rb', line 50 def generate_sample_dataset(prep) dataset = { } unless @header_group.nil? header = prep.group(@header_group) dataset[:header] = header.generate_sample_dataset(prep) end iterator = prep.group(@iterator_group) dataset[:values] = [iterator.generate_sample_dataset(prep)] unless @footer_group.nil? = prep.group(@footer_group) dataset[:footer] = .generate_sample_dataset(prep) end return dataset end |