Skip to content

Commit

Permalink
Add option to interpret size option as icon height rather than font size
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnve committed Dec 5, 2024
1 parent 788a6ce commit b89866d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/prawn/icon/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,15 @@ def format_hash

def render
@pdf.font(@data.path) do
@pdf.text @unicode, @options
opts = @options
if @options.fetch(:size_mode, :font_size) == :icon_height
requested_size = @options[:size] || @pdf.font_size
actual_height = @pdf.font.height_at(requested_size)
adjusted_size = requested_size / actual_height * requested_size
opts = opts.merge(size: adjusted_size)
end

@pdf.text @unicode, opts
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/integration/icon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

expect(text.font_settings.first[:size]).to eq(60)
end

it 'should handle text options (icon height)' do
pdf.icon 'far-address-book', size: 60, size_mode: :icon_height
text = PDF::Inspector::Text.analyze(pdf.render)

expect(text.font_settings.first[:size]).to eq(58.25243)
end
end

context 'inline_format: true' do
Expand Down

0 comments on commit b89866d

Please sign in to comment.