pdf-core 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pdf/core/graphics_state.rb +8 -2
- data/lib/pdf/core/pdf_object.rb +12 -6
- data/lib/pdf/core/renderer.rb +3 -2
- data/lib/pdf/core/text.rb +6 -5
- data/spec/decimal_rounding_spec.rb +12 -0
- data/spec/pdf_object_spec.rb +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50239bf1d5c19e31512ccee0e9d69a73734d022e
|
4
|
+
data.tar.gz: a3ca5e4b7607e24dc7bb6d5a9b9a9e8e80a0ef8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6098bf18e958d0d6aa0a496a0ddaadef7925e2b94016511f99d62d94b5b6ac395fcc82c1d924a9b8e14ebd56bff8cc5c91805732c5cb1a9b5b1620a674df9036
|
7
|
+
data.tar.gz: 8c77d27a7da4cf581d7311030f5dc28b41447137dcfff66e1d3989a05d1354f9b237fcc6e46cead04ad9476f6cb984c505cefbe2d896769dd7a39d59a9a00145
|
@@ -63,11 +63,17 @@ module PDF
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def dash_setting
|
66
|
+
return "[] 0 d" unless @dash[:dash]
|
67
|
+
|
66
68
|
if @dash[:dash].kind_of?(Array)
|
67
|
-
|
69
|
+
array = @dash[:dash]
|
68
70
|
else
|
69
|
-
|
71
|
+
array = [@dash[:dash], @dash[:space]]
|
70
72
|
end
|
73
|
+
|
74
|
+
|
75
|
+
"[#{PDF::Core.real_params(array)}] "+
|
76
|
+
"#{PDF::Core.real(@dash[:phase])} d"
|
71
77
|
end
|
72
78
|
|
73
79
|
private
|
data/lib/pdf/core/pdf_object.rb
CHANGED
@@ -12,6 +12,14 @@ module PDF
|
|
12
12
|
module Core
|
13
13
|
module_function
|
14
14
|
|
15
|
+
def real(num)
|
16
|
+
num.to_f.round(4)
|
17
|
+
end
|
18
|
+
|
19
|
+
def real_params(array)
|
20
|
+
array.map { |e| real(e) }.join(" ")
|
21
|
+
end
|
22
|
+
|
15
23
|
def utf8_to_utf16(str)
|
16
24
|
"\xFE\xFF".force_encoding(::Encoding::UTF_16BE) + str.encode(::Encoding::UTF_16BE)
|
17
25
|
end
|
@@ -43,12 +51,10 @@ module PDF
|
|
43
51
|
when TrueClass then "true"
|
44
52
|
when FalseClass then "false"
|
45
53
|
when Numeric
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
str
|
51
|
-
end
|
54
|
+
obj = real(obj) unless obj.kind_of?(Integer)
|
55
|
+
|
56
|
+
String(obj) # NOTE: this can fail on huge floating point numbers,
|
57
|
+
# but it seems unlikely to ever happen in practice.
|
52
58
|
when Array
|
53
59
|
"[" << obj.map { |e| PdfObject(e, in_content_stream) }.join(' ') << "]"
|
54
60
|
when PDF::Core::LiteralString
|
data/lib/pdf/core/renderer.rb
CHANGED
@@ -47,8 +47,9 @@ module PDF
|
|
47
47
|
#
|
48
48
|
# # Raw line drawing example:
|
49
49
|
# x1,y1,x2,y2 = 100,500,300,550
|
50
|
-
#
|
51
|
-
# pdf.add_content("
|
50
|
+
#
|
51
|
+
# pdf.add_content("#{PDF::Core.real_params([x1, y1])} m") # move
|
52
|
+
# pdf.add_content("#{PDF::Core.real_params([ x2, y2 ])} l") # draw path
|
52
53
|
# pdf.add_content("S") # stroke
|
53
54
|
#
|
54
55
|
def add_content(str)
|
data/lib/pdf/core/text.rb
CHANGED
@@ -204,9 +204,9 @@ module PDF
|
|
204
204
|
yield
|
205
205
|
else
|
206
206
|
@character_spacing = amount
|
207
|
-
add_content "\n
|
207
|
+
add_content "\n#{PDF::Core.real(amount)} Tc"
|
208
208
|
yield
|
209
|
-
add_content "\n
|
209
|
+
add_content "\n#{PDF::Core.real(original_character_spacing)} Tc"
|
210
210
|
@character_spacing = original_character_spacing
|
211
211
|
end
|
212
212
|
end
|
@@ -222,9 +222,10 @@ module PDF
|
|
222
222
|
yield
|
223
223
|
else
|
224
224
|
@word_spacing = amount
|
225
|
-
add_content "\n
|
225
|
+
add_content "\n#{PDF::Core.real(amount)} Tw"
|
226
226
|
yield
|
227
|
-
add_content "\n
|
227
|
+
add_content "\n#{PDF::Core.real(original_word_spacing)} Tw"
|
228
|
+
|
228
229
|
@word_spacing = original_word_spacing
|
229
230
|
end
|
230
231
|
end
|
@@ -237,7 +238,7 @@ module PDF
|
|
237
238
|
if options[:rotate]
|
238
239
|
rad = options[:rotate].to_f * Math::PI / 180
|
239
240
|
arr = [ Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), x, y ]
|
240
|
-
add_content "
|
241
|
+
add_content "#{PDF::Core.real_params(array)} Tm"
|
241
242
|
else
|
242
243
|
add_content "#{x} #{y} Td"
|
243
244
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: binary
|
2
|
+
require_relative "spec_helper"
|
3
|
+
|
4
|
+
describe "Decimal rounding" do
|
5
|
+
it "should round floating point numbers to four decimal places" do
|
6
|
+
PDF::Core.real(1.23456789).should == 1.2346
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be able to create a PDF parameter list of rounded decimals" do
|
10
|
+
PDF::Core.real_params([1,2.34567,Math::PI]).should == "1.0 2.3457 3.1416"
|
11
|
+
end
|
12
|
+
end
|
data/spec/pdf_object_spec.rb
CHANGED
@@ -14,10 +14,10 @@ describe "PDF Object Serialization" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should convert a Ruby number to PDF number" do
|
17
|
-
PDF::Core::PdfObject(
|
18
|
-
|
19
|
-
#
|
20
|
-
PDF::Core::PdfObject(
|
17
|
+
PDF::Core::PdfObject(42).should == "42"
|
18
|
+
|
19
|
+
# numbers are rounded to four decimal places
|
20
|
+
PDF::Core::PdfObject(1.214112421).should == "1.2141"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should convert a Ruby time object to a PDF timestamp" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory Brown
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-
|
15
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: pdf-reader
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/pdf/core/stream.rb
|
123
123
|
- lib/pdf/core/text.rb
|
124
124
|
- pdf-core.gemspec
|
125
|
+
- spec/decimal_rounding_spec.rb
|
125
126
|
- spec/filters_spec.rb
|
126
127
|
- spec/name_tree_spec.rb
|
127
128
|
- spec/object_store_spec.rb
|