podoff 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/LICENSE.txt +1 -1
- data/README.md +31 -5
- data/lib/podoff.rb +96 -17
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1ef5ecc8cb922c5bd2725af0c936c9eb3291a353a05b2e927e103147e0da499
|
4
|
+
data.tar.gz: e800a9be42f5c3c9ba12097d8c4edfad1a6e8722ae56887710c7939e65616095
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f9ab0d2349c2059c7c8d43695d4db10452cd0b4c2e86628852c5f858e8e6da918e93f3a57f200a9d0f88118ad328bf540d4233d1dff07a5407e4c9afc1ab17a
|
7
|
+
data.tar.gz: 31ce324bce4473a96d8aa07737c1d1938df45af31987f05504f9809b248cbb517e37cdc6f3e7cec8dd4d7164aaafa734a6798ec1f2d915bb5551a552d7f609cb
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2015-
|
2
|
+
Copyright (c) 2015-2020, John Mettraux, jmettraux@gmail.com
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -237,7 +237,7 @@ class Podoff::Obj
|
|
237
237
|
|
238
238
|
### Podoff::Stream
|
239
239
|
|
240
|
-
|
240
|
+
Here are the methods used to write to streams.
|
241
241
|
|
242
242
|
```ruby
|
243
243
|
class Podoff::Stream
|
@@ -245,18 +245,44 @@ class Podoff::Stream
|
|
245
245
|
# set the current font and font size for the stream
|
246
246
|
#
|
247
247
|
def tf(font_name, font_size)
|
248
|
-
alias
|
248
|
+
alias font tf
|
249
249
|
|
250
250
|
# set the current color for the stream
|
251
251
|
#
|
252
252
|
def rg(red, green, blue)
|
253
|
-
|
254
|
-
alias
|
253
|
+
def rg(string) # like '#fffff' or 'white'
|
254
|
+
alias rgb rg
|
255
|
+
alias color rg
|
255
256
|
|
256
257
|
# write a piece of text at a given position
|
257
258
|
#
|
258
259
|
def bt(x, y, text)
|
259
|
-
|
260
|
+
def bt(x, y, text, rgb: 'blue')
|
261
|
+
alias text bt
|
262
|
+
|
263
|
+
# draw a rectangle
|
264
|
+
#
|
265
|
+
def re(x, y, *a)
|
266
|
+
alias rect re
|
267
|
+
alias rectangle re
|
268
|
+
#
|
269
|
+
st.re(10, 20, 30, 40, rgb: [ 0.0, 0.0, 0.0 ])
|
270
|
+
st.rect(11, 21, w: 31, h: 41, rgb: [ 0.1, 0.1, 0.1 ])
|
271
|
+
st.rectangle(12, 22, 32, 42, rgb: [ 0.2, 0.2, 0.2 ])
|
272
|
+
# ...
|
273
|
+
|
274
|
+
# draw a line
|
275
|
+
#
|
276
|
+
def line(x0, y0, x1, y1, *a)
|
277
|
+
#
|
278
|
+
st.line(1, 1, 2, 2)
|
279
|
+
st.line(1, 1, 2, 2, 3, 3)
|
280
|
+
st.line([ 1, 1 ], [ 2, 2 ], [ 3, 3 ])
|
281
|
+
st.line([ 1, 1 ], [ 2, 2 ], [ 3, 3 ], rgb: [ 0.5, 0.5, 0.5 ])
|
282
|
+
st.line(1, 1, 2, 2, rgb: [ 0.7, 0.7, 0.7 ])
|
283
|
+
# ...
|
284
|
+
st.line(1, 1, 2, 2, rgb: [ 0.7, 0.7, 0.7 ], width: 0.3)
|
285
|
+
# ...
|
260
286
|
```
|
261
287
|
|
262
288
|
|
data/lib/podoff.rb
CHANGED
@@ -6,7 +6,7 @@ require 'stringio'
|
|
6
6
|
|
7
7
|
module Podoff
|
8
8
|
|
9
|
-
VERSION = '1.
|
9
|
+
VERSION = '1.3.0'
|
10
10
|
|
11
11
|
def self.load(path, encoding)
|
12
12
|
|
@@ -437,7 +437,7 @@ module Podoff
|
|
437
437
|
|
438
438
|
add_to_attribute(:contents, re)
|
439
439
|
end
|
440
|
-
alias
|
440
|
+
alias insert_content insert_contents
|
441
441
|
|
442
442
|
def to_s
|
443
443
|
|
@@ -509,33 +509,81 @@ module Podoff
|
|
509
509
|
|
510
510
|
@font = "/#{n} #{font_size} Tf "
|
511
511
|
end
|
512
|
-
alias
|
512
|
+
alias font tf
|
513
513
|
|
514
|
-
def rg(
|
514
|
+
def rg(*a)
|
515
515
|
|
516
|
-
@color =
|
516
|
+
@color = to_rg(a)
|
517
517
|
end
|
518
|
-
alias
|
519
|
-
alias
|
518
|
+
alias color rg
|
519
|
+
alias rgb rg
|
520
520
|
|
521
|
-
def bt(x, y, text)
|
521
|
+
def bt(x, y, text, opts={})
|
522
522
|
|
523
523
|
return unless text
|
524
524
|
|
525
|
-
|
526
|
-
|
527
|
-
@content
|
528
|
-
@content
|
529
|
-
@content
|
530
|
-
|
525
|
+
rgb = opts[:rgb]
|
526
|
+
|
527
|
+
@content << "\n" if @content.size > 0
|
528
|
+
@content << 'BT '
|
529
|
+
@content << @font if @font
|
530
|
+
if rgb
|
531
|
+
@content << to_rg(rgb)
|
532
|
+
elsif @color
|
533
|
+
@content << @color
|
534
|
+
end
|
535
|
+
@content << "#{x} #{y} Td (#{escape(text)}) Tj"
|
536
|
+
@content << ' ET'
|
531
537
|
end
|
532
|
-
alias
|
538
|
+
alias text bt
|
533
539
|
|
534
540
|
def write(text)
|
535
541
|
|
536
542
|
@content.write(text)
|
537
543
|
end
|
538
544
|
|
545
|
+
#def re(x, y, w, h, opts={})
|
546
|
+
#def re([ x, y ], [ w, h ], opts={})
|
547
|
+
#def re([ x, y ], opts)
|
548
|
+
#
|
549
|
+
def re(x, *a)
|
550
|
+
|
551
|
+
a = [ x, a ].flatten
|
552
|
+
opts = a.last.is_a?(Hash) ? a.pop : {}
|
553
|
+
x = a.shift; y = a.shift
|
554
|
+
|
555
|
+
rgb = opts[:rgb]
|
556
|
+
w = opts[:width] || opts[:w] || a[0]
|
557
|
+
h = opts[:height] || opts[:h] || a[1]
|
558
|
+
|
559
|
+
@content << "\n" if @content.size > 0
|
560
|
+
@content << to_rg(rgb) if rgb
|
561
|
+
@content << lineup(x, y, w, h) << ' re f'
|
562
|
+
end
|
563
|
+
alias rect re
|
564
|
+
alias rectangle re
|
565
|
+
|
566
|
+
#def line(x0, y0, x1, y1, x2, y2, ..., opts={})
|
567
|
+
#def line([ x0, y0 ], [ x1, y1 ], [ x2, y2 ], ..., opts={})
|
568
|
+
#
|
569
|
+
def line(x0, y0, *a)
|
570
|
+
|
571
|
+
a = [ x0, y0, a ].flatten
|
572
|
+
opts = a.last.is_a?(Hash) ? a.pop : {}
|
573
|
+
x0, y0, *xys = a
|
574
|
+
|
575
|
+
rgb = opts[:rgb] || opts[:rg]
|
576
|
+
w = opts[:width] || opts[:w]
|
577
|
+
|
578
|
+
@content << "\n" if @content.size > 0
|
579
|
+
@content << w.to_s << ' w ' if w
|
580
|
+
@content << to_rg(rgb) if rgb
|
581
|
+
@content << lineup(x0, y0) << ' m '
|
582
|
+
xys.each_slice(2) { |x, y|
|
583
|
+
@content << lineup(x, y, 'l ') }
|
584
|
+
@content << 'h S'
|
585
|
+
end
|
586
|
+
|
539
587
|
def to_s
|
540
588
|
|
541
589
|
s = @content.string
|
@@ -552,9 +600,40 @@ module Podoff
|
|
552
600
|
|
553
601
|
protected
|
554
602
|
|
555
|
-
def escape(s)
|
603
|
+
def escape(s); s.gsub(/\(/, '\(').gsub(/\)/, '\)'); end
|
604
|
+
def lineup(*a); a.flatten.collect(&:to_s).join(' '); end
|
605
|
+
|
606
|
+
COLORS = {
|
607
|
+
'black' => [ 0.0, 0.0, 0.0 ],
|
608
|
+
'white' => [ 1.0, 1.0, 1.0 ],
|
609
|
+
'red' => [ 1.0, 0.0, 0.0 ],
|
610
|
+
'green' => [ 0.0, 1.0, 0.0 ],
|
611
|
+
'blue' => [ 0.0, 0.0, 1.0 ] }
|
612
|
+
|
613
|
+
def to_rg(a)
|
614
|
+
|
615
|
+
a = a[0].to_s if a.length == 1
|
616
|
+
|
617
|
+
lineup(
|
618
|
+
if a.is_a?(Array) && a.length == 3
|
619
|
+
a
|
620
|
+
elsif a.is_a?(String) && a.match(/^#?([0-9a-z]{3}|[0-9a-z]{6})$/i)
|
621
|
+
hex_to_rgb(a)
|
622
|
+
else
|
623
|
+
COLORS[a] || COLORS['red'] # else, stand out in RED
|
624
|
+
end,
|
625
|
+
'rg ')
|
626
|
+
end
|
627
|
+
|
628
|
+
def hex_to_rgb(s)
|
629
|
+
|
630
|
+
s = s[1..-1] if s[0, 1] == '#'
|
556
631
|
|
557
|
-
s.
|
632
|
+
s.chars
|
633
|
+
.each_slice(
|
634
|
+
s.length == 6 ? 2 : 1)
|
635
|
+
.collect { |x|
|
636
|
+
sprintf('%0.4f', (x.join.to_i(16) / 255.0)).gsub(/0+$/, '0') }
|
558
637
|
end
|
559
638
|
end
|
560
639
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: podoff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -56,8 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
|
-
|
60
|
-
rubygems_version: 2.7.6
|
59
|
+
rubygems_version: 3.0.3
|
61
60
|
signing_key:
|
62
61
|
specification_version: 4
|
63
62
|
summary: a tool to deface PDF documents
|