class PREP::Core::Rectangle
矩形描画構成要素クラス
Constants
- FILL_PATTERNS
- STYLES
Attributes
expand[R]
fill_color[R]
fill_pattern[R]
line_color[R]
line_style[R]
line_width[R]
region[R]
Public Class Methods
new(identifier, values = { })
click to toggle source
Calls superclass method
PREP::Core::Drawable::new
# File lib/core/rectangle.rb, line 36 def initialize(identifier, values = { }) values = @@default_values.merge(key_string_to_symbol(values)) super(identifier, values[:layer]) @region = Region.new(values[:region][:x].mm2pixcel, values[:region][:y].mm2pixcel, values[:region][:width].mm2pixcel, values[:region][:height].mm2pixcel) @line_color = Color.new(values[:line_color][:red], values[:line_color][:green], values[:line_color][:blue]) self.line_style = values[:line_style] self.fill_pattern = values[:fill_pattern] @fill_color = Color.new(values[:fill_color][:red], values[:fill_color][:green], values[:fill_color][:blue]) self.line_width = values[:line_width] @expand = values[:expand] @control_visible = values[:control_visible] end
Public Instance Methods
calculate_region(prep, region, value, stop_on_drawable = nil)
click to toggle source
# File lib/core/rectangle.rb, line 89 def calculate_region(prep, region, value, stop_on_drawable = nil) if self === stop_on_drawable raise ReRenderJump.new(region) end puts "Calculate region for #{self.class}: #{self.identifier} region: #{region}" if ENV["DEBUG"] ret_region = Region.new(0, 0, region.width - (@region.x + @region.width), region.height - (@region.y + @region.height)) return @region.x + @region.width, @region.y + @region.height end
draw(prep, region, values, stop_on_drawable = nil)
click to toggle source
矩形の描画
# File lib/core/rectangle.rb, line 101 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) prep.current_page.set_line_width(@line_width.to_f) 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) prep.current_page.rectangle(pos_x, pos_y - @region.height, @region.width, @region.height) fill_and_or_stroke(prep) end @region = region_backup prep.current_page.drawed = true end
expand_region(setting)
click to toggle source
# File lib/core/rectangle.rb, line 57 def expand_region(setting) @expand_region = @region.dup @expand_region.width = setting[:width] if setting[:width] @expand_region.height = setting[:height] if setting[:height] end
fill_pattern=(fp)
click to toggle source
# File lib/core/rectangle.rb, line 81 def fill_pattern=(fp) if FILL_PATTERNS.values.include?(fp) @fill_pattern = fp else raise "Rectangle fill pattern \"#{fp}\" is unknown." end end
line_style=(s)
click to toggle source
# File lib/core/rectangle.rb, line 73 def line_style=(s) if STYLES.values.include?(s) @line_style = s else raise "Rectangle line style \"#{s}\" is unknown." end end
line_width=(w)
click to toggle source
# File lib/core/rectangle.rb, line 63 def line_width=(w) if w > 0 @line_width = w elsif w.zero? @line_color = @fill_color else raise "Rectangle line width must be grater than zero." end end
Private Instance Methods
fill_and_or_stroke(prep)
click to toggle source
# File lib/core/rectangle.rb, line 139 def fill_and_or_stroke(prep) if @fill_color.white? unless @line_color.white? prep.current_page.stroke end elsif @line_color.white? prep.current_page.fill else prep.current_page.fill_stroke end end