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