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:
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:
268:
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
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