lib/rvg/misc.rb in rmagick-5.5.0 vs lib/rvg/misc.rb in rmagick-6.0.0
- old
+ new
@@ -70,11 +70,11 @@
@ctx = context
@ctx.shadow.affine = @ctx.text_attrs.affine
end
def enquote(text)
- return text if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
+ return text if text.length > 2 && /\A(?:"[^\"]+"|'[^\']+'|\{[^\}]+\})\z/.match(text)
if !text['\'']
text = '\'' + text + '\''
return text
elsif !text['"']
@@ -85,11 +85,11 @@
return text
end
# escape existing braces, surround with braces
text.gsub!(/[}]/) { |b| '\\' + b }
- '{' + text + '}'
+ '{' + text + '}'
end
def glyph_metrics(glyph_orientation, glyph)
gm = @ctx.shadow.get_type_metrics('a' + glyph + 'a')
gm2 = @ctx.shadow.get_type_metrics('aa')
@@ -112,11 +112,11 @@
wx, wy = get_word_spacing
x_rel_coords << wx
y_rel_coords << wy
end
first_word = false
- word.split('').each do |glyph|
+ word.chars.each do |glyph|
wx, wy = get_letter_spacing(glyph)
x_rel_coords << wx
y_rel_coords << wy
end
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.reduce(0) { |sum, a| sum + a }
+ dx = x_rel_coords.sum
dy = y_rel_coords.max
# We're handling the anchoring.
@ctx.gc.push
@ctx.gc.text_anchor(Magick::StartAnchor)
@@ -201,11 +201,11 @@
first_word = true
text.split(::Magick::RVG::WORD_SEP).each do |word|
x += x_rel_coords.shift unless first_word
first_word = false
- word.split('').each do |glyph|
+ word.chars.each do |glyph|
render_glyph(@ctx.text_attrs.glyph_orientation_horizontal, x, y, glyph)
x += x_rel_coords.shift
end
end
@@ -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.reduce(0) { |sum, a| sum + a }
+ dy = y_rel_coords.sum
# We're handling the anchoring.
@ctx.gc.push
@ctx.gc.text_anchor(Magick::StartAnchor)
if @ctx.text_attrs.text_anchor == :end
@@ -269,11 +269,11 @@
unless first_word
y += y_rel_coords.shift
x_rel_coords.shift
end
first_word = false
- word.split('').each do |glyph|
+ word.chars.each do |glyph|
case @ctx.text_attrs.glyph_orientation_vertical.to_i
when 0, 90, 270
x_shift = (dx - x_rel_coords.shift) / 2
when 180
x_shift = -(dx - x_rel_coords.shift) / 2
@@ -577,11 +577,11 @@
nil
end
def font_weight(weight)
# If the arg is not in the hash use it directly. Handles numeric values.
- weight = weight.is_a?(Numeric) ? weight : FONT_WEIGHT.fetch(weight.to_sym, Magick::NormalWeight)
+ weight = FONT_WEIGHT.fetch(weight.to_sym, Magick::NormalWeight) unless weight.is_a?(Numeric)
@gc.font_weight(weight)
@shadow[-1].font_weight = weight
nil
end
@@ -666,10 +666,10 @@
@shadow[-1].stroke_width = width
nil
end
def text(x, y, text)
- return if text.length.zero?
+ return if text.empty?
text_renderer = if @text_attrs.non_default?
TEXT_STRATEGIES[@text_attrs.writing_mode].new(self)
else
DefaultTextStrategy.new(self)