thinreports 0.6.0.pre3 → 0.7.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.
Files changed (158) hide show
  1. data/README.rdoc +37 -32
  2. data/doc/yardoc_templates/default/layout/html/footer.erb +1 -1
  3. data/lib/thinreports.rb +2 -1
  4. data/lib/thinreports/config.rb +21 -0
  5. data/lib/thinreports/core/errors.rb +14 -1
  6. data/lib/thinreports/core/format/builder.rb +6 -1
  7. data/lib/thinreports/core/page.rb +6 -6
  8. data/lib/thinreports/core/shape.rb +8 -9
  9. data/lib/thinreports/core/shape/base/internal.rb +6 -12
  10. data/lib/thinreports/core/shape/basic.rb +3 -0
  11. data/lib/thinreports/core/shape/basic/block_format.rb +12 -0
  12. data/lib/thinreports/core/shape/basic/block_interface.rb +25 -0
  13. data/lib/thinreports/core/shape/basic/block_internal.rb +33 -0
  14. data/lib/thinreports/core/shape/basic/interface.rb +37 -11
  15. data/lib/thinreports/core/shape/basic/internal.rb +3 -12
  16. data/lib/thinreports/core/shape/image_block.rb +15 -0
  17. data/lib/thinreports/core/shape/image_block/format.rb +13 -0
  18. data/lib/thinreports/core/shape/image_block/interface.rb +19 -0
  19. data/lib/thinreports/core/shape/image_block/internal.rb +16 -0
  20. data/lib/thinreports/core/shape/list/events.rb +19 -2
  21. data/lib/thinreports/core/shape/list/manager.rb +17 -4
  22. data/lib/thinreports/core/shape/list/page.rb +2 -2
  23. data/lib/thinreports/core/shape/list/page_state.rb +4 -0
  24. data/lib/thinreports/core/shape/list/section_internal.rb +4 -0
  25. data/lib/thinreports/core/shape/manager/format.rb +1 -1
  26. data/lib/thinreports/core/shape/manager/internal.rb +24 -11
  27. data/lib/thinreports/core/shape/manager/target.rb +2 -2
  28. data/lib/thinreports/core/shape/style.rb +15 -0
  29. data/lib/thinreports/core/shape/style/base.rb +149 -0
  30. data/lib/thinreports/core/shape/style/basic.rb +17 -0
  31. data/lib/thinreports/core/shape/style/graphic.rb +60 -0
  32. data/lib/thinreports/core/shape/style/text.rb +138 -0
  33. data/lib/thinreports/core/shape/text/internal.rb +4 -0
  34. data/lib/thinreports/core/shape/text_block.rb +16 -0
  35. data/lib/thinreports/core/shape/{tblock → text_block}/format.rb +3 -3
  36. data/lib/thinreports/core/shape/{tblock → text_block}/formatter.rb +7 -7
  37. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/basic.rb +1 -1
  38. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/datetime.rb +1 -1
  39. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/number.rb +1 -1
  40. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/padding.rb +10 -8
  41. data/lib/thinreports/core/shape/{tblock → text_block}/interface.rb +2 -21
  42. data/lib/thinreports/core/shape/{tblock → text_block}/internal.rb +16 -10
  43. data/lib/thinreports/core/utils.rb +0 -8
  44. data/lib/thinreports/generator.rb +2 -2
  45. data/lib/thinreports/generator/configuration.rb +30 -0
  46. data/lib/thinreports/generator/pdf.rb +13 -10
  47. data/lib/thinreports/generator/pdf/configuration.rb +28 -0
  48. data/lib/thinreports/generator/pdf/document.rb +16 -56
  49. data/lib/thinreports/generator/pdf/document/draw_shape.rb +35 -17
  50. data/lib/thinreports/generator/pdf/document/font.rb +25 -9
  51. data/lib/thinreports/generator/pdf/document/graphics.rb +1 -1
  52. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +18 -4
  53. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +1 -1
  54. data/lib/thinreports/generator/pdf/document/graphics/image.rb +18 -1
  55. data/lib/thinreports/generator/pdf/document/graphics/text.rb +29 -6
  56. data/lib/thinreports/generator/pdf/document/page.rb +70 -0
  57. data/lib/thinreports/generator/pdf/document/parse_color.rb +1 -1
  58. data/lib/thinreports/generator/pdf/document/parse_svg.rb +1 -1
  59. data/lib/thinreports/generator/pdf/drawer.rb +1 -1
  60. data/lib/thinreports/generator/pdf/drawer/base.rb +5 -7
  61. data/lib/thinreports/generator/pdf/drawer/list.rb +4 -4
  62. data/lib/thinreports/generator/pdf/drawer/list_section.rb +8 -3
  63. data/lib/thinreports/generator/pdf/drawer/page.rb +10 -3
  64. data/lib/thinreports/generator/pdf/prawn_ext.rb +16 -21
  65. data/lib/thinreports/layout/format.rb +2 -2
  66. data/lib/thinreports/layout/version.rb +2 -2
  67. data/lib/thinreports/report/base.rb +68 -31
  68. data/tasks/test.rake +48 -4
  69. data/test/benchmark/basic_estimate.tlf +1 -0
  70. data/test/benchmark/bench_basic_estimate.rb +95 -0
  71. data/test/case/character_spacing/character_spacing.rb +7 -0
  72. data/test/case/character_spacing/character_spacing.tlf +1 -0
  73. data/test/case/dynamic_image/dynamic_image.rb +41 -0
  74. data/test/case/dynamic_image/dynamic_image.tlf +1 -0
  75. data/test/case/dynamic_image/img200x100.png +0 -0
  76. data/test/case/dynamic_image/img50x50.png +0 -0
  77. data/test/case/dynamic_style/dynamic_style.rb +154 -0
  78. data/test/case/dynamic_style/dynamic_style.tlf +1 -0
  79. data/test/case/dynamic_style/dynamic_style_in_list.tlf +1 -0
  80. data/test/case/dynamic_style/image.png +0 -0
  81. data/test/case/eudc/eudc.rb +20 -0
  82. data/test/case/eudc/eudc.tlf +1 -0
  83. data/test/case/eudc/eudc.ttf +0 -0
  84. data/test/case/helper.rb +27 -0
  85. data/test/case/hidden_shapes/hidden_shapes.rb +13 -0
  86. data/test/case/hidden_shapes/hidden_shapes.tlf +1 -0
  87. data/test/case/list_events/list_events.rb +32 -0
  88. data/test/case/list_events/list_events.tlf +1 -0
  89. data/test/case/list_header_inheriting/list_header_inheriting.rb +19 -0
  90. data/test/case/list_header_inheriting/list_header_inheriting.tlf +1 -0
  91. data/test/case/list_manual_generation/list_manual_generation.rb +24 -0
  92. data/test/case/list_manual_generation/list_manual_generation.tlf +1 -0
  93. data/test/case/single_line_tblock/single_line_tblock.rb +15 -0
  94. data/test/case/single_line_tblock/single_line_tblock.tlf +1 -0
  95. data/test/case/tblock_styles/tblock_styles.rb +27 -0
  96. data/test/case/tblock_styles/tblock_styles.tlf +1 -0
  97. data/test/case/text_align/text_align.rb +9 -0
  98. data/test/case/text_align/text_align.tlf +1 -0
  99. data/test/unit/core/shape/base/test_internal.rb +65 -85
  100. data/test/unit/core/shape/basic/test_basic_format.rb +30 -0
  101. data/test/unit/core/shape/basic/test_basic_interface.rb +27 -0
  102. data/test/unit/core/shape/basic/test_basic_internal.rb +55 -0
  103. data/test/unit/core/shape/basic/test_interface.rb +84 -36
  104. data/test/unit/core/shape/basic/test_internal.rb +32 -24
  105. data/test/unit/core/shape/image_block/test_format.rb +58 -0
  106. data/test/unit/core/shape/image_block/test_interface.rb +23 -0
  107. data/test/unit/core/shape/image_block/test_internal.rb +28 -0
  108. data/test/unit/core/shape/list/test_events.rb +19 -11
  109. data/test/unit/core/shape/list/test_manager.rb +112 -0
  110. data/test/unit/core/shape/list/test_page.rb +57 -0
  111. data/test/unit/core/shape/list/test_section_format.rb +1 -1
  112. data/test/unit/core/shape/list/test_section_interface.rb +37 -30
  113. data/test/unit/core/shape/list/test_section_internal.rb +39 -14
  114. data/test/unit/core/shape/manager/test_format.rb +12 -18
  115. data/test/unit/core/shape/manager/test_internal.rb +127 -93
  116. data/test/unit/core/shape/manager/test_target.rb +63 -56
  117. data/test/unit/core/shape/styles/test_base.rb +219 -0
  118. data/test/unit/core/shape/styles/test_basic.rb +24 -0
  119. data/test/unit/core/shape/styles/test_graphic.rb +69 -0
  120. data/test/unit/core/shape/styles/test_text.rb +318 -0
  121. data/test/unit/core/shape/{tblock → text_block}/formatter/test_basic.rb +2 -2
  122. data/test/unit/core/shape/{tblock → text_block}/formatter/test_datetime.rb +2 -2
  123. data/test/unit/core/shape/{tblock → text_block}/formatter/test_number.rb +2 -2
  124. data/test/unit/core/shape/{tblock → text_block}/formatter/test_padding.rb +11 -6
  125. data/test/unit/core/shape/text_block/test_format.rb +160 -0
  126. data/test/unit/core/shape/{tblock → text_block}/test_formatter.rb +2 -2
  127. data/test/unit/core/shape/text_block/test_interface.rb +46 -0
  128. data/test/unit/core/shape/text_block/test_internal.rb +128 -0
  129. data/test/unit/core/test_shape.rb +31 -6
  130. data/test/unit/data/basic_layout1.tlf +1 -0
  131. data/test/unit/data/basic_layout2.tlf +1 -0
  132. data/test/unit/data/basic_list_layout.tlf +1 -0
  133. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +81 -52
  134. data/test/unit/generator/pdf/document/graphics/test_text.rb +159 -0
  135. data/test/unit/generator/pdf/document/test_font.rb +21 -6
  136. data/test/unit/generator/pdf/document/test_graphics.rb +2 -2
  137. data/test/unit/generator/pdf/document/test_page.rb +95 -0
  138. data/test/unit/generator/pdf/document/test_parse_color.rb +2 -2
  139. data/test/unit/generator/pdf/test_configuration.rb +24 -0
  140. data/test/unit/generator/pdf/test_document.rb +28 -0
  141. data/test/unit/generator/test_configuration.rb +25 -0
  142. data/test/unit/generator/test_pdf.rb +19 -0
  143. data/test/unit/helper.rb +18 -0
  144. data/test/unit/layout/test_format.rb +24 -7
  145. data/test/unit/layout/test_version.rb +61 -27
  146. data/test/unit/report/test_base.rb +185 -89
  147. data/test/unit/test_config.rb +22 -0
  148. data/test/unit/test_report.rb +4 -4
  149. metadata +94 -43
  150. data/lib/thinreports/core/shape/tblock.rb +0 -16
  151. data/lib/thinreports/generator/pxd.rb +0 -75
  152. data/lib/thinreports/generator/pxd/helper.rb +0 -33
  153. data/lib/thinreports/generator/pxd/list_renderer.rb +0 -58
  154. data/lib/thinreports/generator/pxd/page_renderer.rb +0 -75
  155. data/tasks/clean.rake +0 -6
  156. data/test/unit/core/shape/tblock/test_format.rb +0 -125
  157. data/test/unit/core/shape/tblock/test_interface.rb +0 -40
  158. data/test/unit/core/shape/tblock/test_internal.rb +0 -139
@@ -5,14 +5,6 @@ module ThinReports
5
5
 
6
6
  # @private
7
7
  module Utils
8
- def in_utf8(&block)
9
- original = $KCODE
10
- $KCODE = 'u'
11
- block.call
12
- ensure
13
- $KCODE = original
14
- end
15
-
16
8
  def block_exec_on(context, &block)
17
9
  return context unless block_given?
18
10
 
@@ -8,7 +8,7 @@ module ThinReports
8
8
  # @param options (see ThinReports::Generator::Base#initialize)
9
9
  def self.new(type, report, options = {})
10
10
  unless generator = registry[type]
11
- raise ThinReports::Errors::UnknownGeneratorType
11
+ raise ThinReports::Errors::UnknownGeneratorType.new(type)
12
12
  end
13
13
  generator.new(report, options)
14
14
  end
@@ -25,6 +25,6 @@ module ThinReports
25
25
  end
26
26
  end
27
27
 
28
+ require 'thinreports/generator/configuration'
28
29
  require 'thinreports/generator/base'
29
- require 'thinreports/generator/pxd'
30
30
  require 'thinreports/generator/pdf'
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Generator
5
+
6
+ class Configuration
7
+ # @return [Symbol]
8
+ attr_reader :default
9
+
10
+ def initialize
11
+ @default = :pdf
12
+ end
13
+
14
+ # @return [ThinReports::Generator::PDF::Configuration]
15
+ def pdf
16
+ @pdf ||= PDF::Configuration.new
17
+ end
18
+
19
+ # @param [Symbol] type
20
+ # @return [void]
21
+ def default=(type)
22
+ unless Generator.registry.key?(type)
23
+ raise ThinReports::Errors::UnknownGeneratorType.new(type)
24
+ end
25
+ @default = type
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -1,20 +1,26 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'prawn'
3
+ begin
4
+ gem 'prawn', '0.12.0'
5
+ require 'prawn'
6
+ rescue LoadError
7
+ puts 'ThinReports requires Prawn = 0.12.0. ' +
8
+ 'Please `gem install prawn -v 0.12.0` and try again.'
9
+ end
4
10
 
5
11
  module ThinReports
6
12
  module Generator
7
13
 
8
- class Pdf < Base
14
+ class PDF < Base
9
15
  # @param report (see ThinReports::Generator::Base#initialize)
10
16
  # @param [Hash] options
11
17
  # @option options [Hash] :security (nil)
12
18
  # See Prawn::Document#encrypt_document
13
19
  def initialize(report, options)
14
20
  super
15
- @pdf = Document.new(options)
21
+ @pdf = Document.new(options, :Title => default_layout.format.report_title)
22
+
16
23
  @drawers = {}
17
- @current_format = nil
18
24
  end
19
25
 
20
26
  # @see ThinReports::Generator::Base#generate
@@ -41,12 +47,8 @@ module ThinReports
41
47
  return @pdf.add_blank_page if page.blank?
42
48
 
43
49
  format = page.layout.format
44
- # On format change.
45
- unless @current_format == format.identifier
46
- @pdf.start_new_page(format)
47
- else
48
- @pdf.start_new_page
49
- end
50
+ @pdf.start_new_page(format)
51
+
50
52
  drawer(format).draw(page.manager)
51
53
  end
52
54
 
@@ -58,6 +60,7 @@ module ThinReports
58
60
  end
59
61
  end
60
62
 
63
+ require 'thinreports/generator/pdf/configuration'
61
64
  require 'thinreports/generator/pdf/prawn_ext'
62
65
  require 'thinreports/generator/pdf/document'
63
66
  require 'thinreports/generator/pdf/drawer'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Generator
5
+
6
+ class PDF::Configuration
7
+ # @return [Array]
8
+ attr_reader :eudc_fonts
9
+
10
+ def initialize
11
+ @eudc_fonts = []
12
+ end
13
+
14
+ # @param [String, Array<String>] fonts
15
+ def eudc_fonts=(fonts)
16
+ fonts = [fonts] unless fonts.is_a?(::Array)
17
+
18
+ fonts.each do |f|
19
+ unless File.extname(f.to_s) == '.ttf'
20
+ raise ArgumentError, 'The EUDC Fonts can specify only the TTF file.'
21
+ end
22
+ end
23
+ @eudc_fonts = fonts
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -5,28 +5,31 @@ require 'thinreports/generator/pdf/document/parse_color'
5
5
  require 'thinreports/generator/pdf/document/graphics'
6
6
  require 'thinreports/generator/pdf/document/draw_shape'
7
7
  require 'thinreports/generator/pdf/document/parse_svg'
8
+ require 'thinreports/generator/pdf/document/page'
8
9
 
9
10
  module ThinReports
10
11
  module Generator
11
12
 
12
13
  # @private
13
- class Pdf::Document
14
- include Pdf::Font
15
- include Pdf::ParseColor
16
- include Pdf::Graphics
17
- include Pdf::DrawShape
18
- include Pdf::ParseSVG
19
-
20
- # @param options (see ThinReports::Generator::Pdf#initialize)
21
- def initialize(options = {})
14
+ class PDF::Document
15
+ include PDF::Font
16
+ include PDF::ParseColor
17
+ include PDF::Graphics
18
+ include PDF::DrawShape
19
+ include PDF::ParseSVG
20
+ include PDF::Page
21
+
22
+ # @param options (see ThinReports::Generator::PDF#initialize)
23
+ # @param [Hash] metadata
24
+ # @option metadata [String] :Title
25
+ def initialize(options = {}, metadata = {})
22
26
  @pdf = Prawn::Document.new(
23
27
  :skip_page_creation => true,
24
28
  :margin => [0, 0],
25
- :info => {:Creator => 'ThinReports Generator for Ruby ' +
26
- ThinReports::VERSION}
29
+ :info => {:CreationDate => Time.now,
30
+ :Creator => 'ThinReports Generator for Ruby ' +
31
+ ThinReports::VERSION}.merge(metadata)
27
32
  )
28
- @format_stamp_registry = []
29
-
30
33
  # Setup to Prawn::Document.
31
34
  setup_fonts
32
35
  setup_custom_graphic_states
@@ -37,38 +40,6 @@ module ThinReports
37
40
  end
38
41
  end
39
42
 
40
- # @param [ThinReports::Layout::Format] format (nil)
41
- def start_new_page(format = nil)
42
- options = {}
43
- format_id = format.identifier
44
-
45
- if format
46
- options[:layout] = format.page_orientation.to_sym
47
- options[:size] = if format.user_paper_type?
48
- [format.page_width.to_f, format.page_height.to_f]
49
- else
50
- format.page_paper_type
51
- end
52
- end
53
-
54
- pdf.start_new_page(options)
55
-
56
- # @note
57
- # The best way is to create a template for each layout.
58
- # However, in the latest Prawn library, because of problems handling
59
- # the template that you want supported by future releases.
60
- # @see https://github.com/sandal/prawn/issues/199
61
- unless format_stamp_registry.include?(format_id)
62
- create_format_stamp(format)
63
- end
64
- # Apply the static shapes of current format.
65
- stamp(format_id.to_s)
66
- end
67
-
68
- def add_blank_page
69
- pdf.start_new_page(pdf.page_count.zero? ? {:size => 'A4'} : {})
70
- end
71
-
72
43
  # Delegate to Prawn::Document#render
73
44
  # @see Prawn::Document#render
74
45
  def render
@@ -119,21 +90,10 @@ module ThinReports
119
90
  # @return [Prawn::Document]
120
91
  attr_reader :pdf
121
92
 
122
- # @return [Array<Symbol>]
123
- attr_reader :format_stamp_registry
124
-
125
93
  def finalize
126
94
  clean_temp_images
127
95
  end
128
96
 
129
- # @param [ThinReports::Layout::Format] format
130
- def create_format_stamp(format)
131
- create_stamp(format.identifier.to_s) do
132
- parse_svg(format.layout, '/svg/g')
133
- end
134
- format_stamp_registry << format.identifier
135
- end
136
-
137
97
  # @param [Array<String, Numeric>] values
138
98
  # @return [Numeric, Array<Numeric>, nil]
139
99
  def s2f(*values)
@@ -4,25 +4,43 @@ module ThinReports
4
4
  module Generator
5
5
 
6
6
  # @private
7
- module Pdf::DrawShape
8
- # @param [ThinReports::Core::Shape::Tblock::Internal] shape
7
+ module PDF::DrawShape
8
+ # @param [ThinReports::Core::Shape::TextBlock::Internal] shape
9
9
  def draw_shape_tblock(shape)
10
10
  x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
11
11
 
12
12
  content = shape.real_value.to_s
13
- unless shape.multiple?
14
- content = content.gsub(/\n/, ' ')
13
+ unless content.empty?
14
+ attrs = shape_text_attrs(shape)
15
+
16
+ unless shape.multiple?
17
+ content = content.gsub(/\n/, ' ')
18
+ attrs[:single] = true
19
+ end
20
+ text_box(content, x, y, w, h, attrs)
15
21
  end
16
- text_box(content, x, y, w, h, common_text_attrs(shape.attributes))
17
22
  end
18
23
 
19
24
  # @param [ThinReports::Core::Shape::Basic::Internal] shape
20
25
  def draw_shape_image(shape)
21
- x, y, w, h = shape.svg_attrs.values_at('x', 'y', 'width', 'height')
22
- base64image(extract_base64_string(shape.svg_attrs['xlink:href']),
26
+ x, y, w, h = shape.style.svg_attrs.values_at('x', 'y', 'width', 'height')
27
+ base64image(extract_base64_string(shape.style.svg_attrs['xlink:href']),
23
28
  x, y, w, h)
24
29
  end
25
30
 
31
+ # @param [ThinReports::Core::Shape::ImageBlock::Internal] shape
32
+ def draw_shape_iblock(shape)
33
+ x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
34
+ unless shape.src.blank?
35
+ posx = shape.format.position_x
36
+ posy = shape.format.position_y
37
+
38
+ image_box(shape.src, x, y, w, h,
39
+ :position_x => posx ? posx.to_sym : nil,
40
+ :position_y => posy ? posy.to_sym : nil)
41
+ end
42
+ end
43
+
26
44
  # @param [ThinReports::Core::Shape::Text::Internal] shape
27
45
  def draw_shape_text(shape)
28
46
  x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
@@ -32,39 +50,39 @@ module ThinReports
32
50
 
33
51
  # @param [ThinReports::Core::Shape::Basic::Internal] shape
34
52
  def draw_shape_ellipse(shape)
35
- args = shape.svg_attrs.values_at('cx', 'cy', 'rx', 'ry')
36
- args << common_graphic_attrs(shape.attributes)
53
+ args = shape.style.svg_attrs.values_at('cx', 'cy', 'rx', 'ry')
54
+ args << common_graphic_attrs(shape.style.svg_attrs)
37
55
  ellipse(*args)
38
56
  end
39
57
 
40
58
  # @param [ThinReports::Core::Shape::Basic::Internal] shape
41
59
  def draw_shape_line(shape)
42
- args = shape.svg_attrs.values_at('x1', 'y1', 'x2', 'y2')
43
- args << common_graphic_attrs(shape.attributes)
60
+ args = shape.style.svg_attrs.values_at('x1', 'y1', 'x2', 'y2')
61
+ args << common_graphic_attrs(shape.style.svg_attrs)
44
62
  line(*args)
45
63
  end
46
64
 
47
65
  # @param [ThinReports::Core::Shape::Basic::Internal] shape
48
66
  def draw_shape_rect(shape)
49
- args = shape.svg_attrs.values_at('x', 'y', 'width', 'height')
50
- args << common_graphic_attrs(shape.attributes) do |attrs|
51
- attrs[:radius] = shape.svg_attrs['rx']
67
+ args = shape.style.svg_attrs.values_at('x', 'y', 'width', 'height')
68
+ args << common_graphic_attrs(shape.style.svg_attrs) do |attrs|
69
+ attrs[:radius] = shape.style.svg_attrs['rx']
52
70
  end
53
71
  rect(*args)
54
72
  end
55
73
 
56
74
  private
57
75
 
58
- # @param [ThinReports::Core::Shape::Text::Internal]
76
+ # @param [ThinReports::Core::Shape::Text::Internal, ThinReports::Core::Shape::TextBlock::Internal]
59
77
  # @return [Hash]
60
78
  def shape_text_attrs(shape)
61
79
  format = shape.format
62
80
 
63
- common_text_attrs(shape.attributes) do |attrs|
81
+ common_text_attrs(shape.style.svg_attrs) do |attrs|
64
82
  # Set the :line_height option.
65
83
  attrs[:line_height] = format.line_height unless format.line_height.blank?
66
84
  # Set the :valign option.
67
- attrs[:valign] = text_valign(format.valign)
85
+ attrs[:valign] = shape.style.valign
68
86
  end
69
87
  end
70
88
 
@@ -4,7 +4,7 @@ module ThinReports
4
4
  module Generator
5
5
 
6
6
  # @private
7
- module Pdf::Font
7
+ module PDF::Font
8
8
  FONT_STORE = File.join(ThinReports::ROOTDIR, 'resources', 'fonts')
9
9
 
10
10
  BUILTIN_FONTS = {
@@ -20,14 +20,21 @@ module ThinReports
20
20
  # Install built-in fonts.
21
21
  pdf.font_families.update(BUILTIN_FONTS)
22
22
 
23
- # Install fall-back font that IPAMincho.
24
- fallback_font = BUILTIN_FONTS['IPAMincho'][:normal]
25
- pdf.font_families['FallbackFont'] = {:normal => fallback_font,
26
- :bold => fallback_font,
27
- :italic => fallback_font,
28
- :bold_italic => fallback_font}
29
- # Setup fallback font.
30
- pdf.fallback_fonts(['FallbackFont'])
23
+ fallback_fonts = []
24
+
25
+ # Install EUDC fonts.
26
+ ThinReports.config.generator.pdf.eudc_fonts.each_with_index do |eudc, i|
27
+ eudc_name = "EUDC#{i}"
28
+ install_font_family(eudc_name, eudc)
29
+ fallback_fonts << eudc_name
30
+ end
31
+
32
+ # Install fall-back font(default font) that IPAMincho.
33
+ install_font_family('DefaultFont', BUILTIN_FONTS['IPAMincho'][:normal])
34
+ fallback_fonts << 'DefaultFont'
35
+
36
+ # Setup fallback fonts.
37
+ pdf.fallback_fonts(fallback_fonts)
31
38
 
32
39
  # Create aliases from the font list provided by Prawn.
33
40
  pdf.font_families.update(
@@ -36,6 +43,15 @@ module ThinReports
36
43
  )
37
44
  end
38
45
 
46
+ # @param [String] name
47
+ # @param [String] file
48
+ def install_font_family(name, file)
49
+ pdf.font_families[name] = {:normal => file,
50
+ :bold => file,
51
+ :italic => file,
52
+ :bold_italic => file}
53
+ end
54
+
39
55
  # @return [String]
40
56
  def default_family
41
57
  'Helvetica'
@@ -4,7 +4,7 @@ module ThinReports
4
4
  module Generator
5
5
 
6
6
  # @private
7
- module Pdf::Graphics
7
+ module PDF::Graphics
8
8
 
9
9
  BASE_LINE_WIDTH = 0.9
10
10
 
@@ -3,7 +3,7 @@
3
3
  module ThinReports
4
4
  module Generator
5
5
 
6
- module Pdf::Graphics
6
+ module PDF::Graphics
7
7
  # @param [Hash] svg_attrs
8
8
  # @yield [attrs]
9
9
  # @yieldparam [Hash] attrs
@@ -36,9 +36,17 @@ module ThinReports
36
36
  :color => svg_attrs['fill'],
37
37
  :align => text_align(svg_attrs['text-anchor']),
38
38
  :styles => font_styles(svg_attrs)}
39
- # Letter Spacing.
40
- if space = svg_attrs['letter-spacing']
41
- attrs[:letter_spacing] = space unless space == 'normal'
39
+
40
+ # The Letter Spacing Property.
41
+ #
42
+ # When the version of Layout is
43
+ # smaller then 0.6.0:
44
+ # Use letter-spacing attribute (normal is none).
45
+ # 0.6.0 or more:
46
+ # Use kerning attribute (auto is none).
47
+ #
48
+ if space = text_letter_spacing(svg_attrs['kerning'] || svg_attrs['letter-spacing'])
49
+ attrs[:letter_spacing] = space
42
50
  end
43
51
  block.call(attrs) if block_given?
44
52
  attrs
@@ -59,6 +67,12 @@ module ThinReports
59
67
  styles
60
68
  end
61
69
 
70
+ # @param [String] space
71
+ # @return [String, nil]
72
+ def text_letter_spacing(space)
73
+ %w( normal auto ).include?(space) ? nil : space
74
+ end
75
+
62
76
  # @param [String] svg_align
63
77
  # @return [Symbol]
64
78
  def text_align(svg_align)