chupa-text-decomposer-pdf 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/chupa-text-decomposer-pdf.gemspec +5 -4
- data/doc/text/news.md +6 -0
- data/lib/chupa-text/decomposers/pdf.rb +34 -1
- data/test/fixture/screenshot.odt +0 -0
- data/test/fixture/screenshot.pdf +0 -0
- data/test/fixture/screenshot.png +0 -0
- data/test/test-pdf.rb +46 -2
- metadata +22 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6ed1f4617372748a026ff23cf24bcd756889a84
|
4
|
+
data.tar.gz: f9ee6fcc62fee9017def6027534dfa47967b1e99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4083d5d3a4edfc11fd72719091d4e7133d5bd4a2895205d82f8686a1d95a2c463200e2f7e611514efaae75ac946bb0eb317bbf3652e1dc968661b610531d898c
|
7
|
+
data.tar.gz: '001095acd4220a0c302ed9762120531c576a51b8192069516eb27b07e1303129574dff7973e2810e97d0053589902a41361a9aba652fb258862dd22d17e38873'
|
data/.yardopts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013-
|
3
|
+
# Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
#
|
5
5
|
# This library is free software; you can redistribute it and/or
|
6
6
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -22,7 +22,7 @@ end
|
|
22
22
|
|
23
23
|
Gem::Specification.new do |spec|
|
24
24
|
spec.name = "chupa-text-decomposer-pdf"
|
25
|
-
spec.version = "1.0.
|
25
|
+
spec.version = "1.0.5"
|
26
26
|
spec.homepage = "https://github.com/ranguba/chupa-text-decomposer-pdf"
|
27
27
|
spec.authors = ["Kouhei Sutou"]
|
28
28
|
spec.email = ["kou@clear-code.com"]
|
@@ -39,12 +39,13 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.files += Dir.glob("doc/text/*")
|
40
40
|
spec.files += Dir.glob("test/**/*")
|
41
41
|
|
42
|
-
spec.add_runtime_dependency("chupa-text")
|
42
|
+
spec.add_runtime_dependency("chupa-text", ">= 1.0.7")
|
43
43
|
spec.add_runtime_dependency("poppler")
|
44
44
|
|
45
45
|
spec.add_development_dependency("bundler")
|
46
46
|
spec.add_development_dependency("rake")
|
47
47
|
spec.add_development_dependency("test-unit")
|
48
48
|
spec.add_development_dependency("packnga")
|
49
|
-
spec.add_development_dependency("
|
49
|
+
spec.add_development_dependency("kramdown")
|
50
|
+
spec.add_development_dependency("gdk_pixbuf2")
|
50
51
|
end
|
data/doc/text/news.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013-
|
1
|
+
# Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -53,6 +53,9 @@ module ChupaText
|
|
53
53
|
add_attribute(text_data, document, :creator)
|
54
54
|
add_attribute(text_data, document, :producer)
|
55
55
|
add_attribute(text_data, document, :creation_date, :created_time)
|
56
|
+
if data.need_screenshot?
|
57
|
+
text_data.screenshot = create_screenshot(data, document)
|
58
|
+
end
|
56
59
|
yield(text_data)
|
57
60
|
end
|
58
61
|
|
@@ -99,6 +102,36 @@ module ChupaText
|
|
99
102
|
data_attribute_name ||= pdf_attribute_name.to_s.gsub(/_/, "-")
|
100
103
|
text_data[data_attribute_name] = value
|
101
104
|
end
|
105
|
+
|
106
|
+
def create_screenshot(data, document)
|
107
|
+
screenshot_width, screenshot_height = data.expected_screenshot_size
|
108
|
+
|
109
|
+
page = document[0]
|
110
|
+
page_width, page_height = page.size
|
111
|
+
|
112
|
+
surface = Cairo::ImageSurface.new(:argb32,
|
113
|
+
screenshot_width,
|
114
|
+
screenshot_height)
|
115
|
+
context = Cairo::Context.new(surface)
|
116
|
+
context.set_source_color(:white)
|
117
|
+
context.paint
|
118
|
+
if page_width > page_height
|
119
|
+
ratio = screenshot_width / page_width
|
120
|
+
context.translate(0,
|
121
|
+
((screenshot_height - page_height * ratio) / 2))
|
122
|
+
context.scale(ratio, ratio)
|
123
|
+
else
|
124
|
+
ratio = screenshot_height / page_height
|
125
|
+
context.translate(((screenshot_width - page_width * ratio) / 2),
|
126
|
+
0)
|
127
|
+
context.scale(ratio, ratio)
|
128
|
+
end
|
129
|
+
context.render_poppler_page(page)
|
130
|
+
png = StringIO.new
|
131
|
+
surface.write_to_png(png)
|
132
|
+
|
133
|
+
Screenshot.new("image/png", [png.string].pack("m*"), "base64")
|
134
|
+
end
|
102
135
|
end
|
103
136
|
end
|
104
137
|
end
|
Binary file
|
Binary file
|
Binary file
|
data/test/test-pdf.rb
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
16
|
|
17
17
|
require "pathname"
|
18
|
+
require "gdk_pixbuf2"
|
18
19
|
|
19
20
|
class TestPDF < Test::Unit::TestCase
|
20
21
|
def setup
|
@@ -110,8 +111,13 @@ class TestPDF < Test::Unit::TestCase
|
|
110
111
|
end
|
111
112
|
|
112
113
|
def test_created_time
|
113
|
-
|
114
|
-
|
114
|
+
if ENV["TRAVIS"] # TODO: Why? We set TZ=JST in run-test.rb
|
115
|
+
assert_equal([Time.parse("2014-01-05T15:52:45Z")],
|
116
|
+
decompose("created_time"))
|
117
|
+
else
|
118
|
+
assert_equal([Time.parse("2014-01-05T06:52:45Z")],
|
119
|
+
decompose("created_time"))
|
120
|
+
end
|
115
121
|
end
|
116
122
|
|
117
123
|
private
|
@@ -168,5 +174,43 @@ class TestPDF < Test::Unit::TestCase
|
|
168
174
|
super(fixture_path("encrypted.pdf"))
|
169
175
|
end
|
170
176
|
end
|
177
|
+
|
178
|
+
sub_test_case("screenshot") do
|
179
|
+
def test_with_password
|
180
|
+
assert_equal([
|
181
|
+
{
|
182
|
+
"mime-type" => "image/png",
|
183
|
+
"pixels" => load_image_fixture("screenshot.png"),
|
184
|
+
"encoding" => "base64",
|
185
|
+
},
|
186
|
+
],
|
187
|
+
decompose("screenshot.pdf"))
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
def decompose(fixture_name)
|
192
|
+
super(fixture_path(fixture_name)).collect do |decompose|
|
193
|
+
screenshot = decompose.screenshot
|
194
|
+
{
|
195
|
+
"mime-type" => screenshot.mime_type,
|
196
|
+
"pixels" => load_image_data(screenshot.decoded_data),
|
197
|
+
"encoding" => screenshot.encoding,
|
198
|
+
}
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def load_image_data(data)
|
203
|
+
loader = GdkPixbuf::PixbufLoader.new
|
204
|
+
loader.write(data)
|
205
|
+
loader.close
|
206
|
+
loader.pixbuf.pixels
|
207
|
+
end
|
208
|
+
|
209
|
+
def load_image_fixture(fixture_name)
|
210
|
+
File.open(fixture_path(fixture_name), "rb") do |file|
|
211
|
+
load_image_data(file.read)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
171
215
|
end
|
172
216
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chupa-text-decomposer-pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chupa-text
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.0.7
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.0.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: poppler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +95,21 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: kramdown
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: gdk_pixbuf2
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|
@@ -135,6 +149,9 @@ files:
|
|
135
149
|
- test/fixture/multi-pages.pdf
|
136
150
|
- test/fixture/one-page.odt
|
137
151
|
- test/fixture/one-page.pdf
|
152
|
+
- test/fixture/screenshot.odt
|
153
|
+
- test/fixture/screenshot.pdf
|
154
|
+
- test/fixture/screenshot.png
|
138
155
|
- test/run-test.rb
|
139
156
|
- test/test-pdf.rb
|
140
157
|
homepage: https://github.com/ranguba/chupa-text-decomposer-pdf
|