thinreports 0.6.0.pre3 → 0.7.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.
- data/README.rdoc +37 -32
- data/doc/yardoc_templates/default/layout/html/footer.erb +1 -1
- data/lib/thinreports.rb +2 -1
- data/lib/thinreports/config.rb +21 -0
- data/lib/thinreports/core/errors.rb +14 -1
- data/lib/thinreports/core/format/builder.rb +6 -1
- data/lib/thinreports/core/page.rb +6 -6
- data/lib/thinreports/core/shape.rb +8 -9
- data/lib/thinreports/core/shape/base/internal.rb +6 -12
- data/lib/thinreports/core/shape/basic.rb +3 -0
- data/lib/thinreports/core/shape/basic/block_format.rb +12 -0
- data/lib/thinreports/core/shape/basic/block_interface.rb +25 -0
- data/lib/thinreports/core/shape/basic/block_internal.rb +33 -0
- data/lib/thinreports/core/shape/basic/interface.rb +37 -11
- data/lib/thinreports/core/shape/basic/internal.rb +3 -12
- data/lib/thinreports/core/shape/image_block.rb +15 -0
- data/lib/thinreports/core/shape/image_block/format.rb +13 -0
- data/lib/thinreports/core/shape/image_block/interface.rb +19 -0
- data/lib/thinreports/core/shape/image_block/internal.rb +16 -0
- data/lib/thinreports/core/shape/list/events.rb +19 -2
- data/lib/thinreports/core/shape/list/manager.rb +17 -4
- data/lib/thinreports/core/shape/list/page.rb +2 -2
- data/lib/thinreports/core/shape/list/page_state.rb +4 -0
- data/lib/thinreports/core/shape/list/section_internal.rb +4 -0
- data/lib/thinreports/core/shape/manager/format.rb +1 -1
- data/lib/thinreports/core/shape/manager/internal.rb +24 -11
- data/lib/thinreports/core/shape/manager/target.rb +2 -2
- data/lib/thinreports/core/shape/style.rb +15 -0
- data/lib/thinreports/core/shape/style/base.rb +149 -0
- data/lib/thinreports/core/shape/style/basic.rb +17 -0
- data/lib/thinreports/core/shape/style/graphic.rb +60 -0
- data/lib/thinreports/core/shape/style/text.rb +138 -0
- data/lib/thinreports/core/shape/text/internal.rb +4 -0
- data/lib/thinreports/core/shape/text_block.rb +16 -0
- data/lib/thinreports/core/shape/{tblock → text_block}/format.rb +3 -3
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter.rb +7 -7
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/basic.rb +1 -1
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/datetime.rb +1 -1
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/number.rb +1 -1
- data/lib/thinreports/core/shape/{tblock → text_block}/formatter/padding.rb +10 -8
- data/lib/thinreports/core/shape/{tblock → text_block}/interface.rb +2 -21
- data/lib/thinreports/core/shape/{tblock → text_block}/internal.rb +16 -10
- data/lib/thinreports/core/utils.rb +0 -8
- data/lib/thinreports/generator.rb +2 -2
- data/lib/thinreports/generator/configuration.rb +30 -0
- data/lib/thinreports/generator/pdf.rb +13 -10
- data/lib/thinreports/generator/pdf/configuration.rb +28 -0
- data/lib/thinreports/generator/pdf/document.rb +16 -56
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +35 -17
- data/lib/thinreports/generator/pdf/document/font.rb +25 -9
- data/lib/thinreports/generator/pdf/document/graphics.rb +1 -1
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +18 -4
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +1 -1
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +18 -1
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +29 -6
- data/lib/thinreports/generator/pdf/document/page.rb +70 -0
- data/lib/thinreports/generator/pdf/document/parse_color.rb +1 -1
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +1 -1
- data/lib/thinreports/generator/pdf/drawer.rb +1 -1
- data/lib/thinreports/generator/pdf/drawer/base.rb +5 -7
- data/lib/thinreports/generator/pdf/drawer/list.rb +4 -4
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +8 -3
- data/lib/thinreports/generator/pdf/drawer/page.rb +10 -3
- data/lib/thinreports/generator/pdf/prawn_ext.rb +16 -21
- data/lib/thinreports/layout/format.rb +2 -2
- data/lib/thinreports/layout/version.rb +2 -2
- data/lib/thinreports/report/base.rb +68 -31
- data/tasks/test.rake +48 -4
- data/test/benchmark/basic_estimate.tlf +1 -0
- data/test/benchmark/bench_basic_estimate.rb +95 -0
- data/test/case/character_spacing/character_spacing.rb +7 -0
- data/test/case/character_spacing/character_spacing.tlf +1 -0
- data/test/case/dynamic_image/dynamic_image.rb +41 -0
- data/test/case/dynamic_image/dynamic_image.tlf +1 -0
- data/test/case/dynamic_image/img200x100.png +0 -0
- data/test/case/dynamic_image/img50x50.png +0 -0
- data/test/case/dynamic_style/dynamic_style.rb +154 -0
- data/test/case/dynamic_style/dynamic_style.tlf +1 -0
- data/test/case/dynamic_style/dynamic_style_in_list.tlf +1 -0
- data/test/case/dynamic_style/image.png +0 -0
- data/test/case/eudc/eudc.rb +20 -0
- data/test/case/eudc/eudc.tlf +1 -0
- data/test/case/eudc/eudc.ttf +0 -0
- data/test/case/helper.rb +27 -0
- data/test/case/hidden_shapes/hidden_shapes.rb +13 -0
- data/test/case/hidden_shapes/hidden_shapes.tlf +1 -0
- data/test/case/list_events/list_events.rb +32 -0
- data/test/case/list_events/list_events.tlf +1 -0
- data/test/case/list_header_inheriting/list_header_inheriting.rb +19 -0
- data/test/case/list_header_inheriting/list_header_inheriting.tlf +1 -0
- data/test/case/list_manual_generation/list_manual_generation.rb +24 -0
- data/test/case/list_manual_generation/list_manual_generation.tlf +1 -0
- data/test/case/single_line_tblock/single_line_tblock.rb +15 -0
- data/test/case/single_line_tblock/single_line_tblock.tlf +1 -0
- data/test/case/tblock_styles/tblock_styles.rb +27 -0
- data/test/case/tblock_styles/tblock_styles.tlf +1 -0
- data/test/case/text_align/text_align.rb +9 -0
- data/test/case/text_align/text_align.tlf +1 -0
- data/test/unit/core/shape/base/test_internal.rb +65 -85
- data/test/unit/core/shape/basic/test_basic_format.rb +30 -0
- data/test/unit/core/shape/basic/test_basic_interface.rb +27 -0
- data/test/unit/core/shape/basic/test_basic_internal.rb +55 -0
- data/test/unit/core/shape/basic/test_interface.rb +84 -36
- data/test/unit/core/shape/basic/test_internal.rb +32 -24
- data/test/unit/core/shape/image_block/test_format.rb +58 -0
- data/test/unit/core/shape/image_block/test_interface.rb +23 -0
- data/test/unit/core/shape/image_block/test_internal.rb +28 -0
- data/test/unit/core/shape/list/test_events.rb +19 -11
- data/test/unit/core/shape/list/test_manager.rb +112 -0
- data/test/unit/core/shape/list/test_page.rb +57 -0
- data/test/unit/core/shape/list/test_section_format.rb +1 -1
- data/test/unit/core/shape/list/test_section_interface.rb +37 -30
- data/test/unit/core/shape/list/test_section_internal.rb +39 -14
- data/test/unit/core/shape/manager/test_format.rb +12 -18
- data/test/unit/core/shape/manager/test_internal.rb +127 -93
- data/test/unit/core/shape/manager/test_target.rb +63 -56
- data/test/unit/core/shape/styles/test_base.rb +219 -0
- data/test/unit/core/shape/styles/test_basic.rb +24 -0
- data/test/unit/core/shape/styles/test_graphic.rb +69 -0
- data/test/unit/core/shape/styles/test_text.rb +318 -0
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_basic.rb +2 -2
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_datetime.rb +2 -2
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_number.rb +2 -2
- data/test/unit/core/shape/{tblock → text_block}/formatter/test_padding.rb +11 -6
- data/test/unit/core/shape/text_block/test_format.rb +160 -0
- data/test/unit/core/shape/{tblock → text_block}/test_formatter.rb +2 -2
- data/test/unit/core/shape/text_block/test_interface.rb +46 -0
- data/test/unit/core/shape/text_block/test_internal.rb +128 -0
- data/test/unit/core/test_shape.rb +31 -6
- data/test/unit/data/basic_layout1.tlf +1 -0
- data/test/unit/data/basic_layout2.tlf +1 -0
- data/test/unit/data/basic_list_layout.tlf +1 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +81 -52
- data/test/unit/generator/pdf/document/graphics/test_text.rb +159 -0
- data/test/unit/generator/pdf/document/test_font.rb +21 -6
- data/test/unit/generator/pdf/document/test_graphics.rb +2 -2
- data/test/unit/generator/pdf/document/test_page.rb +95 -0
- data/test/unit/generator/pdf/document/test_parse_color.rb +2 -2
- data/test/unit/generator/pdf/test_configuration.rb +24 -0
- data/test/unit/generator/pdf/test_document.rb +28 -0
- data/test/unit/generator/test_configuration.rb +25 -0
- data/test/unit/generator/test_pdf.rb +19 -0
- data/test/unit/helper.rb +18 -0
- data/test/unit/layout/test_format.rb +24 -7
- data/test/unit/layout/test_version.rb +61 -27
- data/test/unit/report/test_base.rb +185 -89
- data/test/unit/test_config.rb +22 -0
- data/test/unit/test_report.rb +4 -4
- metadata +94 -43
- data/lib/thinreports/core/shape/tblock.rb +0 -16
- data/lib/thinreports/generator/pxd.rb +0 -75
- data/lib/thinreports/generator/pxd/helper.rb +0 -33
- data/lib/thinreports/generator/pxd/list_renderer.rb +0 -58
- data/lib/thinreports/generator/pxd/page_renderer.rb +0 -75
- data/tasks/clean.rake +0 -6
- data/test/unit/core/shape/tblock/test_format.rb +0 -125
- data/test/unit/core/shape/tblock/test_interface.rb +0 -40
- data/test/unit/core/shape/tblock/test_internal.rb +0 -139
|
@@ -8,7 +8,7 @@ module ThinReports
|
|
|
8
8
|
# @param options (see ThinReports::Generator::Base#initialize)
|
|
9
9
|
def self.new(type, report, options = {})
|
|
10
10
|
unless generator = registry[type]
|
|
11
|
-
raise ThinReports::Errors::UnknownGeneratorType
|
|
11
|
+
raise ThinReports::Errors::UnknownGeneratorType.new(type)
|
|
12
12
|
end
|
|
13
13
|
generator.new(report, options)
|
|
14
14
|
end
|
|
@@ -25,6 +25,6 @@ module ThinReports
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
require 'thinreports/generator/configuration'
|
|
28
29
|
require 'thinreports/generator/base'
|
|
29
|
-
require 'thinreports/generator/pxd'
|
|
30
30
|
require 'thinreports/generator/pdf'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
module ThinReports
|
|
4
|
+
module Generator
|
|
5
|
+
|
|
6
|
+
class Configuration
|
|
7
|
+
# @return [Symbol]
|
|
8
|
+
attr_reader :default
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@default = :pdf
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @return [ThinReports::Generator::PDF::Configuration]
|
|
15
|
+
def pdf
|
|
16
|
+
@pdf ||= PDF::Configuration.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @param [Symbol] type
|
|
20
|
+
# @return [void]
|
|
21
|
+
def default=(type)
|
|
22
|
+
unless Generator.registry.key?(type)
|
|
23
|
+
raise ThinReports::Errors::UnknownGeneratorType.new(type)
|
|
24
|
+
end
|
|
25
|
+
@default = type
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
gem 'prawn', '0.12.0'
|
|
5
|
+
require 'prawn'
|
|
6
|
+
rescue LoadError
|
|
7
|
+
puts 'ThinReports requires Prawn = 0.12.0. ' +
|
|
8
|
+
'Please `gem install prawn -v 0.12.0` and try again.'
|
|
9
|
+
end
|
|
4
10
|
|
|
5
11
|
module ThinReports
|
|
6
12
|
module Generator
|
|
7
13
|
|
|
8
|
-
class
|
|
14
|
+
class PDF < Base
|
|
9
15
|
# @param report (see ThinReports::Generator::Base#initialize)
|
|
10
16
|
# @param [Hash] options
|
|
11
17
|
# @option options [Hash] :security (nil)
|
|
12
18
|
# See Prawn::Document#encrypt_document
|
|
13
19
|
def initialize(report, options)
|
|
14
20
|
super
|
|
15
|
-
@pdf
|
|
21
|
+
@pdf = Document.new(options, :Title => default_layout.format.report_title)
|
|
22
|
+
|
|
16
23
|
@drawers = {}
|
|
17
|
-
@current_format = nil
|
|
18
24
|
end
|
|
19
25
|
|
|
20
26
|
# @see ThinReports::Generator::Base#generate
|
|
@@ -41,12 +47,8 @@ module ThinReports
|
|
|
41
47
|
return @pdf.add_blank_page if page.blank?
|
|
42
48
|
|
|
43
49
|
format = page.layout.format
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@pdf.start_new_page(format)
|
|
47
|
-
else
|
|
48
|
-
@pdf.start_new_page
|
|
49
|
-
end
|
|
50
|
+
@pdf.start_new_page(format)
|
|
51
|
+
|
|
50
52
|
drawer(format).draw(page.manager)
|
|
51
53
|
end
|
|
52
54
|
|
|
@@ -58,6 +60,7 @@ module ThinReports
|
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
|
|
63
|
+
require 'thinreports/generator/pdf/configuration'
|
|
61
64
|
require 'thinreports/generator/pdf/prawn_ext'
|
|
62
65
|
require 'thinreports/generator/pdf/document'
|
|
63
66
|
require 'thinreports/generator/pdf/drawer'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
module ThinReports
|
|
4
|
+
module Generator
|
|
5
|
+
|
|
6
|
+
class PDF::Configuration
|
|
7
|
+
# @return [Array]
|
|
8
|
+
attr_reader :eudc_fonts
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@eudc_fonts = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @param [String, Array<String>] fonts
|
|
15
|
+
def eudc_fonts=(fonts)
|
|
16
|
+
fonts = [fonts] unless fonts.is_a?(::Array)
|
|
17
|
+
|
|
18
|
+
fonts.each do |f|
|
|
19
|
+
unless File.extname(f.to_s) == '.ttf'
|
|
20
|
+
raise ArgumentError, 'The EUDC Fonts can specify only the TTF file.'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
@eudc_fonts = fonts
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -5,28 +5,31 @@ require 'thinreports/generator/pdf/document/parse_color'
|
|
|
5
5
|
require 'thinreports/generator/pdf/document/graphics'
|
|
6
6
|
require 'thinreports/generator/pdf/document/draw_shape'
|
|
7
7
|
require 'thinreports/generator/pdf/document/parse_svg'
|
|
8
|
+
require 'thinreports/generator/pdf/document/page'
|
|
8
9
|
|
|
9
10
|
module ThinReports
|
|
10
11
|
module Generator
|
|
11
12
|
|
|
12
13
|
# @private
|
|
13
|
-
class
|
|
14
|
-
include
|
|
15
|
-
include
|
|
16
|
-
include
|
|
17
|
-
include
|
|
18
|
-
include
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
class PDF::Document
|
|
15
|
+
include PDF::Font
|
|
16
|
+
include PDF::ParseColor
|
|
17
|
+
include PDF::Graphics
|
|
18
|
+
include PDF::DrawShape
|
|
19
|
+
include PDF::ParseSVG
|
|
20
|
+
include PDF::Page
|
|
21
|
+
|
|
22
|
+
# @param options (see ThinReports::Generator::PDF#initialize)
|
|
23
|
+
# @param [Hash] metadata
|
|
24
|
+
# @option metadata [String] :Title
|
|
25
|
+
def initialize(options = {}, metadata = {})
|
|
22
26
|
@pdf = Prawn::Document.new(
|
|
23
27
|
:skip_page_creation => true,
|
|
24
28
|
:margin => [0, 0],
|
|
25
|
-
:info => {:
|
|
26
|
-
|
|
29
|
+
:info => {:CreationDate => Time.now,
|
|
30
|
+
:Creator => 'ThinReports Generator for Ruby ' +
|
|
31
|
+
ThinReports::VERSION}.merge(metadata)
|
|
27
32
|
)
|
|
28
|
-
@format_stamp_registry = []
|
|
29
|
-
|
|
30
33
|
# Setup to Prawn::Document.
|
|
31
34
|
setup_fonts
|
|
32
35
|
setup_custom_graphic_states
|
|
@@ -37,38 +40,6 @@ module ThinReports
|
|
|
37
40
|
end
|
|
38
41
|
end
|
|
39
42
|
|
|
40
|
-
# @param [ThinReports::Layout::Format] format (nil)
|
|
41
|
-
def start_new_page(format = nil)
|
|
42
|
-
options = {}
|
|
43
|
-
format_id = format.identifier
|
|
44
|
-
|
|
45
|
-
if format
|
|
46
|
-
options[:layout] = format.page_orientation.to_sym
|
|
47
|
-
options[:size] = if format.user_paper_type?
|
|
48
|
-
[format.page_width.to_f, format.page_height.to_f]
|
|
49
|
-
else
|
|
50
|
-
format.page_paper_type
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
pdf.start_new_page(options)
|
|
55
|
-
|
|
56
|
-
# @note
|
|
57
|
-
# The best way is to create a template for each layout.
|
|
58
|
-
# However, in the latest Prawn library, because of problems handling
|
|
59
|
-
# the template that you want supported by future releases.
|
|
60
|
-
# @see https://github.com/sandal/prawn/issues/199
|
|
61
|
-
unless format_stamp_registry.include?(format_id)
|
|
62
|
-
create_format_stamp(format)
|
|
63
|
-
end
|
|
64
|
-
# Apply the static shapes of current format.
|
|
65
|
-
stamp(format_id.to_s)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def add_blank_page
|
|
69
|
-
pdf.start_new_page(pdf.page_count.zero? ? {:size => 'A4'} : {})
|
|
70
|
-
end
|
|
71
|
-
|
|
72
43
|
# Delegate to Prawn::Document#render
|
|
73
44
|
# @see Prawn::Document#render
|
|
74
45
|
def render
|
|
@@ -119,21 +90,10 @@ module ThinReports
|
|
|
119
90
|
# @return [Prawn::Document]
|
|
120
91
|
attr_reader :pdf
|
|
121
92
|
|
|
122
|
-
# @return [Array<Symbol>]
|
|
123
|
-
attr_reader :format_stamp_registry
|
|
124
|
-
|
|
125
93
|
def finalize
|
|
126
94
|
clean_temp_images
|
|
127
95
|
end
|
|
128
96
|
|
|
129
|
-
# @param [ThinReports::Layout::Format] format
|
|
130
|
-
def create_format_stamp(format)
|
|
131
|
-
create_stamp(format.identifier.to_s) do
|
|
132
|
-
parse_svg(format.layout, '/svg/g')
|
|
133
|
-
end
|
|
134
|
-
format_stamp_registry << format.identifier
|
|
135
|
-
end
|
|
136
|
-
|
|
137
97
|
# @param [Array<String, Numeric>] values
|
|
138
98
|
# @return [Numeric, Array<Numeric>, nil]
|
|
139
99
|
def s2f(*values)
|
|
@@ -4,25 +4,43 @@ module ThinReports
|
|
|
4
4
|
module Generator
|
|
5
5
|
|
|
6
6
|
# @private
|
|
7
|
-
module
|
|
8
|
-
# @param [ThinReports::Core::Shape::
|
|
7
|
+
module PDF::DrawShape
|
|
8
|
+
# @param [ThinReports::Core::Shape::TextBlock::Internal] shape
|
|
9
9
|
def draw_shape_tblock(shape)
|
|
10
10
|
x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
|
|
11
11
|
|
|
12
12
|
content = shape.real_value.to_s
|
|
13
|
-
unless
|
|
14
|
-
|
|
13
|
+
unless content.empty?
|
|
14
|
+
attrs = shape_text_attrs(shape)
|
|
15
|
+
|
|
16
|
+
unless shape.multiple?
|
|
17
|
+
content = content.gsub(/\n/, ' ')
|
|
18
|
+
attrs[:single] = true
|
|
19
|
+
end
|
|
20
|
+
text_box(content, x, y, w, h, attrs)
|
|
15
21
|
end
|
|
16
|
-
text_box(content, x, y, w, h, common_text_attrs(shape.attributes))
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
# @param [ThinReports::Core::Shape::Basic::Internal] shape
|
|
20
25
|
def draw_shape_image(shape)
|
|
21
|
-
x, y, w, h = shape.svg_attrs.values_at('x', 'y', 'width', 'height')
|
|
22
|
-
base64image(extract_base64_string(shape.svg_attrs['xlink:href']),
|
|
26
|
+
x, y, w, h = shape.style.svg_attrs.values_at('x', 'y', 'width', 'height')
|
|
27
|
+
base64image(extract_base64_string(shape.style.svg_attrs['xlink:href']),
|
|
23
28
|
x, y, w, h)
|
|
24
29
|
end
|
|
25
30
|
|
|
31
|
+
# @param [ThinReports::Core::Shape::ImageBlock::Internal] shape
|
|
32
|
+
def draw_shape_iblock(shape)
|
|
33
|
+
x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
|
|
34
|
+
unless shape.src.blank?
|
|
35
|
+
posx = shape.format.position_x
|
|
36
|
+
posy = shape.format.position_y
|
|
37
|
+
|
|
38
|
+
image_box(shape.src, x, y, w, h,
|
|
39
|
+
:position_x => posx ? posx.to_sym : nil,
|
|
40
|
+
:position_y => posy ? posy.to_sym : nil)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
26
44
|
# @param [ThinReports::Core::Shape::Text::Internal] shape
|
|
27
45
|
def draw_shape_text(shape)
|
|
28
46
|
x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
|
|
@@ -32,39 +50,39 @@ module ThinReports
|
|
|
32
50
|
|
|
33
51
|
# @param [ThinReports::Core::Shape::Basic::Internal] shape
|
|
34
52
|
def draw_shape_ellipse(shape)
|
|
35
|
-
args = shape.svg_attrs.values_at('cx', 'cy', 'rx', 'ry')
|
|
36
|
-
args << common_graphic_attrs(shape.
|
|
53
|
+
args = shape.style.svg_attrs.values_at('cx', 'cy', 'rx', 'ry')
|
|
54
|
+
args << common_graphic_attrs(shape.style.svg_attrs)
|
|
37
55
|
ellipse(*args)
|
|
38
56
|
end
|
|
39
57
|
|
|
40
58
|
# @param [ThinReports::Core::Shape::Basic::Internal] shape
|
|
41
59
|
def draw_shape_line(shape)
|
|
42
|
-
args = shape.svg_attrs.values_at('x1', 'y1', 'x2', 'y2')
|
|
43
|
-
args << common_graphic_attrs(shape.
|
|
60
|
+
args = shape.style.svg_attrs.values_at('x1', 'y1', 'x2', 'y2')
|
|
61
|
+
args << common_graphic_attrs(shape.style.svg_attrs)
|
|
44
62
|
line(*args)
|
|
45
63
|
end
|
|
46
64
|
|
|
47
65
|
# @param [ThinReports::Core::Shape::Basic::Internal] shape
|
|
48
66
|
def draw_shape_rect(shape)
|
|
49
|
-
args = shape.svg_attrs.values_at('x', 'y', 'width', 'height')
|
|
50
|
-
args << common_graphic_attrs(shape.
|
|
51
|
-
attrs[:radius] = shape.svg_attrs['rx']
|
|
67
|
+
args = shape.style.svg_attrs.values_at('x', 'y', 'width', 'height')
|
|
68
|
+
args << common_graphic_attrs(shape.style.svg_attrs) do |attrs|
|
|
69
|
+
attrs[:radius] = shape.style.svg_attrs['rx']
|
|
52
70
|
end
|
|
53
71
|
rect(*args)
|
|
54
72
|
end
|
|
55
73
|
|
|
56
74
|
private
|
|
57
75
|
|
|
58
|
-
# @param [ThinReports::Core::Shape::Text::Internal]
|
|
76
|
+
# @param [ThinReports::Core::Shape::Text::Internal, ThinReports::Core::Shape::TextBlock::Internal]
|
|
59
77
|
# @return [Hash]
|
|
60
78
|
def shape_text_attrs(shape)
|
|
61
79
|
format = shape.format
|
|
62
80
|
|
|
63
|
-
common_text_attrs(shape.
|
|
81
|
+
common_text_attrs(shape.style.svg_attrs) do |attrs|
|
|
64
82
|
# Set the :line_height option.
|
|
65
83
|
attrs[:line_height] = format.line_height unless format.line_height.blank?
|
|
66
84
|
# Set the :valign option.
|
|
67
|
-
attrs[:valign] =
|
|
85
|
+
attrs[:valign] = shape.style.valign
|
|
68
86
|
end
|
|
69
87
|
end
|
|
70
88
|
|
|
@@ -4,7 +4,7 @@ module ThinReports
|
|
|
4
4
|
module Generator
|
|
5
5
|
|
|
6
6
|
# @private
|
|
7
|
-
module
|
|
7
|
+
module PDF::Font
|
|
8
8
|
FONT_STORE = File.join(ThinReports::ROOTDIR, 'resources', 'fonts')
|
|
9
9
|
|
|
10
10
|
BUILTIN_FONTS = {
|
|
@@ -20,14 +20,21 @@ module ThinReports
|
|
|
20
20
|
# Install built-in fonts.
|
|
21
21
|
pdf.font_families.update(BUILTIN_FONTS)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
fallback_fonts = []
|
|
24
|
+
|
|
25
|
+
# Install EUDC fonts.
|
|
26
|
+
ThinReports.config.generator.pdf.eudc_fonts.each_with_index do |eudc, i|
|
|
27
|
+
eudc_name = "EUDC#{i}"
|
|
28
|
+
install_font_family(eudc_name, eudc)
|
|
29
|
+
fallback_fonts << eudc_name
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Install fall-back font(default font) that IPAMincho.
|
|
33
|
+
install_font_family('DefaultFont', BUILTIN_FONTS['IPAMincho'][:normal])
|
|
34
|
+
fallback_fonts << 'DefaultFont'
|
|
35
|
+
|
|
36
|
+
# Setup fallback fonts.
|
|
37
|
+
pdf.fallback_fonts(fallback_fonts)
|
|
31
38
|
|
|
32
39
|
# Create aliases from the font list provided by Prawn.
|
|
33
40
|
pdf.font_families.update(
|
|
@@ -36,6 +43,15 @@ module ThinReports
|
|
|
36
43
|
)
|
|
37
44
|
end
|
|
38
45
|
|
|
46
|
+
# @param [String] name
|
|
47
|
+
# @param [String] file
|
|
48
|
+
def install_font_family(name, file)
|
|
49
|
+
pdf.font_families[name] = {:normal => file,
|
|
50
|
+
:bold => file,
|
|
51
|
+
:italic => file,
|
|
52
|
+
:bold_italic => file}
|
|
53
|
+
end
|
|
54
|
+
|
|
39
55
|
# @return [String]
|
|
40
56
|
def default_family
|
|
41
57
|
'Helvetica'
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module ThinReports
|
|
4
4
|
module Generator
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module PDF::Graphics
|
|
7
7
|
# @param [Hash] svg_attrs
|
|
8
8
|
# @yield [attrs]
|
|
9
9
|
# @yieldparam [Hash] attrs
|
|
@@ -36,9 +36,17 @@ module ThinReports
|
|
|
36
36
|
:color => svg_attrs['fill'],
|
|
37
37
|
:align => text_align(svg_attrs['text-anchor']),
|
|
38
38
|
:styles => font_styles(svg_attrs)}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
|
|
40
|
+
# The Letter Spacing Property.
|
|
41
|
+
#
|
|
42
|
+
# When the version of Layout is
|
|
43
|
+
# smaller then 0.6.0:
|
|
44
|
+
# Use letter-spacing attribute (normal is none).
|
|
45
|
+
# 0.6.0 or more:
|
|
46
|
+
# Use kerning attribute (auto is none).
|
|
47
|
+
#
|
|
48
|
+
if space = text_letter_spacing(svg_attrs['kerning'] || svg_attrs['letter-spacing'])
|
|
49
|
+
attrs[:letter_spacing] = space
|
|
42
50
|
end
|
|
43
51
|
block.call(attrs) if block_given?
|
|
44
52
|
attrs
|
|
@@ -59,6 +67,12 @@ module ThinReports
|
|
|
59
67
|
styles
|
|
60
68
|
end
|
|
61
69
|
|
|
70
|
+
# @param [String] space
|
|
71
|
+
# @return [String, nil]
|
|
72
|
+
def text_letter_spacing(space)
|
|
73
|
+
%w( normal auto ).include?(space) ? nil : space
|
|
74
|
+
end
|
|
75
|
+
|
|
62
76
|
# @param [String] svg_align
|
|
63
77
|
# @return [Symbol]
|
|
64
78
|
def text_align(svg_align)
|