prawn-icon 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d57a618536d834a1bd0152e30fb00c47d676fe191c59cf951c615b51ac50eb23
4
- data.tar.gz: 1e9d4b34b75ebef98c0cbca35547f3f49a909670461d5e9b85d4baaab3299acf
3
+ metadata.gz: 65ec086141aaa9ec4ddbe0f192c2a5a56b1be5eed7857fd6d48692561c484efa
4
+ data.tar.gz: 925215c0ad8f8ae7ed3cff3ce2d6ded45e461b181f7f37f3aeb6d34824a177c8
5
5
  SHA512:
6
- metadata.gz: f1ba430c458287e398baf22c25d524036b9f77ad7f9c2d2bec39ce1557000bce273f604e77ef2b9581a8dd7fc08be77dee895017b6d2143cf3672115d0b81c09
7
- data.tar.gz: 4f1912f735e51d02758f971c6dc3ea6ea3162b4ec2c8dc358daed23344027ba8ae6fb220cae5c8ecb78f4f5140975038c16fb73892e6ebe25589d033532201e4
6
+ metadata.gz: 8c6bf1ac1d9242b0b6c319ff1aac9ee0f01bc744e19a40047d860815e4dc1f608c0e150ac8181f993932f16b1618e4354f8f60b0cecbcfe80e8360de5bfa18b5
7
+ data.tar.gz: c4d8601c087a96c442a237ebeb54b94e5e0cc86fec0aa7e0557b48225cd42d852035b811ad8c4bdbd69929c246f8564c62f6a429f97c36c81580b9c7a426b7b2
data/CHANGELOG.md CHANGED
@@ -1,12 +1,18 @@
1
+ # 4.1.0 - December 12, 2024
2
+
3
+ * Add a `size_mode` option to the `icon` method that scales the size of the rendered icon to fit within the requested value.
4
+
5
+ Please see the documentation [here](https://github.com/jessedoyle/prawn-icon?tab=readme-ov-file#icon-size-mode) for further information. Thanks @pepijnve! [Pull Request](https://github.com/jessedoyle/prawn-icon/pull/65)
6
+
1
7
  # 4.0.0 - November 25, 2024
2
8
 
3
- * **breaking change** - Update from FontAwesom 5.11.2 to 6.7.1. Please see the notes [here](https://fontawesome.com/changelog#v6-0-0) for information related to changed or removed icons in the set. Thanks @pepijnve! [https://github.com/jessedoyle/prawn-icon/pull/62](Pull Request)
9
+ * **breaking change** - Update from FontAwesome 5.11.2 to 6.7.1. Please see the notes [here](https://fontawesome.com/changelog#v6-0-0) for information related to changed or removed icons in the set. Thanks @pepijnve! [Pull Request](https://github.com/jessedoyle/prawn-icon/pull/62)
4
10
 
5
11
  # 3.1.0 - September 1, 2022
6
12
 
7
13
  * Update our CI matrix to include recent versions of Prawn and Ruby! Thanks @petergoldstein! (#55)
8
14
  * Resolve a few code smells that were flagged by Rubocop.
9
- * [Material Design Icons](https://materialdesignicons.com) are now supported! Currently version `7.0.96` is included. Thanks @maneex! [https://github.com/jessedoyle/prawn-icon/pull/59](Pull Request).
15
+ * [Material Design Icons](https://materialdesignicons.com) are now supported! Currently version `7.0.96` is included. Thanks @maneex! [Pull Request](https://github.com/jessedoyle/prawn-icon/pull/59).
10
16
  * Memoize calls to `Prawn::Icon::FontData#path` to improve performance.
11
17
 
12
18
  #### Material Design Icons
data/README.md CHANGED
@@ -101,7 +101,7 @@ If you wish to fork this repository and add a new font, you'll likely need to su
101
101
 
102
102
  ## Examples
103
103
 
104
- A Rake task is included to generate documents that display each icon and it's corresponding icon key.
104
+ A Rake task is included to generate documents that display each icon and its corresponding icon key.
105
105
 
106
106
  The command:
107
107
 
@@ -121,6 +121,23 @@ Prawn::Icon.configure do |config|
121
121
  end
122
122
  ```
123
123
 
124
+ ## Icon Size Mode
125
+
126
+ Some font families (in particular those of FontAwesome 6) define metrics that may render an icon at a size larger than requested (as described [here](https://github.com/jessedoyle/prawn-icon/pull/62#issuecomment-2501622305)).
127
+
128
+ Prawn::Icon provides a `size_mode` parameter that can be utilized to control this behaviour:
129
+
130
+ * `size_mode: :font_size` (**default**) - Renders the icon at a size calculated via font metrics. This may result in an icon that renders larger than requested due to ascender/descender metrics.
131
+ * `size_mode: :icon_height` - Renders the icon at a size scaled down to the requested size.
132
+
133
+ You can specify the size mode as follows:
134
+
135
+ ```ruby
136
+ Prawn::Document.generate('size_mode.pdf') do |pdf|
137
+ pdf.icon 'far-circle', size: 100, size_mode: :icon_height
138
+ end
139
+ ```
140
+
124
141
  ## Contributing
125
142
 
126
143
  I'll gladly accept pull requests that are well tested for any bug found in Prawn::Icon.
@@ -225,7 +225,16 @@ module Prawn
225
225
 
226
226
  def render
227
227
  @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
229
238
  end
230
239
  end
231
240
 
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Icon
11
- VERSION = '4.0.0'
11
+ VERSION = '4.1.0'
12
12
  end
13
13
  end
@@ -18,6 +18,13 @@ describe Prawn::Icon::Interface do
18
18
 
19
19
  expect(text.font_settings.first[:size]).to eq(60)
20
20
  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
21
28
  end
22
29
 
23
30
  context 'inline_format: true' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-icon
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Doyle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-26 00:00:00.000000000 Z
11
+ date: 2024-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -203,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  - !ruby/object:Gem::Version
204
204
  version: 1.3.6
205
205
  requirements: []
206
- rubygems_version: 3.5.23
206
+ rubygems_version: 3.5.22
207
207
  signing_key:
208
208
  specification_version: 4
209
209
  summary: Provides icon fonts for PrawnPDF