prawn-icon 2.5.0 → 3.0.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: cdc8d2f00cba2e00c1205ed4de7c247b0f38b27aa853923d3b1f9f4860e95308
4
- data.tar.gz: d5911e59b2076987f2cf47ba1f2ec2f51f5cd3588d268f528287ce88bcafca05
3
+ metadata.gz: 8c9cf8d2f79db2e2732626f6b46ebb9f0a019243b29e68379ccc95e63a604dbd
4
+ data.tar.gz: a3f67c49dd586f4c45ec9ebcf846514d38f08b6aadd031ca60028fa464a09633
5
5
  SHA512:
6
- metadata.gz: d0ac31b6d85219aa25a593fc9a14c39cae53876f67290b9b3406e2aaf1dd416de3d37c184330d8f8aa2b5e891e7532c7f487d9270a340a2b4dcbfc19e97a09d8
7
- data.tar.gz: 02a6738e896b3e7decbd790e302233cd49ce04c7022be9cb4a4f399fd76ec6f49f361ee4f9d6ebc9b7621f83cc316720735c5766770942cf0a820028238dc89a
6
+ metadata.gz: 1bf95fa8ae5852d32880167fa6d0fcbc24498b43d0a3db8b5ea4eba6358f403fa4c08ceb68e9a7581a9e637e73a9b6d8774446f09d72c517f4f1098a5cd56230
7
+ data.tar.gz: ce1dce62f8eabb83c543a8f596848d0417cc2520f706bc6cb2e420850410f7889020d2ed33e231f82181988ae9532ec3d9c9ffa1f2fb12018479e6f94b3ffeb4
@@ -1,3 +1,36 @@
1
+ # 3.0.0 - November 10, 2020
2
+
3
+ * **breaking change** - Fix incorrect layout and line-wrapping logic for inline-formatted icons. Please see [Inline Format Changes](#inline-format-changes) for more details.
4
+ * Add a `#formatted_icon_box` method to retain the previous inline icon behaviour.
5
+ * Allow `#formatted_icon_box` to accept absolute positioning parameters (`x`, `y`, and `at`). Thanks @navinspm!
6
+ * Update fontawesome from version `5.11.2` to `5.15.1`.
7
+ * See FontAwesome's [upgrade guide](https://github.com/FortAwesome/Font-Awesome/blob/57005cea6da7d1c67f3466974aecd25485f60452/UPGRADING.md) for more details.
8
+ * Introduce a configuration mechanism so that the font directory can be customized as follows:
9
+
10
+ ```ruby
11
+ Prawn::Icon.configure do |config|
12
+ config.font_directory = '/path/to/fonts'
13
+ end
14
+ ```
15
+
16
+ * Deprecate the global variables of `Prawn::Icon::Base::FONTDIR` and `Prawn::Icon::Compatibility::SHIMS`. Use `Prawn::Icon.configuration.font_directory` and `Prawn::Icon::Compatibility.shims` instead.
17
+ * Use `Gem::Specification#full_gem_path` to get the root path of the gem directory to resolve https://github.com/jessedoyle/prawn-icon/issues/45.
18
+
19
+ #### Inline Format Changes
20
+
21
+ As noted in https://github.com/jessedoyle/prawn-icon/issues/49, `Prawn::Icon` did not correctly respect page boundaries for inline-formatted icons.
22
+
23
+ The fix for the issue requires `Prawn::Icon` to use the inline layout and formatting logic implemented in `Prawn`.
24
+
25
+ This change has ramifications to the `#icon` and `#inline_icon` method return values, but most applications should not require changes.
26
+
27
+ Changes are listed below:
28
+
29
+ * `#icon` - returns `nil` with the `inline_format: true` parameter.
30
+ * `#inline_icon` - returns `nil` (instead of a `Prawn::Text::Formatted::Box` instance).
31
+
32
+ You can call `#formatted_icon_box` to retain the previous inline icon functionality.
33
+
1
34
  # 2.5.0 - October 4, 2019
2
35
 
3
36
  * Update FontAwesome from `5.8.2` to `5.11.2`.
data/README.md CHANGED
@@ -110,6 +110,16 @@ rake legend
110
110
 
111
111
  should generate these files when run from Prawn::Icon's gem directory.
112
112
 
113
+ ## Configuration
114
+
115
+ You can optionally configure Prawn::Icon to use an alternate data directory for font files.
116
+
117
+ ```ruby
118
+ Prawn::Icon.configure do |config|
119
+ config.font_directory = '/path/to/my/fonts'
120
+ end
121
+ ```
122
+
113
123
  ## Contributing
114
124
 
115
125
  I'll gladly accept pull requests that are well tested for any bug found in Prawn::Icon.
data/Rakefile CHANGED
@@ -31,4 +31,3 @@ task :legend do
31
31
  end
32
32
 
33
33
  RuboCop::RakeTask.new
34
-
Binary file
@@ -1,12 +1,11 @@
1
1
  ---
2
2
  fab:
3
- __font_version__: 5.11.2
3
+ __font_version__: 5.15.1
4
4
  500px: ""
5
5
  accessible-icon: ""
6
6
  accusoft: ""
7
7
  acquisitions-incorporated: ""
8
8
  adn: ""
9
- adobe: ""
10
9
  adversal: ""
11
10
  affiliatetheme: ""
12
11
  airbnb: ""
@@ -67,6 +66,7 @@ fab:
67
66
  centos: ""
68
67
  chrome: ""
69
68
  chromecast: ""
69
+ cloudflare: ""
70
70
  cloudscale: ""
71
71
  cloudsmith: ""
72
72
  cloudversify: ""
@@ -97,7 +97,9 @@ fab:
97
97
  cuttlefish: ""
98
98
  d-and-d: ""
99
99
  d-and-d-beyond: ""
100
+ dailymotion: ""
100
101
  dashcube: ""
102
+ deezer: ""
101
103
  delicious: ""
102
104
  deploydog: ""
103
105
  deskpro: ""
@@ -120,6 +122,7 @@ fab:
120
122
  earlybirds: ""
121
123
  ebay: ""
122
124
  edge: ""
125
+ edge-legacy: ""
123
126
  elementor: ""
124
127
  ello: ""
125
128
  ember: ""
@@ -139,6 +142,7 @@ fab:
139
142
  fedora: ""
140
143
  figma: ""
141
144
  firefox: ""
145
+ firefox-browser: ""
142
146
  first-order: ""
143
147
  first-order-alt: ""
144
148
  firstdraft: ""
@@ -179,6 +183,7 @@ fab:
179
183
  goodreads-g: ""
180
184
  google: ""
181
185
  google-drive: ""
186
+ google-pay: ""
182
187
  google-play: ""
183
188
  google-plus: ""
184
189
  google-plus-g: ""
@@ -188,20 +193,26 @@ fab:
188
193
  grav: ""
189
194
  gripfire: ""
190
195
  grunt: ""
196
+ guilded: ""
191
197
  gulp: ""
192
198
  hacker-news: ""
193
199
  hacker-news-square: ""
194
200
  hackerrank: ""
195
201
  hips: ""
196
202
  hire-a-helper: ""
203
+ hive: ""
197
204
  hooli: ""
198
205
  hornbill: ""
199
206
  hotjar: ""
200
207
  houzz: ""
201
208
  html5: ""
202
209
  hubspot: ""
210
+ ideal: ""
203
211
  imdb: ""
212
+ innosoft: ""
204
213
  instagram: ""
214
+ instagram-square: ""
215
+ instalod: ""
205
216
  intercom: ""
206
217
  internet-explorer: ""
207
218
  invision: ""
@@ -249,9 +260,11 @@ fab:
249
260
  meetup: ""
250
261
  megaport: ""
251
262
  mendeley: ""
263
+ microblog: ""
252
264
  microsoft: ""
253
265
  mix: ""
254
266
  mixcloud: ""
267
+ mixer: ""
255
268
  mizuni: ""
256
269
  modx: ""
257
270
  monero: ""
@@ -263,6 +276,7 @@ fab:
263
276
  npm: ""
264
277
  ns8: ""
265
278
  nutritionix: ""
279
+ octopus-deploy: ""
266
280
  odnoklassniki: ""
267
281
  odnoklassniki-square: ""
268
282
  old-republic: ""
@@ -278,6 +292,7 @@ fab:
278
292
  patreon: ""
279
293
  paypal: ""
280
294
  penny-arcade: ""
295
+ perbyte: ""
281
296
  periscope: ""
282
297
  phabricator: ""
283
298
  phoenix-framework: ""
@@ -287,6 +302,7 @@ fab:
287
302
  pied-piper-alt: ""
288
303
  pied-piper-hat: ""
289
304
  pied-piper-pp: ""
305
+ pied-piper-square: ""
290
306
  pinterest: ""
291
307
  pinterest-p: ""
292
308
  pinterest-square: ""
@@ -316,6 +332,7 @@ fab:
316
332
  rev: ""
317
333
  rocketchat: ""
318
334
  rockrms: ""
335
+ rust: ""
319
336
  safari: ""
320
337
  salesforce: ""
321
338
  sass: ""
@@ -326,6 +343,7 @@ fab:
326
343
  sellsy: ""
327
344
  servicestack: ""
328
345
  shirtsinbulk: ""
346
+ shopify: ""
329
347
  shopware: ""
330
348
  simplybuilt: ""
331
349
  sistrix: ""
@@ -372,6 +390,7 @@ fab:
372
390
  themeco: ""
373
391
  themeisle: ""
374
392
  think-peaks: ""
393
+ tiktok: ""
375
394
  trade-federation: ""
376
395
  trello: ""
377
396
  tripadvisor: ""
@@ -385,7 +404,10 @@ fab:
385
404
  ubuntu: ""
386
405
  uikit: ""
387
406
  umbraco: ""
407
+ uncharted: ""
388
408
  uniregistry: ""
409
+ unity: ""
410
+ unsplash: ""
389
411
  untappd: ""
390
412
  ups: ""
391
413
  usb: ""
@@ -403,6 +425,7 @@ fab:
403
425
  vk: ""
404
426
  vnv: ""
405
427
  vuejs: ""
428
+ watchman-monitoring: ""
406
429
  waze: ""
407
430
  weebly: ""
408
431
  weibo: ""
@@ -414,6 +437,7 @@ fab:
414
437
  windows: ""
415
438
  wix: ""
416
439
  wizards-of-the-coast: ""
440
+ wodu: ""
417
441
  wolf-pack-battalion: ""
418
442
  wordpress: ""
419
443
  wordpress-simple: ""
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  far:
3
- __font_version__: 5.11.2
3
+ __font_version__: 5.15.1
4
4
  address-book: ""
5
5
  address-card: ""
6
6
  angry: ""
Binary file
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  fas:
3
- __font_version__: 5.11.2
3
+ __font_version__: 5.15.1
4
4
  ad: ""
5
5
  address-book: ""
6
6
  address-card: ""
@@ -54,6 +54,9 @@ fas:
54
54
  backspace: ""
55
55
  backward: ""
56
56
  bacon: ""
57
+ bacteria: ""
58
+ bacterium: ""
59
+ bahai: ""
57
60
  balance-scale: ""
58
61
  balance-scale-left: ""
59
62
  balance-scale-right: ""
@@ -101,6 +104,7 @@ fas:
101
104
  bowling-ball: ""
102
105
  box: ""
103
106
  box-open: ""
107
+ box-tissue: ""
104
108
  boxes: ""
105
109
  braille: ""
106
110
  brain: ""
@@ -138,6 +142,7 @@ fas:
138
142
  car-battery: ""
139
143
  car-crash: ""
140
144
  car-side: ""
145
+ caravan: ""
141
146
  caret-down: ""
142
147
  caret-left: ""
143
148
  caret-right: ""
@@ -222,6 +227,7 @@ fas:
222
227
  compact-disc: ""
223
228
  compass: ""
224
229
  compress: ""
230
+ compress-alt: ""
225
231
  compress-arrows-alt: ""
226
232
  concierge-bell: ""
227
233
  cookie: ""
@@ -257,6 +263,7 @@ fas:
257
263
  dice-two: ""
258
264
  digital-tachograph: ""
259
265
  directions: ""
266
+ disease: ""
260
267
  divide: ""
261
268
  dizzy: ""
262
269
  dna: ""
@@ -298,6 +305,7 @@ fas:
298
305
  exclamation-circle: ""
299
306
  exclamation-triangle: ""
300
307
  expand: ""
308
+ expand-alt: ""
301
309
  expand-arrows-alt: ""
302
310
  external-link-alt: ""
303
311
  external-link-square-alt: ""
@@ -307,6 +315,7 @@ fas:
307
315
  fan: ""
308
316
  fast-backward: ""
309
317
  fast-forward: ""
318
+ faucet: ""
310
319
  fax: ""
311
320
  feather: ""
312
321
  feather-alt: ""
@@ -412,7 +421,9 @@ fas:
412
421
  hamsa: ""
413
422
  hand-holding: ""
414
423
  hand-holding-heart: ""
424
+ hand-holding-medical: ""
415
425
  hand-holding-usd: ""
426
+ hand-holding-water: ""
416
427
  hand-lizard: ""
417
428
  hand-middle-finger: ""
418
429
  hand-paper: ""
@@ -424,18 +435,25 @@ fas:
424
435
  hand-pointer: ""
425
436
  hand-rock: ""
426
437
  hand-scissors: ""
438
+ hand-sparkles: ""
427
439
  hand-spock: ""
428
440
  hands: ""
429
441
  hands-helping: ""
442
+ hands-wash: ""
430
443
  handshake: ""
444
+ handshake-alt-slash: ""
445
+ handshake-slash: ""
431
446
  hanukiah: ""
432
447
  hard-hat: ""
433
448
  hashtag: ""
434
449
  hat-cowboy: ""
435
450
  hat-cowboy-side: ""
436
451
  hat-wizard: ""
437
- haykal: ""
438
452
  hdd: ""
453
+ head-side-cough: ""
454
+ head-side-cough-slash: ""
455
+ head-side-mask: ""
456
+ head-side-virus: ""
439
457
  heading: ""
440
458
  headphones: ""
441
459
  headphones-alt: ""
@@ -456,6 +474,7 @@ fas:
456
474
  hospital: ""
457
475
  hospital-alt: ""
458
476
  hospital-symbol: ""
477
+ hospital-user: ""
459
478
  hot-tub: ""
460
479
  hotdog: ""
461
480
  hotel: ""
@@ -464,6 +483,7 @@ fas:
464
483
  hourglass-half: ""
465
484
  hourglass-start: ""
466
485
  house-damage: ""
486
+ house-user: ""
467
487
  hryvnia: ""
468
488
  i-cursor: ""
469
489
  ice-cream: ""
@@ -497,6 +517,7 @@ fas:
497
517
  language: ""
498
518
  laptop: ""
499
519
  laptop-code: ""
520
+ laptop-house: ""
500
521
  laptop-medical: ""
501
522
  laugh: ""
502
523
  laugh-beam: ""
@@ -526,6 +547,8 @@ fas:
526
547
  long-arrow-alt-up: ""
527
548
  low-vision: ""
528
549
  luggage-cart: ""
550
+ lungs: ""
551
+ lungs-virus: ""
529
552
  magic: ""
530
553
  magnet: ""
531
554
  mail-bulk: ""
@@ -616,6 +639,7 @@ fas:
616
639
  pen-square: ""
617
640
  pencil-alt: ""
618
641
  pencil-ruler: ""
642
+ people-arrows: ""
619
643
  people-carry: ""
620
644
  pepper-hot: ""
621
645
  percent: ""
@@ -635,6 +659,7 @@ fas:
635
659
  plane: ""
636
660
  plane-arrival: ""
637
661
  plane-departure: ""
662
+ plane-slash: ""
638
663
  play: ""
639
664
  play-circle: ""
640
665
  plug: ""
@@ -658,6 +683,8 @@ fas:
658
683
  print: ""
659
684
  procedures: ""
660
685
  project-diagram: ""
686
+ pump-medical: ""
687
+ pump-soap: ""
661
688
  puzzle-piece: ""
662
689
  qrcode: ""
663
690
  question: ""
@@ -720,6 +747,7 @@ fas:
720
747
  share-square: ""
721
748
  shekel-sign: ""
722
749
  shield-alt: ""
750
+ shield-virus: ""
723
751
  ship: ""
724
752
  shipping-fast: ""
725
753
  shoe-prints: ""
@@ -735,6 +763,7 @@ fas:
735
763
  signal: ""
736
764
  signature: ""
737
765
  sim-card: ""
766
+ sink: ""
738
767
  sitemap: ""
739
768
  skating: ""
740
769
  skiing: ""
@@ -755,6 +784,7 @@ fas:
755
784
  snowflake: ""
756
785
  snowman: ""
757
786
  snowplow: ""
787
+ soap: ""
758
788
  socks: ""
759
789
  solar-panel: ""
760
790
  sort: ""
@@ -796,8 +826,11 @@ fas:
796
826
  stop: ""
797
827
  stop-circle: ""
798
828
  stopwatch: ""
829
+ stopwatch-20: ""
799
830
  store: ""
800
831
  store-alt: ""
832
+ store-alt-slash: ""
833
+ store-slash: ""
801
834
  stream: ""
802
835
  street-view: ""
803
836
  strikethrough: ""
@@ -858,6 +891,7 @@ fas:
858
891
  toggle-on: ""
859
892
  toilet: ""
860
893
  toilet-paper: ""
894
+ toilet-paper-slash: ""
861
895
  toolbox: ""
862
896
  tools: ""
863
897
  tooth: ""
@@ -866,6 +900,7 @@ fas:
866
900
  tractor: ""
867
901
  trademark: ""
868
902
  traffic-light: ""
903
+ trailer: ""
869
904
  train: ""
870
905
  tram: ""
871
906
  transgender: ""
@@ -921,17 +956,23 @@ fas:
921
956
  user-times: ""
922
957
  users: ""
923
958
  users-cog: ""
959
+ users-slash: ""
924
960
  utensil-spoon: ""
925
961
  utensils: ""
926
962
  vector-square: ""
927
963
  venus: ""
928
964
  venus-double: ""
929
965
  venus-mars: ""
966
+ vest: ""
967
+ vest-patches: ""
930
968
  vial: ""
931
969
  vials: ""
932
970
  video: ""
933
971
  video-slash: ""
934
972
  vihara: ""
973
+ virus: ""
974
+ virus-slash: ""
975
+ viruses: ""
935
976
  voicemail: ""
936
977
  volleyball-ball: ""
937
978
  volume-down: ""
@@ -11,8 +11,9 @@ STYLES = {
11
11
 
12
12
  STYLES.each do |specifier, type|
13
13
  Prawn::Document.generate("fontawesome_#{type.downcase}.pdf") do
14
- deja_path = File.join \
15
- Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
14
+ deja_path = Prawn::Icon.configuration.font_directory
15
+ .join('DejaVuSans.ttf')
16
+ .to_s
16
17
 
17
18
  font_families.update(
18
19
  'deja' => { normal: deja_path }
@@ -4,8 +4,9 @@ require_relative '../lib/prawn/icon'
4
4
  require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('foundation_icons.pdf') do
7
- deja_path = File.join \
8
- Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
7
+ deja_path = Prawn::Icon.configuration.font_directory
8
+ .join('DejaVuSans.ttf')
9
+ .to_s
9
10
 
10
11
  font_families.update({
11
12
  'deja' => { normal: deja_path }
@@ -4,8 +4,9 @@ require_relative '../lib/prawn/icon'
4
4
  require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('paymentfont.pdf') do
7
- deja_path = File.join \
8
- Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
7
+ deja_path = Prawn::Icon.configuration.font_directory
8
+ .join('DejaVuSans.ttf')
9
+ .to_s
9
10
 
10
11
  font_families.update({
11
12
  'deja' => { normal: deja_path }
@@ -6,7 +6,9 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
+ require 'pathname'
9
10
  require_relative 'icon/version'
11
+ require_relative 'icon/configuration'
10
12
  require_relative 'icon/base'
11
13
  require_relative 'icon/font_data'
12
14
  require_relative 'icon/parser'
@@ -11,9 +11,21 @@ require_relative 'errors'
11
11
 
12
12
  module Prawn
13
13
  class Icon
14
+ class << self
15
+ attr_writer :configuration
16
+
17
+ def configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+
21
+ def configure
22
+ yield(configuration)
23
+ end
24
+ end
25
+
14
26
  module Base
15
- FONTDIR = File.join \
16
- File.expand_path('../../../..', __FILE__), 'data/fonts'
27
+ # @deprecated Use {Prawn::Icon.configuration.font_directory} instead
28
+ FONTDIR = Prawn::Icon.configuration.font_directory.to_s
17
29
  end
18
30
  end
19
31
  end
@@ -9,14 +9,22 @@
9
9
  module Prawn
10
10
  class Icon
11
11
  class Compatibility
12
+ # @deprecated Use {Prawn::Icon::Compatibility.shims} instead
12
13
  SHIMS = YAML.load_file(
13
- File.join(
14
- Base::FONTDIR,
14
+ Prawn::Icon.configuration.font_directory.join(
15
15
  'fa4',
16
16
  'shims.yml'
17
17
  )
18
18
  ).freeze
19
19
 
20
+ class << self
21
+ def shims
22
+ @shims ||= YAML.load_file(
23
+ Icon.configuration.font_directory.join('fa4', 'shims.yml').to_s
24
+ )
25
+ end
26
+ end
27
+
20
28
  attr_accessor :key
21
29
 
22
30
  def initialize(opts = {})
@@ -36,7 +44,7 @@ module Prawn
36
44
  private
37
45
 
38
46
  def map
39
- SHIMS.fetch(key) do
47
+ self.class.shims.fetch(key) do
40
48
  # FontAwesome shim metadata assumes "fas" as the default
41
49
  # font family if not explicity referenced.
42
50
  "fas-#{key.sub(/fa-/, '')}"
@@ -48,7 +56,7 @@ module Prawn
48
56
  [Prawn::Icon - DEPRECATION WARNING]
49
57
  FontAwesome 4 icon was referenced as '#{old_key}'.
50
58
  Use the FontAwesome 5 icon '#{new_key}' instead.
51
- This compatibility layer will be removed in Prawn::Icon 3.0.0.
59
+ This compatibility layer will be removed in Prawn::Icon 4.0.0.
52
60
  DEPRECATION
53
61
  end
54
62
  end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ #
3
+ # configuration.rb: Prawn icon configuration.
4
+ #
5
+ # Copyright October 2020, Jesse Doyle. All rights reserved.
6
+ #
7
+ # This is free software. Please see the LICENSE and COPYING files for details.
8
+
9
+ module Prawn
10
+ class Icon
11
+ class Configuration
12
+ def font_directory=(path)
13
+ @font_directory = Pathname.new(path)
14
+ end
15
+
16
+ def font_directory
17
+ @font_directory ||= default_font_directory
18
+ end
19
+
20
+ private
21
+
22
+ def default_font_directory
23
+ Pathname.new(gem_path).join('data', 'fonts')
24
+ end
25
+
26
+ # :nocov:
27
+ def gem_path
28
+ spec = Gem.loaded_specs.fetch('prawn-icon') do
29
+ Struct.new(:full_gem_path).new(failsafe_gem_path)
30
+ end
31
+ spec.full_gem_path
32
+ end
33
+
34
+ def failsafe_gem_path
35
+ File.expand_path('../../../..', __FILE__)
36
+ end
37
+ # :nocov:
38
+ end
39
+ end
40
+ end
@@ -63,15 +63,17 @@ module Prawn
63
63
  end
64
64
 
65
65
  def path
66
- ttf = File.join(Icon::Base::FONTDIR, @set.to_s, '*.ttf')
67
- font = Dir[ttf].first
66
+ font = Icon.configuration.font_directory
67
+ .join(@set.to_s)
68
+ .glob('*.ttf')
69
+ .first
68
70
 
69
71
  if font.nil?
70
72
  raise Prawn::Errors::UnknownFont,
71
73
  "Icon font not found for set: #{@set}"
72
74
  end
73
75
 
74
- @path ||= font
76
+ @path ||= font.to_s
75
77
  end
76
78
 
77
79
  def specifier
@@ -19,7 +19,7 @@ module Prawn
19
19
  # rule, included icon keys should match the keys from
20
20
  # the font provider. The icon key mapping is specified
21
21
  # in the font's +legend_file+, which is a +YAML+ file
22
- # located in Prawn::Icon::Base::FONTDIR/font/font.yml.
22
+ # located in {Prawn::Icon.configuration.font_directory}/font/font.yml.
23
23
  #
24
24
  # Prawn::Icon::
25
25
  # Houses the methods and interfaces necessary for
@@ -38,6 +38,7 @@ module Prawn
38
38
  # to Prawn's internal formatted text parser.
39
39
  #
40
40
  class Icon
41
+ # @deprecated Use {Prawn::Icon.configuration.font_directory} instead
41
42
  FONTDIR = Icon::Base::FONTDIR
42
43
 
43
44
  module Interface
@@ -63,11 +64,10 @@ module Prawn
63
64
  #
64
65
  def icon(key, opts = {})
65
66
  key = translate_key(key)
66
- make_icon(key, opts).tap(&:render)
67
+ make_icon(key, opts).tap { |i| i && i.render }
67
68
  end
68
69
 
69
- # Initialize a new icon object, but do
70
- # not render it to the document.
70
+ # Initialize a new icon object.
71
71
  #
72
72
  # == Parameters:
73
73
  # key::
@@ -90,9 +90,9 @@ module Prawn
90
90
  end
91
91
  end
92
92
 
93
- # Initialize a new formatted text box containing
94
- # icon information, but don't render it to the
95
- # document.
93
+ # Render formatted icon content to the document from
94
+ # a string containing icons. Content will correctly
95
+ # transition to a new page when necessary.
96
96
  #
97
97
  # == Parameters:
98
98
  # text::
@@ -107,10 +107,37 @@ module Prawn
107
107
  def inline_icon(text, opts = {})
108
108
  parsed = Icon::Parser.format(self, text)
109
109
  content = Text::Formatted::Parser.format(parsed)
110
+ formatted_text(content, opts)
111
+ end
112
+
113
+ # Initialize a formatted icon box from an icon-conatining
114
+ # string. Content is not directly rendered to the document,
115
+ # instead a +Prawn::Text::Formatted::Box+ instance is returned
116
+ # that responds to the +render+ method.
117
+ #
118
+ # == Parameters:
119
+ # text::
120
+ # Input text to be parsed initially for <icon>
121
+ # tags, then passed to Prawn's formatted text
122
+ # parser.
123
+ #
124
+ # opts::
125
+ # A hash of options that may be supplied to the
126
+ # underlying text call.
127
+ #
128
+ def formatted_icon_box(text, opts = {})
129
+ parsed = Icon::Parser.format(self, text)
130
+ content = Text::Formatted::Parser.format(parsed)
131
+ position = opts.fetch(:at) do
132
+ [
133
+ opts.fetch(:x) { bounds.left },
134
+ opts.fetch(:y) { cursor }
135
+ ]
136
+ end
110
137
  box_options = opts.merge(
111
138
  inline_format: true,
112
139
  document: self,
113
- at: [bounds.left, cursor]
140
+ at: position
114
141
  )
115
142
  icon_box(content, box_options)
116
143
  end
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Icon
11
- VERSION = '2.5.0'.freeze
11
+ VERSION = '3.0.0'.freeze
12
12
  end
13
13
  end
@@ -47,20 +47,28 @@ describe Prawn::Icon::Interface do
47
47
  pdf.move_down 10
48
48
  pdf.text 'More'
49
49
  pdf.move_down 20
50
- icon = pdf.icon icon_text, inline_format: true
50
+ pdf.icon icon_text, inline_format: true
51
51
  pdf.move_down 30
52
52
  pdf.text 'End'
53
+ inspector = PDF::Inspector::Text.analyze(pdf.render)
54
+ x, y = inspector.positions[2]
53
55
 
54
- expect(icon.at.first).to eq(0)
55
- expect(icon.at.last.round).to eq(734)
56
+ expect(x).to eq(0)
57
+ expect(y.round).to eq(724)
56
58
  end
57
59
 
58
60
  context 'with final_gap: false' do
59
61
  it 'renders the icon without a final gap' do
60
- icon = pdf.icon '<icon size="60">far-address-book</icon>',
62
+ pdf.icon(
63
+ '<icon size="60">far-address-book</icon>',
61
64
  inline_format: true,
62
65
  final_gap: false
63
- expect(icon.at.last.round).to eq(792)
66
+ )
67
+ pdf.text('Hello')
68
+ inspector = PDF::Inspector::Text.analyze(pdf.render)
69
+ y = inspector.positions[1].last.round
70
+
71
+ expect(y).to eq(723)
64
72
  end
65
73
  end
66
74
  end
@@ -102,19 +110,63 @@ describe Prawn::Icon::Interface do
102
110
  end
103
111
 
104
112
  context ':inline_format => true' do
105
- it 'should return a Prawn::::Text::Formatted::Box instance' do
113
+ it 'returns nil' do
106
114
  icon = pdf.make_icon '<icon>far-address-book</icon>', inline_format: true
107
115
 
108
- expect(icon).to be_a(Prawn::Text::Formatted::Box)
116
+ expect(icon).to be_nil
109
117
  end
110
118
  end
111
119
  end
112
120
 
113
121
  describe '::inline_icon' do
114
- it 'should return a Prawn::Text::Formatted::Box instance' do
122
+ it 'returns nil' do
115
123
  icon = pdf.inline_icon '<icon>far-address-book</icon>'
116
124
 
117
- expect(icon).to be_a(Prawn::Text::Formatted::Box)
125
+ expect(icon).to be_nil
126
+ end
127
+
128
+ it 'starts a new page if necessary', github_issue: '49' do
129
+ text = 209.times.map { 'Hello, World!' }.join(' ')
130
+ pdf.text(text, size: 18)
131
+ pdf.icon('Hello, <icon>fas-globe</icon>', inline_format: true, size: 18)
132
+ inspector = PDF::Inspector::Page.analyze(pdf.render)
133
+
134
+ expect(inspector.pages.size).to eq(2)
135
+ end
136
+ end
137
+
138
+ describe '::formatted_icon_box' do
139
+ it 'returns a Prawn::Text::Formatted::Box instance' do
140
+ icon_text = <<~CONTENT
141
+ <icon size="20">fas-broom</icon>
142
+ <strikethrough>cancel that</strikethrough>
143
+ <icon>fas-check</icon>
144
+ CONTENT
145
+ box = pdf.formatted_icon_box(icon_text, inline_format: true)
146
+
147
+ expect(box).to be_a(Prawn::Text::Formatted::Box)
148
+ end
149
+
150
+ it 'accepts an absolute position parameter' do
151
+ icon_text = 'Hello, <icon>fas-globe</icon>!'
152
+ pdf.formatted_icon_box(icon_text, inline_format: true, x: 200, y: 100).render
153
+ inspector = PDF::Inspector::Text.analyze(pdf.render)
154
+ x, y = inspector.positions[0]
155
+
156
+ expect(x).to eq(200)
157
+ expect(y.round).to eq(90)
158
+ end
159
+
160
+ it 'handles final_gap: false correctly' do
161
+ icon_text = <<~CONTENT
162
+ Hello, <icon size="60">fas-globe</icon>
163
+ Next line.
164
+ CONTENT
165
+ pdf.formatted_icon_box(icon_text, inline_format: true, final_gap: false).render
166
+ inspector = PDF::Inspector::Text.analyze(pdf.render)
167
+ x = inspector.positions[1].first
168
+
169
+ expect(x.round).to eq(34)
118
170
  end
119
171
  end
120
172
 
@@ -4,12 +4,31 @@
4
4
  #
5
5
  # This is free software. Please see the LICENSE and COPYING files for details.
6
6
 
7
- describe Prawn::Icon::Base do
8
- describe 'FONTDIR' do
9
- it 'returns the data/fonts directory' do
10
- path = File.expand_path '../../..', __FILE__
11
- path = File.join path, 'data/fonts'
12
- expect(Prawn::Icon::Base::FONTDIR).to eq(path)
7
+ describe Prawn::Icon do
8
+ describe '#configuration' do
9
+ it 'returns an instance of Prawn::Icon::Configuration' do
10
+ expect(described_class.configuration).to be_a(Prawn::Icon::Configuration)
11
+ end
12
+ end
13
+
14
+ describe '#configure' do
15
+ around(:each) do |example|
16
+ old = described_class.configuration.dup
17
+ described_class.configure do |config|
18
+ config.font_directory = '/tmp/fonts'
19
+ end
20
+ example.run
21
+ described_class.configuration = old
22
+ end
23
+
24
+ it 'yields control' do
25
+ expect { |b| described_class.configure(&b) }.to yield_control
26
+ end
27
+
28
+ it 'configures properties' do
29
+ expect(described_class.configuration.font_directory).to eq(
30
+ Pathname.new('/tmp/fonts')
31
+ )
13
32
  end
14
33
  end
15
34
  end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright October 2020, Jesse Doyle. All rights reserved.
4
+ #
5
+ # This is free software. Please see the LICENSE and COPYING files for details.
6
+
7
+ describe Prawn::Icon::Configuration do
8
+ describe '#font_directory' do
9
+ before(:each) do
10
+ subject.font_directory = '/tmp/fakedir'
11
+ end
12
+
13
+ it 'returns a Pathname' do
14
+ expect(subject.font_directory).to be_a(Pathname)
15
+ end
16
+
17
+ it 'returns the configured path' do
18
+ expect(subject.font_directory.to_s).to eq('/tmp/fakedir')
19
+ end
20
+ end
21
+ end
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: 2.5.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Doyle
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-05 00:00:00.000000000 Z
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -158,6 +158,7 @@ files:
158
158
  - lib/prawn/icon.rb
159
159
  - lib/prawn/icon/base.rb
160
160
  - lib/prawn/icon/compatibility.rb
161
+ - lib/prawn/icon/configuration.rb
161
162
  - lib/prawn/icon/errors.rb
162
163
  - lib/prawn/icon/font_data.rb
163
164
  - lib/prawn/icon/interface.rb
@@ -170,6 +171,7 @@ files:
170
171
  - spec/support/pdf_helper.rb
171
172
  - spec/unit/base_spec.rb
172
173
  - spec/unit/compatibility_spec.rb
174
+ - spec/unit/configuration_spec.rb
173
175
  - spec/unit/errors/icon_key_empty_spec.rb
174
176
  - spec/unit/errors/icon_not_found_spec.rb
175
177
  - spec/unit/font_data_spec.rb
@@ -181,7 +183,7 @@ licenses:
181
183
  - GPL-2
182
184
  - GPL-3
183
185
  metadata: {}
184
- post_install_message:
186
+ post_install_message:
185
187
  rdoc_options: []
186
188
  require_paths:
187
189
  - lib
@@ -196,9 +198,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
198
  - !ruby/object:Gem::Version
197
199
  version: 1.3.6
198
200
  requirements: []
199
- rubyforge_project:
200
- rubygems_version: 2.7.6.2
201
- signing_key:
201
+ rubygems_version: 3.1.2
202
+ signing_key:
202
203
  specification_version: 4
203
204
  summary: Provides icon fonts for PrawnPDF
204
205
  test_files: []