Skip to content

Commit

Permalink
Merge branch 'master' into update-readme-for-release
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieujobin authored Jan 11, 2024
2 parents 67295c3 + 208c300 commit ca8e7d6
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
- "3.1"
- "3.2.0"
- "3.2"
- "3.3.0"
- "head"
- "jruby-9.3"
- "jruby-9.4"
Expand All @@ -62,6 +63,13 @@ jobs:
restore-keys: |
gems-${{ matrix.ruby }}-
- name: Install dependencies
if: ${{ startsWith(matrix.ruby, '2.') }}
run: |
gem install bundler -v 2.4.22
bundle config path ~/gems
bundle install --jobs 4 --retry 3
- name: Install dependencies
if: ${{ ! startsWith(matrix.ruby, '2.') }}
run: |
gem install bundler
bundle config path ~/gems
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

(Thomas Leitner)

## Fixed keyword arguments in Prawn::View

(Kim Burgestrand, [1284](https://github.com/prawnpdf/prawn/pull/1284))

### Look for glyph in correct font

Take the font style into account when looking for a glyph and fallback fonts are enabled.
Expand All @@ -46,6 +50,16 @@ Take the font style into account when looking for a glyph and fallback fonts are

(Alexander Mankuta)

### Fixed font caching

It's a subtle bug that could result in use of incorrect fonts.

(maerch, [#924](https://github.com/prawnpdf/prawn/pull/924), Alexander Mankuta)

### Fixed line spacing in text boxes with indentation

(Jakub Stasiak, [#1079](https://github.com/prawnpdf/prawn/pull/1079))

## PrawnPDF 2.4.0

### Added support for Ruby 3
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/font.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def find_font(name, options = {}) # :nodoc:
name = options[:file]
end
end
key = "#{name}:#{options[:font] || 0}"
key = "#{family}:#{name}:#{options[:font] || 0}"

if name.is_a? Prawn::Font
font_registry[key] = name
Expand Down
8 changes: 7 additions & 1 deletion lib/prawn/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,13 @@ def fill_formatted_text_box(text, options)
@all_text_printed = box.everything_printed?

self.y -= box.height
self.y -= box.line_gap + box.leading if @final_gap

# If there's no remaining_text we don't really want to treat this line
# in a special way, we printed everything we wanted so the special
# single_line logic should not be triggered here.
if @final_gap || (options[:single_line] && !@all_text_printed)
self.y -= box.line_gap + box.leading
end

remaining_text
end
Expand Down
4 changes: 2 additions & 2 deletions lib/prawn/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def document

# Delegates all unhandled calls to object returned by +document+ method.
# (which is an instance of Prawn::Document by default)
def method_missing(method_name, *arguments, &block)
def method_missing(method_name, *args, **kwargs, &block)
return super unless document.respond_to?(method_name)

document.public_send(method_name, *arguments, &block)
document.public_send(method_name, *args, **kwargs, &block)
end

def respond_to_missing?(method_name, _include_all = false)
Expand Down
24 changes: 24 additions & 0 deletions spec/prawn/font_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,28 @@ def page_should_not_include_font(font)
expect(pdf.font.character_count('Hello, world!')).to eq(13)
end
end

it 'properly caches fonts' do
pdf.font_families.update(
'DejaVu Sans' => {
normal: "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf",
bold: "#{Prawn::DATADIR}/fonts/DejaVuSans-Bold.ttf"
},
'Dustismo' => {
# This has to be the same font file as in the other family.
normal: "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf",
bold: "#{Prawn::DATADIR}/fonts/Dustismo_Roman.ttf"
},
)

pdf.font 'DejaVu Sans'

pdf.font 'Dustismo' do
pdf.text 'Dustismo bold', style: :bold
end

text = PDF::Inspector::Text.analyze(pdf.render)
font_name = text.font_settings.first[:name].to_s.sub(/\w+\+/, 'subset+')
expect(font_name).to eq 'subset+DustismoRoman'
end
end
38 changes: 38 additions & 0 deletions spec/prawn/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,44 @@
end
end

describe 'when :final_gap is set to false, there should still be ' \
'a gap between the first line and the rest' do
it 'spaces the first and the second line correctly' do
text = 'hello ' * 30
original_y = pdf.y
# First rendering with no indentation so we know what the correct
# render height should be
pdf.text(text, final_gap: false)
height_with_no_indentation = original_y - pdf.y
y_between_paragraphs = pdf.y
# The indentation size doesn't matter, it's about triggering
# a different path in the code
pdf.text(text, indent_paragraphs: 1, final_gap: false)
height_with_indentation = y_between_paragraphs - pdf.y
expect(height_with_indentation).to be_within(0.0001)
.of(height_with_no_indentation)
end
end

describe 'single line height with no final_gap should not depend on '\
'indentation' do
it 'does not affect the height of a single line' do
text = 'hello'
original_y = pdf.y
# First rendering with no indentation so we know what the correct
# render height should be
pdf.text(text, final_gap: false)
height_with_no_indentation = original_y - pdf.y
y_between_paragraphs = pdf.y
# The indentation size doesn't matter, it's about triggering
# a different path in the code
pdf.text(text, indent_paragraphs: 1, final_gap: false)
height_with_indentation = y_between_paragraphs - pdf.y
expect(height_with_indentation).to be_within(0.0001)
.of(height_with_no_indentation)
end
end

describe 'when wrap to new page, and first line of new page' \
' is not the start of a new paragraph, that line should' \
' not be indented' do
Expand Down
6 changes: 3 additions & 3 deletions spec/prawn/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
it 'delegates unhandled methods to object returned by document method' do
doc = instance_double('Document')
allow(view_object).to receive(:document).and_return(doc)

allow(doc).to receive(:some_delegated_method)
block = proc {}

view_object.some_delegated_method
view_object.some_delegated_method('positional', keyword: 'argument', &block)

expect(doc).to have_received(:some_delegated_method)
expect(doc).to have_received(:some_delegated_method).with('positional', keyword: 'argument', &block)
end

it 'allows a block-like DSL via the update method' do
Expand Down
4 changes: 2 additions & 2 deletions spec/prawn_manual_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
MANUAL_HASH =
case RUBY_ENGINE
when 'ruby'
'2c0279e0bff2a9120494a52aa46216c1871902b5e66a3537bd4d3cbd66db0096b43b6e1ae0e4e189b561c4db9fa1afacb6c41f260e3aaf942faae2fee352d35b'
'a2a111c8b3ef808b734c506dc9184520888bc5904c2eb12ab299a634d63e9e0f9ede52e54a701f346a3b48364c9e48ebb82a6b2351becde08e2382fe349158a9'
when 'jruby'
'51baf6440907e9e38d22f50deafa91572aec1174e621c044ae077cfe3d4361982a505dae5f013dd06f64f38cb9b3a38d5a3f8f0903849591774e298a3c91d39a'
'eb3742d593861f6ca35667198b796265a58ac63aecdb8415bdee2d191f83341bb466e3b3c136a8609acf9e7c589612fe8b19d97f99cfc183d78962c6e2aa3546'
end

RSpec.describe Prawn do
Expand Down

0 comments on commit ca8e7d6

Please sign in to comment.