Skip to content

Commit 37c64e7

Browse files
authored
Merge pull request #65 from pepijnve/icon_size
Add option to interpret size option as icon height rather than font size
2 parents 00cae42 + 4eeea45 commit 37c64e7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/prawn/icon/interface.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,16 @@ def format_hash
225225

226226
def render
227227
@pdf.font(@data.path) do
228-
@pdf.text @unicode, @options
228+
opts = @options
229+
230+
if @options.fetch(:size_mode, :font_size) == :icon_height
231+
requested_size = @options[:size] || @pdf.font_size
232+
actual_height = @pdf.font.height_at(requested_size)
233+
adjusted_size = requested_size / actual_height * requested_size
234+
opts = opts.merge(size: adjusted_size)
235+
end
236+
237+
@pdf.text @unicode, opts
229238
end
230239
end
231240

spec/integration/icon_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818

1919
expect(text.font_settings.first[:size]).to eq(60)
2020
end
21+
22+
it 'should handle text options (icon height)' do
23+
pdf.icon 'far-address-book', size: 60, size_mode: :icon_height
24+
text = PDF::Inspector::Text.analyze(pdf.render)
25+
26+
expect(text.font_settings.first[:size]).to be_within(0.0001).of(58.25243)
27+
end
2128
end
2229

2330
context 'inline_format: true' do

0 commit comments

Comments
 (0)