Class: PdfWatermark::WaterMark::Base

Inherits:
Object
  • Object
show all
Includes:
HexaPDF::Utils::MathHelpers
Defined in:
lib/pdf_watermark/water_mark/base.rb

Direct Known Subclasses

Repeated, Single

Instance Method Summary collapse

Constructor Details

#initialize(mark_string, source_path, options) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pdf_watermark/water_mark/base.rb', line 9

def initialize(mark_string, source_path, options)
  @source_path = source_path
  @options = options
  source_size = page_size
  @content_width = source_size[0] - (options[:margin][1] + options[:margin][3])
  @content_height = source_size[1] - (options[:margin][0] + options[:margin][2])
  @angle = options[:angle] == :diagonal ? rad_to_deg(Math.atan(@content_height.to_f/@content_width.to_f)) : options[:angle]
  @mark_string = mark_string

  @font_size = @options[:font_size]
  if @font_size.is_a?(String)
    if @font_size =~ /(\d+[.]?\d*)%/
      @font_size = ($1.to_f / 100) * @content_width
      @font_size = [@font_size, @options[:max_font_size]].min
      @font_size = [@font_size, @options[:min_font_size]].max
    else
      @font_size = @font_size.to_i
    end
  end
  @options[:font]
  @x = @options[:x] || 0
  @y = @options[:y] || @content_height

  @font = load_font(@options[:font], :watermark_font)
end