thinreports 0.10.0 → 0.12.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 +5 -5
- data/.github/CONTRIBUTING.md +2 -2
- data/.github/workflows/test.yml +51 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +49 -0
- data/Dockerfile +12 -0
- data/Gemfile +2 -1
- data/README.md +46 -21
- data/Rakefile +13 -29
- data/gemfiles/prawn-2.2.gemfile +5 -0
- data/gemfiles/prawn-2.3.gemfile +5 -0
- data/gemfiles/prawn-2.4.gemfile +5 -0
- data/lib/thinreports.rb +5 -0
- data/lib/thinreports/core/shape.rb +4 -3
- data/lib/thinreports/core/shape/base/interface.rb +0 -1
- data/lib/thinreports/core/shape/basic/format.rb +5 -0
- data/lib/thinreports/core/shape/image_block.rb +1 -1
- data/lib/thinreports/core/shape/list.rb +1 -1
- data/lib/thinreports/core/shape/list/manager.rb +1 -4
- data/lib/thinreports/core/shape/list/page.rb +2 -5
- data/lib/thinreports/core/shape/manager/internal.rb +0 -1
- data/lib/thinreports/core/shape/page_number.rb +1 -1
- data/lib/thinreports/core/shape/page_number/internal.rb +0 -1
- data/lib/thinreports/core/shape/stack_view.rb +17 -0
- data/lib/thinreports/core/shape/stack_view/format.rb +27 -0
- data/lib/thinreports/core/shape/stack_view/interface.rb +17 -0
- data/lib/thinreports/core/shape/stack_view/internal.rb +22 -0
- data/lib/thinreports/core/shape/stack_view/row_format.rb +39 -0
- data/lib/thinreports/core/shape/style/basic.rb +4 -1
- data/lib/thinreports/core/shape/text.rb +1 -1
- data/lib/thinreports/core/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +21 -9
- data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
- data/lib/thinreports/core/utils.rb +6 -3
- data/lib/thinreports/generate.rb +11 -0
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -11
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -2
- data/lib/thinreports/generator/pdf/document/font.rb +16 -10
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +0 -1
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +0 -1
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -8
- data/lib/thinreports/generator/pdf/document/page.rb +13 -4
- data/lib/thinreports/generator/pdf/drawer/list.rb +0 -1
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +1 -3
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
- data/lib/thinreports/layout/base.rb +2 -4
- data/lib/thinreports/layout/format.rb +0 -1
- data/lib/thinreports/layout/legacy_schema.rb +2 -6
- data/lib/thinreports/layout/version.rb +1 -1
- data/lib/thinreports/report/internal.rb +4 -4
- data/lib/thinreports/report/page.rb +2 -7
- data/lib/thinreports/section_report/build.rb +32 -0
- data/lib/thinreports/section_report/builder/item_builder.rb +49 -0
- data/lib/thinreports/section_report/builder/report_builder.rb +82 -0
- data/lib/thinreports/section_report/builder/report_data.rb +13 -0
- data/lib/thinreports/section_report/builder/stack_view_builder.rb +55 -0
- data/lib/thinreports/section_report/builder/stack_view_data.rb +11 -0
- data/lib/thinreports/section_report/generate.rb +26 -0
- data/lib/thinreports/section_report/pdf/render.rb +23 -0
- data/lib/thinreports/section_report/pdf/renderer/draw_item.rb +68 -0
- data/lib/thinreports/section_report/pdf/renderer/group_renderer.rb +57 -0
- data/lib/thinreports/section_report/pdf/renderer/headers_renderer.rb +24 -0
- data/lib/thinreports/section_report/pdf/renderer/section_height.rb +100 -0
- data/lib/thinreports/section_report/pdf/renderer/section_renderer.rb +39 -0
- data/lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb +55 -0
- data/lib/thinreports/section_report/pdf/renderer/stack_view_row_renderer.rb +38 -0
- data/lib/thinreports/section_report/schema/loader.rb +28 -0
- data/lib/thinreports/section_report/schema/parser.rb +52 -0
- data/lib/thinreports/section_report/schema/report.rb +30 -0
- data/lib/thinreports/section_report/schema/section.rb +47 -0
- data/lib/thinreports/version.rb +1 -1
- data/thinreports.gemspec +11 -11
- metadata +48 -164
- data/.rubocop.yml +0 -41
- data/.travis.yml +0 -17
- data/examples/character_spacing/character_spacing.rb +0 -8
- data/examples/character_spacing/character_spacing.tlf +0 -293
- data/examples/dynamic_image/dynamic_image.rb +0 -31
- data/examples/dynamic_image/dynamic_image.tlf +0 -661
- data/examples/dynamic_image/img200x100.png +0 -0
- data/examples/dynamic_image/img50x50.png +0 -0
- data/examples/dynamic_style/dynamic_style.rb +0 -150
- data/examples/dynamic_style/dynamic_style.tlf +0 -1835
- data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
- data/examples/dynamic_style/image.png +0 -0
- data/examples/eudc/eudc.rb +0 -20
- data/examples/eudc/eudc.tlf +0 -180
- data/examples/eudc/eudc.ttf +0 -0
- data/examples/helper.rb +0 -50
- data/examples/hidden_shapes/hidden_shapes.rb +0 -9
- data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
- data/examples/list_events/list_events.rb +0 -32
- data/examples/list_events/list_events.tlf +0 -361
- data/examples/list_manual_generation/list_manual_generation.rb +0 -22
- data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
- data/examples/list_page_number/list_page_number.rb +0 -17
- data/examples/list_page_number/list_page_number.tlf +0 -254
- data/examples/page_number/page_number.rb +0 -33
- data/examples/page_number/page_number.tlf +0 -215
- data/examples/palleted_png/palleted_png.png +0 -0
- data/examples/palleted_png/palleted_png.rb +0 -9
- data/examples/palleted_png/palleted_png.tlf +0 -47
- data/examples/password_setting/password_setting.rb +0 -10
- data/examples/password_setting/password_setting.tlf +0 -45
- data/examples/report_callbacks/report_callbacks.rb +0 -14
- data/examples/report_callbacks/report_callbacks.tlf +0 -147
- data/examples/single_line_tblock/single_line_tblock.rb +0 -13
- data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
- data/examples/tblock_overflow/tblock_overflow.rb +0 -20
- data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
- data/examples/tblock_styles/font_size.tlf +0 -383
- data/examples/tblock_styles/tblock_styles.rb +0 -43
- data/examples/tblock_styles/tblock_styles.tlf +0 -889
- data/examples/text_align/text_align.rb +0 -8
- data/examples/text_align/text_align.tlf +0 -241
- data/examples/typeB_page_size/B4_ISO.tlf +0 -45
- data/examples/typeB_page_size/B4_JIS.tlf +0 -45
- data/examples/typeB_page_size/typeB_page_size.rb +0 -17
- data/examples/word_wrap/word_wrap.rb +0 -26
- data/examples/word_wrap/word_wrap.tlf +0 -297
- data/test/data/font.ttf +0 -0
- data/test/data/image_normal.jpg +0 -0
- data/test/data/image_normal.png +0 -0
- data/test/data/image_normal_jpg_noext +0 -0
- data/test/data/image_normal_png_noext +0 -0
- data/test/data/image_pallete_based.png +0 -0
- data/test/data/legacy_layout/all-items.tlf +0 -1
- data/test/schema_helper.rb +0 -122
- data/test/test_helper.rb +0 -48
- data/test/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +0 -152
- data/test/unit/core/shape/base/test_internal.rb +0 -87
- data/test/unit/core/shape/basic/test_block_format.rb +0 -23
- data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
- data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
- data/test/unit/core/shape/basic/test_format.rb +0 -37
- data/test/unit/core/shape/basic/test_interface.rb +0 -108
- data/test/unit/core/shape/basic/test_internal.rb +0 -55
- data/test/unit/core/shape/image_block/test_interface.rb +0 -24
- data/test/unit/core/shape/image_block/test_internal.rb +0 -31
- data/test/unit/core/shape/list/test_format.rb +0 -111
- data/test/unit/core/shape/list/test_manager.rb +0 -67
- data/test/unit/core/shape/list/test_page.rb +0 -82
- data/test/unit/core/shape/list/test_page_state.rb +0 -31
- data/test/unit/core/shape/list/test_section_format.rb +0 -36
- data/test/unit/core/shape/list/test_section_interface.rb +0 -75
- data/test/unit/core/shape/list/test_section_internal.rb +0 -50
- data/test/unit/core/shape/manager/test_format.rb +0 -38
- data/test/unit/core/shape/manager/test_internal.rb +0 -132
- data/test/unit/core/shape/manager/test_target.rb +0 -140
- data/test/unit/core/shape/page_number/test_format.rb +0 -55
- data/test/unit/core/shape/page_number/test_interface.rb +0 -33
- data/test/unit/core/shape/page_number/test_internal.rb +0 -81
- data/test/unit/core/shape/styles/test_base.rb +0 -191
- data/test/unit/core/shape/styles/test_basic.rb +0 -24
- data/test/unit/core/shape/styles/test_graphic.rb +0 -50
- data/test/unit/core/shape/styles/test_text.rb +0 -97
- data/test/unit/core/shape/text/test_format.rb +0 -44
- data/test/unit/core/shape/text/test_internal.rb +0 -20
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
- data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
- data/test/unit/core/shape/text_block/test_format.rb +0 -169
- data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
- data/test/unit/core/shape/text_block/test_interface.rb +0 -63
- data/test/unit/core/shape/text_block/test_internal.rb +0 -128
- data/test/unit/core/test_shape.rb +0 -52
- data/test/unit/core/test_utils.rb +0 -68
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -46
- data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -46
- data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
- data/test/unit/generator/pdf/document/test_font.rb +0 -84
- data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
- data/test/unit/generator/pdf/document/test_page.rb +0 -122
- data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
- data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
- data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +0 -22
- data/test/unit/generator/pdf/test_document.rb +0 -22
- data/test/unit/generator/test_pdf.rb +0 -26
- data/test/unit/layout/test_base.rb +0 -41
- data/test/unit/layout/test_format.rb +0 -100
- data/test/unit/layout/test_legacy_schema.rb +0 -574
- data/test/unit/layout/test_version.rb +0 -26
- data/test/unit/report/test_base.rb +0 -248
- data/test/unit/report/test_internal.rb +0 -206
- data/test/unit/test_config.rb +0 -36
- data/test/unit/test_layout.rb +0 -12
- data/test/unit/test_report.rb +0 -18
|
@@ -74,7 +74,6 @@ module Thinreports
|
|
|
74
74
|
|
|
75
75
|
# @param [Thinreports::Report::Page] new_parent
|
|
76
76
|
# @return [Thinreports::Core::Shape::List::Page]
|
|
77
|
-
# rubocop:disable Metrics/AbcSize
|
|
78
77
|
def copy(new_parent)
|
|
79
78
|
if manager.auto_page_break?
|
|
80
79
|
new_list = self.class.new(new_parent, internal.format,
|
|
@@ -87,12 +86,10 @@ module Thinreports
|
|
|
87
86
|
internal.rows.each do |row|
|
|
88
87
|
new_list.internal.rows << row.copy(new_list)
|
|
89
88
|
end
|
|
90
|
-
new_list.finalized!
|
|
89
|
+
new_list.internal.finalized!
|
|
91
90
|
end
|
|
92
91
|
|
|
93
|
-
if internal.format.has_header?
|
|
94
|
-
new_list.internal.header = internal.header.copy(new_list)
|
|
95
|
-
end
|
|
92
|
+
new_list.internal.header = internal.header.copy(new_list) if internal.format.has_header?
|
|
96
93
|
new_list
|
|
97
94
|
end
|
|
98
95
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Thinreports
|
|
4
|
+
module Core
|
|
5
|
+
module Shape
|
|
6
|
+
module StackView
|
|
7
|
+
TYPE_NAME = 'stack-view'.freeze
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
require_relative 'stack_view/format'
|
|
14
|
+
require_relative 'stack_view/interface'
|
|
15
|
+
require_relative 'stack_view/internal'
|
|
16
|
+
|
|
17
|
+
require_relative 'stack_view/row_format'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Thinreports
|
|
4
|
+
module Core
|
|
5
|
+
module Shape
|
|
6
|
+
module StackView
|
|
7
|
+
class Format < Basic::Format
|
|
8
|
+
attr_reader :rows
|
|
9
|
+
|
|
10
|
+
def initialize(*)
|
|
11
|
+
super
|
|
12
|
+
initialize_rows
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def initialize_rows
|
|
18
|
+
@rows = []
|
|
19
|
+
attributes['rows'].each do |row|
|
|
20
|
+
@rows << StackView::RowFormat.new(row)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Thinreports
|
|
4
|
+
module Core
|
|
5
|
+
module Shape
|
|
6
|
+
module StackView
|
|
7
|
+
class Interface < Basic::Interface
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def init_internal(parent, format)
|
|
11
|
+
StackView::Internal.new(parent, format)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Thinreports
|
|
4
|
+
module Core
|
|
5
|
+
module Shape
|
|
6
|
+
module StackView
|
|
7
|
+
class Internal < Basic::Internal
|
|
8
|
+
def initialize(parent, format)
|
|
9
|
+
super
|
|
10
|
+
@rows = []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
attr_accessor :rows
|
|
14
|
+
|
|
15
|
+
def type_of?(type_name)
|
|
16
|
+
type_name == StackView::TYPE_NAME
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Thinreports
|
|
4
|
+
module Core
|
|
5
|
+
module Shape
|
|
6
|
+
module StackView
|
|
7
|
+
class RowFormat < Core::Format::Base
|
|
8
|
+
config_reader :id
|
|
9
|
+
config_reader :height
|
|
10
|
+
config_checker true, :display
|
|
11
|
+
config_checker true, auto_stretch: 'auto-stretch'
|
|
12
|
+
|
|
13
|
+
attr_reader :items
|
|
14
|
+
|
|
15
|
+
def initialize(*)
|
|
16
|
+
super
|
|
17
|
+
@items = []
|
|
18
|
+
@item_with_ids = {}
|
|
19
|
+
initialize_items(attributes['items'])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def find_item(id)
|
|
23
|
+
@item_with_ids[id.to_sym]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def initialize_items(item_schemas)
|
|
29
|
+
item_schemas.each do |item_schema|
|
|
30
|
+
item = Core::Shape::Format(item_schema['type']).new(item_schema)
|
|
31
|
+
@items << item
|
|
32
|
+
@item_with_ids[item.id.to_sym] = item unless item.id.empty?
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -5,9 +5,12 @@ module Thinreports
|
|
|
5
5
|
module Shape
|
|
6
6
|
module Style
|
|
7
7
|
class Basic < Style::Base
|
|
8
|
-
style_accessible :visible
|
|
8
|
+
style_accessible :visible, :offset_x, :offset_y
|
|
9
9
|
attr_accessor :visible
|
|
10
10
|
|
|
11
|
+
style_accessor :offset_x, 'offset-x'
|
|
12
|
+
style_accessor :offset_y, 'offset-y'
|
|
13
|
+
|
|
11
14
|
def initialize(*args)
|
|
12
15
|
super
|
|
13
16
|
@visible = @format.display?
|
|
@@ -15,12 +15,8 @@ module Thinreports
|
|
|
15
15
|
delimiter = format.format_number_delimiter
|
|
16
16
|
|
|
17
17
|
if_applicable value do |val|
|
|
18
|
-
unless blank_value?(precision)
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
unless blank_value?(delimiter)
|
|
22
|
-
val = number_with_delimiter(val, delimiter)
|
|
23
|
-
end
|
|
18
|
+
val = number_with_precision(val, precision) unless blank_value?(precision)
|
|
19
|
+
val = number_with_delimiter(val, delimiter) unless blank_value?(delimiter)
|
|
24
20
|
val
|
|
25
21
|
end
|
|
26
22
|
end
|
|
@@ -32,21 +28,37 @@ module Thinreports
|
|
|
32
28
|
|
|
33
29
|
def normalize(value)
|
|
34
30
|
if value.is_a?(String)
|
|
35
|
-
|
|
36
|
-
(Integer(value) rescue nil) || (Float(value) rescue nil)
|
|
31
|
+
convert_to_integer(value) || convert_to_float(value)
|
|
37
32
|
else
|
|
38
33
|
value
|
|
39
34
|
end
|
|
40
35
|
end
|
|
41
36
|
|
|
42
37
|
def number_with_delimiter(value, delimiter = ',')
|
|
43
|
-
value.to_s.
|
|
38
|
+
value_int, value_float = value.to_s.split('.')
|
|
39
|
+
|
|
40
|
+
[
|
|
41
|
+
value_int.gsub(/(\d)(?=(\d{3})+(?!\d))/) { "#{$1}#{delimiter}" },
|
|
42
|
+
value_float
|
|
43
|
+
].compact.join('.')
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def number_with_precision(value, precision = 3)
|
|
47
47
|
value = BigDecimal(value.to_s).round(precision)
|
|
48
48
|
sprintf("%.#{precision}f", value)
|
|
49
49
|
end
|
|
50
|
+
|
|
51
|
+
def convert_to_integer(value)
|
|
52
|
+
Integer(value)
|
|
53
|
+
rescue ArgumentError
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def convert_to_float(value)
|
|
58
|
+
Float(value)
|
|
59
|
+
rescue ArgumentError
|
|
60
|
+
nil
|
|
61
|
+
end
|
|
50
62
|
end
|
|
51
63
|
end
|
|
52
64
|
end
|
|
@@ -6,13 +6,16 @@ module Thinreports
|
|
|
6
6
|
klass.extend self
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
# rubocop:disable Style/RescueModifier
|
|
10
9
|
def deep_copy(src)
|
|
11
10
|
case src
|
|
12
11
|
when Hash
|
|
13
|
-
src.each_with_object({})
|
|
12
|
+
src.each_with_object({}) do |(k, v), h|
|
|
13
|
+
h[k] = v.dup rescue v
|
|
14
|
+
end
|
|
14
15
|
when Array
|
|
15
|
-
src.map
|
|
16
|
+
src.map do |a|
|
|
17
|
+
a.dup rescue a
|
|
18
|
+
end
|
|
16
19
|
else
|
|
17
20
|
raise ArgumentError
|
|
18
21
|
end
|
|
@@ -5,21 +5,26 @@ module Thinreports
|
|
|
5
5
|
class PDF
|
|
6
6
|
module DrawShape
|
|
7
7
|
# @param [Thinreports::Core::Shape::TextBlock::Internal] shape
|
|
8
|
-
#
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
# @param [Numeric] height (nil) It will be used as rendering height if present.
|
|
9
|
+
# Otherwise, the rendering height is the height of schema.
|
|
10
|
+
# @param [:truncate, :shrink_to_fit, :expand] overflow (nil) It will be set the overflow attribute if present.
|
|
11
|
+
def draw_shape_tblock(shape, height: nil, overflow: nil, &block)
|
|
12
|
+
x, y, w = shape.format.attributes.values_at('x', 'y', 'width')
|
|
13
|
+
|
|
14
|
+
h = height || shape.format.attributes['height']
|
|
11
15
|
|
|
12
16
|
content = shape.real_value.to_s
|
|
13
17
|
return if content.empty?
|
|
14
18
|
|
|
15
19
|
attrs = build_text_attributes(shape.style.finalized_styles)
|
|
20
|
+
attrs[:overflow] = overflow if overflow
|
|
16
21
|
|
|
17
22
|
unless shape.multiple?
|
|
18
23
|
content = content.tr("\n", ' ')
|
|
19
24
|
attrs[:single] = true
|
|
20
25
|
end
|
|
21
26
|
|
|
22
|
-
text_box(content, x, y, w, h, attrs)
|
|
27
|
+
text_box(content, x, y, w, h, attrs, &block)
|
|
23
28
|
end
|
|
24
29
|
|
|
25
30
|
def draw_shape_pageno(shape, page_no, page_count)
|
|
@@ -45,6 +50,21 @@ module Thinreports
|
|
|
45
50
|
style = shape.style.finalized_styles
|
|
46
51
|
|
|
47
52
|
image_box(
|
|
53
|
+
shape.src, x, y, w, h,
|
|
54
|
+
position_x: image_position_x(style['position-x']),
|
|
55
|
+
position_y: image_position_y(style['position-y']),
|
|
56
|
+
offset_x: style['offset-x'],
|
|
57
|
+
offset_y: style['offset-y']
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def shape_iblock_dimenions(shape)
|
|
62
|
+
return nil if blank_value?(shape.src)
|
|
63
|
+
|
|
64
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
|
65
|
+
style = shape.style.finalized_styles
|
|
66
|
+
|
|
67
|
+
image_dimensions(
|
|
48
68
|
shape.src, x, y, w, h,
|
|
49
69
|
position_x: image_position_x(style['position-x']),
|
|
50
70
|
position_y: image_position_y(style['position-y'])
|
|
@@ -52,10 +72,10 @@ module Thinreports
|
|
|
52
72
|
end
|
|
53
73
|
|
|
54
74
|
# @param [Thinreports::Core::Shape::Text::Internal] shape
|
|
55
|
-
def draw_shape_text(shape)
|
|
75
|
+
def draw_shape_text(shape, dheight = 0)
|
|
56
76
|
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
|
57
77
|
text(
|
|
58
|
-
shape.texts.join("\n"), x, y, w, h,
|
|
78
|
+
shape.texts.join("\n"), x, y, w, h + dheight,
|
|
59
79
|
build_text_attributes(shape.style.finalized_styles)
|
|
60
80
|
)
|
|
61
81
|
end
|
|
@@ -67,18 +87,18 @@ module Thinreports
|
|
|
67
87
|
end
|
|
68
88
|
|
|
69
89
|
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
|
70
|
-
def draw_shape_line(shape)
|
|
90
|
+
def draw_shape_line(shape, dy1 = 0, dy2 = 0)
|
|
71
91
|
x1, y1, x2, y2 = shape.format.attributes.values_at('x1', 'y1', 'x2', 'y2')
|
|
72
|
-
line(x1, y1, x2, y2, build_graphic_attributes(shape.style.finalized_styles))
|
|
92
|
+
line(x1, y1 + dy1, x2, y2 + dy2, build_graphic_attributes(shape.style.finalized_styles))
|
|
73
93
|
end
|
|
74
94
|
|
|
75
95
|
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
|
76
|
-
def draw_shape_rect(shape)
|
|
96
|
+
def draw_shape_rect(shape, dheight = 0)
|
|
77
97
|
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
|
78
98
|
rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs|
|
|
79
|
-
attrs[:radius] = shape.format.attributes['
|
|
99
|
+
attrs[:radius] = shape.format.attributes['border-radius']
|
|
80
100
|
end
|
|
81
|
-
rect(x, y, w, h, rect_attributes)
|
|
101
|
+
rect(x, y, w, h + dheight, rect_attributes)
|
|
82
102
|
end
|
|
83
103
|
end
|
|
84
104
|
end
|
|
@@ -5,7 +5,6 @@ module Thinreports
|
|
|
5
5
|
class PDF
|
|
6
6
|
module DrawTemplateItems
|
|
7
7
|
# @param [Array<Hash>] items
|
|
8
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
9
8
|
def draw_template_items(items)
|
|
10
9
|
items.each do |item_attributes|
|
|
11
10
|
next unless drawable?(item_attributes)
|
|
@@ -26,7 +25,7 @@ module Thinreports
|
|
|
26
25
|
def draw_rect(item_attributes)
|
|
27
26
|
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
|
28
27
|
graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
|
|
29
|
-
attrs[:radius] = item_attributes['
|
|
28
|
+
attrs[:radius] = item_attributes['border-radius']
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
rect(x, y, w, h, graphic_attributes)
|
|
@@ -7,10 +7,10 @@ module Thinreports
|
|
|
7
7
|
FONT_STORE = Thinreports.root.join('fonts')
|
|
8
8
|
|
|
9
9
|
BUILTIN_FONTS = {
|
|
10
|
-
'IPAMincho' =>
|
|
11
|
-
'IPAPMincho' =>
|
|
12
|
-
'IPAGothic' =>
|
|
13
|
-
'IPAPGothic' =>
|
|
10
|
+
'IPAMincho' => FONT_STORE.join('ipam.ttf').to_s,
|
|
11
|
+
'IPAPMincho' => FONT_STORE.join('ipamp.ttf').to_s,
|
|
12
|
+
'IPAGothic' => FONT_STORE.join('ipag.ttf').to_s,
|
|
13
|
+
'IPAPGothic' => FONT_STORE.join('ipagp.ttf').to_s
|
|
14
14
|
}.freeze
|
|
15
15
|
|
|
16
16
|
DEFAULT_FALLBACK_FONTS = %w[IPAMincho].freeze
|
|
@@ -20,10 +20,11 @@ module Thinreports
|
|
|
20
20
|
'Times New Roman' => 'Times-Roman'
|
|
21
21
|
}.freeze
|
|
22
22
|
|
|
23
|
-
# rubocop:disable Metrics/AbcSize
|
|
24
23
|
def setup_fonts
|
|
25
24
|
# Install built-in fonts.
|
|
26
|
-
|
|
25
|
+
BUILTIN_FONTS.each do |font_name, font_path|
|
|
26
|
+
install_font(font_name, font_path)
|
|
27
|
+
end
|
|
27
28
|
|
|
28
29
|
# Create aliases from the font list provided by Prawn.
|
|
29
30
|
PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name|
|
|
@@ -70,11 +71,16 @@ module Thinreports
|
|
|
70
71
|
pdf.font_families.key?(family) ? family : default_family
|
|
71
72
|
end
|
|
72
73
|
|
|
73
|
-
# @param [String]
|
|
74
|
-
# @param [
|
|
74
|
+
# @param [String] font_name
|
|
75
|
+
# @param [:bold, :italic] font_style
|
|
75
76
|
# @return [Boolean]
|
|
76
|
-
def font_has_style?(
|
|
77
|
-
|
|
77
|
+
def font_has_style?(font_name, font_style)
|
|
78
|
+
font = pdf.font_families[font_name]
|
|
79
|
+
|
|
80
|
+
return false unless font
|
|
81
|
+
return false unless font.key?(font_style)
|
|
82
|
+
|
|
83
|
+
font[font_style] != font[:normal]
|
|
78
84
|
end
|
|
79
85
|
end
|
|
80
86
|
end
|