thinreports 0.7.7 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -6
- data/.travis.yml +4 -10
- data/CHANGELOG.md +220 -0
- data/Gemfile +3 -3
- data/MIT-LICENSE +1 -1
- data/README.md +286 -0
- data/Rakefile +38 -8
- data/examples/character_spacing/character_spacing.rb +8 -0
- data/examples/character_spacing/character_spacing.tlf +1 -0
- data/examples/dynamic_image/dynamic_image.rb +31 -0
- data/examples/dynamic_image/dynamic_image.tlf +1 -0
- data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
- data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
- data/examples/dynamic_style/dynamic_style.rb +150 -0
- data/examples/dynamic_style/dynamic_style.tlf +1 -0
- data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
- data/{test/case → examples}/dynamic_style/image.png +0 -0
- data/examples/eudc/eudc.rb +20 -0
- data/examples/eudc/eudc.tlf +1 -0
- data/{test/case → examples}/eudc/eudc.ttf +0 -0
- data/{test/case → examples}/helper.rb +14 -12
- data/examples/hidden_shapes/hidden_shapes.rb +9 -0
- data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
- data/examples/list_events/list_events.rb +59 -0
- data/examples/list_events/list_events_0_7_7.tlf +1 -0
- data/examples/list_events/list_events_0_8.tlf +1 -0
- data/{test/case → examples}/list_manual_generation/list_manual_generation.rb +4 -4
- data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
- data/{test/case → examples}/list_page_number/list_page_number.rb +3 -3
- data/examples/list_page_number/list_page_number.tlf +1 -0
- data/examples/page_number/page_number.rb +33 -0
- data/examples/page_number/page_number.tlf +1 -0
- data/examples/password_setting/password_setting.rb +10 -0
- data/examples/password_setting/password_setting.tlf +1 -0
- data/examples/report_callbacks/report_callbacks.rb +31 -0
- data/examples/report_callbacks/report_callbacks.tlf +1 -0
- data/{test/case → examples}/single_line_tblock/single_line_tblock.rb +2 -2
- data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
- data/examples/tblock_overflow/tblock_overflow.rb +20 -0
- data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
- data/examples/tblock_styles/font_size.tlf +1 -0
- data/examples/tblock_styles/tblock_styles.rb +43 -0
- data/examples/tblock_styles/tblock_styles.tlf +1 -0
- data/examples/text_align/text_align.rb +8 -0
- data/examples/text_align/text_align.tlf +1 -0
- data/examples/typeB_page_size/B4_ISO.tlf +1 -0
- data/examples/typeB_page_size/B4_JIS.tlf +1 -0
- data/{test/case → examples}/typeB_page_size/typeB_page_size.rb +3 -3
- data/examples/word_wrap/word_wrap.rb +26 -0
- data/examples/word_wrap/word_wrap.tlf +1 -0
- data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
- data/{resources/fonts → fonts}/ipag.ttf +0 -0
- data/{resources/fonts → fonts}/ipagp.ttf +0 -0
- data/{resources/fonts → fonts}/ipam.ttf +0 -0
- data/{resources/fonts → fonts}/ipamp.ttf +0 -0
- data/lib/thinreports.rb +14 -2
- data/lib/thinreports/config.rb +30 -10
- data/lib/thinreports/core/errors.rb +23 -20
- data/lib/thinreports/core/events.rb +18 -19
- data/lib/thinreports/core/format/base.rb +20 -20
- data/lib/thinreports/core/format/builder.rb +14 -22
- data/lib/thinreports/core/shape.rb +9 -13
- data/lib/thinreports/core/shape/base.rb +4 -5
- data/lib/thinreports/core/shape/base/interface.rb +15 -15
- data/lib/thinreports/core/shape/base/internal.rb +15 -20
- data/lib/thinreports/core/shape/basic.rb +1 -1
- data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
- data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
- data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
- data/lib/thinreports/core/shape/basic/format.rb +11 -10
- data/lib/thinreports/core/shape/basic/interface.rb +3 -3
- data/lib/thinreports/core/shape/basic/internal.rb +4 -5
- data/lib/thinreports/core/shape/image_block.rb +1 -1
- data/lib/thinreports/core/shape/image_block/format.rb +5 -6
- data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
- data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
- data/lib/thinreports/core/shape/list.rb +1 -1
- data/lib/thinreports/core/shape/list/configuration.rb +30 -15
- data/lib/thinreports/core/shape/list/events.rb +11 -11
- data/lib/thinreports/core/shape/list/format.rb +27 -28
- data/lib/thinreports/core/shape/list/manager.rb +128 -95
- data/lib/thinreports/core/shape/list/page.rb +54 -50
- data/lib/thinreports/core/shape/list/page_state.rb +15 -16
- data/lib/thinreports/core/shape/list/section_format.rb +14 -15
- data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
- data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
- data/lib/thinreports/core/shape/list/store.rb +10 -11
- data/lib/thinreports/core/shape/manager.rb +1 -1
- data/lib/thinreports/core/shape/manager/format.rb +10 -11
- data/lib/thinreports/core/shape/manager/internal.rb +21 -20
- data/lib/thinreports/core/shape/manager/target.rb +63 -34
- data/lib/thinreports/core/shape/page_number.rb +1 -1
- data/lib/thinreports/core/shape/page_number/format.rb +3 -3
- data/lib/thinreports/core/shape/page_number/interface.rb +2 -2
- data/lib/thinreports/core/shape/page_number/internal.rb +3 -3
- data/lib/thinreports/core/shape/style.rb +1 -1
- data/lib/thinreports/core/shape/style/base.rb +29 -29
- data/lib/thinreports/core/shape/style/basic.rb +1 -1
- data/lib/thinreports/core/shape/style/graphic.rb +10 -25
- data/lib/thinreports/core/shape/style/text.rb +36 -30
- data/lib/thinreports/core/shape/text.rb +1 -1
- data/lib/thinreports/core/shape/text/format.rb +8 -9
- data/lib/thinreports/core/shape/text/interface.rb +2 -2
- data/lib/thinreports/core/shape/text/internal.rb +6 -7
- data/lib/thinreports/core/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape/text_block/format.rb +17 -18
- data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
- data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
- data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
- data/lib/thinreports/core/utils.rb +33 -32
- data/lib/thinreports/generator.rb +6 -8
- data/lib/thinreports/generator/base.rb +15 -24
- data/lib/thinreports/generator/configuration.rb +10 -9
- data/lib/thinreports/generator/pdf.rb +27 -30
- data/lib/thinreports/generator/pdf/configuration.rb +11 -6
- data/lib/thinreports/generator/pdf/document.rb +28 -28
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +30 -31
- data/lib/thinreports/generator/pdf/document/font.rb +53 -44
- data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +25 -25
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +40 -41
- data/lib/thinreports/generator/pdf/document/page.rb +20 -21
- data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
- data/lib/thinreports/generator/pdf/drawer/base.rb +13 -14
- data/lib/thinreports/generator/pdf/drawer/list.rb +13 -14
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +13 -14
- data/lib/thinreports/generator/pdf/drawer/page.rb +16 -17
- data/lib/thinreports/generator/pdf/prawn_ext.rb +17 -33
- data/lib/thinreports/layout.rb +2 -2
- data/lib/thinreports/layout/base.rb +22 -36
- data/lib/thinreports/layout/configuration.rb +11 -9
- data/lib/thinreports/layout/format.rb +26 -27
- data/lib/thinreports/layout/version.rb +8 -9
- data/lib/thinreports/report.rb +10 -14
- data/lib/thinreports/report/base.rb +104 -126
- data/lib/thinreports/report/events.rb +5 -5
- data/lib/thinreports/report/internal.rb +41 -33
- data/lib/thinreports/{core → report}/page.rb +38 -30
- data/lib/thinreports/version.rb +2 -3
- data/test/data/font.ttf +0 -0
- data/test/data/layout_block.tlf +1 -0
- data/test/data/layout_list.tlf +1 -0
- data/test/data/layout_list_noheader.tlf +1 -0
- data/test/data/layout_text1.tlf +1 -0
- data/test/data/layout_text2.tlf +1 -0
- data/test/test_helper.rb +74 -0
- data/test/{unit/tmp → tmp}/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +14 -14
- data/test/unit/core/format/test_builder.rb +19 -23
- data/test/unit/core/shape/base/test_internal.rb +34 -37
- data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
- data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
- data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
- data/test/unit/core/shape/basic/test_format.rb +4 -4
- data/test/unit/core/shape/basic/test_interface.rb +36 -46
- data/test/unit/core/shape/basic/test_internal.rb +23 -20
- data/test/unit/core/shape/image_block/test_format.rb +5 -5
- data/test/unit/core/shape/image_block/test_interface.rb +17 -16
- data/test/unit/core/shape/image_block/test_internal.rb +19 -16
- data/test/unit/core/shape/list/test_configuration.rb +45 -33
- data/test/unit/core/shape/list/test_events.rb +7 -7
- data/test/unit/core/shape/list/test_format.rb +16 -18
- data/test/unit/core/shape/list/test_manager.rb +5 -5
- data/test/unit/core/shape/list/test_page.rb +80 -22
- data/test/unit/core/shape/list/test_page_state.rb +12 -12
- data/test/unit/core/shape/list/test_section_format.rb +16 -17
- data/test/unit/core/shape/list/test_section_interface.rb +30 -22
- data/test/unit/core/shape/list/test_section_internal.rb +21 -19
- data/test/unit/core/shape/list/test_store.rb +7 -7
- data/test/unit/core/shape/manager/test_format.rb +11 -15
- data/test/unit/core/shape/manager/test_internal.rb +9 -9
- data/test/unit/core/shape/manager/test_target.rb +85 -57
- data/test/unit/core/shape/page_number/test_format.rb +4 -4
- data/test/unit/core/shape/page_number/test_interface.rb +11 -8
- data/test/unit/core/shape/page_number/test_internal.rb +5 -5
- data/test/unit/core/shape/styles/test_base.rb +9 -9
- data/test/unit/core/shape/styles/test_basic.rb +5 -5
- data/test/unit/core/shape/styles/test_graphic.rb +19 -33
- data/test/unit/core/shape/styles/test_text.rb +18 -7
- data/test/unit/core/shape/text/test_format.rb +6 -6
- data/test/unit/core/shape/text/test_internal.rb +11 -12
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +4 -4
- data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
- data/test/unit/core/shape/text_block/test_format.rb +8 -8
- data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
- data/test/unit/core/shape/text_block/test_interface.rb +37 -20
- data/test/unit/core/shape/text_block/test_internal.rb +38 -38
- data/test/unit/core/test_events.rb +5 -5
- data/test/unit/core/test_shape.rb +6 -6
- data/test/unit/core/test_utils.rb +68 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +4 -4
- data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
- data/test/unit/generator/pdf/document/test_draw_shape.rb +9 -7
- data/test/unit/generator/pdf/document/test_font.rb +79 -58
- data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
- data/test/unit/generator/pdf/document/test_page.rb +44 -45
- data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
- data/test/unit/generator/pdf/test_configuration.rb +16 -9
- data/test/unit/generator/pdf/test_document.rb +8 -16
- data/test/unit/generator/test_base.rb +31 -42
- data/test/unit/generator/test_configuration.rb +6 -6
- data/test/unit/generator/test_pdf.rb +17 -14
- data/test/unit/layout/test_base.rb +34 -79
- data/test/unit/layout/test_configuration.rb +12 -37
- data/test/unit/layout/test_format.rb +36 -39
- data/test/unit/layout/test_version.rb +4 -4
- data/test/unit/report/test_base.rb +134 -213
- data/test/unit/report/test_events.rb +4 -4
- data/test/unit/report/test_internal.rb +84 -86
- data/test/unit/test_config.rb +31 -12
- data/test/unit/test_layout.rb +7 -7
- data/test/unit/test_report.rb +12 -24
- data/thinreports.gemspec +18 -22
- metadata +101 -200
- data/LICENSE +0 -1
- data/README.rdoc +0 -166
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- data/lib/thinreports/core.rb +0 -20
- data/lib/thinreports/core/ext.rb +0 -5
- data/lib/thinreports/core/ext/array.rb +0 -19
- data/lib/thinreports/core/ext/hash.rb +0 -19
- data/lib/thinreports/core/ext/object.rb +0 -25
- data/lib/thinreports/core/format.rb +0 -14
- data/lib/thinreports/core/ordered_hash.rb +0 -39
- data/lib/thinreports/generator/pdf/drawer.rb +0 -16
- data/tasks/doc.rake +0 -12
- data/tasks/test.rake +0 -56
- data/test/benchmark/basic_estimate.tlf +0 -1
- data/test/benchmark/bench_basic_estimate.rb +0 -95
- data/test/case/character_spacing/character_spacing.rb +0 -8
- data/test/case/character_spacing/character_spacing.tlf +0 -1
- data/test/case/dynamic_image/dynamic_image.rb +0 -41
- data/test/case/dynamic_image/dynamic_image.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style.rb +0 -154
- data/test/case/dynamic_style/dynamic_style.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
- data/test/case/eudc/eudc.rb +0 -20
- data/test/case/eudc/eudc.tlf +0 -1
- data/test/case/hidden_shapes/hidden_shapes.rb +0 -9
- data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
- data/test/case/list_events/list_events.rb +0 -32
- data/test/case/list_events/list_events.tlf +0 -1
- data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
- data/test/case/list_page_number/list_page_number.tlf +0 -1
- data/test/case/page_number/page_number.rb +0 -33
- data/test/case/page_number/page_number.tlf +0 -1
- data/test/case/password_setting/password_setting.rb +0 -10
- data/test/case/password_setting/password_setting.tlf +0 -1
- data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
- data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
- data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
- data/test/case/tblock_styles/tblock_styles.rb +0 -27
- data/test/case/tblock_styles/tblock_styles.tlf +0 -1
- data/test/case/text_align/text_align.rb +0 -8
- data/test/case/text_align/text_align.tlf +0 -1
- data/test/case/typeB_page_size/B4_ISO.tlf +0 -1
- data/test/case/typeB_page_size/B4_JIS.tlf +0 -1
- data/test/case/word_wrap/word_wrap.rb +0 -26
- data/test/case/word_wrap/word_wrap.tlf +0 -1
- data/test/unit/core/ext/array_spec.rb +0 -29
- data/test/unit/core/ext/hash_spec.rb +0 -29
- data/test/unit/core/ext/object_spec.rb +0 -30
- data/test/unit/core/ordered_hash_spec.rb +0 -51
- data/test/unit/core/shape/base/test_interface.rb +0 -52
- data/test/unit/core/utils_spec.rb +0 -56
- data/test/unit/data/basic_layout1.tlf +0 -1
- data/test/unit/data/basic_layout2.tlf +0 -1
- data/test/unit/data/basic_list_layout.tlf +0 -1
- data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
- data/test/unit/helper.rb +0 -87
@@ -1,40 +1,41 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
module Thinreports
|
4
|
+
module Utils
|
5
|
+
def self.included(klass)
|
6
|
+
klass.extend self
|
7
|
+
end
|
8
|
+
|
9
|
+
def deep_copy(src)
|
10
|
+
case src
|
11
|
+
when Hash
|
12
|
+
src.inject({}) {|h, (k, v)| h[k] = (v.dup rescue v); h }
|
13
|
+
when Array
|
14
|
+
src.map {|a| a.dup rescue a }
|
15
|
+
else
|
16
|
+
raise ArgumentError
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def blank_value?(value)
|
21
|
+
case value
|
22
|
+
when String then value.empty?
|
23
|
+
when NilClass then true
|
24
|
+
else false
|
17
25
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def call_block_in(scope, &block)
|
29
|
+
return scope unless block_given?
|
30
|
+
|
31
|
+
if block.arity == 1
|
32
|
+
block.call(scope)
|
26
33
|
else
|
27
|
-
|
28
|
-
false
|
29
|
-
end
|
30
|
-
def ruby_19
|
31
|
-
yield
|
32
|
-
end
|
34
|
+
scope.instance_eval(&block)
|
33
35
|
end
|
36
|
+
scope
|
34
37
|
end
|
35
|
-
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
extend Utils
|
41
|
+
end
|
@@ -1,24 +1,22 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
|
5
5
|
module Generator
|
6
6
|
# @param [Symbol] type
|
7
|
-
# @param report (see
|
8
|
-
# @param options (see
|
7
|
+
# @param report (see Thinreports::Generator::Base#initialize)
|
8
|
+
# @param options (see Thinreports::Generator::Base#initialize)
|
9
9
|
def self.new(type, report, options = {})
|
10
10
|
unless generator = registry[type]
|
11
|
-
raise
|
11
|
+
raise Thinreports::Errors::UnknownGeneratorType.new(type)
|
12
12
|
end
|
13
13
|
generator.new(report, options)
|
14
14
|
end
|
15
|
-
|
16
|
-
# @private
|
15
|
+
|
17
16
|
def self.register(type, generator)
|
18
17
|
registry[type] = generator
|
19
18
|
end
|
20
|
-
|
21
|
-
# @private
|
19
|
+
|
22
20
|
def self.registry
|
23
21
|
@generators ||= {}
|
24
22
|
end
|
@@ -1,49 +1,40 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
5
|
+
|
6
6
|
# @abstract
|
7
7
|
class Base
|
8
|
-
# @return [
|
9
|
-
# @private
|
8
|
+
# @return [Thinreports::Report::Base]
|
10
9
|
attr_reader :report
|
11
10
|
|
12
11
|
# @return [Hash]
|
13
|
-
# @private
|
14
12
|
attr_reader :options
|
15
|
-
|
16
|
-
# @private
|
13
|
+
|
17
14
|
def self.inherited(g)
|
18
15
|
Generator.register(g.name.split('::').last.downcase.to_sym, g);
|
19
16
|
end
|
20
|
-
|
21
|
-
# @param [
|
17
|
+
|
18
|
+
# @param [Thinreports::Report::Base] report
|
22
19
|
# @param [Hash] options
|
23
20
|
def initialize(report, options = {})
|
24
21
|
report.finalize
|
25
|
-
|
22
|
+
|
26
23
|
@report = report.internal
|
27
24
|
@options = options || {}
|
28
25
|
end
|
29
|
-
|
30
|
-
# @
|
31
|
-
# @
|
32
|
-
def generate
|
33
|
-
raise NotImplementedError
|
34
|
-
end
|
35
|
-
|
36
|
-
# @param [String] filename
|
26
|
+
|
27
|
+
# @param [String, nil] filename
|
28
|
+
# @return [String, nil]
|
37
29
|
# @abstract
|
38
|
-
def
|
30
|
+
def generate(filename = nil)
|
39
31
|
raise NotImplementedError
|
40
32
|
end
|
41
|
-
|
42
|
-
# @private
|
33
|
+
|
43
34
|
def default_layout
|
44
35
|
report.default_layout
|
45
|
-
end
|
36
|
+
end
|
46
37
|
end
|
47
|
-
|
38
|
+
|
48
39
|
end
|
49
|
-
end
|
40
|
+
end
|
@@ -1,30 +1,31 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
5
|
+
|
6
|
+
# @deprecated This class will be removed in the next major version.
|
6
7
|
class Configuration
|
7
8
|
# @return [Symbol]
|
8
9
|
attr_reader :default
|
9
|
-
|
10
|
+
|
10
11
|
def initialize
|
11
12
|
@default = :pdf
|
12
13
|
end
|
13
|
-
|
14
|
-
# @return [
|
14
|
+
|
15
|
+
# @return [Thinreports::Generator::PDF::Configuration]
|
15
16
|
def pdf
|
16
17
|
@pdf ||= PDF::Configuration.new
|
17
18
|
end
|
18
|
-
|
19
|
+
|
19
20
|
# @param [Symbol] type
|
20
21
|
# @return [void]
|
21
22
|
def default=(type)
|
22
23
|
unless Generator.registry.key?(type)
|
23
|
-
raise
|
24
|
+
raise Thinreports::Errors::UnknownGeneratorType.new(type)
|
24
25
|
end
|
25
26
|
@default = type
|
26
27
|
end
|
27
28
|
end
|
28
|
-
|
29
|
+
|
29
30
|
end
|
30
|
-
end
|
31
|
+
end
|
@@ -1,68 +1,65 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
begin
|
4
|
-
gem 'prawn', '
|
4
|
+
gem 'prawn', '1.3.0'
|
5
5
|
require 'prawn'
|
6
6
|
rescue LoadError
|
7
|
-
puts '
|
8
|
-
'Please `gem install prawn -v
|
7
|
+
puts 'Thinreports requires Prawn = 1.3.0. ' +
|
8
|
+
'Please `gem install prawn -v 1.3.0` and try again.'
|
9
9
|
end
|
10
10
|
|
11
|
-
module
|
11
|
+
module Thinreports
|
12
12
|
module Generator
|
13
|
-
|
13
|
+
|
14
14
|
class PDF < Base
|
15
|
-
# @param report (see
|
15
|
+
# @param report (see Thinreports::Generator::Base#initialize)
|
16
16
|
# @param [Hash] options
|
17
17
|
# @option options [Hash] :security (nil)
|
18
18
|
# See Prawn::Document#encrypt_document
|
19
19
|
def initialize(report, options)
|
20
20
|
super
|
21
|
-
|
21
|
+
|
22
22
|
title = default_layout ? default_layout.format.report_title : nil
|
23
23
|
|
24
|
-
@
|
24
|
+
@document = Document.new(options, Title: title)
|
25
25
|
@drawers = {}
|
26
26
|
end
|
27
|
-
|
28
|
-
# @see
|
29
|
-
def generate
|
30
|
-
draw_report
|
31
|
-
@pdf.render
|
32
|
-
end
|
33
|
-
|
34
|
-
# @see ThinReports::Generator::Base#generate_file
|
35
|
-
def generate_file(filename)
|
27
|
+
|
28
|
+
# @see Thinreports::Generator::Base#generate
|
29
|
+
def generate(filename = nil)
|
36
30
|
draw_report
|
37
|
-
@
|
31
|
+
filename ? @document.render_file(filename) : @document.render
|
38
32
|
end
|
39
|
-
|
33
|
+
|
40
34
|
private
|
41
|
-
|
35
|
+
|
42
36
|
def draw_report
|
43
37
|
report.pages.each do |page|
|
44
38
|
draw_page(page)
|
45
39
|
end
|
46
40
|
end
|
47
|
-
|
41
|
+
|
48
42
|
def draw_page(page)
|
49
|
-
return @
|
50
|
-
|
43
|
+
return @document.add_blank_page if page.blank?
|
44
|
+
|
51
45
|
format = page.layout.format
|
52
|
-
@
|
53
|
-
|
46
|
+
@document.start_new_page(format)
|
47
|
+
|
54
48
|
drawer(format).draw(page)
|
55
49
|
end
|
56
|
-
|
50
|
+
|
57
51
|
def drawer(format)
|
58
|
-
@drawers[format.identifier] ||= Drawer::Page.new(@
|
59
|
-
end
|
52
|
+
@drawers[format.identifier] ||= Drawer::Page.new(@document, format)
|
53
|
+
end
|
60
54
|
end
|
61
|
-
|
55
|
+
|
62
56
|
end
|
63
57
|
end
|
64
58
|
|
65
59
|
require 'thinreports/generator/pdf/configuration'
|
66
60
|
require 'thinreports/generator/pdf/prawn_ext'
|
67
61
|
require 'thinreports/generator/pdf/document'
|
68
|
-
require 'thinreports/generator/pdf/drawer'
|
62
|
+
require 'thinreports/generator/pdf/drawer/base'
|
63
|
+
require 'thinreports/generator/pdf/drawer/page'
|
64
|
+
require 'thinreports/generator/pdf/drawer/list'
|
65
|
+
require 'thinreports/generator/pdf/drawer/list_section'
|
@@ -1,20 +1,25 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
5
|
+
|
6
|
+
# @deprecated This class will be removed in the next major version.
|
6
7
|
class PDF::Configuration
|
7
8
|
# @return [Array]
|
8
9
|
attr_reader :eudc_fonts
|
9
|
-
|
10
|
+
|
10
11
|
def initialize
|
11
12
|
@eudc_fonts = []
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
# @param [String, Array<String>] fonts
|
15
16
|
def eudc_fonts=(fonts)
|
17
|
+
warn '[DEPRECATION] `eudc_fonts=` is deprecated and will be removed in ' +
|
18
|
+
'the next major version of thinreports. ' +
|
19
|
+
'Please use `Thinreports.config.fallback_fonts=` instead.'
|
20
|
+
|
16
21
|
fonts = [fonts] unless fonts.is_a?(::Array)
|
17
|
-
|
22
|
+
|
18
23
|
fonts.each do |f|
|
19
24
|
unless File.extname(f.to_s) == '.ttf'
|
20
25
|
raise ArgumentError, 'The EUDC Fonts can specify only the TTF file.'
|
@@ -23,6 +28,6 @@ module ThinReports
|
|
23
28
|
@eudc_fonts = fonts
|
24
29
|
end
|
25
30
|
end
|
26
|
-
|
31
|
+
|
27
32
|
end
|
28
33
|
end
|
@@ -7,39 +7,43 @@ require 'thinreports/generator/pdf/document/draw_shape'
|
|
7
7
|
require 'thinreports/generator/pdf/document/parse_svg'
|
8
8
|
require 'thinreports/generator/pdf/document/page'
|
9
9
|
|
10
|
-
module
|
10
|
+
module Thinreports
|
11
11
|
module Generator
|
12
|
-
|
13
|
-
# @private
|
12
|
+
|
14
13
|
class PDF::Document
|
14
|
+
include Utils
|
15
|
+
|
15
16
|
include PDF::Font
|
16
17
|
include PDF::ParseColor
|
17
18
|
include PDF::Graphics
|
18
19
|
include PDF::DrawShape
|
19
20
|
include PDF::ParseSVG
|
20
21
|
include PDF::Page
|
21
|
-
|
22
|
-
# @
|
22
|
+
|
23
|
+
# @return [Prawn::Document]
|
24
|
+
attr_reader :pdf
|
25
|
+
|
26
|
+
# @param options (see Thinreports::Generator::PDF#initialize)
|
23
27
|
# @param [Hash] metadata
|
24
28
|
# @option metadata [String] :Title
|
25
29
|
def initialize(options = {}, metadata = {})
|
26
30
|
@pdf = Prawn::Document.new(
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
|
31
|
+
skip_page_creation: true,
|
32
|
+
margin: [0, 0],
|
33
|
+
info: {CreationDate: Time.now,
|
34
|
+
Creator: 'Thinreports Generator for Ruby ' +
|
35
|
+
Thinreports::VERSION}.merge(metadata)
|
32
36
|
)
|
33
37
|
# Setup to Prawn::Document.
|
34
38
|
setup_fonts
|
35
39
|
setup_custom_graphic_states
|
36
|
-
|
40
|
+
|
37
41
|
# Encrypts the document.
|
38
42
|
if options[:security]
|
39
43
|
@pdf.encrypt_document(options[:security])
|
40
44
|
end
|
41
45
|
end
|
42
|
-
|
46
|
+
|
43
47
|
# Delegate to Prawn::Document#render
|
44
48
|
# @see Prawn::Document#render
|
45
49
|
def render
|
@@ -47,21 +51,21 @@ module ThinReports
|
|
47
51
|
finalize
|
48
52
|
result
|
49
53
|
end
|
50
|
-
|
54
|
+
|
51
55
|
# Delegate to Prawn::Document#render_file
|
52
56
|
# @see Prawn::Document#render_file
|
53
57
|
def render_file(*args)
|
54
58
|
finalize
|
55
59
|
pdf.render_file(*args)
|
56
60
|
end
|
57
|
-
|
61
|
+
|
58
62
|
# @param [Numeric, String] x
|
59
63
|
# @param [Numeric, String] y
|
60
64
|
def translate(x, y, &block)
|
61
65
|
x, y = rpos(x, y)
|
62
66
|
pdf.translate(x, y, &block)
|
63
67
|
end
|
64
|
-
|
68
|
+
|
65
69
|
# @param [String] stamp_id
|
66
70
|
# @param [Array<Numeric>] at (nil)
|
67
71
|
def stamp(stamp_id, at = nil)
|
@@ -71,34 +75,30 @@ module ThinReports
|
|
71
75
|
pdf.stamp(stamp_id)
|
72
76
|
end
|
73
77
|
end
|
74
|
-
|
78
|
+
|
75
79
|
# Delegate to Prawn::Document#create_stamp
|
76
80
|
# @param [String] id
|
77
81
|
# @see Prawn::Document#create_stamp
|
78
82
|
def create_stamp(id, &block)
|
79
83
|
pdf.create_stamp(id, &block)
|
80
84
|
end
|
81
|
-
|
82
|
-
# @private
|
85
|
+
|
83
86
|
# @see #pdf
|
84
87
|
def internal
|
85
88
|
@pdf
|
86
89
|
end
|
87
|
-
|
90
|
+
|
88
91
|
private
|
89
|
-
|
90
|
-
# @return [Prawn::Document]
|
91
|
-
attr_reader :pdf
|
92
|
-
|
92
|
+
|
93
93
|
def finalize
|
94
94
|
clean_temp_images
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
# @param [Array<String, Numeric>] values
|
98
98
|
# @return [Numeric, Array<Numeric>, nil]
|
99
99
|
def s2f(*values)
|
100
100
|
return nil if values.empty?
|
101
|
-
|
101
|
+
|
102
102
|
if values.size == 1
|
103
103
|
if value = values.first
|
104
104
|
value.is_a?(::Numeric) ? value : value.to_f
|
@@ -107,7 +107,7 @@ module ThinReports
|
|
107
107
|
values.map {|v| s2f(v) }
|
108
108
|
end
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
# @param [Numeric, String] x
|
112
112
|
# @param [Numeric, String] y
|
113
113
|
# @return [Array<Float>]
|
@@ -116,7 +116,7 @@ module ThinReports
|
|
116
116
|
[x, -y]
|
117
117
|
end
|
118
118
|
alias_method :rpos, :map_to_upper_left_relative_position
|
119
|
-
|
119
|
+
|
120
120
|
# @param [Numeric, String] x
|
121
121
|
# @param [Numeric, String] y
|
122
122
|
# @return [Array<Float>]
|
@@ -126,6 +126,6 @@ module ThinReports
|
|
126
126
|
end
|
127
127
|
alias_method :pos, :map_to_upper_left_position
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
end
|
131
131
|
end
|