def encode_text(text, fonts)
      # text must be a unicode string and fonts must be an array.
      # this is an internal method, don't perform tests.
      fonts_array = []
      fonts.each do |name|
        f = Fonts.get_font name
        fonts_array << f if f
      end

      # before starting, we should reorder any RTL content in the string
      text = reorder_rtl_content text

      out = []
      text.chars.each do |c|
        fonts_array.each_index do |i|
          next unless fonts_array[i].cmap.nil? || (fonts_array[i].cmap && fonts_array[i].cmap[c])
          # add to array
          if out.last.nil? || out.last[0] != fonts[i]
            out.last[1] << '>' unless out.last.nil?
            out << [fonts[i], '<', 0, 0]
          end
          out.last[1] << (fonts_array[i].cmap.nil? ? (c.unpack('H*')[0]) : fonts_array[i].cmap[c])
          if fonts_array[i].metrics[c]
            out.last[2] += fonts_array[i].metrics[c][:wx].to_f
            out.last[3] += fonts_array[i].metrics[c][:wy].to_f
          end
          break
        end
      end
      out.last[1] << '>' if out.last
      out
    end
def encode_text(text, fonts)
      # text must be a unicode string and fonts must be an array.
      # this is an internal method, don't perform tests.
      fonts_array = []
      fonts.each do |name|
        f = Fonts.get_font name
        fonts_array << f if f
      end

      # before starting, we should reorder any RTL content in the string
      text = reorder_rtl_content text

      out = []
      text.chars.each do |c|
        fonts_array.each_index do |i|
          next unless fonts_array[i].cmap.nil? || (fonts_array[i].cmap && fonts_array[i].cmap[c])
          # add to array
          if out.last.nil? || out.last[0] != fonts[i]
            out.last[1] << '>' unless out.last.nil?
            out << [fonts[i], '<', 0, 0]
          end
          out.last[1] << (fonts_array[i].cmap.nil? ? (c.unpack('H*')[0]) : fonts_array[i].cmap[c])
          if fonts_array[i].metrics[c]
            out.last[2] += fonts_array[i].metrics[c][:wx].to_f
            out.last[3] += fonts_array[i].metrics[c][:wy].to_f
          end
          break
        end
      end
      out.last[1] << '>' if out.last
      out
    end
encodes the text in an array of [:font_name, <PDFHexString>] for use in textbox