pdf_watermark 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91ceda149c41dbf7b66cd7bba37971ab21c8b6e8
4
- data.tar.gz: 6235870366f989ccbd9292e4475b55373ee208b5
3
+ metadata.gz: 46599b8f4b91af1c163d275ca81427a998be6c98
4
+ data.tar.gz: 569d552420e51a16afaf2ae9ae89b7fe750e2337
5
5
  SHA512:
6
- metadata.gz: 8e83967df208855745451bce6b8a712005944a53bf287bd698918941fda150205d3fffcb1ffae65a480679d0c75c603f94555d45e95ca5a7f88f3f2075630aca
7
- data.tar.gz: f436fd5ee503d665eb9b9cf61b6e5ad4e0db881cbccc01bdbca3d024a6f02d5ac237edc5dafbe394f35041adc0ef437f48c86cccfb8be9d0f0c26e88d567e493
6
+ metadata.gz: f6d478b9f211a103a287cd8421350c20ab8af50243e8b47f9a64264db8e18e18bccbc51dd353c931bbf8109fe3d063d281787d298cfa4dfb4b1444fcda843bdc
7
+ data.tar.gz: 3b4778e4e272633c19c51fc44deed4535f8b311436a95d1faa60c683d791ac3adce778df1382cdab90396bc2707de0e71079a46162e10d1d5b4aa9ed5cf15488
@@ -6,21 +6,22 @@ module PdfWatermark
6
6
  LIB_DIR = File.dirname(File.realpath(__FILE__))
7
7
  BASEDIR = File.join(LIB_DIR, '..')
8
8
  FONT_DIR = File.join(LIB_DIR, '..', 'fonts')
9
- MAX_FONT_SIZE= 75
10
9
  REPEAT_X_OFFSET = 80
11
10
  REPEAT_Y_OFFSET = 80
12
11
 
13
12
  def self.watermark(mark_string, source, destination = nil, options: {})
14
13
  default={
15
14
  angle: :diagonal,
16
- margin: [50, 50, 50, 50],
15
+ margin: [10, 10, 10, 10],
17
16
  font: "#{FONT_DIR}/SourceHanSansSC-Regular.ttf",
18
- font_size: 12,
17
+ font_size: '12px',
19
18
  font_color: "999999",
20
19
  transparent: 0.2,
21
20
  align: :left,
22
21
  valign: :center,
23
- mode: :fill
22
+ mode: :fill,
23
+ max_font_size: 50,
24
+ min_font_size: 15,
24
25
  }
25
26
  options = default.merge(options)
26
27
 
@@ -1,3 +1,3 @@
1
1
  module PdfWatermark
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -10,6 +10,16 @@ module PdfWatermark
10
10
  @angle = options[:angle] == :diagonal ? rad_to_degree(Math.atan(@content_height.to_f/@content_width.to_f)) : options[:angle]
11
11
  @mark_string = mark_string
12
12
  @font_size = @options[:font_size]
13
+ if @font_size.is_a?(String)
14
+ if @font_size =~ /(\d+[.]?\d*)%/
15
+ @font_size = ($1.to_f / 100) * @content_width
16
+ @font_size = [@font_size, @options[:max_font_size]].min
17
+ @font_size = [@font_size, @options[:min_font_size]].max
18
+ else
19
+ @font_size = @font_size.to_i
20
+ end
21
+ end
22
+
13
23
  @font = @options[:font]
14
24
  @x = @options[:x] || 0
15
25
  @y = @options[:y] || @content_height
@@ -37,7 +47,7 @@ module PdfWatermark
37
47
  else
38
48
  @max_text_width = (@content_height/Math.sin(rad)).abs
39
49
  end
40
- @font_size ||= calculated_font_size(@mark_string, MAX_FONT_SIZE, @max_text_width)
50
+ @font_size ||= calculated_font_size(@mark_string, @options[:max_font_size], @max_text_width)
41
51
 
42
52
  font(@options[:font]) do
43
53
  bounding_box([@x, @y], width: @content_width, height: @content_height) do
@@ -63,10 +73,12 @@ module PdfWatermark
63
73
  box_width = text_width(@mark_string, @font_size)
64
74
  temp_y = @y
65
75
  indent = false
76
+ offset_x = box_width + [3 * @font_size, REPEAT_X_OFFSET].max
77
+ offset_y = box_height + [3 * @font_size, REPEAT_Y_OFFSET].max
66
78
  bounding_box([@x, @y], width: @content_width, height: @content_height) do
67
79
  while temp_y > 0 do
68
80
  rotate @angle, origin: [@content_width/2, @content_height/2] do
69
- temp_x = indent ? ((box_width + REPEAT_X_OFFSET) / 2) : 0
81
+ temp_x = indent ? (offset_x / 2.0) : 0
70
82
  while temp_x <= @content_width
71
83
  formatted_text_box(
72
84
  [{ text: @mark_string, color: @options[:font_color] }],
@@ -75,10 +87,10 @@ module PdfWatermark
75
87
  align: @options[:align], valign: @options[:valign],
76
88
  size: @font_size,
77
89
  )
78
- temp_x += box_width + REPEAT_X_OFFSET
90
+ temp_x += offset_x
79
91
  end
80
92
  end
81
- temp_y -= box_height + REPEAT_Y_OFFSET
93
+ temp_y -= offset_y
82
94
  indent = !indent
83
95
  end
84
96
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf_watermark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - bruce
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-23 00:00:00.000000000 Z
11
+ date: 2017-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -145,9 +145,7 @@ files:
145
145
  - Rakefile
146
146
  - bin/console
147
147
  - bin/setup
148
- - fonts/NotoSansSC-Regular.ttf
149
148
  - fonts/SourceHanSansSC-Regular.ttf
150
- - fonts/wqyzenhei.ttf
151
149
  - lib/pdf_watermark.rb
152
150
  - lib/pdf_watermark/version.rb
153
151
  - lib/pdf_watermark/water_mark.rb
Binary file
Binary file