258: def render(x, y, text)
259: x_rel_coords, y_rel_coords = text_rel_coords(text)
260: dx = x_rel_coords.max
261: dy = y_rel_coords.inject(0) {|sum, a| sum + a}
262:
263:
264: @ctx.gc.push()
265: @ctx.gc.text_anchor(Magick::StartAnchor)
266: if @ctx.text_attrs.text_anchor == :end
267: y -= dy
268: elsif @ctx.text_attrs.text_anchor == :middle
269: y -= dy / 2
270: end
271:
272:
273:
274:
275: case @ctx.text_attrs.glyph_orientation_vertical
276: when 0
277: x -= x_rel_coords.max / 2
278: y += y_rel_coords[0]
279: when 90
280: x -= x_rel_coords.max / 2
281: when 180
282: x += x_rel_coords.max / 2
283: when 270
284: x += x_rel_coords.max / 2
285: y += y_rel_coords.shift
286: y_rel_coords << 0
287: end
288:
289: x -= shift_baseline(@ctx.text_attrs.glyph_orientation_vertical, text[0,1])
290:
291: first_word = true
292: text.split(::Magick::RVG::WORD_SEP).each do |word|
293: unless first_word
294: y += y_rel_coords.shift
295: x_rel_coords.shift
296: end
297: first_word = false
298: word.split('').each do |glyph|
299: case @ctx.text_attrs.glyph_orientation_vertical.to_i
300: when 0, 90, 270
301: x_shift = (dx - x_rel_coords.shift) / 2
302: when 180
303: x_shift = -(dx - x_rel_coords.shift) / 2
304: end
305:
306: render_glyph(@ctx.text_attrs.glyph_orientation_vertical, x+x_shift, y, glyph)
307: y += y_rel_coords.shift
308: end
309: end
310:
311: @ctx.gc.pop()
312: [0, dy]
313: end