thinreports 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CONTRIBUTING.md +2 -0
- data/.travis.yml +3 -3
- data/CHANGELOG.md +98 -1
- data/README.md +0 -9
- data/Rakefile +1 -2
- data/examples/character_spacing/character_spacing.tlf +293 -1
- data/examples/dynamic_image/dynamic_image.tlf +661 -1
- data/examples/dynamic_style/dynamic_style.rb +4 -4
- data/examples/dynamic_style/dynamic_style.tlf +1835 -1
- data/examples/dynamic_style/dynamic_style_in_list.tlf +344 -1
- data/examples/eudc/eudc.tlf +180 -1
- data/examples/hidden_shapes/hidden_shapes.tlf +449 -1
- data/examples/list_events/list_events.rb +1 -28
- data/examples/list_events/list_events.tlf +361 -0
- data/examples/list_manual_generation/list_manual_generation.tlf +132 -1
- data/examples/list_page_number/list_page_number.tlf +254 -1
- data/examples/page_number/page_number.tlf +215 -1
- data/examples/palleted_png/palleted_png.rb +2 -0
- data/examples/palleted_png/palleted_png.tlf +47 -1
- data/examples/password_setting/password_setting.tlf +45 -1
- data/examples/report_callbacks/report_callbacks.rb +1 -18
- data/examples/report_callbacks/report_callbacks.tlf +147 -1
- data/examples/single_line_tblock/single_line_tblock.tlf +170 -1
- data/examples/tblock_overflow/tblock_overflow.tlf +538 -1
- data/examples/tblock_styles/font_size.tlf +383 -1
- data/examples/tblock_styles/tblock_styles.tlf +889 -1
- data/examples/text_align/text_align.tlf +241 -1
- data/examples/typeB_page_size/B4_ISO.tlf +45 -1
- data/examples/typeB_page_size/B4_JIS.tlf +45 -1
- data/examples/word_wrap/word_wrap.tlf +297 -1
- data/lib/thinreports.rb +0 -1
- data/lib/thinreports/config.rb +3 -0
- data/lib/thinreports/core/errors.rb +0 -3
- data/lib/thinreports/core/format/base.rb +4 -4
- data/lib/thinreports/core/shape.rb +1 -9
- data/lib/thinreports/core/shape/basic.rb +3 -3
- data/lib/thinreports/core/shape/basic/block_format.rb +1 -1
- data/lib/thinreports/core/shape/basic/format.rb +2 -14
- data/lib/thinreports/core/shape/basic/internal.rb +2 -2
- data/lib/thinreports/core/shape/image_block.rb +3 -3
- data/lib/thinreports/core/shape/image_block/format.rb +0 -2
- data/lib/thinreports/core/shape/image_block/internal.rb +1 -1
- data/lib/thinreports/core/shape/list.rb +3 -7
- data/lib/thinreports/core/shape/list/format.rb +37 -24
- data/lib/thinreports/core/shape/list/manager.rb +1 -36
- data/lib/thinreports/core/shape/list/page.rb +0 -15
- data/lib/thinreports/core/shape/list/page_state.rb +1 -1
- data/lib/thinreports/core/shape/list/section_format.rb +14 -12
- data/lib/thinreports/core/shape/list/section_internal.rb +4 -7
- data/lib/thinreports/core/shape/manager/format.rb +0 -2
- data/lib/thinreports/core/shape/manager/internal.rb +1 -1
- data/lib/thinreports/core/shape/page_number.rb +1 -1
- data/lib/thinreports/core/shape/page_number/format.rb +9 -6
- data/lib/thinreports/core/shape/page_number/interface.rb +1 -1
- data/lib/thinreports/core/shape/page_number/internal.rb +2 -6
- data/lib/thinreports/core/shape/style/base.rb +11 -13
- data/lib/thinreports/core/shape/style/basic.rb +4 -4
- data/lib/thinreports/core/shape/style/graphic.rb +4 -10
- data/lib/thinreports/core/shape/style/text.rb +36 -69
- data/lib/thinreports/core/shape/text.rb +3 -3
- data/lib/thinreports/core/shape/text/format.rb +3 -13
- data/lib/thinreports/core/shape/text/internal.rb +2 -2
- data/lib/thinreports/core/shape/text_block.rb +3 -3
- data/lib/thinreports/core/shape/text_block/format.rb +9 -6
- data/lib/thinreports/core/shape/text_block/interface.rb +7 -7
- data/lib/thinreports/core/shape/text_block/internal.rb +1 -1
- data/lib/thinreports/generator/pdf.rb +0 -1
- data/lib/thinreports/generator/pdf/document.rb +2 -2
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +25 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +66 -0
- data/lib/thinreports/generator/pdf/document/font.rb +3 -8
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +97 -77
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +18 -13
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +17 -12
- data/lib/thinreports/generator/pdf/document/page.rb +1 -1
- data/lib/thinreports/generator/pdf/drawer/list.rb +5 -1
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +1 -4
- data/lib/thinreports/generator/pdf/drawer/page.rb +9 -9
- data/lib/thinreports/layout.rb +3 -3
- data/lib/thinreports/layout/base.rb +0 -16
- data/lib/thinreports/layout/format.rb +38 -57
- data/lib/thinreports/layout/legacy_schema.rb +354 -0
- data/lib/thinreports/layout/version.rb +1 -1
- data/lib/thinreports/report.rb +0 -1
- data/lib/thinreports/report/base.rb +3 -17
- data/lib/thinreports/report/internal.rb +13 -55
- data/lib/thinreports/report/page.rb +1 -1
- data/lib/thinreports/version.rb +1 -1
- data/test/data/legacy_layout/all-items.tlf +1 -0
- data/test/schema_helper.rb +121 -0
- data/test/test_helper.rb +13 -50
- data/test/unit/core/format/test_base.rb +35 -31
- data/test/unit/core/shape/base/test_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_block_format.rb +23 -0
- data/test/unit/core/shape/basic/{test_basic_interface.rb → test_block_interface.rb} +1 -1
- data/test/unit/core/shape/basic/{test_basic_internal.rb → test_block_internal.rb} +4 -7
- data/test/unit/core/shape/basic/test_format.rb +25 -47
- data/test/unit/core/shape/basic/test_interface.rb +5 -5
- data/test/unit/core/shape/basic/test_internal.rb +6 -11
- data/test/unit/core/shape/image_block/test_interface.rb +5 -5
- data/test/unit/core/shape/image_block/test_internal.rb +2 -2
- data/test/unit/core/shape/list/test_format.rb +86 -44
- data/test/unit/core/shape/list/test_manager.rb +10 -65
- data/test/unit/core/shape/list/test_page.rb +10 -61
- data/test/unit/core/shape/list/test_page_state.rb +1 -1
- data/test/unit/core/shape/list/test_section_format.rb +19 -28
- data/test/unit/core/shape/list/test_section_interface.rb +14 -6
- data/test/unit/core/shape/list/test_section_internal.rb +17 -23
- data/test/unit/core/shape/manager/test_format.rb +1 -1
- data/test/unit/core/shape/manager/test_internal.rb +59 -98
- data/test/unit/core/shape/manager/test_target.rb +21 -30
- data/test/unit/core/shape/page_number/test_format.rb +34 -52
- data/test/unit/core/shape/page_number/test_interface.rb +1 -1
- data/test/unit/core/shape/page_number/test_internal.rb +2 -2
- data/test/unit/core/shape/styles/test_base.rb +16 -41
- data/test/unit/core/shape/styles/test_basic.rb +7 -7
- data/test/unit/core/shape/styles/test_graphic.rb +27 -32
- data/test/unit/core/shape/styles/test_text.rb +68 -311
- data/test/unit/core/shape/text/test_format.rb +30 -59
- data/test/unit/core/shape/text/test_internal.rb +5 -5
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +13 -13
- data/test/unit/core/shape/text_block/test_format.rb +145 -146
- data/test/unit/core/shape/text_block/test_interface.rb +9 -9
- data/test/unit/core/shape/text_block/test_internal.rb +9 -9
- data/test/unit/core/test_shape.rb +19 -31
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +112 -122
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +45 -0
- data/test/unit/generator/pdf/document/graphics/test_image.rb +5 -5
- data/test/unit/generator/pdf/document/test_font.rb +4 -10
- data/test/unit/generator/pdf/document/test_page.rb +13 -11
- data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
- data/test/unit/generator/test_base.rb +5 -5
- data/test/unit/generator/test_configuration.rb +4 -8
- data/test/unit/generator/test_pdf.rb +3 -2
- data/test/unit/layout/test_base.rb +16 -22
- data/test/unit/layout/test_format.rb +66 -86
- data/test/unit/layout/test_legacy_schema.rb +587 -0
- data/test/unit/layout/test_version.rb +20 -20
- data/test/unit/report/test_base.rb +32 -45
- data/test/unit/report/test_internal.rb +43 -99
- data/test/unit/test_config.rb +4 -2
- data/test/unit/test_layout.rb +1 -1
- metadata +20 -48
- data/examples/list_events/list_events_0_7_7.tlf +0 -1
- data/examples/list_events/list_events_0_8.tlf +0 -1
- data/lib/thinreports/core/events.rb +0 -69
- data/lib/thinreports/core/format/builder.rb +0 -62
- data/lib/thinreports/core/shape/list/configuration.rb +0 -54
- data/lib/thinreports/core/shape/list/events.rb +0 -47
- data/lib/thinreports/core/shape/list/store.rb +0 -33
- data/lib/thinreports/generator/pdf/configuration.rb +0 -33
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +0 -104
- data/lib/thinreports/layout/configuration.rb +0 -29
- data/test/data/layout_block.tlf +0 -1
- data/test/data/layout_list.tlf +0 -1
- data/test/data/layout_list_noheader.tlf +0 -1
- data/test/data/layout_text1.tlf +0 -1
- data/test/data/layout_text2.tlf +0 -1
- data/test/unit/core/format/test_builder.rb +0 -109
- data/test/unit/core/shape/basic/test_basic_format.rb +0 -30
- data/test/unit/core/shape/image_block/test_format.rb +0 -58
- data/test/unit/core/shape/list/test_configuration.rb +0 -69
- data/test/unit/core/shape/list/test_events.rb +0 -36
- data/test/unit/core/shape/list/test_store.rb +0 -41
- data/test/unit/core/test_events.rb +0 -93
- data/test/unit/generator/pdf/document/test_draw_shape.rb +0 -44
- data/test/unit/generator/pdf/test_configuration.rb +0 -31
- data/test/unit/layout/test_configuration.rb +0 -21
- data/test/unit/report/test_events.rb +0 -22
@@ -4,9 +4,12 @@ module Thinreports
|
|
4
4
|
module Core::Shape
|
5
5
|
|
6
6
|
class TextBlock::Format < Basic::BlockFormat
|
7
|
-
|
8
|
-
config_reader :
|
9
|
-
config_reader
|
7
|
+
# For saving compatible 0.8.x format API
|
8
|
+
config_reader ref_id: %w( reference-id )
|
9
|
+
config_reader valign: %w( style vertical-align )
|
10
|
+
config_reader overflow: %w( style overflow )
|
11
|
+
config_reader line_height: %w( style line-height )
|
12
|
+
|
10
13
|
config_reader format_base: %w( format base ),
|
11
14
|
format_type: %w( format type ),
|
12
15
|
format_datetime_format: %w( format datetime format ),
|
@@ -14,9 +17,8 @@ module Thinreports
|
|
14
17
|
format_number_precision: %w( format number precision ),
|
15
18
|
format_padding_char: %w( format padding char ),
|
16
19
|
format_padding_dir: %w( format padding direction )
|
17
|
-
config_reader word_wrap: %w( word-wrap )
|
18
20
|
|
19
|
-
config_checker
|
21
|
+
config_checker true, multiple: %w( multiple-line )
|
20
22
|
config_checker 'R', format_padding_rdir: %w( format padding direction )
|
21
23
|
|
22
24
|
config_reader format_padding_length: %w( format padding length ) do |len|
|
@@ -27,7 +29,8 @@ module Thinreports
|
|
27
29
|
%w( datetime number padding ).include?(type)
|
28
30
|
end
|
29
31
|
|
30
|
-
|
32
|
+
# For saving compatible 0.8.x format API
|
33
|
+
def has_reference?
|
31
34
|
!blank_value?(ref_id)
|
32
35
|
end
|
33
36
|
end
|
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
module Thinreports
|
4
4
|
module Core::Shape
|
5
|
-
|
5
|
+
|
6
6
|
class TextBlock::Interface < Basic::BlockInterface
|
7
7
|
internal_delegators :format_enabled?
|
8
|
-
|
8
|
+
|
9
9
|
# @param [Boolean] enabled
|
10
10
|
# @return [self]
|
11
11
|
def format_enabled(enabled)
|
12
12
|
internal.format_enabled(enabled)
|
13
13
|
self
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# @param [Object] val
|
17
17
|
# @param [Hash<Symbol, Object>] style_settings
|
18
18
|
# @return [self]
|
@@ -20,14 +20,14 @@ module Thinreports
|
|
20
20
|
value(val)
|
21
21
|
styles(style_settings) #=> self
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
private
|
25
|
-
|
25
|
+
|
26
26
|
# @see Thinreports::Core::Shape::Base::Interface#init_internal
|
27
27
|
def init_internal(parent, format)
|
28
28
|
TextBlock::Internal.new(parent, format)
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -4,7 +4,7 @@ require 'thinreports/generator/pdf/document/font'
|
|
4
4
|
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
|
-
require 'thinreports/generator/pdf/document/
|
7
|
+
require 'thinreports/generator/pdf/document/draw_template_items'
|
8
8
|
require 'thinreports/generator/pdf/document/page'
|
9
9
|
|
10
10
|
module Thinreports
|
@@ -17,7 +17,7 @@ module Thinreports
|
|
17
17
|
include PDF::ParseColor
|
18
18
|
include PDF::Graphics
|
19
19
|
include PDF::DrawShape
|
20
|
-
include PDF::
|
20
|
+
include PDF::DrawTemplateItems
|
21
21
|
include PDF::Page
|
22
22
|
|
23
23
|
# @return [Prawn::Document]
|
@@ -6,11 +6,11 @@ module Thinreports
|
|
6
6
|
module PDF::DrawShape
|
7
7
|
# @param [Thinreports::Core::Shape::TextBlock::Internal] shape
|
8
8
|
def draw_shape_tblock(shape)
|
9
|
-
x, y, w, h = shape.
|
9
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
10
10
|
|
11
11
|
content = shape.real_value.to_s
|
12
12
|
unless content.empty?
|
13
|
-
attrs =
|
13
|
+
attrs = build_text_attributes(shape.style.finalized_styles)
|
14
14
|
|
15
15
|
unless shape.multiple?
|
16
16
|
content = content.gsub(/\n/, ' ')
|
@@ -21,83 +21,57 @@ module Thinreports
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def draw_shape_pageno(shape, page_no, page_count)
|
24
|
-
x, y, w, h = shape.
|
24
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
25
25
|
|
26
26
|
text_box(shape.build_format(page_no, page_count), x, y, w, h,
|
27
|
-
|
27
|
+
build_text_attributes(shape.style.finalized_styles))
|
28
28
|
end
|
29
29
|
|
30
30
|
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
31
31
|
def draw_shape_image(shape)
|
32
|
-
x, y, w, h = shape.
|
32
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
33
33
|
|
34
|
-
|
35
|
-
base64image(
|
34
|
+
image_data = shape.format.attributes['data']
|
35
|
+
base64image(image_data['mime-type'], image_data['base64'], x, y, w, h)
|
36
36
|
end
|
37
37
|
|
38
38
|
# @param [Thinreports::Core::Shape::ImageBlock::Internal] shape
|
39
39
|
def draw_shape_iblock(shape)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
40
|
+
return if blank_value?(shape.src)
|
41
|
+
|
42
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
43
|
+
style = shape.style.finalized_styles
|
44
|
+
|
45
|
+
image_box(shape.src, x, y, w, h,
|
46
|
+
position_x: image_position_x(style['position-x']),
|
47
|
+
position_y: image_position_y(style['position-y']))
|
49
48
|
end
|
50
49
|
|
51
50
|
# @param [Thinreports::Core::Shape::Text::Internal] shape
|
52
51
|
def draw_shape_text(shape)
|
53
|
-
x, y, w, h = shape.
|
54
|
-
text(shape.
|
55
|
-
shape_text_attrs(shape))
|
52
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
53
|
+
text(shape.texts.join("\n"), x, y, w, h, build_text_attributes(shape.style.finalized_styles))
|
56
54
|
end
|
57
55
|
|
58
56
|
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
59
57
|
def draw_shape_ellipse(shape)
|
60
|
-
|
61
|
-
|
62
|
-
ellipse(*args)
|
58
|
+
cx, cy, rx, ry = shape.format.attributes.values_at('cx', 'cy', 'rx', 'ry')
|
59
|
+
ellipse(cx, cy, rx, ry, build_graphic_attributes(shape.style.finalized_styles))
|
63
60
|
end
|
64
61
|
|
65
62
|
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
66
63
|
def draw_shape_line(shape)
|
67
|
-
|
68
|
-
|
69
|
-
line(*args)
|
64
|
+
x1, y1, x2, y2 = shape.format.attributes.values_at('x1', 'y1', 'x2', 'y2')
|
65
|
+
line(x1, y1, x2, y2, build_graphic_attributes(shape.style.finalized_styles))
|
70
66
|
end
|
71
67
|
|
72
68
|
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
73
69
|
def draw_shape_rect(shape)
|
74
|
-
|
75
|
-
|
76
|
-
attrs[:radius] = shape.
|
77
|
-
end
|
78
|
-
rect(*args)
|
79
|
-
end
|
80
|
-
|
81
|
-
private
|
82
|
-
|
83
|
-
# @param [Thinreports::Core::Shape::Text::Internal, Thinreports::Core::Shape::TextBlock::Internal] shape
|
84
|
-
# @return [Hash]
|
85
|
-
def shape_text_attrs(shape)
|
86
|
-
format = shape.format
|
87
|
-
|
88
|
-
common_text_attrs(shape.style.svg_attrs) do |attrs|
|
89
|
-
# Set the :line_height option.
|
90
|
-
attrs[:line_height] = format.line_height unless blank_value?(format.line_height)
|
91
|
-
# Set the :valign option.
|
92
|
-
attrs[:valign] = shape.style.valign
|
93
|
-
|
94
|
-
if shape.type_of?(:tblock)
|
95
|
-
# Set the :overflow option.
|
96
|
-
attrs[:overflow] = text_overflow(format.overflow)
|
97
|
-
# Set the :word_wrap option
|
98
|
-
attrs[:word_wrap] = text_word_wrap(format.word_wrap)
|
99
|
-
end
|
70
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
71
|
+
rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs|
|
72
|
+
attrs[:radius] = shape.format.attributes['rx']
|
100
73
|
end
|
74
|
+
rect(x, y, w, h, rect_attributes)
|
101
75
|
end
|
102
76
|
end
|
103
77
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module Generator
|
5
|
+
|
6
|
+
module PDF::DrawTemplateItems
|
7
|
+
# @param [Array<Hash>] items
|
8
|
+
def draw_template_items(items)
|
9
|
+
items.each do |item_attributes|
|
10
|
+
next unless drawable?(item_attributes)
|
11
|
+
|
12
|
+
case item_attributes['type']
|
13
|
+
when 'text' then draw_text(item_attributes)
|
14
|
+
when 'image' then draw_image(item_attributes)
|
15
|
+
when 'rect' then draw_rect(item_attributes)
|
16
|
+
when 'ellipse' then draw_ellipse(item_attributes)
|
17
|
+
when 'line' then draw_line(item_attributes)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# @param [Hash] item_attributes
|
25
|
+
def draw_rect(item_attributes)
|
26
|
+
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
27
|
+
graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
|
28
|
+
attrs[:radius] = item_attributes['rx']
|
29
|
+
end
|
30
|
+
|
31
|
+
rect(x, y, w, h, graphic_attributes)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @see #draw_rect
|
35
|
+
def draw_ellipse(item_attributes)
|
36
|
+
x, y, rx, ry = item_attributes.values_at('cx', 'cy', 'rx', 'ry')
|
37
|
+
ellipse(x, y, rx, ry, build_graphic_attributes(item_attributes['style']))
|
38
|
+
end
|
39
|
+
|
40
|
+
# @see #draw_rect
|
41
|
+
def draw_line(item_attributes)
|
42
|
+
x1, y1, x2, y2 = item_attributes.values_at('x1', 'y1', 'x2', 'y2')
|
43
|
+
line(x1, y1, x2, y2, build_graphic_attributes(item_attributes['style']))
|
44
|
+
end
|
45
|
+
|
46
|
+
# @see #draw_rect
|
47
|
+
def draw_text(item_attributes)
|
48
|
+
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
49
|
+
text(item_attributes['texts'].join("\n"), x, y, w, h, build_text_attributes(item_attributes['style']))
|
50
|
+
end
|
51
|
+
|
52
|
+
# @see #draw_rect
|
53
|
+
def draw_image(item_attributes)
|
54
|
+
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
55
|
+
image_data = item_attributes['data']
|
56
|
+
|
57
|
+
base64image(image_data['mime-type'], image_data['base64'], x, y, w, h)
|
58
|
+
end
|
59
|
+
|
60
|
+
def drawable?(item_attributes)
|
61
|
+
item_attributes['id'].empty? && item_attributes['display']
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -15,7 +15,7 @@ module Thinreports
|
|
15
15
|
|
16
16
|
DEFAULT_FALLBACK_FONTS = %w( Helvetica IPAMincho )
|
17
17
|
|
18
|
-
|
18
|
+
PRAWN_BUINTIN_FONT_ALIASES = {
|
19
19
|
'Courier New' => 'Courier',
|
20
20
|
'Times New Roman' => 'Times-Roman'
|
21
21
|
}
|
@@ -25,17 +25,12 @@ module Thinreports
|
|
25
25
|
pdf.font_families.update(BUILTIN_FONTS)
|
26
26
|
|
27
27
|
# Create aliases from the font list provided by Prawn.
|
28
|
-
|
28
|
+
PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name|
|
29
29
|
pdf.font_families[alias_name] = pdf.font_families[name]
|
30
30
|
end
|
31
31
|
|
32
32
|
# Setup custom fallback fonts
|
33
|
-
fallback_fonts =
|
34
|
-
# For compatible to v0.7 or less
|
35
|
-
fallback_fonts |= Thinreports.config.generator.pdf.eudc_fonts
|
36
|
-
fallback_fonts |= Thinreports.config.fallback_fonts
|
37
|
-
fallback_fonts.uniq!
|
38
|
-
|
33
|
+
fallback_fonts = Thinreports.config.fallback_fonts.uniq
|
39
34
|
fallback_fonts.map!.with_index do |font, i|
|
40
35
|
unless pdf.font_families.key?(font)
|
41
36
|
install_font "Custom-fallback-font#{i}", font
|
@@ -4,122 +4,142 @@ module Thinreports
|
|
4
4
|
module Generator
|
5
5
|
|
6
6
|
module PDF::Graphics
|
7
|
-
# @param [Hash]
|
7
|
+
# @param [Hash] style
|
8
8
|
# @yield [attrs]
|
9
9
|
# @yieldparam [Hash] attrs
|
10
10
|
# @return [Hash]
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# Setting for stroke dash.
|
22
|
-
if (dash = svg_attrs['stroke-dasharray']) && dash != 'none'
|
23
|
-
attrs[:stroke_dash] = dash.split(',')
|
24
|
-
end
|
25
|
-
block.call(attrs) if block_given?
|
26
|
-
attrs
|
11
|
+
def build_graphic_attributes(style, &block)
|
12
|
+
graphic_attributes = {
|
13
|
+
stroke: style['border-color'],
|
14
|
+
stroke_width: style['border-width'],
|
15
|
+
stroke_type: style['border-style'],
|
16
|
+
fill: style['fill-color']
|
17
|
+
}
|
18
|
+
block.call(graphic_attributes) if block_given?
|
19
|
+
graphic_attributes
|
27
20
|
end
|
28
21
|
|
29
|
-
# @param [Hash]
|
22
|
+
# @param [Hash] style
|
30
23
|
# @yield [attrs]
|
31
24
|
# @yieldparam [Hash] attrs
|
32
25
|
# @return [Hash]
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
attrs[:letter_spacing] = spacing if spacing
|
26
|
+
def build_text_attributes(style, &block)
|
27
|
+
text_attributes = {
|
28
|
+
font: font_family(style['font-family']),
|
29
|
+
size: style['font-size'],
|
30
|
+
color: style['color'],
|
31
|
+
align: text_align(style['text-align']),
|
32
|
+
valign: text_valign(style['vertical-align']),
|
33
|
+
styles: font_styles(style['font-style']),
|
34
|
+
letter_spacing: letter_spacing(style['letter-spacing']),
|
35
|
+
line_height: line_height(style['line-height']),
|
36
|
+
overflow: text_overflow(style['overflow']),
|
37
|
+
word_wrap: word_wrap(style['word-wrap'])
|
38
|
+
}
|
39
|
+
block.call(text_attributes) if block_given?
|
40
|
+
text_attributes
|
41
|
+
end
|
50
42
|
|
51
|
-
|
52
|
-
|
43
|
+
# @param [Array<String>] font_names
|
44
|
+
# @return [String]
|
45
|
+
def font_family(font_names)
|
46
|
+
font_name = font_names.first
|
47
|
+
default_family_if_missing(font_name)
|
53
48
|
end
|
54
49
|
|
55
|
-
# @param [
|
50
|
+
# @param [Array<String>] styles
|
56
51
|
# @return [Array<Symbol>]
|
57
|
-
def font_styles(
|
58
|
-
styles
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
styles << :strikethrough if deco.include?('line-through')
|
52
|
+
def font_styles(styles)
|
53
|
+
styles.map do |font_style|
|
54
|
+
case font_style
|
55
|
+
when 'bold' then :bold
|
56
|
+
when 'italic' then :italic
|
57
|
+
when 'underline' then :underline
|
58
|
+
when 'linethrough' then :strikethrough
|
59
|
+
end
|
66
60
|
end
|
67
|
-
styles
|
68
61
|
end
|
69
62
|
|
70
|
-
# @param [
|
71
|
-
# @return [
|
72
|
-
def
|
73
|
-
|
63
|
+
# @param [Float, "", nil] spacing
|
64
|
+
# @return [Float, nil]
|
65
|
+
def letter_spacing(spacing)
|
66
|
+
blank_value?(spacing) ? nil : spacing
|
74
67
|
end
|
75
68
|
|
76
|
-
# @param [
|
77
|
-
# @return [
|
78
|
-
def text_align(
|
79
|
-
case
|
80
|
-
when '
|
81
|
-
when '
|
82
|
-
when '
|
69
|
+
# @param ["left", "center", "right", ""] align
|
70
|
+
# @return [:left, :center, :right]
|
71
|
+
def text_align(align)
|
72
|
+
case align
|
73
|
+
when 'left' then :left
|
74
|
+
when 'center' then :center
|
75
|
+
when 'right' then :right
|
76
|
+
when '' then :left
|
83
77
|
else :left
|
84
78
|
end
|
85
79
|
end
|
86
80
|
|
87
|
-
# @param [
|
88
|
-
# @return [
|
89
|
-
def text_valign(
|
90
|
-
case
|
91
|
-
when 'top'
|
92
|
-
when '
|
81
|
+
# @param ["top", "middle", "bottom", "", nil] valign
|
82
|
+
# @return [:top, :center, :bottom]
|
83
|
+
def text_valign(valign)
|
84
|
+
case valign
|
85
|
+
when 'top' then :top
|
86
|
+
when 'middle' then :center
|
93
87
|
when 'bottom' then :bottom
|
88
|
+
when '' then :top
|
94
89
|
else :top
|
95
90
|
end
|
96
91
|
end
|
97
92
|
|
98
|
-
# @param [
|
99
|
-
# @return [
|
93
|
+
# @param ["truncate", "fit", "expand", "", nil] overflow
|
94
|
+
# @return [:truncate, :shrink_to_fit, :expand]
|
100
95
|
def text_overflow(overflow)
|
101
96
|
case overflow
|
102
97
|
when 'truncate' then :truncate
|
103
|
-
when 'fit'
|
104
|
-
when 'expand'
|
98
|
+
when 'fit' then :shrink_to_fit
|
99
|
+
when 'expand' then :expand
|
100
|
+
when '' then :truncate
|
105
101
|
else :truncate
|
106
102
|
end
|
107
103
|
end
|
108
104
|
|
109
|
-
# @param [
|
110
|
-
# @return [
|
111
|
-
def
|
105
|
+
# @param ["break-word", "none", "", nil] word_wrap
|
106
|
+
# @return [:break_word, :none]
|
107
|
+
def word_wrap(word_wrap)
|
112
108
|
case word_wrap
|
113
109
|
when 'break-word' then :break_word
|
110
|
+
when 'none' then :none
|
114
111
|
else :none
|
115
112
|
end
|
116
113
|
end
|
117
114
|
|
118
|
-
# @param [
|
119
|
-
# @return [
|
120
|
-
def
|
121
|
-
|
122
|
-
|
115
|
+
# @param [Float, "", nil] height
|
116
|
+
# @return [Float, nil]
|
117
|
+
def line_height(height)
|
118
|
+
blank_value?(height) ? nil : height
|
119
|
+
end
|
120
|
+
|
121
|
+
# @param ["left", "center", "right", ""] position
|
122
|
+
# @return [:left, :center, :right]
|
123
|
+
def image_position_x(position)
|
124
|
+
case position
|
125
|
+
when 'left' then :left
|
126
|
+
when 'center' then :center
|
127
|
+
when 'right' then :right
|
128
|
+
when '' then :left
|
129
|
+
else :left
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# @param ["top", "middle", "bottom", ""] position
|
134
|
+
# @return [:left, :center, :right]
|
135
|
+
def image_position_y(position)
|
136
|
+
case position
|
137
|
+
when 'top' then :top
|
138
|
+
when 'middle' then :center
|
139
|
+
when 'bottom' then :bottom
|
140
|
+
when '' then :top
|
141
|
+
else :top
|
142
|
+
end
|
123
143
|
end
|
124
144
|
end
|
125
145
|
|