Skip to content

Commit

Permalink
Merge pull request #25 from jessedoyle/inline-cursor
Browse files Browse the repository at this point in the history
Fix Inline Icon Render Position
  • Loading branch information
jessedoyle authored Jun 25, 2016
2 parents 532213a + 17218cd commit aed8bcd
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 32 deletions.
26 changes: 8 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
language: ruby
before_install:
- gem install bundler
- bundle --version
rvm:
- 1.9.3
- 2.2.0
- rbx-2
- jruby-19mode

- 2.1.0-p0
- 2.2.4
- 2.3.0
- jruby-9.0.5.0
- rbx-3.19
gemfile:
- gemfiles/prawn-1.2.1.gemfile
- gemfiles/prawn-1.3.0.gemfile
- gemfiles/prawn-2.0.2.gemfile
- gemfiles/prawn-2.1.0.gemfile
- gemfiles/prawn-master.gemfile

matrix:
exclude:
- rvm: 1.9.3
gemfile: gemfiles/prawn-2.0.2.gemfile

- rvm: jruby-19mode
gemfile: gemfiles/prawn-2.0.2.gemfile


allow_failures:
- rvm: rbx-2
- gemfile: gemfiles/prawn-master.gemfile
- rvm: rbx-3.19
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.1 - Jun 24, 2016

- BUGFIX: Inline icons now properly render at the correct cursor position with the correct line gap and box leading[#24](https://github.com/jessedoyle/prawn-icon/issues/24). Thanks @ToniTornado for reporting!

# 1.1.0 - March 16, 2016

- Update FontAwesome from v4.4.0 to v4.5.0. See [changelog](http://fontawesome.io/icons#new).
Expand Down
5 changes: 0 additions & 5 deletions gemfiles/prawn-2.0.2.gemfile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'

gem 'prawn', '~> 1.2.1'
gem 'prawn', '~> 2.1.0'

gemspec path: '..'
26 changes: 21 additions & 5 deletions lib/prawn/icon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ def make_icon(key, opts = {})
# underlying text call.
#
def inline_icon(text, opts = {})
parsed = Icon::Parser.format(self, text)
content = Text::Formatted::Parser.format(parsed)
opts.merge!(inline_format: true, document: self)
Text::Formatted::Box.new(content, opts)
parsed = Icon::Parser.format(self, text)
content = Text::Formatted::Parser.format(parsed)
box_options = opts.merge(
inline_format: true,
document: self,
at: [bounds.left, cursor]
)
icon_box(content, box_options)
end

# Initialize a new Prawn::Icon, but don't render
Expand Down Expand Up @@ -170,6 +174,18 @@ def table_icon(key, opts = {})
make_icon(key, opts).format_hash
end
end

private

def icon_box(content, opts = {}) # :nodoc:
Text::Formatted::Box.new(content, opts).tap do |box|
box.render(dry_run: true)
self.y -= box.height
unless opts.fetch(:final_gap, true)
self.y -= box.line_gap + box.leading
end
end
end
end

attr_reader :set, :unicode
Expand Down Expand Up @@ -200,7 +216,7 @@ def render

private

def strip_specifier_from_key(key) #:nodoc:
def strip_specifier_from_key(key) # :nodoc:
reg = Regexp.new "#{@data.specifier}-"
key.sub(reg, '') # Only one specifier
end
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/icon/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

module Prawn
class Icon
VERSION = '1.1.0'.freeze
VERSION = '1.1.1'.freeze
end
end
2 changes: 0 additions & 2 deletions prawn-icon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency('pdf-inspector', '~> 1.2.1')
spec.add_development_dependency('rspec', '~> 3.4.0')
spec.add_development_dependency('rubocop', '~> 0.38.0')
spec.add_development_dependency('mocha')
spec.add_development_dependency('rake')
spec.add_development_dependency('simplecov')
spec.add_development_dependency('pdf-reader', '~> 1.4')

spec.description = <<-END_DESC
Expand Down
15 changes: 15 additions & 0 deletions spec/integration/icon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@
expect(text1.strings.first).to eq("\uf047")
expect(text2.strings.first).to eq("\uf047")
end

it 'renders the icon at the proper cursor position (#24)' do
icon_text = '<icon>fa-info-circle</icon> icon here!'
pdf = create_pdf
pdf.text 'Start'
pdf.move_down 10
pdf.text 'More'
pdf.move_down 20
icon = pdf.icon icon_text, inline_format: true
pdf.move_down 30
pdf.text 'End'

expect(icon.at.first).to eq(0)
expect(icon.at.last.round).to eq(734)
end
end

context 'without options' do
Expand Down

0 comments on commit aed8bcd

Please sign in to comment.