From b89866d7f3492f81045ab4ad5bca5448a466b742 Mon Sep 17 00:00:00 2001 From: Pepijn Van Eeckhoudt Date: Sun, 1 Dec 2024 12:15:54 +0100 Subject: [PATCH] Add option to interpret size option as icon height rather than font size --- lib/prawn/icon/interface.rb | 10 +++++++++- spec/integration/icon_spec.rb | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/prawn/icon/interface.rb b/lib/prawn/icon/interface.rb index 1f50996..cd8f898 100644 --- a/lib/prawn/icon/interface.rb +++ b/lib/prawn/icon/interface.rb @@ -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 diff --git a/spec/integration/icon_spec.rb b/spec/integration/icon_spec.rb index 6b5ec73..8b6d6b6 100644 --- a/spec/integration/icon_spec.rb +++ b/spec/integration/icon_spec.rb @@ -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