thinreports 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,22 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module TextBlock
|
7
|
+
module Formatter
|
8
|
+
class Padding < Formatter::Basic
|
9
|
+
private
|
5
10
|
|
6
|
-
|
11
|
+
def apply_format_to(value)
|
12
|
+
value.to_s.send(format.format_padding_rdir? ? :ljust : :rjust,
|
13
|
+
format.format_padding_length,
|
14
|
+
format.format_padding_char)
|
15
|
+
end
|
7
16
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
format.format_padding_char)
|
14
|
-
end
|
15
|
-
|
16
|
-
def applicable?(_value)
|
17
|
-
!blank_value?(format.format_padding_char) && format.format_padding_length > 0
|
17
|
+
def applicable?(_value)
|
18
|
+
!blank_value?(format.format_padding_char) && format.format_padding_length > 0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
20
|
-
|
21
24
|
end
|
22
25
|
end
|
@@ -1,33 +1,35 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module TextBlock
|
7
|
+
class Interface < Basic::BlockInterface
|
8
|
+
internal_delegators :format_enabled?
|
5
9
|
|
6
|
-
|
7
|
-
|
10
|
+
# @param [Boolean] enabled
|
11
|
+
# @return [self]
|
12
|
+
def format_enabled(enabled)
|
13
|
+
internal.format_enabled(enabled)
|
14
|
+
self
|
15
|
+
end
|
8
16
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# @param [Object] val
|
17
|
-
# @param [Hash<Symbol, Object>] style_settings
|
18
|
-
# @return [self]
|
19
|
-
def set(val, style_settings = {})
|
20
|
-
value(val)
|
21
|
-
styles(style_settings) #=> self
|
22
|
-
end
|
17
|
+
# @param [Object] val
|
18
|
+
# @param [Hash<Symbol, Object>] style_settings
|
19
|
+
# @return [self]
|
20
|
+
def set(val, style_settings = {})
|
21
|
+
value(val)
|
22
|
+
styles(style_settings) #=> self
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
+
private
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
# @see Thinreports::Core::Shape::Base::Interface#init_internal
|
28
|
+
def init_internal(parent, format)
|
29
|
+
TextBlock::Internal.new(parent, format)
|
30
|
+
end
|
31
|
+
end
|
29
32
|
end
|
30
33
|
end
|
31
|
-
|
32
34
|
end
|
33
35
|
end
|
@@ -1,75 +1,75 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module TextBlock
|
7
|
+
class Internal < Basic::BlockInternal
|
8
|
+
format_delegators :multiple?
|
9
|
+
|
10
|
+
attr_reader :style
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super(*args)
|
14
|
+
|
15
|
+
@reference = nil
|
16
|
+
@formatter = nil
|
17
|
+
|
18
|
+
@style = Style::Text.new(format)
|
19
|
+
@style.accessible_styles.delete(:valign) unless multiple?
|
20
|
+
end
|
21
|
+
|
22
|
+
def read_value
|
23
|
+
if format.has_reference?
|
24
|
+
@reference ||= parent.item(format.ref_id)
|
25
|
+
@reference.value
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def write_value(val)
|
32
|
+
if format.has_reference?
|
33
|
+
warn 'The set value was not saved, ' \
|
34
|
+
"Because '#{format.id}' has reference to '#{format.ref_id}'."
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def real_value
|
41
|
+
if format_enabled?
|
42
|
+
formatter.apply(read_value)
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def format_enabled(enabled)
|
49
|
+
states[:format_enabled] = enabled
|
50
|
+
end
|
51
|
+
|
52
|
+
def format_enabled?
|
53
|
+
return false if multiple?
|
54
|
+
|
55
|
+
if states.key?(:format_enabled)
|
56
|
+
states[:format_enabled]
|
57
|
+
else
|
58
|
+
!blank_value?(format.format_base) || format.has_format?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def type_of?(type_name)
|
63
|
+
type_name == TextBlock::TYPE_NAME || super
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def formatter
|
69
|
+
@formatter ||= TextBlock::Formatter.setup(format)
|
70
|
+
end
|
60
71
|
end
|
61
72
|
end
|
62
|
-
|
63
|
-
def type_of?(type_name)
|
64
|
-
type_name == TextBlock::TYPE_NAME || super
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def formatter
|
70
|
-
@formatter ||= TextBlock::Formatter.setup(format)
|
71
|
-
end
|
72
73
|
end
|
73
|
-
|
74
74
|
end
|
75
75
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
4
|
module Utils
|
@@ -6,12 +6,13 @@ module Thinreports
|
|
6
6
|
klass.extend self
|
7
7
|
end
|
8
8
|
|
9
|
+
# rubocop:disable Style/RescueModifier
|
9
10
|
def deep_copy(src)
|
10
11
|
case src
|
11
12
|
when Hash
|
12
|
-
src.
|
13
|
+
src.each_with_object({}) { |(k, v), h| h[k] = v.dup rescue v }
|
13
14
|
when Array
|
14
|
-
src.map {|a| a.dup rescue a }
|
15
|
+
src.map { |a| a.dup rescue a }
|
15
16
|
else
|
16
17
|
raise ArgumentError
|
17
18
|
end
|
@@ -1,37 +1,37 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
gem 'prawn', '1.3.0'
|
5
|
-
require 'prawn'
|
6
|
-
rescue LoadError
|
7
|
-
puts 'Thinreports requires Prawn = 1.3.0. ' +
|
8
|
-
'Please `gem install prawn -v 1.3.0` and try again.'
|
9
|
-
end
|
3
|
+
require 'prawn'
|
10
4
|
|
11
5
|
module Thinreports
|
12
6
|
module Generator
|
7
|
+
class PDF
|
8
|
+
# @return [Thinreports::Report::Base]
|
9
|
+
attr_reader :report
|
13
10
|
|
14
|
-
|
15
|
-
# @param
|
16
|
-
|
17
|
-
|
18
|
-
# See Prawn::Document#encrypt_document
|
19
|
-
def initialize(report, options)
|
20
|
-
super
|
11
|
+
# @param [Thinreports::Report::Base] report
|
12
|
+
# @param [Hash] security (nil)
|
13
|
+
def initialize(report, security: nil)
|
14
|
+
report.finalize
|
21
15
|
|
16
|
+
@report = report.internal
|
22
17
|
title = default_layout ? default_layout.format.report_title : nil
|
23
18
|
|
24
|
-
@document = Document.new(
|
19
|
+
@document = Document.new(title: title, security: security)
|
25
20
|
@drawers = {}
|
26
21
|
end
|
27
22
|
|
28
|
-
# @
|
23
|
+
# @param [String, nil] filename
|
24
|
+
# @return [String, nil]
|
29
25
|
def generate(filename = nil)
|
30
26
|
draw_report
|
31
27
|
filename ? @document.render_file(filename) : @document.render
|
32
28
|
end
|
33
29
|
|
34
|
-
|
30
|
+
def default_layout
|
31
|
+
report.default_layout
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
35
|
|
36
36
|
def draw_report
|
37
37
|
report.pages.each do |page|
|
@@ -52,13 +52,12 @@ module Thinreports
|
|
52
52
|
@drawers[format.identifier] ||= Drawer::Page.new(@document, format)
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
require_relative 'pdf/prawn_ext'
|
59
|
+
require_relative 'pdf/document'
|
60
|
+
require_relative 'pdf/drawer/base'
|
61
|
+
require_relative 'pdf/drawer/page'
|
62
|
+
require_relative 'pdf/drawer/list'
|
63
|
+
require_relative 'pdf/drawer/list_section'
|
@@ -1,131 +1,130 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
require_relative 'document/font'
|
4
|
+
require_relative 'document/parse_color'
|
5
|
+
require_relative 'document/graphics'
|
6
|
+
require_relative 'document/draw_shape'
|
7
|
+
require_relative 'document/draw_template_items'
|
8
|
+
require_relative 'document/page'
|
9
9
|
|
10
10
|
module Thinreports
|
11
11
|
module Generator
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@pdf.encrypt_document(
|
12
|
+
class PDF
|
13
|
+
class Document
|
14
|
+
include Utils
|
15
|
+
|
16
|
+
include PDF::Font
|
17
|
+
include PDF::ParseColor
|
18
|
+
include PDF::Graphics
|
19
|
+
include PDF::DrawShape
|
20
|
+
include PDF::DrawTemplateItems
|
21
|
+
include PDF::Page
|
22
|
+
|
23
|
+
# @return [Prawn::Document]
|
24
|
+
attr_reader :pdf
|
25
|
+
|
26
|
+
# @param [String] title (nil)
|
27
|
+
# @param [Hash] security (nil)
|
28
|
+
def initialize(title: nil, security: nil)
|
29
|
+
@pdf = Prawn::Document.new(
|
30
|
+
skip_page_creation: true,
|
31
|
+
margin: [0, 0],
|
32
|
+
info: {
|
33
|
+
CreationDate: Time.now,
|
34
|
+
Creator: 'Thinreports Generator for Ruby ' + Thinreports::VERSION,
|
35
|
+
Title: title
|
36
|
+
}
|
37
|
+
)
|
38
|
+
# Setup to Prawn::Document.
|
39
|
+
setup_fonts
|
40
|
+
setup_custom_graphic_states
|
41
|
+
|
42
|
+
# Encrypts the document.
|
43
|
+
@pdf.encrypt_document(security) if security
|
44
44
|
end
|
45
|
-
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
# Delegate to Prawn::Document#render
|
47
|
+
# @see Prawn::Document#render
|
48
|
+
def render
|
49
|
+
result = pdf.render
|
50
|
+
finalize
|
51
|
+
result
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
# Delegate to Prawn::Document#render_file
|
55
|
+
# @see Prawn::Document#render_file
|
56
|
+
def render_file(*args)
|
57
|
+
finalize
|
58
|
+
pdf.render_file(*args)
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
# @param [Numeric, String] x
|
62
|
+
# @param [Numeric, String] y
|
63
|
+
def translate(x, y, &block)
|
64
|
+
x, y = rpos(x, y)
|
65
|
+
pdf.translate(x, y, &block)
|
66
|
+
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
# @param [String] stamp_id
|
69
|
+
# @param [Array<Numeric>] at (nil)
|
70
|
+
def stamp(stamp_id, at = nil)
|
71
|
+
if at.nil?
|
72
|
+
pdf.stamp(stamp_id)
|
73
|
+
else
|
74
|
+
pdf.stamp_at(stamp_id, rpos(*at))
|
75
|
+
end
|
76
76
|
end
|
77
|
-
end
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
# Delegate to Prawn::Document#create_stamp
|
79
|
+
# @param [String] id
|
80
|
+
# @see Prawn::Document#create_stamp
|
81
|
+
def create_stamp(id, &block)
|
82
|
+
pdf.create_stamp(id, &block)
|
83
|
+
end
|
85
84
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
# @see #pdf
|
86
|
+
def internal
|
87
|
+
@pdf
|
88
|
+
end
|
90
89
|
|
91
|
-
|
90
|
+
private
|
92
91
|
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
def finalize
|
93
|
+
clean_temp_images
|
94
|
+
end
|
96
95
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
96
|
+
# @param [Array<String, Numeric>] values
|
97
|
+
# @return [Numeric, Array<Numeric>, nil]
|
98
|
+
def s2f(*values)
|
99
|
+
return nil if values.empty?
|
100
|
+
|
101
|
+
if values.size == 1
|
102
|
+
value = values.first
|
103
|
+
return nil unless value
|
104
|
+
value.is_a?(::Numeric) ? value : value.to_f
|
105
|
+
else
|
106
|
+
values.map { |v| s2f(v) }
|
107
|
+
end
|
108
108
|
end
|
109
|
-
end
|
110
109
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
110
|
+
# @param [Numeric, String] x
|
111
|
+
# @param [Numeric, String] y
|
112
|
+
# @return [Array<Float>]
|
113
|
+
def map_to_upper_left_relative_position(x, y)
|
114
|
+
x, y = s2f(x, y)
|
115
|
+
[x, -y]
|
116
|
+
end
|
117
|
+
alias rpos map_to_upper_left_relative_position
|
118
|
+
|
119
|
+
# @param [Numeric, String] x
|
120
|
+
# @param [Numeric, String] y
|
121
|
+
# @return [Array<Float>]
|
122
|
+
def map_to_upper_left_position(x, y)
|
123
|
+
x, y = s2f(x, y)
|
124
|
+
[x, pdf.bounds.height - y]
|
125
|
+
end
|
126
|
+
alias pos map_to_upper_left_position
|
126
127
|
end
|
127
|
-
alias_method :pos, :map_to_upper_left_position
|
128
128
|
end
|
129
|
-
|
130
129
|
end
|
131
130
|
end
|