Class Magick::RVG::Utility::TBTextStrategy
In: lib/rvg/misc.rb
Parent: TextStrategy
Enum GeometryValue Stylable RVG\n[lib/rvg/clippath.rb\nlib/rvg/container.rb\nlib/rvg/deep_equal.rb\nlib/rvg/describable.rb\nlib/rvg/embellishable.rb\nlib/rvg/misc.rb\nlib/rvg/paint.rb\nlib/rvg/pathdata.rb\nlib/rvg/rvg.rb\nlib/rvg/stretchable.rb\nlib/rvg/stylable.rb\nlib/rvg/text.rb\nlib/rvg/transformable.rb\nlib/rvg/units.rb] Transformable Stretchable Embellishable Describable Duplicatable Comparable Image ImageList Array Geometry HatchFill Draw lib/RMagick.rb lib/rvg/units.rb Magick Module: Magick

Methods

Public Instance methods

[Source]

     # File lib/rvg/misc.rb, line 248
248:         def get_letter_spacing(glyph)
249:             gx, gy = glyph_metrics(@ctx.text_attrs.glyph_orientation_vertical, glyph)
250:             [gx, gy+@ctx.text_attrs.letter_spacing]
251:         end

[Source]

     # File lib/rvg/misc.rb, line 243
243:         def get_word_spacing()
244:             @word_space ||= glyph_metrics(@ctx.text_attrs.glyph_orientation_vertical, ' ')[1]
245:             [0, @word_space + @ctx.text_attrs.word_spacing]
246:         end

[Source]

     # File lib/rvg/misc.rb, line 253
253:         def render(x, y, text)
254:             x_rel_coords, y_rel_coords = text_rel_coords(text)
255:             dx = x_rel_coords.max
256:             dy = y_rel_coords.inject(0) {|sum, a| sum + a}
257: 
258:             # We're handling the anchoring.
259:             @ctx.gc.push()
260:             @ctx.gc.text_anchor(Magick::StartAnchor)
261:             if @ctx.text_attrs.text_anchor == :end
262:                 y -= dy
263:             elsif @ctx.text_attrs.text_anchor == :middle
264:                 y -= dy / 2
265:             end
266: 
267:             # Align the first glyph such that its center
268:             # is aligned on x and its top is aligned on y.
269: 
270:             case @ctx.text_attrs.glyph_orientation_vertical
271:                 when 0
272:                     x -= x_rel_coords.max / 2
273:                     y += y_rel_coords[0]
274:                 when 90
275:                     x -= x_rel_coords.max / 2
276:                 when 180
277:                     x += x_rel_coords.max / 2
278:                 when 270
279:                     x += x_rel_coords.max / 2
280:                     y += y_rel_coords.shift
281:                     y_rel_coords << 0   # since we used an element we need to add a dummy
282:             end
283: 
284:             x -= shift_baseline(@ctx.text_attrs.glyph_orientation_vertical, text[0,1])
285: 
286:             first_word = true
287:             text.split(::Magick::RVG::WORD_SEP).each do |word|
288:                 unless first_word
289:                     y += y_rel_coords.shift
290:                     x_rel_coords.shift
291:                 end
292:                 first_word = false
293:                 word.split('').each do |glyph|
294:                     case @ctx.text_attrs.glyph_orientation_vertical
295:                         when 0, 90, 270
296:                             x_shift = (dx - x_rel_coords.shift) / 2
297:                         when 180
298:                             x_shift = -(dx - x_rel_coords.shift) / 2
299:                     end
300: 
301:                     render_glyph(@ctx.text_attrs.glyph_orientation_vertical, x+x_shift, y, glyph)
302:                     y += y_rel_coords.shift
303:                 end
304:             end
305: 
306:             @ctx.gc.pop()
307:             [0, dy]
308:         end

[Validate]