pdflib_mini 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +9 -0
  5. data/CODE_OF_CONDUCT.md +49 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +160 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/pdflib_mini.rb +38 -0
  13. data/lib/pdflib_mini/handle.rb +4 -0
  14. data/lib/pdflib_mini/handle/action.rb +10 -0
  15. data/lib/pdflib_mini/handle/asset.rb +10 -0
  16. data/lib/pdflib_mini/handle/base.rb +16 -0
  17. data/lib/pdflib_mini/handle/bookmark.rb +10 -0
  18. data/lib/pdflib_mini/handle/color.rb +10 -0
  19. data/lib/pdflib_mini/handle/data3d.rb +10 -0
  20. data/lib/pdflib_mini/handle/data3d_view.rb +10 -0
  21. data/lib/pdflib_mini/handle/folder.rb +22 -0
  22. data/lib/pdflib_mini/handle/font.rb +42 -0
  23. data/lib/pdflib_mini/handle/graphics.rb +39 -0
  24. data/lib/pdflib_mini/handle/graphics_state.rb +16 -0
  25. data/lib/pdflib_mini/handle/image.rb +39 -0
  26. data/lib/pdflib_mini/handle/item.rb +22 -0
  27. data/lib/pdflib_mini/handle/layer.rb +17 -0
  28. data/lib/pdflib_mini/handle/path.rb +45 -0
  29. data/lib/pdflib_mini/handle/pattern.rb +16 -0
  30. data/lib/pdflib_mini/handle/pdf.rb +6 -0
  31. data/lib/pdflib_mini/handle/pdf/document.rb +51 -0
  32. data/lib/pdflib_mini/handle/pdf/page.rb +72 -0
  33. data/lib/pdflib_mini/handle/profile.rb +10 -0
  34. data/lib/pdflib_mini/handle/shading.rb +16 -0
  35. data/lib/pdflib_mini/handle/table_cell.rb +39 -0
  36. data/lib/pdflib_mini/handle/template.rb +16 -0
  37. data/lib/pdflib_mini/handle/textflow.rb +42 -0
  38. data/lib/pdflib_mini/handle/textline.rb +33 -0
  39. data/lib/pdflib_mini/info.rb +237 -0
  40. data/lib/pdflib_mini/info_reader.rb +54 -0
  41. data/lib/pdflib_mini/pdflib.rb +457 -0
  42. data/lib/pdflib_mini/version.rb +3 -0
  43. data/pdflib_mini.gemspec +28 -0
  44. metadata +142 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac6c70a4f3d759d36b442cae5f7a9ff26f876bc3
4
+ data.tar.gz: 8f4a353c22262f01ac88fff07ff7d8c185638468
5
+ SHA512:
6
+ metadata.gz: 09d93ee6c6a8d68734dce4283716d91d6497838a6917fac45f0ed15c6b8a77e50b65f2746d891fb87e1b000e68db3de6cb68f40967d0bfa38d2b2ac8a8f00ee5
7
+ data.tar.gz: 90810954a8fe0fef5bc9461ef14096dad36e0451c85dd3d0bc6fb5edc718aa720d507c25380db99f317475ca29d349ceb2a28454694ddaa6294a3814c43bb47f
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1
5
+ - 2.2
6
+ before_install: gem install bundler -v 1.11.2
7
+ script:
8
+ - bundle install
9
+ - bundle exec rake spec
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at trot.thunder@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pdflib_mini.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Takumi IINO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,160 @@
1
+ # PdflibMini
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/pdflib_mini.svg)](http://badge.fury.io/rb/pdflib_mini)
4
+ [![Build Status](https://travis-ci.org/troter/pdflib_mini.svg?branch=master)](https://travis-ci.org/troter/pdflib_mini)
5
+ [![Coverage Status](https://coveralls.io/repos/troter/pdflib_mini/badge.svg)](https://coveralls.io/r/troter/pdflib_mini)
6
+ [![Code Climate](https://codeclimate.com/github/troter/pdflib_mini/badges/gpa.svg)](https://codeclimate.com/github/troter/pdflib_mini)
7
+
8
+ PdflibMini is a mini wrapper for PDFlib. this provides useful methods and some extension point.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'pdflib_mini'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install pdflib_mini
25
+
26
+ ## Usage
27
+
28
+ Require PDFlib and this gem, and replace PDFlib by PDFlibMini.
29
+
30
+ ```ruby
31
+ require './PDFlib'
32
+ require 'pdflib_mini'
33
+
34
+ # p = PDFlib.new
35
+ p = PDFlibMini.new
36
+ ```
37
+
38
+ PdflibMini does not break the interface of PDFlib.
39
+
40
+ ## Handle object
41
+
42
+ PdflibMini returns a handle object that wrapping PDFlib's handle in most cases.
43
+
44
+ ```ruby
45
+ p = PDFlilbMini.new
46
+ p.load_font("Helvetica", "unicode", '').class # => PdflibMini::Handle::Font
47
+ p.load_image('auto', imagefile, '').class # => PdflibMini::Handle::Image
48
+ p.open_pdi_document(infile, '').class # => PdflibMini::Handle::Pdf::Document
49
+ ```
50
+
51
+ ### Easy access to information for handle object
52
+
53
+ Handle object has reader methods there easy access to information for itself.
54
+
55
+ ```ruby
56
+ # raw (float) values
57
+ doc = p.open_pdi_document(infile, '')
58
+ page = doc.open_pdi_page(1, '')
59
+ page.pagewidth
60
+ page.pageheight
61
+
62
+ # string values
63
+ image = p.load_image('auto', imagefile, '')
64
+ image.filename
65
+ image.imagetype
66
+
67
+ font = p.load_font('Helvetica', 'unicode', '')
68
+ font.feature('name=liga')
69
+ font.featurelist
70
+
71
+ # handle object
72
+ font.clippingpath # PdflibMini::Handle::Path instance
73
+
74
+ # boolean
75
+ font.hostfont
76
+ font.symbolfont? # more ruby-ish
77
+
78
+ # conversion
79
+ font.clippingpath(as: :path) # PdflibMini::Handle::Path instance
80
+ font.clippingpath(as: :raw) # float (PDFlib's handle)
81
+ image.imagetype # string
82
+ image.imagetype(as: :raw) # float (PDFlib's string index)
83
+ ```
84
+
85
+ ### Handle specific methods.
86
+
87
+ Handle object has some method like `fit_xxx`, `info_xxx`, and `fit_xxxblock`.
88
+
89
+ ```ruby
90
+ doc = p.open_pdi_document(infile, '')
91
+ page = doc.open_pdi_page(1, '')
92
+ page.fit_pdi_page(0, 0, '')
93
+
94
+ image = p.load_image('auto', imagefile, '')
95
+ image.info_image('imagewidth', '')
96
+ ```
97
+
98
+ ### Extension point
99
+
100
+ Handle object is not singleton. it can be easily extended.
101
+
102
+ ```ruby
103
+ image = p.load_image('auto', imagefile, '')
104
+
105
+ module ImagePathname
106
+ def filename(*args)
107
+ Pathname(super(*args))
108
+ end
109
+ end
110
+
111
+ # extend each instance
112
+ image.extend ImagePathname
113
+
114
+ # or prepend module
115
+ module PdflibMini
116
+ module Handle
117
+ class Image
118
+ prepend ImagePathname
119
+ end
120
+ end
121
+ end
122
+
123
+ image.filename.expand_path
124
+ ```
125
+
126
+ ## Using blocks for scope management
127
+
128
+ Passing blocks to begin_xxx, open_xxx, and some other methods.
129
+
130
+ ```ruby
131
+ p = PDFlilbMini.new
132
+ p.begin_document(outfile, '') do |result|
133
+ fail if result == -1
134
+ p.open_pdi_document(infile, '') do |indoc|
135
+ fail if indoc == -1
136
+ indoc.open_pdi_page(1, '') do |inpage|
137
+ fail if (inpage == -1)
138
+ p.begin_page_ext(10, 10, '') do
139
+ inpage.fit_pdi_page(0, 0, '')
140
+ end
141
+ end
142
+ end
143
+ end
144
+ ```
145
+
146
+ ## Development
147
+
148
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
149
+
150
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
151
+
152
+ ## Contributing
153
+
154
+ Bug reports and pull requests are welcome on GitHub at https://github.com/troter/pdflib_mini. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
155
+
156
+
157
+ ## License
158
+
159
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
160
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pdflib_mini"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ require 'delegate'
2
+ require_relative 'pdflib_mini/info'
3
+ require_relative 'pdflib_mini/info_reader'
4
+ require_relative 'pdflib_mini/handle'
5
+ require_relative 'pdflib_mini/handle/base'
6
+ require_relative 'pdflib_mini/handle/action'
7
+ require_relative 'pdflib_mini/handle/asset'
8
+ require_relative 'pdflib_mini/handle/bookmark'
9
+ require_relative 'pdflib_mini/handle/color'
10
+ require_relative 'pdflib_mini/handle/data3d'
11
+ require_relative 'pdflib_mini/handle/data3d_view'
12
+ require_relative 'pdflib_mini/handle/folder'
13
+ require_relative 'pdflib_mini/handle/font'
14
+ require_relative 'pdflib_mini/handle/graphics'
15
+ require_relative 'pdflib_mini/handle/image'
16
+ require_relative 'pdflib_mini/handle/item'
17
+ require_relative 'pdflib_mini/handle/layer'
18
+ require_relative 'pdflib_mini/handle/path'
19
+ require_relative 'pdflib_mini/handle/pattern'
20
+ require_relative 'pdflib_mini/handle/pdf'
21
+ require_relative 'pdflib_mini/handle/pdf/document'
22
+ require_relative 'pdflib_mini/handle/pdf/page'
23
+ require_relative 'pdflib_mini/handle/profile'
24
+ require_relative 'pdflib_mini/handle/shading'
25
+ require_relative 'pdflib_mini/handle/table_cell'
26
+ require_relative 'pdflib_mini/handle/template'
27
+ require_relative 'pdflib_mini/handle/textflow'
28
+ require_relative 'pdflib_mini/handle/textline'
29
+ require_relative 'pdflib_mini/pdflib'
30
+ require_relative "pdflib_mini/version"
31
+
32
+ module PdflibMini
33
+ def self.new
34
+ PdflibMini::Pdflib.new(Kernel.const_get(:PDFlib).new)
35
+ end
36
+ end
37
+
38
+ PDFlibMini = PdflibMini
@@ -0,0 +1,4 @@
1
+ module PdflibMini
2
+ module Handle
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Action < Base
4
+ def initialize(action, p)
5
+ super(action)
6
+ @p = p
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Asset < Base
4
+ def initialize(asset, p)
5
+ super(asset)
6
+ @p = p
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module PdflibMini
2
+ module Handle
3
+ Error = Class.new(SimpleDelegator)
4
+ ERROR = Error.new(-1)
5
+
6
+ class Base < SimpleDelegator
7
+ def self.create(*args)
8
+ if args.first == -1
9
+ ERROR
10
+ else
11
+ new(*args)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Bookmark < Base
4
+ def initialize(bookmark, p)
5
+ super(bookmark)
6
+ @p = p
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Color < Base
4
+ def initialize(color, p)
5
+ super(color)
6
+ @p = p
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Data3d < Base
4
+ def initialize(data3d, p)
5
+ super(data3d)
6
+ @p = p
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Data3dView < Base
4
+ def initialize(data3d_view, p)
5
+ super(data3d_view)
6
+ @p = p
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Folder < Base
4
+ def initialize(folder, p)
5
+ super(folder)
6
+ @p = p
7
+ end
8
+
9
+ # 12.6 PDF Packages and Portfolios
10
+ # int add_portfolio_folder(int parent, string foldername, string optlist)
11
+ def add_portfolio_folder(*args)
12
+ @p.add_portfolio_folder(self, *args)
13
+ end
14
+
15
+ # 12.6 PDF Packages and Portfolios
16
+ # int add_portfolio_file(int folder, string filename, string optlist)
17
+ def add_portfolio_file(*args)
18
+ @p.add_portfolio_file(self, *args)
19
+ end
20
+ end
21
+ end
22
+ end