class PdfWatermark::WaterMark::Repeated

Public Class Methods

new(*args) click to toggle source
Calls superclass method PdfWatermark::WaterMark::Base::new
# File lib/pdf_watermark/water_mark/repeated.rb, line 6
def initialize(*args)
  super(*args)
end

Public Instance Methods

render() click to toggle source
# File lib/pdf_watermark/water_mark/repeated.rb, line 10
def render
  document.pages.each do |page|
    canvas = page.canvas(type: :overlay)
    canvas.font(:watermark_font, size: @font_size)
    canvas.fill_color(@options[:font_color])
    box_height = @font_size
    box_width = canvas.width_of(@mark_string)
    temp_y = @y
    indent = false
    offset_x = box_width + @options[:repeat_offset] * @font_size
    offset_y = box_height + @options[:repeat_offset] * @font_size


    canvas.opacity(fill_alpha: @options[:transparent]) do
      canvas.rotate(@angle, origin: [@content_width/2, @content_height/2]) do
        while temp_y > 0 do
          temp_x = indent ? (offset_x / 2.0) : 0
          while temp_x <= @content_width
            canvas.text(@mark_string, at: [temp_x, temp_y])
            temp_x += offset_x
          end
          temp_y -= offset_y
          indent = !indent
        end
      end
    end
  end
  document
end