thinreports 0.7.6 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -5
- data/.travis.yml +8 -4
- data/CHANGELOG.md +220 -0
- data/Gemfile +2 -9
- 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/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/examples/eudc/eudc.rb +20 -0
- data/examples/eudc/eudc.tlf +1 -0
- data/examples/helper.rb +50 -0
- 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/examples/list_manual_generation/list_manual_generation.rb +22 -0
- data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
- data/examples/list_page_number/list_page_number.rb +17 -0
- 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/examples/single_line_tblock/single_line_tblock.rb +13 -0
- 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/examples/typeB_page_size/typeB_page_size.rb +17 -0
- data/examples/word_wrap/word_wrap.rb +26 -0
- data/examples/word_wrap/word_wrap.tlf +1 -0
- 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 -25
- data/lib/thinreports/core/format/builder.rb +19 -27
- 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/base.rb +4 -5
- 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 +9 -6
- data/lib/thinreports/core/shape/basic.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/image_block.rb +1 -1
- data/lib/thinreports/core/shape/list/configuration.rb +37 -16
- 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 +135 -95
- data/lib/thinreports/core/shape/list/page.rb +57 -51
- data/lib/thinreports/core/shape/list/page_state.rb +19 -17
- 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/list.rb +1 -1
- data/lib/thinreports/core/shape/manager/format.rb +10 -11
- data/lib/thinreports/core/shape/manager/internal.rb +22 -21
- data/lib/thinreports/core/shape/manager/target.rb +63 -34
- data/lib/thinreports/core/shape/manager.rb +1 -1
- data/lib/thinreports/core/shape/page_number/format.rb +25 -0
- data/lib/thinreports/core/shape/page_number/interface.rb +27 -0
- data/lib/thinreports/core/shape/page_number/internal.rb +57 -0
- data/lib/thinreports/core/shape/page_number.rb +15 -0
- 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 +41 -31
- data/lib/thinreports/core/shape/style.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.rb +1 -1
- data/lib/thinreports/core/shape/text_block/format.rb +17 -17
- 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/formatter.rb +7 -8
- 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/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape.rb +11 -13
- data/lib/thinreports/core/utils.rb +33 -32
- data/lib/thinreports/generator/base.rb +15 -24
- data/lib/thinreports/generator/configuration.rb +10 -9
- data/lib/thinreports/generator/pdf/configuration.rb +11 -6
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +41 -32
- data/lib/thinreports/generator/pdf/document/font.rb +53 -44
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +34 -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 +43 -41
- data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
- data/lib/thinreports/generator/pdf/document/page.rb +37 -23
- 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/document.rb +28 -28
- data/lib/thinreports/generator/pdf/drawer/base.rb +16 -22
- data/lib/thinreports/generator/pdf/drawer/list.rb +39 -21
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +17 -18
- data/lib/thinreports/generator/pdf/drawer/page.rb +37 -26
- data/lib/thinreports/generator/pdf/prawn_ext.rb +18 -17
- data/lib/thinreports/generator/pdf.rb +28 -31
- data/lib/thinreports/generator.rb +6 -8
- data/lib/thinreports/layout/base.rb +24 -36
- data/lib/thinreports/layout/configuration.rb +11 -9
- data/lib/thinreports/layout/format.rb +26 -31
- data/lib/thinreports/layout/version.rb +8 -9
- data/lib/thinreports/layout.rb +2 -2
- data/lib/thinreports/report/base.rb +117 -109
- data/lib/thinreports/report/events.rb +5 -5
- data/lib/thinreports/report/internal.rb +48 -38
- data/lib/thinreports/{core → report}/page.rb +42 -32
- data/lib/thinreports/report.rb +10 -14
- data/lib/thinreports/version.rb +2 -3
- data/lib/thinreports.rb +14 -2
- 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/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +14 -14
- data/test/unit/core/format/test_builder.rb +20 -25
- 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 +29 -18
- 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 +50 -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 +15 -5
- data/test/unit/core/shape/list/test_page.rb +80 -22
- data/test/unit/core/shape/list/test_page_state.rb +13 -13
- 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 +73 -0
- data/test/unit/core/shape/page_number/test_interface.rb +33 -0
- data/test/unit/core/shape/page_number/test_internal.rb +81 -0
- 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 +29 -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 +22 -20
- 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 +13 -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 +10 -8
- data/test/unit/core/test_shape.rb +11 -7
- data/test/unit/core/test_utils.rb +68 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +10 -4
- data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
- data/test/unit/generator/pdf/document/test_draw_shape.rb +14 -6
- 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 +68 -43
- 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 +15 -21
- 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 +160 -192
- data/test/unit/report/test_events.rb +4 -4
- data/test/unit/report/test_internal.rb +102 -82
- 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 +23 -26
- metadata +118 -181
- data/.yardopts +0 -1
- data/LICENSE +0 -1
- data/README.rdoc +0 -167
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- 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/ext.rb +0 -5
- data/lib/thinreports/core/format.rb +0 -14
- data/lib/thinreports/core/ordered_hash.rb +0 -39
- data/lib/thinreports/core.rb +0 -20
- data/lib/thinreports/generator/pdf/drawer.rb +0 -16
- data/tasks/doc.rake +0 -13
- 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 -7
- 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/helper.rb +0 -29
- data/test/case/hidden_shapes/hidden_shapes.rb +0 -13
- 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_header_inheriting/list_header_inheriting.rb +0 -17
- data/test/case/list_header_inheriting/list_header_inheriting.tlf +0 -1
- data/test/case/list_manual_generation/list_manual_generation.rb +0 -22
- data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
- data/test/case/single_line_tblock/single_line_tblock.rb +0 -15
- 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 -9
- data/test/case/text_align/text_align.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 -65
- /data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
- /data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
- /data/{test/case → examples}/dynamic_style/image.png +0 -0
- /data/{test/case → examples}/eudc/eudc.ttf +0 -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
@@ -1,28 +1,35 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
4
|
-
module Generator
|
5
|
-
|
6
|
-
|
7
|
-
class PDF::Drawer::Page < PDF::Drawer::Base
|
3
|
+
module Thinreports
|
4
|
+
module Generator::PDF::Drawer
|
5
|
+
|
6
|
+
class Page < Base
|
8
7
|
# @param (see PDF::Drawer::Base#initialize)
|
9
8
|
def initialize(pdf, format)
|
10
9
|
super
|
11
10
|
@lists = {}
|
12
11
|
end
|
13
|
-
|
14
|
-
# @param [
|
15
|
-
def draw(
|
12
|
+
|
13
|
+
# @param [Thinreports::Report::Page] page
|
14
|
+
def draw(page)
|
15
|
+
manager = page.manager
|
16
|
+
|
16
17
|
manager.format.shapes.each_key do |id|
|
17
|
-
|
18
|
-
|
18
|
+
next unless shape = manager.final_shape(id)
|
19
|
+
|
20
|
+
shape = shape.internal
|
21
|
+
|
22
|
+
if shape.type_of?(:pageno)
|
23
|
+
# Do not draw pageno if is not for Report
|
24
|
+
draw_pageno_shape(shape, page) if page.count? && shape.for_report?
|
25
|
+
else
|
26
|
+
draw_shape(shape)
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
22
|
-
|
30
|
+
|
23
31
|
private
|
24
|
-
|
25
|
-
# @param [ThinReports::Core::Shape::Base::Internal] shape
|
32
|
+
|
26
33
|
def draw_shape(shape)
|
27
34
|
case
|
28
35
|
when shape.type_of?(:tblock)
|
@@ -32,7 +39,7 @@ module ThinReports
|
|
32
39
|
when shape.type_of?(:iblock)
|
33
40
|
draw_iblock_shape(shape)
|
34
41
|
else
|
35
|
-
id =
|
42
|
+
id = shape.identifier
|
36
43
|
unless @stamps.include?(id)
|
37
44
|
create_basic_shape_stamp(shape)
|
38
45
|
@stamps << id
|
@@ -40,24 +47,28 @@ module ThinReports
|
|
40
47
|
pdf_stamp(shape)
|
41
48
|
end
|
42
49
|
end
|
43
|
-
|
50
|
+
|
51
|
+
def draw_pageno_shape(shape, page)
|
52
|
+
@pdf.draw_shape_pageno(shape, page.no, page.report.page_count)
|
53
|
+
end
|
54
|
+
|
44
55
|
# @see #draw_shape
|
45
56
|
def draw_list_shape(shape)
|
46
|
-
drawer = @lists[shape.id] ||=
|
57
|
+
drawer = @lists[shape.id] ||= List.new(@pdf, shape.format)
|
47
58
|
drawer.draw(shape)
|
48
59
|
end
|
49
|
-
|
60
|
+
|
50
61
|
# @see #draw_shape
|
51
62
|
def draw_tblock_shape(shape)
|
52
63
|
@pdf.draw_shape_tblock(shape)
|
53
64
|
end
|
54
|
-
|
65
|
+
|
55
66
|
# @see #draw_shape
|
56
67
|
def draw_iblock_shape(shape)
|
57
68
|
@pdf.draw_shape_iblock(shape)
|
58
69
|
end
|
59
|
-
|
60
|
-
# @param [
|
70
|
+
|
71
|
+
# @param [Thinreports::Core::Shape::Base::Internal] shape
|
61
72
|
def create_basic_shape_stamp(shape)
|
62
73
|
case
|
63
74
|
when shape.type_of?(:text) then create_text_stamp(shape)
|
@@ -67,35 +78,35 @@ module ThinReports
|
|
67
78
|
when shape.type_of?(:line) then create_line_stamp(shape)
|
68
79
|
end
|
69
80
|
end
|
70
|
-
|
81
|
+
|
71
82
|
# @see #create_basic_shape_stamp
|
72
83
|
def create_image_stamp(shape)
|
73
84
|
create_pdf_stamp(shape) do
|
74
85
|
@pdf.draw_shape_image(shape)
|
75
86
|
end
|
76
87
|
end
|
77
|
-
|
88
|
+
|
78
89
|
# @see #create_basic_shape_stamp
|
79
90
|
def create_rect_stamp(shape)
|
80
91
|
create_pdf_stamp(shape) do
|
81
92
|
@pdf.draw_shape_rect(shape)
|
82
93
|
end
|
83
94
|
end
|
84
|
-
|
95
|
+
|
85
96
|
# @see #create_basic_shape_stamp
|
86
97
|
def create_ellipse_stamp(shape)
|
87
98
|
create_pdf_stamp(shape) do
|
88
99
|
@pdf.draw_shape_ellipse(shape)
|
89
100
|
end
|
90
101
|
end
|
91
|
-
|
102
|
+
|
92
103
|
# @see #create_basic_shape_stamp
|
93
104
|
def create_line_stamp(shape)
|
94
105
|
create_pdf_stamp(shape) do
|
95
106
|
@pdf.draw_shape_line(shape)
|
96
107
|
end
|
97
108
|
end
|
98
|
-
|
109
|
+
|
99
110
|
# @see #create_basic_shape_stamp
|
100
111
|
def create_text_stamp(shape)
|
101
112
|
create_pdf_stamp(shape) do
|
@@ -103,6 +114,6 @@ module ThinReports
|
|
103
114
|
end
|
104
115
|
end
|
105
116
|
end
|
106
|
-
|
117
|
+
|
107
118
|
end
|
108
119
|
end
|
@@ -1,31 +1,32 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
# @private
|
4
3
|
module Prawn
|
5
|
-
# @private
|
6
4
|
class Document
|
7
|
-
# Create around alias.
|
8
5
|
alias_method :original_width_of, :width_of
|
9
|
-
|
6
|
+
|
10
7
|
def width_of(string, options={})
|
11
8
|
font.compute_width_of(string, options) +
|
12
9
|
(character_spacing * (font.character_count(string) - 1))
|
13
10
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
end
|
12
|
+
|
13
|
+
module Images
|
14
|
+
class Image
|
15
|
+
alias_method :original_calc_image_dimensions, :calc_image_dimensions
|
16
|
+
|
17
|
+
def calc_image_dimensions(options)
|
18
|
+
if options[:auto_fit]
|
19
|
+
w = options[:width] || width
|
20
|
+
h = options[:height] || height
|
21
|
+
|
22
|
+
box_width, box_height = options.delete(:auto_fit)
|
23
|
+
|
24
|
+
if w > box_width || h > box_height
|
25
|
+
options[:fit] = [box_width, box_height]
|
26
|
+
end
|
26
27
|
end
|
28
|
+
original_calc_image_dimensions(options)
|
27
29
|
end
|
28
|
-
original_calc_image_dimensions(info, options)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
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
|
-
|
54
|
-
drawer(format).draw(page
|
46
|
+
@document.start_new_page(format)
|
47
|
+
|
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,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,36 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Layout
|
5
|
-
|
5
|
+
|
6
6
|
class Base
|
7
7
|
EXT_NAME = 'tlf'
|
8
|
-
|
8
|
+
include Utils
|
9
|
+
|
9
10
|
class << self
|
10
11
|
# @param [String] filename
|
11
|
-
# @return [
|
12
|
-
# @raise [
|
13
|
-
# @raise [
|
14
|
-
# @private
|
12
|
+
# @return [Thinreports::Layout::Format]
|
13
|
+
# @raise [Thinreports::Errors::InvalidLayoutFormat]
|
14
|
+
# @raise [Thinreports::Errors::IncompatibleLayoutFormat]
|
15
15
|
def load_format(filename)
|
16
16
|
filename += ".#{EXT_NAME}" unless filename =~/\.#{EXT_NAME}$/
|
17
|
-
|
17
|
+
|
18
18
|
unless File.exists?(filename)
|
19
|
-
raise
|
19
|
+
raise Thinreports::Errors::LayoutFileNotFound
|
20
20
|
end
|
21
21
|
# Build format.
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
# @private
|
26
|
-
def Page
|
27
|
-
const_defined?(:Page) ? Page : Core::Page
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
# @private
|
33
|
-
def PageHelpers(&block)
|
34
|
-
const_set(:Page, ::Class.new(Core::Page, &block))
|
22
|
+
Thinreports::Layout::Format.build(filename)
|
35
23
|
end
|
36
24
|
end
|
37
|
-
|
38
|
-
# @private
|
25
|
+
|
39
26
|
attr_reader :format
|
40
|
-
|
27
|
+
|
41
28
|
# @return [String]
|
42
29
|
attr_reader :filename
|
43
|
-
|
30
|
+
|
44
31
|
# @return [Symbol]
|
45
32
|
attr_reader :id
|
46
|
-
|
33
|
+
|
47
34
|
# @param [String] filename
|
48
35
|
# @param [Hash] options
|
49
36
|
# @option options [Symbol] :id (nil)
|
@@ -52,27 +39,28 @@ module ThinReports
|
|
52
39
|
@format = self.class.load_format(filename)
|
53
40
|
@id = options[:id]
|
54
41
|
end
|
55
|
-
|
42
|
+
|
56
43
|
# @return [Boolean] Return the true if is default layout.
|
57
44
|
def default?
|
58
45
|
@id.nil?
|
59
46
|
end
|
60
|
-
|
47
|
+
|
61
48
|
# @yield [config]
|
62
49
|
# @yieldparam [List::Configuration] config
|
63
50
|
# @return [List::Configuration]
|
64
51
|
def config(&block)
|
65
52
|
@config ||= Layout::Configuration.new(self)
|
66
|
-
|
53
|
+
call_block_in(@config, &block)
|
67
54
|
end
|
68
|
-
|
69
|
-
# @param [
|
55
|
+
|
56
|
+
# @param [Thinreports::Report::Base] parent
|
57
|
+
# @param [Hash] options ({})
|
58
|
+
# @option option [Boolean] :count (true)
|
70
59
|
# @return [Page]
|
71
|
-
|
72
|
-
|
73
|
-
self.class.Page.new(parent, self)
|
60
|
+
def new_page(parent, options = {})
|
61
|
+
Report::Page.new(parent, self, options)
|
74
62
|
end
|
75
63
|
end
|
76
|
-
|
64
|
+
|
77
65
|
end
|
78
66
|
end
|
@@ -1,27 +1,29 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Layout
|
5
|
-
|
5
|
+
|
6
|
+
# @deprecated This class will be removed in the next major version.
|
6
7
|
class Configuration
|
7
8
|
include Core::Shape::Manager::Target
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# @param [ThinReports::Layout::Base] layout
|
9
|
+
|
10
|
+
# @param [Thinreports::Layout::Base] layout
|
12
11
|
def initialize(layout)
|
13
12
|
initialize_manager(layout.format) do |f|
|
14
13
|
Core::Shape::Configuration(f.type).new
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
# @param [String, Symbol] shape_id
|
19
18
|
# @return [Object, nil]
|
20
|
-
# @private
|
21
19
|
def activate(shape_id)
|
22
20
|
(config = manager.shapes[shape_id.to_sym]) && config.copy
|
23
21
|
end
|
22
|
+
|
23
|
+
def values
|
24
|
+
raise NoMethodError
|
25
|
+
end
|
24
26
|
end
|
25
|
-
|
27
|
+
|
26
28
|
end
|
27
29
|
end
|
@@ -2,44 +2,39 @@
|
|
2
2
|
|
3
3
|
require 'digest/sha1'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Thinreports
|
6
6
|
module Layout
|
7
|
-
|
8
|
-
# @private
|
7
|
+
|
9
8
|
class Format < Core::Shape::Manager::Format
|
10
|
-
config_reader :
|
11
|
-
config_reader :
|
12
|
-
config_reader :
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
:page_margin_left => %w( config page margin-right )
|
20
|
-
|
21
|
-
config_checker 'user', :user_paper_type => %w( config page paper-type )
|
22
|
-
|
9
|
+
config_reader last_version: %w( version )
|
10
|
+
config_reader report_title: %w( config title )
|
11
|
+
config_reader page_paper_type: %w( config page paper-type ),
|
12
|
+
page_width: %w( config page width ),
|
13
|
+
page_height: %w( config page height ),
|
14
|
+
page_orientation: %w( config page orientation )
|
15
|
+
|
16
|
+
config_checker 'user', user_paper_type: %w( config page paper-type )
|
17
|
+
|
23
18
|
class << self
|
24
|
-
|
19
|
+
|
25
20
|
private
|
26
|
-
|
21
|
+
|
27
22
|
# @param [String] filename
|
28
23
|
# @param [Hash] options
|
29
24
|
# @option options [Boolean] :force (false)
|
30
25
|
def build_internal(filename, options = {})
|
31
26
|
build_once(filename, options[:force]) do |content, id|
|
32
27
|
raw_format = parse_json(content)
|
33
|
-
|
28
|
+
|
34
29
|
# Check the compatibility of specified layout file.
|
35
|
-
unless
|
30
|
+
unless Thinreports::Layout::Version.compatible?(raw_format['version'])
|
36
31
|
info = [filename, raw_format['version'],
|
37
|
-
|
38
|
-
raise
|
32
|
+
Thinreports::Layout::Version.inspect_required_rules]
|
33
|
+
raise Thinreports::Errors::IncompatibleLayoutFormat.new(*info)
|
39
34
|
end
|
40
|
-
|
35
|
+
|
41
36
|
compact_format!(raw_format)
|
42
|
-
|
37
|
+
|
43
38
|
# Build and initialize format.
|
44
39
|
new(raw_format, id) do |f|
|
45
40
|
build_layout(f) do |type, shape_format|
|
@@ -49,17 +44,17 @@ module ThinReports
|
|
49
44
|
end
|
50
45
|
end
|
51
46
|
end
|
52
|
-
|
47
|
+
|
53
48
|
# @param [Hash] raw_format A parsed json.
|
54
49
|
def compact_format!(raw_format)
|
55
50
|
%w( finger-print state version ).each {|attr| raw_format.delete(attr) }
|
56
51
|
end
|
57
|
-
|
52
|
+
|
58
53
|
# @param [String] filename
|
59
54
|
# @param [Boolean] force (false)
|
60
55
|
def build_once(filename, force = false, &block)
|
61
56
|
content = read_format_file(filename)
|
62
|
-
|
57
|
+
|
63
58
|
if force
|
64
59
|
block.call(content, nil)
|
65
60
|
else
|
@@ -67,19 +62,19 @@ module ThinReports
|
|
67
62
|
built_format_registry[id] ||= block.call(content, id)
|
68
63
|
end
|
69
64
|
end
|
70
|
-
|
65
|
+
|
71
66
|
# @param [String] filename
|
72
67
|
# @return [String]
|
73
68
|
def read_format_file(filename)
|
74
69
|
File.open(filename, 'r:UTF-8') {|f| f.read }
|
75
70
|
end
|
76
|
-
|
71
|
+
|
77
72
|
# @return [Hash]
|
78
73
|
def built_format_registry
|
79
74
|
@built_format_registry ||= {}
|
80
|
-
end
|
75
|
+
end
|
81
76
|
end
|
82
77
|
end
|
83
|
-
|
78
|
+
|
84
79
|
end
|
85
80
|
end
|
@@ -1,18 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Layout
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
module Version
|
8
|
-
REQUIRED_RULES = ['>= 0.
|
9
|
-
|
7
|
+
REQUIRED_RULES = ['>= 0.7.7.0', '< 1.0.0']
|
8
|
+
|
10
9
|
# @param [String] version
|
11
10
|
# @return [Boolean]
|
12
11
|
def self.compatible?(version)
|
13
12
|
compare(version, *REQUIRED_RULES)
|
14
13
|
end
|
15
|
-
|
14
|
+
|
16
15
|
# @param [String] base
|
17
16
|
# @param [Array<String>] rules
|
18
17
|
# @return [Boolean]
|
@@ -22,12 +21,12 @@ module ThinReports
|
|
22
21
|
comparable_version(base).send(op.to_sym, comparable_version(ver))
|
23
22
|
end
|
24
23
|
end
|
25
|
-
|
24
|
+
|
26
25
|
# @return [String]
|
27
26
|
def self.inspect_required_rules
|
28
27
|
'(' + REQUIRED_RULES.join(' and ') + ')'
|
29
28
|
end
|
30
|
-
|
29
|
+
|
31
30
|
# @param [String] version
|
32
31
|
# @return [String]
|
33
32
|
def self.comparable_version(version)
|
@@ -38,6 +37,6 @@ module ThinReports
|
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
41
|
-
|
40
|
+
|
42
41
|
end
|
43
42
|
end
|
data/lib/thinreports/layout.rb
CHANGED