lib/prawn/svg/elements/text_component.rb in prawn-svg-0.29.1 vs lib/prawn/svg/elements/text_component.rb in prawn-svg-0.30.0

- old
+ new

@@ -1,10 +1,10 @@ class Prawn::SVG::Elements::TextComponent < Prawn::SVG::Elements::DepthFirstBase attr_reader :commands Printable = Struct.new(:element, :text, :leading_space?, :trailing_space?) - TextState = Struct.new(:parent, :x, :y, :dx, :dy, :rotation, :spacing, :mode) + TextState = Struct.new(:parent, :x, :y, :dx, :dy, :rotation, :spacing, :mode, :text_length, :length_adjust) def parse if state.inside_clip_path raise SkipElementError, "<text> elements are not supported in clip paths" end @@ -12,10 +12,12 @@ state.text.x = (attributes['x'] || "").split(COMMA_WSP_REGEXP).collect { |n| x(n) } state.text.y = (attributes['y'] || "").split(COMMA_WSP_REGEXP).collect { |n| y(n) } state.text.dx = (attributes['dx'] || "").split(COMMA_WSP_REGEXP).collect { |n| x_pixels(n) } state.text.dy = (attributes['dy'] || "").split(COMMA_WSP_REGEXP).collect { |n| y_pixels(n) } state.text.rotation = (attributes['rotate'] || "").split(COMMA_WSP_REGEXP).collect(&:to_f) + state.text.text_length = normalize_length(attributes['textLength']) + state.text.length_adjust = attributes['lengthAdjust'] state.text.spacing = calculate_character_spacing state.text.mode = calculate_text_rendering_mode @commands = [] @@ -131,10 +133,18 @@ opts[:rotate] = -rotate else opts.delete(:rotate) end + if state.text.text_length + if state.text.length_adjust == 'spacingAndGlyphs' + opts[:stretch_to_width] = state.text.text_length + else + opts[:pad_to_width] = state.text.text_length + end + end + if remaining add_call 'draw_text', text[0..0], opts.dup text = text[1..-1] else add_call 'draw_text', text, opts.dup @@ -219,7 +229,11 @@ spacing == 'normal' ? 0 : pixels(spacing) end # overridden, we don't want to call fill/stroke as draw_text does this for us def apply_drawing_call + end + + def normalize_length(length) + x_pixels(length) if length && length.match(/\d/) end end