Class: Magick::RVG::Utility::LRTextStrategy
- Inherits:
-
TextStrategy
- Object
- TextStrategy
- Magick::RVG::Utility::LRTextStrategy
- Defined in:
- lib/rvg/misc.rb
Overview
class TextStrategy
Instance Method Summary collapse
Methods inherited from TextStrategy
#enquote, #glyph_metrics, #initialize, #render_glyph, #shift_baseline, #text_rel_coords
Constructor Details
This class inherits a constructor from Magick::RVG::Utility::TextStrategy
Instance Method Details
#get_letter_spacing(glyph) ⇒ Object
183 184 185 186 |
# File 'lib/rvg/misc.rb', line 183 def get_letter_spacing(glyph) gx, gy = glyph_metrics(@ctx.text_attrs.glyph_orientation_horizontal, glyph) [gx+@ctx.text_attrs.letter_spacing, gy] end |
#get_word_spacing ⇒ Object
178 179 180 181 |
# File 'lib/rvg/misc.rb', line 178 def get_word_spacing() @word_space ||= glyph_metrics(@ctx.text_attrs.glyph_orientation_horizontal, ' ')[0] [@word_space + @ctx.text_attrs.word_spacing, 0] end |
#render(x, y, text) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/rvg/misc.rb', line 188 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} dy = y_rel_coords.max # We're handling the anchoring. @ctx.gc.push() @ctx.gc.text_anchor(Magick::StartAnchor) if @ctx.text_attrs.text_anchor == :end x -= dx elsif @ctx.text_attrs.text_anchor == :middle x -= dx / 2 end # Align the first glyph case @ctx.text_attrs.glyph_orientation_horizontal when 0 ; when 90 y -= dy when 180 x += x_rel_coords.shift x_rel_coords << 0 y -= dy when 270 x += x_rel_coords[0] end y += shift_baseline(@ctx.text_attrs.glyph_orientation_horizontal, text[0,1]) first_word = true text.split(::Magick::RVG::WORD_SEP).each do |word| unless first_word x += x_rel_coords.shift end first_word = false word.split('').each do |glyph| render_glyph(@ctx.text_attrs.glyph_orientation_horizontal, x, y, glyph) x += x_rel_coords.shift end end @ctx.gc.pop() [dx, 0] end |