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
@@ -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 [Numeric, String] x1
8
8
  # @param [Numeric, String] y1
9
9
  # @param [Numeric, String] x2
@@ -6,7 +6,7 @@ require 'base64'
6
6
  module ThinReports
7
7
  module Generator
8
8
 
9
- module Pdf::Graphics
9
+ module PDF::Graphics
10
10
  # @param [String] filename
11
11
  # @param [Numeric, Strng] x
12
12
  # @param [Numeric, Strng] y
@@ -24,6 +24,23 @@ module ThinReports
24
24
  image(image.path, x, y, w, h)
25
25
  end
26
26
 
27
+ # @param file (see Prawn#image)
28
+ # @param [Numeric, Strng] x
29
+ # @param [Numeric, Strng] y
30
+ # @param [Numeric, Strng] w
31
+ # @param [Numeric, Strng] h
32
+ # @param [Hash] options
33
+ # @option options [:left, :center, :right] :position_x (:left)
34
+ # @option options [:top, :center, :bottom] :position_y (:top)
35
+ def image_box(file, x, y, w, h, options = {})
36
+ w, h = s2f(w, h)
37
+ pdf.bounding_box(pos(x, y), :width => w, :height => h) do
38
+ pdf.image(file, :position => options[:position_x] || :left,
39
+ :vposition => options[:position_y] || :top,
40
+ :auto_fit => [w, h])
41
+ end
42
+ end
43
+
27
44
  private
28
45
 
29
46
  def clean_temp_images
@@ -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 [String] content
8
8
  # @param [Numeric, String] x
9
9
  # @param [Numeric, String] y
@@ -19,15 +19,22 @@ module ThinReports
19
19
  # @option attrs [:top, :center, :bottom] :valign (:top)
20
20
  # @option attrs [Numeric, String] :line_height The total height of an text line.
21
21
  # @option attrs [Numeric, String] :letter_spacing
22
+ # @option attrs [Boolean] :single (false)
22
23
  def text_box(content, x, y, w, h, attrs = {})
23
24
  w, h = s2f(w, h)
25
+ box_attrs = text_box_attrs(x, y, w, h, attrs.delete(:single))
26
+
24
27
  with_text_styles(attrs) do |built_attrs, font_styles|
25
28
  pdf.formatted_text_box([{:text => text_without_line_wrap(content),
26
29
  :styles => font_styles}],
27
- built_attrs.merge(:at => pos(x, y),
28
- :width => w,
29
- :height => h))
30
+ built_attrs.merge(box_attrs))
30
31
  end
32
+ rescue Prawn::Errors::CannotFit => e
33
+ # Nothing to do.
34
+ #
35
+ # When the area is too small compared
36
+ # with the content and the style of the text.
37
+ # (See prawn/core/text/formatted/line_wrap.rb#L185)
31
38
  end
32
39
 
33
40
  # @see #text_box
@@ -38,6 +45,22 @@ module ThinReports
38
45
 
39
46
  private
40
47
 
48
+ # @param x (see #text_box)
49
+ # @param y (see #text_box)
50
+ # @param w (see #text_box)
51
+ # @param h (see #text_box)
52
+ # @param [Boolean, nil] single
53
+ # @return [Hash]
54
+ def text_box_attrs(x, y, w, h, single = nil)
55
+ attrs = {:at => pos(x, y),
56
+ :width => s2f(w)}
57
+ if single
58
+ attrs.merge(:single_line => true)
59
+ else
60
+ attrs.merge(:height => s2f(h))
61
+ end
62
+ end
63
+
41
64
  # @param attrs (see #text)
42
65
  # @yield [built_attrs, font_styles]
43
66
  # @yieldparam [Hash] built_attrs The finalized attributes.
@@ -104,7 +127,7 @@ module ThinReports
104
127
  end
105
128
 
106
129
  # Emulate bold style.
107
- if manual.include?(:bold)
130
+ if manual && manual.include?(:bold)
108
131
  pdf.stroke_color(font[:color])
109
132
  pdf.line_width(font[:size] * 0.025)
110
133
 
@@ -113,7 +136,7 @@ module ThinReports
113
136
  end
114
137
 
115
138
  # Emulate italic style.
116
- if manual.include?(:italic)
139
+ if manual && manual.include?(:italic)
117
140
  # FIXME
118
141
  # pdf.transformation_matrix(1, 0, 0.26, 1, 0, 0)
119
142
  end
@@ -0,0 +1,70 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Generator
5
+
6
+ # @private
7
+ module PDF::Page
8
+
9
+ # @param [ThinReports::Layout::Format] format
10
+ def start_new_page(format)
11
+ format_id = if change_page_format?(format)
12
+ pdf.start_new_page(new_basic_page_options(format))
13
+ @current_page_format = format
14
+
15
+ unless format_stamp_registry.include?(format.identifier)
16
+ create_format_stamp(format)
17
+ end
18
+ format.identifier
19
+ else
20
+ pdf.start_new_page(new_basic_page_options(current_page_format))
21
+ current_page_format.identifier
22
+ end
23
+
24
+ stamp(format_id.to_s)
25
+ end
26
+
27
+ def add_blank_page
28
+ pdf.start_new_page(pdf.page_count.zero? ? {:size => 'A4'} : {})
29
+ end
30
+
31
+ private
32
+
33
+ # @return [ThinReports::Layout::Format]
34
+ attr_reader :current_page_format
35
+
36
+ # @param [ThinReports::Layout::Format] new_format
37
+ # @return [Boolean]
38
+ def change_page_format?(new_format)
39
+ !current_page_format ||
40
+ current_page_format.identifier != new_format.identifier
41
+ end
42
+
43
+ # @param [ThinReports::Layout::Format] format
44
+ def create_format_stamp(format)
45
+ create_stamp(format.identifier.to_s) do
46
+ parse_svg(format.layout, '/svg/g')
47
+ end
48
+ format_stamp_registry << format.identifier
49
+ end
50
+
51
+ # @return [Array]
52
+ def format_stamp_registry
53
+ @format_stamp_registry ||= []
54
+ end
55
+
56
+ # @param [ThinReports::Layout::Format] format
57
+ # @return [Hash]
58
+ def new_basic_page_options(format)
59
+ options = {:layout => format.page_orientation.to_sym}
60
+ options[:size] = if format.user_paper_type?
61
+ [format.page_width.to_f, format.page_height.to_f]
62
+ else
63
+ format.page_paper_type
64
+ end
65
+ options
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -4,7 +4,7 @@ module ThinReports
4
4
  module Generator
5
5
 
6
6
  # @private
7
- module Pdf::ParseColor
7
+ module PDF::ParseColor
8
8
  # @param [String] color
9
9
  # @return [String]
10
10
  def parse_color(color)
@@ -6,7 +6,7 @@ module ThinReports
6
6
  module Generator
7
7
 
8
8
  # @private
9
- module Pdf::ParseSVG
9
+ module PDF::ParseSVG
10
10
  # @param [String] source
11
11
  # @param [String] base_path
12
12
  def parse_svg(source, base_path)
@@ -4,7 +4,7 @@ module ThinReports
4
4
  module Generator
5
5
 
6
6
  # @private
7
- module Pdf::Drawer
7
+ module PDF::Drawer
8
8
  end
9
9
 
10
10
  end
@@ -5,8 +5,8 @@ module ThinReports
5
5
 
6
6
  # @abstract
7
7
  # @private
8
- class Pdf::Drawer::Base
9
- # @param [ThinReports::Generator::Pdf::Document] pdf
8
+ class PDF::Drawer::Base
9
+ # @param [ThinReports::Generator::PDF::Document] pdf
10
10
  # @param [ThinReports::Core::Shape::Manager::Format] format
11
11
  def initialize(pdf, format)
12
12
  @pdf = pdf
@@ -30,13 +30,11 @@ module ThinReports
30
30
 
31
31
  # @see #pdf_stamp_id
32
32
  def shape_stamp_id(shape)
33
- id = shape.id.dup
34
- id << shape.attrs.values_at('fill', 'stroke').join unless shape.attrs.empty?
35
- id.gsub(/#/, '')
33
+ "#{shape.id}#{shape.style.identifier}"
36
34
  end
37
35
 
38
- # @overload pdf_stamp('stamp_id')
39
- # @param [String] shape
36
+ # @overload pdf_stamp(shape_id)
37
+ # @param [String] shape_id
40
38
  # @overload pdf_stamp(shape)
41
39
  # @param [ThinReports::Core::Shape::Base::Internal] shape
42
40
  def pdf_stamp(shape)
@@ -4,8 +4,8 @@ module ThinReports
4
4
  module Generator
5
5
 
6
6
  # @private
7
- class Pdf::Drawer::List < Pdf::Drawer::Base
8
- # @param (see Pdf::Drawer::Base#initialize)
7
+ class PDF::Drawer::List < PDF::Drawer::Base
8
+ # @param (see PDF::Drawer::Base#initialize)
9
9
  def initialize(pdf, format)
10
10
  super
11
11
  @sections = {}
@@ -28,10 +28,10 @@ module ThinReports
28
28
  end
29
29
 
30
30
  # @param [ThinReports::Core::Shape::List::SectionInternal] section
31
- # @return [ThinReports::Generator::Pdf::Drawer::ListSection]
31
+ # @return [ThinReports::Generator::PDF::Drawer::ListSection]
32
32
  def drawer(section)
33
33
  @sections[section.section_name] ||=
34
- Pdf::Drawer::ListSection.new(@pdf, section)
34
+ PDF::Drawer::ListSection.new(@pdf, section)
35
35
  end
36
36
  end
37
37
 
@@ -4,8 +4,8 @@ module ThinReports
4
4
  module Generator
5
5
 
6
6
  # @private
7
- class Pdf::Drawer::ListSection < Pdf::Drawer::Page
8
- # @param pdf (see Pdf::Drawer::Page#initialize)
7
+ class PDF::Drawer::ListSection < PDF::Drawer::Page
8
+ # @param pdf (see PDF::Drawer::Page#initialize)
9
9
  # @param section [ThinReports::Core::Shape::List::SectionInternal] section
10
10
  def initialize(pdf, section)
11
11
  super(pdf, section.format)
@@ -36,10 +36,15 @@ module ThinReports
36
36
  pdf_stamp(id)
37
37
  end
38
38
 
39
- # @see ThinReports::Generator::Pdf::Drawer::Page#draw_tblock_shape
39
+ # @see ThinReports::Generator::PDF::Drawer::Page#draw_tblock_shape
40
40
  def draw_tblock_shape(shape)
41
41
  @pdf.translate(*@draw_at) { super }
42
42
  end
43
+
44
+ # @see ThinReports::Generator::PDF::Drawer::Page#draw_iblock_shape
45
+ def draw_iblock_shape(shape)
46
+ @pdf.translate(*@draw_at) { super }
47
+ end
43
48
  end
44
49
 
45
50
  end
@@ -4,8 +4,8 @@ module ThinReports
4
4
  module Generator
5
5
 
6
6
  # @private
7
- class Pdf::Drawer::Page < Pdf::Drawer::Base
8
- # @param see Pdf::Drawer::Base#initialize)
7
+ class PDF::Drawer::Page < PDF::Drawer::Base
8
+ # @param see PDF::Drawer::Base#initialize)
9
9
  def initialize(pdf, format)
10
10
  super
11
11
  @lists = {}
@@ -29,6 +29,8 @@ module ThinReports
29
29
  draw_tblock_shape(shape)
30
30
  when shape.type_of?(:list)
31
31
  draw_list_shape(shape)
32
+ when shape.type_of?(:iblock)
33
+ draw_iblock_shape(shape)
32
34
  else
33
35
  id = shape_stamp_id(shape)
34
36
  unless @stamps.include?(id)
@@ -41,7 +43,7 @@ module ThinReports
41
43
 
42
44
  # @see #draw_shape
43
45
  def draw_list_shape(shape)
44
- drawer = @lists[shape.id] ||= Pdf::Drawer::List.new(@pdf, shape.format)
46
+ drawer = @lists[shape.id] ||= PDF::Drawer::List.new(@pdf, shape.format)
45
47
  drawer.draw(shape)
46
48
  end
47
49
 
@@ -50,6 +52,11 @@ module ThinReports
50
52
  @pdf.draw_shape_tblock(shape)
51
53
  end
52
54
 
55
+ # @see #draw_shape
56
+ def draw_iblock_shape(shape)
57
+ @pdf.draw_shape_iblock(shape)
58
+ end
59
+
53
60
  # @param [ThinReports::Core::Shape::Base::Internal] shape
54
61
  def create_basic_shape_stamp(shape)
55
62
  case
@@ -2,35 +2,30 @@
2
2
 
3
3
  # @private
4
4
  module Prawn
5
- # Patch for issue {https://github.com/sandal/prawn/issues/245 #245}.
6
- # @private
7
- class Font::TTF
8
- def character_width_by_code(code)
9
- return 0 unless cmap[code]
10
- return 0.0 if code == 10
11
- @char_widths[code] ||= Integer(hmtx.widths[cmap[code]] * scale_factor)
12
- end
13
- end
14
-
15
5
  # @private
16
6
  class Document
17
7
  # Create around alias.
18
8
  alias_method :original_width_of, :width_of
19
9
 
20
- # For Ruby 1.8
21
- ruby_18 do
22
- def width_of(string, options={})
23
- str_length = in_utf8 { string.split(//).size }
24
- font.compute_width_of(string, options) + character_spacing * (str_length - 1)
25
- end
10
+ def width_of(string, options={})
11
+ font.compute_width_of(string, options) +
12
+ (character_spacing * (font.character_count(string) - 1))
26
13
  end
27
14
 
28
- # For Ruby 1.9
29
- ruby_19 do
30
- def width_of(string, options={})
31
- font.compute_width_of(string, options) + character_spacing * (string.length - 1)
15
+ private
16
+ # Create around alias.
17
+ alias_method :original_calc_image_dimensions, :calc_image_dimensions
18
+
19
+ def calc_image_dimensions(info, options)
20
+ if options[:auto_fit]
21
+ w, h = info.width, info.height
22
+ sw, sh = options.delete(:auto_fit)
23
+
24
+ if w > sw || h > sh
25
+ options[:fit] = [sw, sh]
26
+ end
32
27
  end
28
+ original_calc_image_dimensions(info, options)
33
29
  end
34
30
  end
35
-
36
31
  end
@@ -8,7 +8,7 @@ module ThinReports
8
8
  # @private
9
9
  class Format < Core::Shape::Manager::Format
10
10
  config_reader :last_version => %w( version )
11
- config_reader :report_title => %w( title )
11
+ config_reader :report_title => %w( config title )
12
12
  config_reader :page_paper_type => %w( config page paper-type ),
13
13
  :page_width => %w( config page width ),
14
14
  :page_height => %w( config page height ),
@@ -35,7 +35,7 @@ module ThinReports
35
35
  # Check the compatibility of specified layout file.
36
36
  unless ThinReports::Layout::Version.compatible?(raw_format['version'])
37
37
  info = [filename, raw_format['version'],
38
- ThinReports::Layout::Version.required_rules_inspect]
38
+ ThinReports::Layout::Version.inspect_required_rules]
39
39
  raise ThinReports::Errors::IncompatibleLayoutFormat.new(*info)
40
40
  end
41
41
 
@@ -5,7 +5,7 @@ module ThinReports
5
5
 
6
6
  # @private
7
7
  module Version
8
- REQUIRED_RULES = ["== #{ThinReports::VERSION}"]
8
+ REQUIRED_RULES = ['>= 0.6.0.pre3', '< 0.8.0']
9
9
 
10
10
  # @param [String] version
11
11
  # @return [Boolean]
@@ -24,7 +24,7 @@ module ThinReports
24
24
  end
25
25
 
26
26
  # @return [String]
27
- def self.required_rules_inspect
27
+ def self.inspect_required_rules
28
28
  '(' + REQUIRED_RULES.join(' and ') + ')'
29
29
  end
30
30
 
@@ -10,6 +10,7 @@ module ThinReports
10
10
 
11
11
  class << self
12
12
  # @param options (see #initialize)
13
+ # @option options (see #initialize)
13
14
  # @yield [report]
14
15
  # @yieldparam [ThinReports::Report::Base] report
15
16
  # @return [ThinReports::Report::Base]
@@ -24,39 +25,61 @@ module ThinReports
24
25
  report
25
26
  end
26
27
 
27
- # @param [Symbol] type
28
- # @param [Hash] options
29
- # @option options [Hash] :report Options for Report (see #initialize)
30
- # @option options [Hash] :generator Options for Generator.
31
- # @yield (see #create)
28
+ # @overload generate(type, options = {}, &block)
29
+ # @param [Symbol] type
30
+ # @param [Hash] options
31
+ # @option options [Hash] :report ({}) Options for Report.
32
+ # @option options [Hash] :generator ({}) Options for Generator.
33
+ # @overload generate(options = {}, &block)
34
+ # @param [Hash] options
35
+ # @option options [Hash] :report ({}) Options for Report.
36
+ # @option options [Hash] :generator ({}) Options for Generator.
37
+ # @yield (see .create)
38
+ # @yieldparam (see .create)
32
39
  # @return [String]
33
- def generate(type, options = {}, &block)
34
- init_generate_params(options, &block)
40
+ def generate(*args, &block)
41
+ raise ArgumentError, '#generate requires a block' unless block_given?
35
42
 
36
- create(options[:report], &block).generate(type, options[:generator])
43
+ report_opts, generator_opts = extract_options!(args)
44
+
45
+ report = create(report_opts, &block)
46
+ report.generate(*args.push(generator_opts))
37
47
  end
38
48
 
39
- # @param [Symbol] type
40
- # @param [String] filename
41
- # @param options (see #generate)
42
- # @yield (see #create)
43
- def generate_file(type, filename, options = {}, &block)
44
- init_generate_params(options, &block)
49
+ # @overload generate_file(type, filename, options = {}, &block)
50
+ # @overload generate_file(filename, options = {}, &block)
51
+ # @param filename (see #generate_file)
52
+ # @yield (see .create)
53
+ # @yieldparam (see .create)
54
+ # @see .generate
55
+ # @return [void]
56
+ def generate_file(*args, &block)
57
+ raise ArgumentError, '#generate_file requires a block' unless block_given?
58
+
59
+ report_opts, generator_opts = extract_options!(args)
45
60
 
46
- create(options[:report], &block).
47
- generate_file(type, filename, options[:generator])
61
+ report = create(report_opts, &block)
62
+ report.generate_file(*args.push(generator_opts))
48
63
  end
49
64
 
50
65
  private
51
66
 
52
- # @param (see #generate)
53
- # @private
54
- def init_generate_params(options, &block)
55
- unless block_given?
56
- raise ArgumentError, '#generate or #generate_file requires a block'
67
+ # @param [Array] args
68
+ # @return [Array<Hash>]
69
+ def extract_options!(args)
70
+ if args.last.is_a?(::Hash)
71
+ options = args.pop
72
+
73
+ generator = options.delete(:generator) || {}
74
+ report = options.delete(:report) || {}
75
+
76
+ if options.key?(:layout)
77
+ report[:layout] = options.delete(:layout)
78
+ end
79
+ [report, generator.merge(options)]
80
+ else
81
+ [{}, {}]
57
82
  end
58
- options[:report] ||= {}
59
- options[:generator] ||= {}
60
83
  end
61
84
  end
62
85
 
@@ -66,19 +89,20 @@ module ThinReports
66
89
  @internal = Report::Internal.new(self, options)
67
90
  end
68
91
 
69
- # @param [String] path of layout-file.
92
+ # @param [String] layout path to layout-file.
70
93
  # @param [Hash] options
71
94
  # @option options [Boolean] :default (true)
72
95
  # @option options [Symbol] :id (nil)
73
- # @yield [config,]
96
+ # @yield [config]
74
97
  # @yieldparam [ThinReports::Layout::Configuration] config
98
+ # @return [void]
75
99
  def use_layout(layout, options = {}, &block)
76
100
  internal.register_layout(layout, options, &block)
77
101
  end
78
102
 
79
103
  # @param [Hash] options
80
104
  # @option options [String, Symbol] :layout (nil)
81
- # @yield [page,]
105
+ # @yield [page]
82
106
  # @yieldparam [ThinReports::Core::Page] page
83
107
  # @return [ThinReports::Core::Page]
84
108
  def start_new_page(options = {}, &block)
@@ -115,17 +139,29 @@ module ThinReports
115
139
  internal.default_layout
116
140
  end
117
141
 
118
- # @param [Symbol] type
119
- # @param options (see ThinReports::Generator)
142
+ # @overload generate(type, options = {})
143
+ # Specify the generator type.
144
+ # @param [Symbol] type
145
+ # @overload generate(options = {})
146
+ # Using the default generator type.
147
+ # @param [Hash] options ({})
120
148
  # @return [String]
121
- def generate(type, options = {})
149
+ def generate(*args)
150
+ options = args.last.is_a?(::Hash) ? args.pop : {}
151
+ type = args.first || ThinReports.config.generator.default
122
152
  ThinReports::Generator.new(type, self, options).generate
123
153
  end
124
154
 
125
- # @param type (see #generate)
155
+ # @overload generate_file(type, filename, options = {})
156
+ # @param type (#generate)
157
+ # @overload generate_file(filename, options = {})
126
158
  # @param [String] filename
127
159
  # @param options (see #generate)
128
- def generate_file(type, filename, options = {})
160
+ # @return [void]
161
+ def generate_file(*args)
162
+ options = args.last.is_a?(::Hash) ? args.pop : {}
163
+ args.unshift(ThinReports.config.generator.default) if args.size == 1
164
+ type, filename = args
129
165
  ThinReports::Generator.new(type, self, options).generate_file(filename)
130
166
  end
131
167
 
@@ -144,6 +180,7 @@ module ThinReports
144
180
  internal.page_count
145
181
  end
146
182
 
183
+ # @return [void]
147
184
  # @private
148
185
  def finalize
149
186
  internal.finalize