hamidashi 0.1.4 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4854e83ea5eda5c7c11a93809d4e29b629341ef2
4
- data.tar.gz: 6c9c29df89bdbb83d1d87431c99545a927a8ede1
3
+ metadata.gz: 0a767e6d490ad96dfc9c40f3f89686dfd9e52361
4
+ data.tar.gz: 444bec65a0b05297c2faddf32175cef233c9e265
5
5
  SHA512:
6
- metadata.gz: aa4fd40cf1fd8e55b47ebd7cb59a8b7343a06e651d8c36f5362c0093513aa8d77206d57c1de96b7d42161192bb07e66ca67b162e8da63b122c97a72da770062b
7
- data.tar.gz: 35c8af4e294f9abaf05540cccab31161cc7d34a737e4d398c558ada7c0897ab3c9be87352d55fcedf2d3970f044d71d3671c0764223498ae4ceb1871e384c794
6
+ metadata.gz: 5e6c06b86b4e4cd05ae2f2e9325103061645671594a1ce3e2a482b1d7d137b861b54ac067523c6a27ff9b423006bfc15a9fa43be67bd4b2ef0f17fa71b5147f7
7
+ data.tar.gz: 209c92e74c6fe93a428377f7641ce7c35ccd0e6d7da5da153c42b5844c692544529f449e1cbdf8b9b1ee41a596bac7b68410c3553057c0992a24c983baec3c2b
data/.gitignore CHANGED
@@ -8,3 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /vendor/bundle/
11
+
12
+ test/fixtures/pdf-src/catalog.yml
13
+
14
+ hamidashi-*/
data/.travis.yml CHANGED
@@ -2,3 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
4
  before_install: gem install bundler -v 1.10.3
5
+ addons:
6
+ code_climate:
7
+ repo_token:
8
+ secure: "GrIzKIN/64aHJLjdD97p+iWYspGCAzGmIqqNmpxV+EUZLXxNFO/90Six8wT/T1wvWvIlhpjg9ive1mKjFuITqbiJZLmUxqvrXJcHqTWMDvdDKHpfB7ZL5FFcVXcAE0BfI6kn4/hBOOQ0QxkZUU+7oP7JxWueuFQenWlRi4F401kLN/wp+dxwT3SsyTNA9h+WI3+NaZx8WnJ9S4IP1ls0jYojdgIypFocSZnbW4Bq/oWg7HyckfyofEukBKFP7KeCNLvczr9spEqLb0x/HP+mIHo1mFREW+szsJQN4tIltTAstdBfb4hIgAZXCvI9Bg8QCLaDuo1dVG5a85Ozy0H1CLniK19KSghrMpq+FI2yA5R0uB8e8dNOwz8gYr3Sl0PRVvCWrzmVPSgZg9E3OXbz8UcKqGN/54qtxLQjeVFR8AIKPcwPP2FAkASGYl+Gq+0SBP1nN6JxQkKOom+UzQ9PxglLpV5X5+ysEgzEmAMz3+OpHF0zlMGRs+WE9RPplHiTYR31RsIo1Hn+TyMmz2apWUmeg5uoE/d9XSOVqKO4D4AUVczfgewJC82mMjKk9ggt9sX2sQd9KwUe11Jkh93ZbbhftjlUmBhAqUmkGe6Z5dZJ3ziSTdwOkGMfs3QV9ABMHTfJpWy4sLtXlW17IeCWcPN396v0uBL/FPb82Yb10Fs="
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in hamidashi.gemspec
4
4
  gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Seiei Miyagi
3
+ Copyright © 2015 [YassLab](http://yasslab.jp)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # Hamidashi
2
+ [![Build Status](https://travis-ci.org/yasslab/hamidashi.svg?branch=master)](https://travis-ci.org/yasslab/hamidashi)
3
+ [![Code Climate](https://codeclimate.com/github/yasslab/hamidashi/badges/gpa.svg)](https://codeclimate.com/github/yasslab/hamidashi)
4
+ [![Test Coverage](https://codeclimate.com/github/yasslab/hamidashi/badges/coverage.svg)](https://codeclimate.com/github/yasslab/hamidashi/coverage)
2
5
 
3
6
  Detect PDF text overflow.
4
7
 
@@ -49,9 +52,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
49
52
 
50
53
  ## Contributing
51
54
 
52
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hamidashi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yasslab/hamidashi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
53
56
 
54
57
 
55
58
  ## License
56
59
 
60
+ Copyright © 2015 [YassLab](http://yasslab.jp)
61
+
57
62
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new
5
+
6
+ task default: :test
data/exe/hamidashi CHANGED
@@ -2,7 +2,6 @@
2
2
  require 'docopt'
3
3
  require 'fileutils'
4
4
  require 'hamidashi'
5
- require 'pdf/reader'
6
5
  require 'tmpdir'
7
6
 
8
7
  doc = <<DOCOPT
@@ -40,21 +39,21 @@ if opt['--version']
40
39
  end
41
40
 
42
41
  pdf_path = File.expand_path(opt['<name>'])
43
- hamidashi = Hamidashi.new(Rational(opt['--margin']))
42
+ hamidashi = Hamidashi.new(Rational(opt['--margin']), pdf_path)
44
43
 
45
44
  if opt['preview']
46
45
  preview_path = File.expand_path("hamidashi-preview-#{Time.now.strftime("%Y%m%d%H%M%S")}-" + File.basename(pdf_path, '.pdf') + "-#{opt['--page']}.png")
47
- hamidashi.save_preview_page(pdf_path, opt['--page'], preview_path)
46
+ hamidashi.save_preview_page(Integer(opt['--page']), preview_path)
48
47
  exit
49
48
  end
50
49
 
51
50
  output_dir = File.expand_path("hamidashi-#{Time.now.strftime("%Y%m%d%H%M%S")}")
52
51
 
53
52
  Dir.mktmpdir('hamidashi') do |temp_dir|
54
- (0...PDF::Reader.new(pdf_path).page_count).each do |page|
55
- if hamidashi.overflow?(pdf_path, page)
53
+ (0...hamidashi.pdf_page_count).each do |page|
54
+ if hamidashi.overflow?(page)
56
55
  puts page
57
- hamidashi.save_page(pdf_path, page, "#{temp_dir}/#{page}.png")
56
+ hamidashi.save_page(page, "#{temp_dir}/#{page}.png")
58
57
  end
59
58
  end
60
59
 
data/hamidashi.gemspec CHANGED
@@ -26,9 +26,12 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- spec.add_dependency "pdf-reader"
30
29
  spec.add_dependency "docopt"
30
+ spec.add_dependency "rmagick"
31
31
  spec.add_development_dependency "bundler", "~> 1.10"
32
+ spec.add_development_dependency "cucumber"
33
+ spec.add_development_dependency "minitest"
32
34
  spec.add_development_dependency "pry"
33
35
  spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "review"
34
37
  end
data/lib/hamidashi.rb CHANGED
@@ -1,46 +1,70 @@
1
1
  require "hamidashi/version"
2
- require "shellwords"
2
+ require "RMagick"
3
3
 
4
4
  class Hamidashi
5
- def initialize(percentage)
6
- @crop_width = (width * percentage / 100).to_i
5
+ attr_reader :percentage
6
+
7
+ def initialize(percentage, pdf_path)
8
+ @percentage = percentage / 100r
9
+ @pdf_path = pdf_path
10
+ end
11
+
12
+ def overflow?(page)
13
+ cropped_page_img = cropped_img(page)
14
+ colornum = cropped_page_img.color_histogram.count
15
+
16
+ cropped_page_img.destroy!
17
+
18
+ expected_colornum != colornum
7
19
  end
8
20
 
9
- def overflow?(pdf_path, page)
10
- colornum=`convert -density 92 -geometry #{width} -crop #{crop} "#{pdf_path.shellescape}[#{page.to_s.shellescape}]" -format %c histogram:info: | wc -l`.to_i
11
- colornum != expected_colornum
21
+ def save_page(page, path)
22
+ pdf_image_list[page].write(path)
12
23
  end
13
24
 
14
- def save_page(pdf_path, page, path)
15
- `convert -density 92 -geometry #{width} "#{pdf_path.shellescape}[#{page.to_s.shellescape}]" #{path.shellescape}`
25
+ def save_preview_page(page, path)
26
+ page_img = pdf_image_list[page].dup
27
+
28
+ draw_preview_frame(page).draw(page_img)
29
+
30
+ page_img.write(path)
31
+
32
+ page_img.destroy!
16
33
  end
17
34
 
18
- def save_preview_page(pdf_path, page, path)
19
- `convert -density 92 -geometry #{width} -fill "rgba(0, 255, 0, 50%)" -strokewidth 0 -draw "rectangle #{width - crop_width},#{height},#{width},0" "#{pdf_path.shellescape}[#{page.to_s.shellescape}]" #{path.shellescape}`
35
+ def pdf_page_count
36
+ pdf_image_list.count
20
37
  end
21
38
 
22
39
  private
23
40
 
24
41
  # TODO provide a way to set these config values
25
42
 
26
- def crop
27
- "#{crop_width}x+#{width - crop_width}+0"
43
+ def cropped_img(page)
44
+ page_img = pdf_image_list[page]
45
+ x = right_margin_width(page)
46
+ page_img.crop(page_img.columns - x, 0, x, page_img.rows)
28
47
  end
29
48
 
30
- def crop_width
31
- @crop_width
49
+ def draw_preview_frame(page)
50
+ Magick::Draw.new.tap {|draw|
51
+ page_img = pdf_image_list[page]
52
+ draw.fill = 'rgba(0, 255, 0, 50%)'
53
+ draw.stroke_width(0)
54
+ draw.rectangle(page_img.columns - right_margin_width(page), 0, page_img.columns, page_img.rows)
55
+ }
32
56
  end
33
57
 
34
58
  def expected_colornum
35
59
  1
36
60
  end
37
61
 
38
- # FIXME
39
- def height
40
- 10000
62
+ def pdf_image_list
63
+ @pdf_image_list ||= Magick::ImageList.new(@pdf_path)
41
64
  end
42
65
 
43
- def width
44
- 640
66
+ def right_margin_width(page)
67
+ page_img = pdf_image_list[page]
68
+ (page_img.columns * percentage).to_i
45
69
  end
46
70
  end
@@ -1,3 +1,3 @@
1
1
  class Hamidashi
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamidashi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiei Miyagi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-15 00:00:00.000000000 Z
11
+ date: 2015-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: pdf-reader
14
+ name: docopt
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: docopt
28
+ name: rmagick
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cucumber
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: pry
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +108,20 @@ dependencies:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
110
  version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: review
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  description:
84
126
  email:
85
127
  - hanachin@gmail.com
@@ -92,7 +134,7 @@ files:
92
134
  - ".travis.yml"
93
135
  - CODE_OF_CONDUCT.md
94
136
  - Gemfile
95
- - LICENSE.txt
137
+ - LICENSE.md
96
138
  - README.md
97
139
  - Rakefile
98
140
  - bin/console