thinreports 0.9.1 → 0.10.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +41 -0
- data/.travis.yml +4 -6
- data/CHANGELOG.md +21 -2
- data/Gemfile +2 -4
- data/README.md +4 -5
- data/Rakefile +7 -8
- data/examples/character_spacing/character_spacing.rb +1 -1
- data/examples/dynamic_image/dynamic_image.rb +3 -3
- data/examples/dynamic_style/dynamic_style.rb +1 -1
- data/examples/eudc/eudc.rb +1 -1
- data/examples/helper.rb +2 -2
- data/examples/hidden_shapes/hidden_shapes.rb +1 -1
- data/examples/list_events/list_events.rb +1 -1
- data/examples/list_manual_generation/list_manual_generation.rb +1 -1
- data/examples/list_page_number/list_page_number.rb +1 -1
- data/examples/page_number/page_number.rb +1 -1
- data/examples/palleted_png/palleted_png.rb +1 -3
- data/examples/password_setting/password_setting.rb +1 -1
- data/examples/report_callbacks/report_callbacks.rb +1 -1
- data/examples/single_line_tblock/single_line_tblock.rb +1 -1
- data/examples/tblock_overflow/tblock_overflow.rb +1 -1
- data/examples/tblock_styles/tblock_styles.rb +1 -1
- data/examples/text_align/text_align.rb +1 -1
- data/examples/typeB_page_size/typeB_page_size.rb +1 -1
- data/examples/word_wrap/word_wrap.rb +1 -1
- data/lib/thinreports.rb +16 -15
- data/lib/thinreports/config.rb +2 -24
- data/lib/thinreports/core/errors.rb +6 -17
- data/lib/thinreports/core/format/base.rb +62 -61
- data/lib/thinreports/core/shape.rb +13 -14
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +35 -32
- data/lib/thinreports/core/shape/base/internal.rb +45 -43
- data/lib/thinreports/core/shape/basic.rb +12 -12
- data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
- data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
- data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
- data/lib/thinreports/core/shape/basic/format.rb +11 -9
- data/lib/thinreports/core/shape/basic/interface.rb +79 -77
- data/lib/thinreports/core/shape/basic/internal.rb +17 -14
- data/lib/thinreports/core/shape/image_block.rb +9 -9
- data/lib/thinreports/core/shape/image_block/format.rb +7 -5
- data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
- data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
- data/lib/thinreports/core/shape/list.rb +13 -13
- data/lib/thinreports/core/shape/list/format.rb +83 -77
- data/lib/thinreports/core/shape/list/manager.rb +182 -176
- data/lib/thinreports/core/shape/list/page.rb +94 -93
- data/lib/thinreports/core/shape/list/page_state.rb +42 -40
- data/lib/thinreports/core/shape/list/section_format.rb +28 -26
- data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
- data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
- data/lib/thinreports/core/shape/manager.rb +4 -13
- data/lib/thinreports/core/shape/manager/format.rb +21 -19
- data/lib/thinreports/core/shape/manager/internal.rb +88 -84
- data/lib/thinreports/core/shape/manager/target.rb +93 -95
- data/lib/thinreports/core/shape/page_number.rb +9 -9
- data/lib/thinreports/core/shape/page_number/format.rb +20 -18
- data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
- data/lib/thinreports/core/shape/page_number/internal.rb +47 -44
- data/lib/thinreports/core/shape/style.rb +5 -14
- data/lib/thinreports/core/shape/style/base.rb +121 -120
- data/lib/thinreports/core/shape/style/basic.rb +12 -10
- data/lib/thinreports/core/shape/style/graphic.rb +35 -33
- data/lib/thinreports/core/shape/style/text.rb +113 -107
- data/lib/thinreports/core/shape/text.rb +9 -9
- data/lib/thinreports/core/shape/text/format.rb +10 -9
- data/lib/thinreports/core/shape/text/interface.rb +13 -11
- data/lib/thinreports/core/shape/text/internal.rb +14 -12
- data/lib/thinreports/core/shape/text_block.rb +10 -10
- data/lib/thinreports/core/shape/text_block/format.rb +35 -33
- data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +45 -39
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
- data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
- data/lib/thinreports/core/shape/text_block/internal.rb +68 -68
- data/lib/thinreports/core/utils.rb +4 -3
- data/lib/thinreports/generator/pdf.rb +24 -25
- data/lib/thinreports/generator/pdf/document.rb +109 -110
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +58 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +51 -47
- data/lib/thinreports/generator/pdf/document/font.rb +62 -59
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +122 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +113 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +152 -137
- data/lib/thinreports/generator/pdf/document/page.rb +63 -64
- data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
- data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
- data/lib/thinreports/generator/pdf/drawer/list.rb +48 -45
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
- data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +29 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -7
- data/lib/thinreports/layout/format.rb +18 -13
- data/lib/thinreports/layout/legacy_schema.rb +18 -10
- data/lib/thinreports/layout/version.rb +22 -25
- data/lib/thinreports/report.rb +4 -6
- data/lib/thinreports/report/base.rb +24 -51
- data/lib/thinreports/report/internal.rb +9 -11
- data/lib/thinreports/report/page.rb +5 -6
- data/lib/thinreports/version.rb +2 -2
- data/test/schema_helper.rb +4 -3
- data/test/test_helper.rb +9 -3
- data/test/unit/core/format/test_base.rb +1 -1
- data/test/unit/core/shape/base/test_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_block_format.rb +1 -1
- data/test/unit/core/shape/basic/test_block_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_block_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_format.rb +1 -1
- data/test/unit/core/shape/basic/test_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_internal.rb +1 -1
- data/test/unit/core/shape/image_block/test_interface.rb +1 -1
- data/test/unit/core/shape/image_block/test_internal.rb +1 -1
- data/test/unit/core/shape/list/test_format.rb +1 -1
- data/test/unit/core/shape/list/test_manager.rb +4 -4
- data/test/unit/core/shape/list/test_page.rb +1 -1
- data/test/unit/core/shape/list/test_page_state.rb +1 -1
- data/test/unit/core/shape/list/test_section_format.rb +1 -1
- data/test/unit/core/shape/list/test_section_interface.rb +2 -2
- data/test/unit/core/shape/list/test_section_internal.rb +1 -1
- data/test/unit/core/shape/manager/test_format.rb +2 -2
- data/test/unit/core/shape/manager/test_internal.rb +3 -3
- data/test/unit/core/shape/manager/test_target.rb +1 -1
- data/test/unit/core/shape/page_number/test_format.rb +1 -1
- data/test/unit/core/shape/page_number/test_interface.rb +1 -1
- data/test/unit/core/shape/page_number/test_internal.rb +1 -1
- data/test/unit/core/shape/styles/test_base.rb +1 -1
- data/test/unit/core/shape/styles/test_basic.rb +1 -1
- data/test/unit/core/shape/styles/test_graphic.rb +1 -1
- data/test/unit/core/shape/styles/test_text.rb +1 -1
- data/test/unit/core/shape/text/test_format.rb +1 -1
- data/test/unit/core/shape/text/test_internal.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_number.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +2 -2
- data/test/unit/core/shape/text_block/test_format.rb +1 -1
- data/test/unit/core/shape/text_block/test_formatter.rb +1 -1
- data/test/unit/core/shape/text_block/test_interface.rb +1 -1
- data/test/unit/core/shape/text_block/test_internal.rb +3 -3
- data/test/unit/core/test_shape.rb +1 -1
- data/test/unit/core/test_utils.rb +2 -2
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +1 -1
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +2 -1
- data/test/unit/generator/pdf/document/graphics/test_image.rb +27 -131
- data/test/unit/generator/pdf/document/graphics/test_text.rb +1 -1
- data/test/unit/generator/pdf/document/test_font.rb +2 -2
- data/test/unit/generator/pdf/document/test_graphics.rb +1 -1
- data/test/unit/generator/pdf/document/test_page.rb +7 -7
- data/test/unit/generator/pdf/document/test_parse_color.rb +1 -1
- data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +41 -0
- data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +22 -0
- data/test/unit/generator/pdf/test_document.rb +8 -6
- data/test/unit/generator/test_pdf.rb +12 -10
- data/test/unit/layout/test_base.rb +1 -1
- data/test/unit/layout/test_format.rb +2 -2
- data/test/unit/layout/test_legacy_schema.rb +4 -4
- data/test/unit/layout/test_version.rb +11 -80
- data/test/unit/report/test_base.rb +45 -59
- data/test/unit/report/test_internal.rb +1 -1
- data/test/unit/test_config.rb +1 -16
- data/test/unit/test_layout.rb +1 -1
- data/test/unit/test_report.rb +1 -1
- data/thinreports.gemspec +11 -14
- metadata +42 -103
- data/lib/thinreports/generator.rb +0 -29
- data/lib/thinreports/generator/base.rb +0 -40
- data/lib/thinreports/generator/configuration.rb +0 -31
- data/lib/thinreports/report/events.rb +0 -32
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
|
@@ -1,120 +1,125 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Thinreports
|
|
4
|
-
module Generator
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
module Generator
|
|
5
|
+
class PDF
|
|
6
|
+
module Drawer
|
|
7
|
+
class Page < Base
|
|
8
|
+
# @param (see PDF::Drawer::Base#initialize)
|
|
9
|
+
def initialize(pdf, format)
|
|
10
|
+
super
|
|
11
|
+
@lists = {}
|
|
12
|
+
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
# @param [Thinreports::Report::Page] page
|
|
15
|
+
def draw(page)
|
|
16
|
+
manager = page.manager
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
manager.format.shapes.each_key do |id|
|
|
19
|
+
shape = manager.final_shape(id)
|
|
20
|
+
next unless shape
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
shape = shape.internal
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
if shape.type_of?(Core::Shape::PageNumber::TYPE_NAME)
|
|
25
|
+
# Do not draw pageno if is not for Report
|
|
26
|
+
draw_pageno_shape(shape, page) if page.count? && shape.for_report?
|
|
27
|
+
else
|
|
28
|
+
draw_shape(shape)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
28
31
|
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def draw_shape(shape)
|
|
36
|
+
if shape.type_of?(Core::Shape::TextBlock::TYPE_NAME)
|
|
37
|
+
draw_tblock_shape(shape)
|
|
38
|
+
elsif shape.type_of?(Core::Shape::List::TYPE_NAME)
|
|
39
|
+
draw_list_shape(shape)
|
|
40
|
+
elsif shape.type_of?(Core::Shape::ImageBlock::TYPE_NAME)
|
|
41
|
+
draw_iblock_shape(shape)
|
|
42
|
+
else
|
|
43
|
+
id = shape.identifier
|
|
44
|
+
unless @stamps.include?(id)
|
|
45
|
+
create_basic_shape_stamp(shape)
|
|
46
|
+
@stamps << id
|
|
47
|
+
end
|
|
48
|
+
pdf_stamp(shape)
|
|
49
|
+
end
|
|
47
50
|
end
|
|
48
|
-
pdf_stamp(shape)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
def draw_pageno_shape(shape, page)
|
|
53
|
+
@pdf.draw_shape_pageno(shape, page.no, page.report.page_count)
|
|
54
|
+
end
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
# @see #draw_shape
|
|
57
|
+
def draw_list_shape(shape)
|
|
58
|
+
drawer = @lists[shape.id] ||= List.new(@pdf, shape.format)
|
|
59
|
+
drawer.draw(shape)
|
|
60
|
+
end
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
# @see #draw_shape
|
|
63
|
+
def draw_tblock_shape(shape)
|
|
64
|
+
@pdf.draw_shape_tblock(shape)
|
|
65
|
+
end
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
# @see #draw_shape
|
|
68
|
+
def draw_iblock_shape(shape)
|
|
69
|
+
@pdf.draw_shape_iblock(shape)
|
|
70
|
+
end
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
# @param [Thinreports::Core::Shape::Base::Internal] shape
|
|
73
|
+
def create_basic_shape_stamp(shape)
|
|
74
|
+
if shape.type_of?('text')
|
|
75
|
+
create_text_stamp(shape)
|
|
76
|
+
elsif shape.type_of?('image')
|
|
77
|
+
create_image_stamp(shape)
|
|
78
|
+
elsif shape.type_of?('ellipse')
|
|
79
|
+
create_ellipse_stamp(shape)
|
|
80
|
+
elsif shape.type_of?('rect')
|
|
81
|
+
create_rect_stamp(shape)
|
|
82
|
+
elsif shape.type_of?('line')
|
|
83
|
+
create_line_stamp(shape)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
# @see #create_basic_shape_stamp
|
|
88
|
+
def create_image_stamp(shape)
|
|
89
|
+
create_pdf_stamp(shape) do
|
|
90
|
+
@pdf.draw_shape_image(shape)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
# @see #create_basic_shape_stamp
|
|
95
|
+
def create_rect_stamp(shape)
|
|
96
|
+
create_pdf_stamp(shape) do
|
|
97
|
+
@pdf.draw_shape_rect(shape)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
96
100
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
# @see #create_basic_shape_stamp
|
|
102
|
+
def create_ellipse_stamp(shape)
|
|
103
|
+
create_pdf_stamp(shape) do
|
|
104
|
+
@pdf.draw_shape_ellipse(shape)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
103
107
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
# @see #create_basic_shape_stamp
|
|
109
|
+
def create_line_stamp(shape)
|
|
110
|
+
create_pdf_stamp(shape) do
|
|
111
|
+
@pdf.draw_shape_line(shape)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
110
114
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
# @see #create_basic_shape_stamp
|
|
116
|
+
def create_text_stamp(shape)
|
|
117
|
+
create_pdf_stamp(shape) do
|
|
118
|
+
@pdf.draw_shape_text(shape)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
115
121
|
end
|
|
116
122
|
end
|
|
117
123
|
end
|
|
118
|
-
|
|
119
124
|
end
|
|
120
125
|
end
|
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
alias_method :original_width_of, :width_of
|
|
3
|
+
require_relative 'prawn_ext/width_of'
|
|
4
|
+
require_relative 'prawn_ext/calc_image_dimensions'
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
font.compute_width_of(string, options) +
|
|
9
|
-
(character_spacing * (font.character_count(string) - 1))
|
|
10
|
-
end
|
|
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
|
|
27
|
-
end
|
|
28
|
-
original_calc_image_dimensions(options)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
6
|
+
Prawn::Font::AFM.hide_m17n_warning = true
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Thinreports
|
|
4
|
+
module Generator
|
|
5
|
+
module PrawnExt
|
|
6
|
+
module CalcImageDimensions
|
|
7
|
+
# Implement :auto_fit option for image size calculation.
|
|
8
|
+
#
|
|
9
|
+
# When the image is larger than the box, the original: fit option does not change
|
|
10
|
+
# the image size. The :auto_fit option changes the image size to fit in the box
|
|
11
|
+
# while maintaining the aspect ratio.
|
|
12
|
+
#
|
|
13
|
+
# Usage:
|
|
14
|
+
# image '/path/to/image.png', at: [100, 100], auto_fit: [100, 100]
|
|
15
|
+
#
|
|
16
|
+
def calc_image_dimensions(options)
|
|
17
|
+
if options[:auto_fit]
|
|
18
|
+
image_width = options[:width] || width
|
|
19
|
+
image_height = options[:height] || height
|
|
20
|
+
|
|
21
|
+
box_width, box_height = options.delete(:auto_fit)
|
|
22
|
+
|
|
23
|
+
if image_width > box_width || image_height > box_height
|
|
24
|
+
options[:fit] = [box_width, box_height]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
super(options)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Prawn::Images::Image.prepend Thinreports::Generator::PrawnExt::CalcImageDimensions
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Thinreports
|
|
4
|
+
module Generator
|
|
5
|
+
module PrawnExt
|
|
6
|
+
module WidthOf
|
|
7
|
+
# Subtract the width of one character space from the string width calculation result.
|
|
8
|
+
#
|
|
9
|
+
# The original Prawn::Document#width_of returns the following result:
|
|
10
|
+
#
|
|
11
|
+
# Width of Character is 1
|
|
12
|
+
# Width of Character Space is 1
|
|
13
|
+
#
|
|
14
|
+
# width_of('abcd') #=> 4 + 4 = 8
|
|
15
|
+
#
|
|
16
|
+
# In this width_of, returns the following result:
|
|
17
|
+
#
|
|
18
|
+
# width_of('abcd') #=> 4 + 3 = 7
|
|
19
|
+
#
|
|
20
|
+
def width_of(*)
|
|
21
|
+
width = super - character_spacing
|
|
22
|
+
width > 0 ? width : 0
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Prawn::Document.prepend Thinreports::Generator::PrawnExt::WidthOf
|
data/lib/thinreports/layout.rb
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Thinreports
|
|
4
|
-
|
|
5
4
|
module Layout
|
|
6
5
|
# @see Thinreports::Layout::Base#initialize
|
|
7
6
|
def self.new(filename, options = {})
|
|
8
7
|
Base.new(filename, options)
|
|
9
8
|
end
|
|
10
9
|
end
|
|
11
|
-
|
|
12
10
|
end
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
require_relative 'layout/version'
|
|
13
|
+
require_relative 'layout/base'
|
|
14
|
+
require_relative 'layout/format'
|
|
15
|
+
require_relative 'layout/legacy_schema'
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Thinreports
|
|
4
4
|
module Layout
|
|
5
|
-
|
|
6
5
|
class Base
|
|
7
|
-
EXT_NAME = 'tlf'
|
|
6
|
+
EXT_NAME = 'tlf'.freeze
|
|
8
7
|
include Utils
|
|
9
8
|
|
|
10
9
|
class << self
|
|
@@ -13,7 +12,7 @@ module Thinreports
|
|
|
13
12
|
# @raise [Thinreports::Errors::InvalidLayoutFormat]
|
|
14
13
|
# @raise [Thinreports::Errors::IncompatibleLayoutFormat]
|
|
15
14
|
def load_format(filename)
|
|
16
|
-
filename += ".#{EXT_NAME}" unless filename
|
|
15
|
+
filename += ".#{EXT_NAME}" unless filename =~ /\.#{EXT_NAME}$/
|
|
17
16
|
|
|
18
17
|
unless File.exist?(filename)
|
|
19
18
|
raise Thinreports::Errors::LayoutFileNotFound
|
|
@@ -36,8 +35,8 @@ module Thinreports
|
|
|
36
35
|
# @option options [Symbol] :id (nil)
|
|
37
36
|
def initialize(filename, options = {})
|
|
38
37
|
@filename = filename
|
|
39
|
-
@format
|
|
40
|
-
@id
|
|
38
|
+
@format = self.class.load_format(filename)
|
|
39
|
+
@id = options[:id]
|
|
41
40
|
end
|
|
42
41
|
|
|
43
42
|
# @return [Boolean] Return the true if is default layout.
|
|
@@ -45,6 +44,5 @@ module Thinreports
|
|
|
45
44
|
@id.nil?
|
|
46
45
|
end
|
|
47
46
|
end
|
|
48
|
-
|
|
49
47
|
end
|
|
50
48
|
end
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'json'
|
|
3
4
|
|
|
4
5
|
module Thinreports
|
|
5
6
|
module Layout
|
|
6
7
|
class Format < Core::Shape::Manager::Format
|
|
7
|
-
config_reader last_version: %w
|
|
8
|
-
config_reader report_title: %w
|
|
9
|
-
config_reader page_paper_type: %w
|
|
10
|
-
page_width: %w
|
|
11
|
-
page_height: %w
|
|
12
|
-
page_orientation: %w
|
|
8
|
+
config_reader last_version: %w[version]
|
|
9
|
+
config_reader report_title: %w[title]
|
|
10
|
+
config_reader page_paper_type: %w[report paper-type],
|
|
11
|
+
page_width: %w[report width],
|
|
12
|
+
page_height: %w[report height],
|
|
13
|
+
page_orientation: %w[report orientation]
|
|
13
14
|
|
|
14
15
|
class << self
|
|
16
|
+
# rubocop:disable Metrics/AbcSize
|
|
15
17
|
def build(filename)
|
|
16
18
|
schema = JSON.parse(read_file(filename))
|
|
19
|
+
schema_version = Layout::Version.new(schema['version'])
|
|
17
20
|
|
|
18
|
-
unless
|
|
21
|
+
unless schema_version.compatible?
|
|
19
22
|
raise Errors::IncompatibleLayoutFormat.new(
|
|
20
|
-
filename, schema['version'],
|
|
23
|
+
filename, schema['version'],
|
|
24
|
+
Layout::Version.compatible_rules.join(' and ')
|
|
21
25
|
)
|
|
22
26
|
end
|
|
23
27
|
|
|
24
|
-
if
|
|
25
|
-
warn '[DEPRECATION] Support for the layout file with old format
|
|
28
|
+
if schema_version.legacy?
|
|
29
|
+
warn '[DEPRECATION] Support for the layout file with old format' \
|
|
30
|
+
' that generated with Editor 0.8 or lower will be dropped in Thinreports 1.1.' \
|
|
26
31
|
' Please convert to new layout format using Thinreports Editor 0.9 or 1.0.'
|
|
27
32
|
schema = Layout::LegacySchema.new(schema).upgrade
|
|
28
33
|
end
|
|
@@ -31,7 +36,7 @@ module Thinreports
|
|
|
31
36
|
end
|
|
32
37
|
|
|
33
38
|
def read_file(filename)
|
|
34
|
-
File.
|
|
39
|
+
File.read(filename, encoding: 'UTF-8')
|
|
35
40
|
end
|
|
36
41
|
end
|
|
37
42
|
|
|
@@ -53,7 +58,7 @@ module Thinreports
|
|
|
53
58
|
next if id.empty? && type != 'page-number'
|
|
54
59
|
|
|
55
60
|
item = Core::Shape::Format(type).new(item_schema)
|
|
56
|
-
|
|
61
|
+
shapes[item.id.to_sym] = item
|
|
57
62
|
end
|
|
58
63
|
end
|
|
59
64
|
end
|