lib/rvg/misc.rb in rmagick-4.1.0.rc2 vs lib/rvg/misc.rb in rmagick-4.1.0
- old
+ new
@@ -32,21 +32,21 @@
end # module Duplicatable
# Convert an array of method arguments to Float objects. If any
# cannot be converted, raise ArgumentError and issue a message.
def self.fmsg(*args)
- "at least one argument cannot be converted to Float (got #{args.collect(&:class).join(', ')})"
+ "at least one argument cannot be converted to Float (got #{args.map(&:class).join(', ')})"
end
def self.convert_to_float(*args)
allow_nil = false
if args.last == :allow_nil
allow_nil = true
args.pop
end
begin
- fargs = args.collect { |a| allow_nil && a.nil? ? a : Float(a) }
+ fargs = args.map { |a| allow_nil && a.nil? ? a : Float(a) }
rescue ArgumentError, TypeError
raise ArgumentError, fmsg(*args)
end
fargs
end
@@ -171,11 +171,11 @@
[gx + @ctx.text_attrs.letter_spacing, gy]
end
def render(x, y, text)
x_rel_coords, y_rel_coords = text_rel_coords(text)
- dx = x_rel_coords.inject(0) { |sum, a| sum + a }
+ dx = x_rel_coords.reduce(0) { |sum, a| sum + a }
dy = y_rel_coords.max
# We're handling the anchoring.
@ctx.gc.push
@ctx.gc.text_anchor(Magick::StartAnchor)
@@ -232,11 +232,11 @@
end
def render(x, y, text)
x_rel_coords, y_rel_coords = text_rel_coords(text)
dx = x_rel_coords.max
- dy = y_rel_coords.inject(0) { |sum, a| sum + a }
+ dy = y_rel_coords.reduce(0) { |sum, a| sum + a }
# We're handling the anchoring.
@ctx.gc.push
@ctx.gc.text_anchor(Magick::StartAnchor)
if @ctx.text_attrs.text_anchor == :end
@@ -476,13 +476,16 @@
overline: Magick::OverlineDecoration,
line_through: Magick::LineThroughDecoration
}
TEXT_STRATEGIES = {
- 'lr-tb' => LRTextStrategy, 'lr' => LRTextStrategy,
- 'rt-tb' => RLTextStrategy, 'rl' => RLTextStrategy,
- 'tb-rl' => TBTextStrategy, 'tb' => TBTextStrategy
+ 'lr-tb' => LRTextStrategy,
+ 'lr' => LRTextStrategy,
+ 'rt-tb' => RLTextStrategy,
+ 'rl' => RLTextStrategy,
+ 'tb-rl' => TBTextStrategy,
+ 'tb' => TBTextStrategy
}
def self.degrees_to_radians(deg)
Math::PI * (deg % 360.0) / 180.0
end
@@ -531,11 +534,11 @@
end
def baseline_shift(value)
@text_attrs.baseline_shift = case value
when 'baseline', 'sub', 'super'
- value.intern
+ value.to_sym
when /[-+]?\d+%/, Numeric
value
else
:baseline
end
@@ -559,18 +562,18 @@
@shadow[-1].pointsize = points
nil
end
def font_stretch(stretch)
- stretch = FONT_STRETCH.fetch(stretch.intern, Magick::NormalStretch)
+ stretch = FONT_STRETCH.fetch(stretch.to_sym, Magick::NormalStretch)
@gc.font_stretch(stretch)
@shadow[-1].font_stretch = stretch
nil
end
def font_style(style)
- style = FONT_STYLE.fetch(style.intern, Magick::NormalStyle)
+ style = FONT_STYLE.fetch(style.to_sym, Magick::NormalStyle)
@gc.font_style(style)
@shadow[-1].font_style = style
nil
end
@@ -675,20 +678,20 @@
text_renderer.render(x, y, text)
end
def text_anchor(anchor)
- anchor = anchor.intern
+ anchor = anchor.to_sym
anchor_enum = TEXT_ANCHOR.fetch(anchor, Magick::StartAnchor)
@gc.text_anchor(anchor_enum)
align = ANCHOR_TO_ALIGN.fetch(anchor, Magick::LeftAlign)
@shadow[-1].align = align
@text_attrs.text_anchor = anchor
nil
end
def text_decoration(decoration)
- decoration = TEXT_DECORATION.fetch(decoration.intern, Magick::NoDecoration)
+ decoration = TEXT_DECORATION.fetch(decoration.to_sym, Magick::NoDecoration)
@gc.decorate(decoration)
@shadow[-1].decorate = decoration
nil
end