prawn-disable_word_break 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b8364a4f45b68738bbc7312b486e8ed741885232bd7a17c96ce71309186e30df
4
+ data.tar.gz: e5394bb7d4f2a39365a8bca5a8cbdbf37027ef024e340a9aa6aed0bd69eca84f
5
+ SHA512:
6
+ metadata.gz: 2427b82f590702adba462958e0cff8ea203d382100fea7d281a8efc4826b0a8ad169146a367674f9e0a91a5f288494937e4c94156830a3d3ac769d99fc17241e
7
+ data.tar.gz: a3bb8bf3b97ecf0588b71d6690e6e04415bbe5f233771b3fb2a0c4a4fdd62066ade574e0949fc2ec68095c40928cdd2d421625dd4ac96f52b3d82bd48ec2ea70
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [hidakatsuya]
@@ -0,0 +1,33 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ name: Test on ruby ${{ matrix.ruby_version }}
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ ruby_version:
12
+ - 2.4.x
13
+ - 2.5.x
14
+ - 2.6.x
15
+ - 2.7.x
16
+ steps:
17
+ - uses: actions/checkout@v1
18
+ - name: Set up diff-pdf
19
+ run: |
20
+ sudo apt-get update
21
+ sudo apt-get install make automake g++ libpoppler-glib-dev poppler-utils libwxgtk3.0-dev
22
+ git clone https://github.com/vslavik/diff-pdf.git -b v0.3 --depth 1 /tmp/diff-pdf-src
23
+ cd /tmp/diff-pdf-src
24
+ ./bootstrap && ./configure && make && sudo make install
25
+ - name: Set up Ruby ${{ matrix.ruby_version }}
26
+ uses: actions/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby_version }}
29
+ - name: Build and test with Rake
30
+ run: |
31
+ gem install bundler
32
+ bundle install --jobs 4 --retry 3
33
+ bundle exec rake test
@@ -0,0 +1,4 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ /pkg/
4
+ /test/features/tmp/*.pdf
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hidakatsuya@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
@@ -0,0 +1,12 @@
1
+ FROM ruby:2.7.1
2
+
3
+ RUN apt-get update -qq && apt-get install -y build-essential xvfb
4
+
5
+ # Install diff-pdf
6
+ WORKDIR /tmp
7
+ RUN apt-get install -y libpoppler-glib-dev poppler-utils libwxgtk3.0-dev && curl -L https://github.com/vslavik/diff-pdf/archive/master.tar.gz -o diff-pdf-master.tar.gz && tar zxf diff-pdf-master.tar.gz && cd diff-pdf-master && ./bootstrap && ./configure && make && make install
8
+
9
+ RUN mkdir /prawn-disable_word_break
10
+
11
+ WORKDIR /prawn-disable_word_break
12
+ VOLUME /prawn-disable_word_break
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake', '>= 0'
6
+ gem 'test-unit', '>= 3.3.5'
7
+ gem 'test-unit-rr', '>= 1.0.5'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Katsuya HIDAKA
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,100 @@
1
+ # Prawn::DisableWordBreak
2
+
3
+ [![Test](https://github.com/hidakatsuya/prawn-disable_word_break/workflows/Test/badge.svg?branch=master)](https://github.com/hidakatsuya/prawn-disable_word_break/actions)
4
+
5
+ Prawn::DisableWordBreak is an extension that adds a method to disable word-breaking by character such as space and hyphen to [Prawn](https://github.com/prawnpdf/prawn).
6
+
7
+ ![](doc/comparison-of-word-breaking.png)
8
+
9
+ See [feature test](test/features/text_line_wrapping_test.rb) for details.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'prawn-disable_word_break'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle install
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install prawn-disable_word_break
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ require 'prawn/disable_word_break'
31
+
32
+ Prawn::Document.generate 'foo.pdf' do
33
+ disable_word_break do
34
+ # word-breaking is disabled here
35
+ text_box 'text without word-breaking', at: [100, 100], width: 50, height: 50
36
+ end
37
+
38
+ word_break(true) do
39
+ # word-breaking is disabled here
40
+ formatted_box [{ text: 'text without word-breaking' }], at: [100, 100], width: 50, height: 50
41
+ end
42
+
43
+ word_break(false) do
44
+ # word-breaking is disabled here
45
+ text_box 'text without word-breaking', at: [100, 100], width: 50, height: 50
46
+ end
47
+
48
+ # word-breaking is enabled here
49
+ formatted_box [{ text: 'text with word-breaking' }], at: [100, 100], width: 50, height: 50
50
+ end
51
+ ```
52
+
53
+ ## Supported Versions
54
+
55
+ ### Ruby
56
+
57
+ 2.6, 2.7
58
+
59
+ ### Prawn
60
+
61
+ 2.2+
62
+
63
+ ## Development
64
+
65
+ 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).
66
+
67
+ ### Testing
68
+
69
+ This project has two test types, each of which can be run with the following command:
70
+
71
+ $ bundle exec rake test:units
72
+ $ bundle exec rake test:features
73
+
74
+ Or, both tests can be run below:
75
+
76
+ $ bundle exec rake test
77
+
78
+ To run `test:features`, you need [diff-pdf](https://github.com/vslavik/diff-pdf). You can run by installing it or using a Docker container for testing.
79
+
80
+ Here's how to run `test:features` in the Docker container:
81
+
82
+ $ docker build -t prawn-disable_word_break-dev .
83
+ $ docker run -v $PWD:/prawn-disable_word_break:cached -it prawn-disable_word_break-dev bash
84
+
85
+ > /prawn-disable_word_break#
86
+ > /prawn-disable_word_break# bundle install
87
+ > /prawn-disable_word_break# bundle exec rake test:features
88
+
89
+ ## Contributing
90
+
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hidakatsuya/prawn-disable_word_break. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hidakatsuya/prawn-disable_word_wrap/blob/master/CODE_OF_CONDUCT.md).
92
+
93
+
94
+ ## License
95
+
96
+ (c) 2020 Katsuya HIDAKA. The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). See [LICENSE.txt](https://github.com/hidakatsuya/prawn-disable_word_break/blob/master/LICENSE.txt) for further details.
97
+
98
+ ## Code of Conduct
99
+
100
+ Everyone interacting in the Prawn::DisableWordBreak project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hidakatsuya/prawn-disable_word_break/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new('test:units') do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/units/**/*_test.rb']
8
+ end
9
+
10
+ Rake::TestTask.new('test:features') do |t|
11
+ t.libs << 'test'
12
+ t.libs << 'lib'
13
+ t.test_files = FileList['test/features/**/*_test.rb']
14
+ end
15
+
16
+ task test: %i( test:units test:features )
@@ -0,0 +1,12 @@
1
+ require 'prawn'
2
+
3
+ require_relative 'disable_word_break/version'
4
+ require_relative 'disable_word_break/disabler'
5
+ require_relative 'disable_word_break/formatted_box'
6
+
7
+ Prawn::DisableWordBreak::Disabler.tap { |mod|
8
+ Prawn::Document.include mod unless Prawn::Document.include?(mod)
9
+ }
10
+ Prawn::DisableWordBreak::FormattedBox.tap { |mod|
11
+ Prawn::Text::Formatted::Box.prepend mod unless Prawn::Text::Formatted::Box.include?(mod)
12
+ }
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prawn
4
+ module DisableWordBreak
5
+ module Disabler
6
+ def word_break(disable, &block)
7
+ if disable
8
+ disable_word_break(&block)
9
+ else
10
+ block.call
11
+ end
12
+ end
13
+
14
+ def disable_word_break
15
+ @word_break_disabled = true
16
+ yield
17
+ ensure
18
+ @word_break_disabled = false
19
+ end
20
+
21
+ def word_break_disabled?
22
+ defined?(@word_break_disabled) ? @word_break_disabled : false
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'line_wrap'
4
+
5
+ module Prawn
6
+ module DisableWordBreak
7
+ module FormattedBox
8
+ def initialize(*)
9
+ super
10
+ @line_wrap = DisableWordBreak::LineWrap.new
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prawn
4
+ module DisableWordBreak
5
+ class LineWrap < Text::Formatted::LineWrap
6
+ private
7
+
8
+ attr_reader :word_break_disabled
9
+
10
+ # Override
11
+ def initialize_line(options)
12
+ super
13
+ @word_break_disabled = @document.word_break_disabled?
14
+ end
15
+
16
+ # Override
17
+ def add_fragment_to_line(fragment)
18
+ if fragment == ''
19
+ true
20
+ elsif fragment == "\n"
21
+ @newline_encountered = true
22
+ false
23
+ else
24
+ if word_break_disabled
25
+ insert_fragment_without_word_break(fragment)
26
+ else
27
+ insert_fragment_with_word_break(fragment)
28
+ end
29
+ end
30
+ end
31
+
32
+ def insert_fragment_without_word_break(fragment)
33
+ fragment = delete_invisible_chars(fragment)
34
+ fragment_width = @document.width_of(fragment, kerning: @kerning)
35
+
36
+ if @accumulated_width + fragment_width <= @width
37
+ @accumulated_width += fragment_width
38
+ @fragment_output += fragment
39
+ fragment_finished(fragment)
40
+ true
41
+ else
42
+ end_of_the_line_reached(fragment)
43
+ fragment_finished(fragment)
44
+ false
45
+ end
46
+ end
47
+
48
+ def insert_fragment_with_word_break(fragment)
49
+ tokenize(fragment).each do |segment|
50
+ segment_width = if segment == zero_width_space(segment.encoding)
51
+ 0
52
+ else
53
+ @document.width_of(segment, kerning: @kerning)
54
+ end
55
+
56
+ if @accumulated_width + segment_width <= @width
57
+ @accumulated_width += segment_width
58
+ shy = soft_hyphen(segment.encoding)
59
+ if segment[-1] == shy
60
+ sh_width = @document.width_of(shy, kerning: @kerning)
61
+ @accumulated_width -= sh_width
62
+ end
63
+ @fragment_output += segment
64
+ else
65
+ if @accumulated_width.zero? && @line_contains_more_than_one_word
66
+ @line_contains_more_than_one_word = false
67
+ end
68
+ end_of_the_line_reached(segment)
69
+ fragment_finished(fragment)
70
+ return false
71
+ end
72
+ end
73
+
74
+ fragment_finished(fragment)
75
+ true
76
+ end
77
+
78
+ def delete_invisible_chars(fragment)
79
+ encoding = fragment.encoding
80
+
81
+ invisible_chars = [
82
+ soft_hyphen(encoding),
83
+ zero_width_space(encoding)
84
+ ].join
85
+ fragment.delete(invisible_chars)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prawn
4
+ module DisableWordBreak
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'lib/prawn/disable_word_break/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'prawn-disable_word_break'
5
+ spec.version = Prawn::DisableWordBreak::VERSION
6
+ spec.authors = ['Katsuya Hidaka']
7
+ spec.email = ['hidakatsuya@gmail.com']
8
+
9
+ spec.summary = 'Adds a method to disable word-breaking by character such as space and hyphen'
10
+ spec.description = 'Prawn::DisableWordBreak is an extension for Prawn that adds a method to disable word-breaking by character such as space and hyphen to Prawn'
11
+ spec.homepage = 'https://github.com/hidakatsuya/prawn-disable_word_break'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
14
+
15
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
17
+ end
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'prawn', '~> 2.2'
21
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prawn-disable_word_break
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Katsuya Hidaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prawn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ description: Prawn::DisableWordBreak is an extension for Prawn that adds a method
28
+ to disable word-breaking by character such as space and hyphen to Prawn
29
+ email:
30
+ - hidakatsuya@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".github/FUNDING.yml"
36
+ - ".github/workflows/test.yml"
37
+ - ".gitignore"
38
+ - CODE_OF_CONDUCT.md
39
+ - Dockerfile
40
+ - Gemfile
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - doc/comparison-of-word-breaking.png
45
+ - lib/prawn/disable_word_break.rb
46
+ - lib/prawn/disable_word_break/disabler.rb
47
+ - lib/prawn/disable_word_break/formatted_box.rb
48
+ - lib/prawn/disable_word_break/line_wrap.rb
49
+ - lib/prawn/disable_word_break/version.rb
50
+ - prawn-disable_word_break.gemspec
51
+ homepage: https://github.com/hidakatsuya/prawn-disable_word_break
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.4.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.1.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Adds a method to disable word-breaking by character such as space and hyphen
74
+ test_files: []