prawn-icon 0.5.0 → 0.5.1

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
  SHA1:
3
- metadata.gz: 7f3481eee108e9e723fecc26c55cbb230b6bbd0b
4
- data.tar.gz: fb577b5eed982b6dc50d1adc0697030cdb9e2e12
3
+ metadata.gz: 4b72801a22245be5c21023bc4dd96f34a9888c3b
4
+ data.tar.gz: 43384f7f447921f7ff5a4dae77fe1aaf4e5ee369
5
5
  SHA512:
6
- metadata.gz: bee190bccfd7d39d325551399ff3124ea13d3b096fd3f30379cad3e9fd3d40236cc278a57bf162bf8666e4df31af1e4e4b10ad916e79fa33f89507e7b40cb787
7
- data.tar.gz: 4b805fd0027c95b5476c0d9ed6222c384b9e9a08b398ca2fc76315e6e6a74801d6cce5dd1beca07d69523bbda50a0db2c2b1145a49c2a26f16733371f3c3fcfd
6
+ metadata.gz: b83ad4e37b575f040ca394ccbb0378bdeef0671ee5106a775ae57bda71113eb85bd0cf000a465f52d56669bd118d77059b33971f921e6f774ea8d0a69bf3bc14
7
+ data.tar.gz: 9cf1c9a029f4487ba0551e9a16c8138e91c39d1c9498b7d9a72a189518e14af2605976f836f1f17193063a9521dc93310e4a62f571c9384ee90e26b408c81333
@@ -12,12 +12,13 @@ module Prawn
12
12
  class Icon
13
13
  class FontData
14
14
  class << self
15
- # Make a simple cache that contains font
16
- # data that has been lazily loaded.
15
+ # Font data lazy-loader that will initialize
16
+ # icon fonts by document.
17
17
  def load(document, set)
18
18
  set = set.to_sym
19
- @data ||= {}
19
+ @data ||= {}
20
20
  @data[set] ||= FontData.new(document, set: set)
21
+ @data[set].load_fonts(document)
21
22
  end
22
23
 
23
24
  # Release all font references if requested.
@@ -44,9 +45,8 @@ module Prawn
44
45
  attr_reader :set
45
46
 
46
47
  def initialize(document, opts = {})
47
- @pdf = document
48
48
  @set = opts[:set] || :fa
49
- update_document_fonts!
49
+ load_fonts(document)
50
50
  end
51
51
 
52
52
  def font_version
@@ -57,6 +57,11 @@ module Prawn
57
57
  File.join(File.dirname(path), "#{@set}.yml")
58
58
  end
59
59
 
60
+ def load_fonts(document)
61
+ document.font_families[@set.to_s] ||= { normal: path }
62
+ self
63
+ end
64
+
60
65
  def path
61
66
  ttf = File.join(Icon::FONTDIR, @set.to_s, '*.ttf')
62
67
  fonts = Dir[ttf]
@@ -92,15 +97,6 @@ module Prawn
92
97
  def yaml
93
98
  @yaml ||= YAML.load_file legend_path
94
99
  end
95
-
96
- private
97
-
98
- def update_document_fonts!
99
- @pdf.font_families.update(
100
- @set.to_s => {
101
- normal: path
102
- })
103
- end
104
100
  end
105
101
  end
106
102
  end
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Icon
11
- VERSION = '0.5.0'.freeze
11
+ VERSION = '0.5.1'.freeze
12
12
  end
13
13
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.required_ruby_version = '>= 1.9.3'
14
14
  spec.required_rubygems_version = '>= 1.3.6'
15
15
 
16
- spec.homepage = "https://github.com/jessedoyle/prawn-icon/"
16
+ spec.homepage = 'https://github.com/jessedoyle/prawn-icon/'
17
17
 
18
18
  spec.test_files = Dir['spec/*_spec.rb']
19
19
  spec.authors = ['Jesse Doyle']
@@ -22,14 +22,24 @@ describe Prawn::Icon::Interface do
22
22
  context 'inline_format: true' do
23
23
  it 'should handle text options (size)' do
24
24
  pdf = create_pdf
25
- # We need to flush the font cache here...
26
- Prawn::Icon::FontData.release_data
27
25
  pdf.icon '<icon size="60">fa-arrows</icon>', inline_format: true
28
26
  text = PDF::Inspector::Text.analyze(pdf.render)
29
27
 
30
28
  expect(text.strings.first).to eq("\uf047")
31
29
  expect(text.font_settings.first[:size]).to eq(60.0)
32
30
  end
31
+
32
+ it 'should be able to render on mulitple documents' do
33
+ pdf1 = create_pdf
34
+ pdf2 = create_pdf
35
+ pdf1.icon '<icon>fa-arrows</icon>', inline_format: true
36
+ pdf2.icon '<icon>fa-arrows</icon>', inline_format: true
37
+ text1 = PDF::Inspector::Text.analyze(pdf1.render)
38
+ text2 = PDF::Inspector::Text.analyze(pdf2.render)
39
+
40
+ expect(text1.strings.first).to eq("\uf047")
41
+ expect(text2.strings.first).to eq("\uf047")
42
+ end
33
43
  end
34
44
 
35
45
  context 'without options' do
@@ -17,7 +17,7 @@ describe Prawn::Icon::FontData do
17
17
  end
18
18
 
19
19
  describe '::load' do
20
- it 'should cache font data on a document basis' do
20
+ it 'should only load a single object for multiple documents' do
21
21
  pdf = create_pdf
22
22
  data = Prawn::Icon::FontData.load(pdf, 'fa')
23
23
  obj_id_1 = data.__id__
@@ -110,6 +110,16 @@ describe Prawn::Icon::FontData do
110
110
  end
111
111
  end
112
112
 
113
+ describe '#load_fonts' do
114
+ it 'should return a FontData object' do
115
+ pdf = create_pdf
116
+ data = Prawn::Icon::FontData.new(pdf)
117
+ ret_val = data.load_fonts(pdf)
118
+
119
+ expect(ret_val.is_a? Prawn::Icon::FontData).to be_true
120
+ end
121
+ end
122
+
113
123
  describe '#path' do
114
124
  it 'should have a valid path to a TTF file' do
115
125
  pdf = create_pdf
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: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Doyle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn