pdf_watermark 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pdf_watermark.rb +5 -4
- data/lib/pdf_watermark/version.rb +1 -1
- data/lib/pdf_watermark/water_mark.rb +16 -4
- metadata +2 -4
- data/fonts/NotoSansSC-Regular.ttf +0 -0
- data/fonts/wqyzenhei.ttf +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46599b8f4b91af1c163d275ca81427a998be6c98
|
4
|
+
data.tar.gz: 569d552420e51a16afaf2ae9ae89b7fe750e2337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d478b9f211a103a287cd8421350c20ab8af50243e8b47f9a64264db8e18e18bccbc51dd353c931bbf8109fe3d063d281787d298cfa4dfb4b1444fcda843bdc
|
7
|
+
data.tar.gz: 3b4778e4e272633c19c51fc44deed4535f8b311436a95d1faa60c683d791ac3adce778df1382cdab90396bc2707de0e71079a46162e10d1d5b4aa9ed5cf15488
|
data/lib/pdf_watermark.rb
CHANGED
@@ -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: [
|
15
|
+
margin: [10, 10, 10, 10],
|
17
16
|
font: "#{FONT_DIR}/SourceHanSansSC-Regular.ttf",
|
18
|
-
font_size:
|
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
|
|
@@ -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,
|
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 ? (
|
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 +=
|
90
|
+
temp_x += offset_x
|
79
91
|
end
|
80
92
|
end
|
81
|
-
temp_y -=
|
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
|
+
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-
|
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
|
data/fonts/wqyzenhei.ttf
DELETED
Binary file
|