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 Enumerable Geometry HatchFill Draw lib/RMagick.rb lib/rvg/misc.rb ObjectData Application Pre_ObjectData_Descriptor Envelope Post_ObjectData_Descriptor IPTC Magick dot/m_14_0.png

Methods

Public Instance methods

[Source]

     # File lib/rvg/misc.rb, line 252
252:                 def get_letter_spacing(glyph)
253:                     gx, gy = glyph_metrics(@ctx.text_attrs.glyph_orientation_vertical, glyph)
254:                     [gx, gy+@ctx.text_attrs.letter_spacing]
255:                 end

[Source]

     # File lib/rvg/misc.rb, line 247
247:                 def get_word_spacing()
248:                     @word_space ||= glyph_metrics(@ctx.text_attrs.glyph_orientation_vertical, ' ')[1]
249:                     [0, @word_space + @ctx.text_attrs.word_spacing]
250:                 end

[Source]

     # File lib/rvg/misc.rb, line 257
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:                     # We're handling the anchoring.
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:                     # Align the first glyph such that its center
272:                     # is aligned on x and its top is aligned on y.
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   # since we used an element we need to add a dummy
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

[Validate]