lib/write_xlsx/shape.rb in write_xlsx-1.09.4 vs lib/write_xlsx/shape.rb in write_xlsx-1.09.5
- old
+ new
@@ -11,15 +11,15 @@
# Converted to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
#
class Shape
include Writexlsx::Utility
- attr_reader :edit_as, :type, :drawing
+ attr_reader :edit_as, :drawing
attr_reader :tx_box, :fill, :line, :format
- attr_reader :align, :valign, :anchor
+ attr_reader :align, :valign, :anchor, :adjustments
attr_accessor :name, :connect, :type, :id, :start, :end, :rotation
- attr_accessor :flip_h, :flip_v, :adjustments, :palette, :text, :stencil
+ attr_accessor :flip_h, :flip_v, :palette, :text, :stencil
attr_accessor :row_start, :row_end, :column_start, :column_end
attr_accessor :x1, :x2, :y1, :y2, :x_abs, :y_abs, :start_index, :end_index
attr_accessor :x_offset, :y_offset, :width, :height, :scale_x, :scale_y
attr_accessor :width_emu, :height_emu, :element, :line_weight, :line_type
attr_accessor :start_side, :end_side
@@ -132,12 +132,11 @@
def set_properties(properties)
# Override default properties with passed arguments
properties.each do |key, value|
# Strip leading "-" from Tk style properties e.g. -color => 'red'.
- k = key.to_s.sub(/^-/, '')
- self.instance_variable_set("@#{key}", value)
+ instance_variable_set("@#{key}", value)
end
end
#
# Set the shape adjustments array (as a reference).
@@ -155,18 +154,18 @@
#
def calc_position_emus(worksheet)
c_start, r_start,
xx1, yy1, c_end, r_end,
xx2, yy2, x_abslt, y_abslt =
- worksheet.position_object_pixels(
- @column_start,
- @row_start,
- @x_offset,
- @y_offset,
- @width * @scale_x,
- @height * @scale_y
- )
+ worksheet.position_object_pixels(
+ @column_start,
+ @row_start,
+ @x_offset,
+ @y_offset,
+ @width * @scale_x,
+ @height * @scale_y
+ )
# Now that x2/y2 have been calculated with a potentially negative
# width/height we use the absolute value and convert to EMUs.
@width_emu = (@width * 9_525).abs.to_i
@height_emu = (@height * 9_525).abs.to_i
@@ -230,16 +229,14 @@
els = shapes.fetch(elink_id, Shape.new)
# Assume shape connections are to the middle of an object, and
# not a corner (for now).
connect_type = @start_side + @end_side
- smidx = sls.x_offset + sls.width / 2
- emidx = els.x_offset + els.width / 2
- smidy = sls.y_offset + sls.height / 2
- emidy = els.y_offset + els.height / 2
- netx = (smidx - emidx).abs
- nety = (smidy - emidy).abs
+ smidx = sls.x_offset + (sls.width / 2)
+ emidx = els.x_offset + (els.width / 2)
+ smidy = sls.y_offset + (sls.height / 2)
+ emidy = els.y_offset + (els.height / 2)
if connect_type == 'bt'
sy = sls.y_offset + sls.height
ey = els.y_offset
@@ -255,13 +252,11 @@
if sy > ey
@flip_v = 1
# Create 3 adjustments for an end shape vertically above a
# start @ Adjustments count from the upper left object.
- if @adjustments.empty?
- @adjustments = [-10, 50, 110]
- end
+ @adjustments = [-10, 50, 110] if @adjustments.empty?
@type = 'bentConnector5'
end
elsif connect_type == 'rl'
@width =
(els.x_offset - (sls.x_offset + sls.width)).to_i.abs
@@ -274,28 +269,22 @@
@flip_h = 1 if smidx > emidx && smidy < emidy
if smidx > emidx
# Create 3 adjustments for an end shape to the left of a
# start @
- if @adjustments.empty?
- @adjustments = [-10, 50, 110]
- end
+ @adjustments = [-10, 50, 110] if @adjustments.empty?
@type = 'bentConnector5'
end
end
end
#
# Check shape attributes to ensure they are valid.
#
def validate(index)
- unless %w[l ctr r just].include?(@align)
- raise "Shape #{index} (#{@type}) alignment (#{@align}) not in ['l', 'ctr', 'r', 'just']\n"
- end
+ raise "Shape #{index} (#{@type}) alignment (#{@align}) not in ['l', 'ctr', 'r', 'just']\n" unless %w[l ctr r just].include?(@align)
- unless %w[t ctr b].include?(@valign)
- raise "Shape #{index} (#{@type}) vertical alignment (#{@valign}) not in ['t', 'ctr', 'v']\n"
- end
+ raise "Shape #{index} (#{@type}) vertical alignment (#{@valign}) not in ['t', 'ctr', 'v']\n" unless %w[t ctr b].include?(@valign)
end
def dimensions
[
@column_start, @row_start,