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,61 +4,49 @@ require 'test_helper'
|
|
4
4
|
|
5
5
|
class Thinreports::Core::TestShape < Minitest::Test
|
6
6
|
include Thinreports::TestHelper
|
7
|
-
|
7
|
+
|
8
8
|
# Alias
|
9
9
|
ShapeModule = Thinreports::Core::Shape
|
10
|
-
|
10
|
+
|
11
11
|
def test_find_by_type_should_return_PageNumber
|
12
|
-
assert_same ShapeModule.find_by_type('
|
12
|
+
assert_same ShapeModule.find_by_type('page-number'), ShapeModule::PageNumber
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_find_by_type_should_return_ImageBlock
|
16
|
-
assert_same ShapeModule.find_by_type('
|
16
|
+
assert_same ShapeModule.find_by_type('image-block'), ShapeModule::ImageBlock
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def test_find_by_type_should_return_TextBlock
|
20
|
-
assert_same ShapeModule.find_by_type('
|
20
|
+
assert_same ShapeModule.find_by_type('text-block'), ShapeModule::TextBlock
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def test_find_by_type_should_return_List
|
24
|
-
assert_same ShapeModule.find_by_type('
|
24
|
+
assert_same ShapeModule.find_by_type('list'), ShapeModule::List
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def test_find_by_type_should_return_Text
|
28
|
-
assert_same ShapeModule.find_by_type('
|
28
|
+
assert_same ShapeModule.find_by_type('text'), ShapeModule::Text
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def test_find_by_type_should_return_Basic_as_Image
|
32
|
-
assert_same ShapeModule.find_by_type('
|
32
|
+
assert_same ShapeModule.find_by_type('image'), ShapeModule::Basic
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def test_find_by_type_should_return_Basic_as_Line
|
36
|
-
assert_same ShapeModule.find_by_type('
|
36
|
+
assert_same ShapeModule.find_by_type('line'), ShapeModule::Basic
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def test_find_by_type_should_return_Basic_as_Rect
|
40
|
-
assert_same ShapeModule.find_by_type('
|
40
|
+
assert_same ShapeModule.find_by_type('rect'), ShapeModule::Basic
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def test_find_by_type_should_return_Basic_as_Ellipse
|
44
|
-
assert_same ShapeModule.find_by_type('
|
44
|
+
assert_same ShapeModule.find_by_type('ellipse'), ShapeModule::Basic
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def test_find_by_type_should_raise
|
48
48
|
assert_raises Thinreports::Errors::UnknownShapeType do
|
49
49
|
ShapeModule.find_by_type('unknown')
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
53
|
-
def test_Configuration_should_return_Configuration_of_List
|
54
|
-
assert_same ShapeModule::Configuration('s-list'),
|
55
|
-
ShapeModule::List::Configuration
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_Configuration_should_raise
|
59
|
-
# When shape don't have a Configuration
|
60
|
-
assert_raises Thinreports::Errors::NoConfigurationFound do
|
61
|
-
ShapeModule::Configuration('s-line')
|
62
|
-
end
|
63
|
-
end
|
64
52
|
end
|
@@ -9,137 +9,127 @@ class Thinreports::Generator::PDF::Graphics::TestAttributes < Minitest::Test
|
|
9
9
|
@pdf = Thinreports::Generator::PDF::Document.new
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def test_build_graphic_attributes
|
13
|
+
graphic_styles = {
|
14
|
+
'border-color' => '#ff0000',
|
15
|
+
'border-width' => 2.0,
|
16
|
+
'border-style' => 'solid',
|
17
|
+
'fill-color' => '#000000'
|
18
|
+
}
|
19
|
+
|
20
|
+
assert_equal(
|
21
|
+
{
|
22
|
+
stroke: '#ff0000',
|
23
|
+
stroke_width: 2.0,
|
24
|
+
stroke_type: 'solid',
|
25
|
+
fill: '#000000'
|
26
|
+
},
|
27
|
+
@pdf.build_graphic_attributes(graphic_styles)
|
28
|
+
)
|
29
|
+
|
30
|
+
customized_attributes = @pdf.build_graphic_attributes(graphic_styles) { |attrs| attrs[:stroke] = 'blue' }
|
31
|
+
assert_equal 'blue', customized_attributes[:stroke]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_build_text_attributes
|
35
|
+
text_styles = {
|
36
|
+
'font-family' => %w( Helvetica IPAMincho ),
|
37
|
+
'font-size' => 18.0,
|
38
|
+
'color' => 'red',
|
39
|
+
'text-align' => 'right',
|
40
|
+
'vertical-align' => 'bottom',
|
41
|
+
'font-style' => %w( bold italic ),
|
42
|
+
'letter-spacing' => 2.0,
|
43
|
+
'line-height' => 20.0,
|
44
|
+
'overflow' => 'expand',
|
45
|
+
'word-wrap' => 'break-word'
|
46
|
+
}
|
47
|
+
|
48
|
+
assert_equal(
|
49
|
+
{
|
50
|
+
font: 'Helvetica',
|
51
|
+
size: 18.0,
|
52
|
+
color: 'red',
|
53
|
+
align: :right,
|
54
|
+
valign: :bottom,
|
55
|
+
styles: [:bold, :italic],
|
56
|
+
letter_spacing: 2.0,
|
57
|
+
line_height: 20.0,
|
58
|
+
overflow: :expand,
|
59
|
+
word_wrap: :break_word
|
60
|
+
},
|
61
|
+
@pdf.build_text_attributes(text_styles)
|
62
|
+
)
|
63
|
+
|
64
|
+
customized_attributes = @pdf.build_text_attributes(text_styles) { |attrs| attrs[:color] = 'blue' }
|
65
|
+
assert_equal 'blue', customized_attributes[:color]
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_font_family
|
69
|
+
assert_equal 'IPAGothic', @pdf.font_family(%w( IPAGothic Helvetica ))
|
70
|
+
assert_equal 'Helvetica', @pdf.font_family(%w( Unknown IPAMincho ))
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_font_styles
|
74
|
+
assert_equal [:bold, :italic, :underline, :strikethrough],
|
75
|
+
@pdf.font_styles(%w( bold italic underline linethrough ))
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_letter_spacing
|
79
|
+
assert_equal 2.0, @pdf.letter_spacing(2.0)
|
80
|
+
assert_nil @pdf.letter_spacing('')
|
81
|
+
assert_nil @pdf.letter_spacing(nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_text_align
|
85
|
+
assert_equal :left, @pdf.text_align('left')
|
86
|
+
assert_equal :center, @pdf.text_align('center')
|
87
|
+
assert_equal :right, @pdf.text_align('right')
|
88
|
+
assert_equal :left, @pdf.text_align('')
|
89
|
+
assert_equal :left, @pdf.text_align(nil)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_text_valign
|
93
|
+
assert_equal :top, @pdf.text_valign('top')
|
94
|
+
assert_equal :center, @pdf.text_valign('middle')
|
95
|
+
assert_equal :bottom, @pdf.text_valign('bottom')
|
96
|
+
assert_equal :top, @pdf.text_valign('')
|
97
|
+
assert_equal :top, @pdf.text_valign(nil)
|
18
98
|
end
|
19
99
|
|
20
|
-
def
|
21
|
-
|
22
|
-
assert_equal
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
result = @pdf.common_graphic_attrs('stroke-dasharray' => 'none')
|
27
|
-
assert_nil result[:stroke_dash]
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_common_graphic_attrs_should_return_nil_as_a_value_of_stroke_dash_attribute_when_value_is_empty
|
31
|
-
result = @pdf.common_graphic_attrs({})
|
32
|
-
assert_nil result[:stroke_dash]
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_common_graphic_attrs_should_set_0_as_a_value_of_stroke_width_attribute_when_opacity_is_0
|
36
|
-
result = @pdf.common_graphic_attrs('stroke-width' => '1',
|
37
|
-
'stroke-opacity' => '0')
|
38
|
-
assert_equal result[:stroke_width], 0
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_common_graphic_attrs_with_block
|
42
|
-
result = @pdf.common_graphic_attrs('stroke' => '#ff0000') do |attrs|
|
43
|
-
attrs[:stroke].gsub!(/0/, 'f')
|
44
|
-
end
|
45
|
-
assert_equal result[:stroke], '#ffffff'
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_text_align_should_return_converted_value_type_of_Symbol
|
49
|
-
aligns = ['start', 'middle', 'end', nil]
|
50
|
-
assert_equal aligns.map {|a| @pdf.text_align(a) },
|
51
|
-
[:left, :center, :right, :left]
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_text_valign_should_return_converted_value_type_of_Symbol
|
55
|
-
valigns = ['top', 'center', 'bottom', nil]
|
56
|
-
assert_equal valigns.map {|a| @pdf.text_valign(a) },
|
57
|
-
[:top, :center, :bottom, :top]
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_text_word_wrap
|
61
|
-
assert_equal @pdf.text_word_wrap('break-word'), :break_word
|
62
|
-
assert_equal @pdf.text_word_wrap('none'), :none
|
63
|
-
assert_equal @pdf.text_word_wrap(''), :none
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_extract_base64_string
|
67
|
-
base64 = 'data:image/png;base64,iVBORw0KGg1+/AAy/plYlzil'
|
68
|
-
assert_equal @pdf.extract_base64_string(base64),
|
69
|
-
['image/png', 'iVBORw0KGg1+/AAy/plYlzil']
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_font_styles_should_return_bold_style_when_font_weight_is_bold
|
73
|
-
assert_equal @pdf.font_styles('font-weight' => 'bold'), [:bold]
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_font_styles_should_return_italic_style_when_font_style_is_italic
|
77
|
-
assert_equal @pdf.font_styles('font-style' => 'italic'), [:italic]
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_font_styles_should_return_underline_and_strikethrough_style_via_text_decoration
|
81
|
-
assert_equal @pdf.font_styles('text-decoration' => 'underline line-through'),
|
82
|
-
[:underline, :strikethrough]
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_common_text_attrs_should_return_the_value_of_font_family_as_font
|
86
|
-
result = @pdf.common_text_attrs('font-family' => 'IPAMincho')
|
87
|
-
assert_equal result[:font], 'IPAMincho'
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_common_text_attrs_should_return_the_value_of_font_size_as_size
|
91
|
-
result = @pdf.common_text_attrs('font-size' => '12')
|
92
|
-
assert_equal result[:size], '12'
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_common_text_attrs_should_return_the_value_of_fill_color_as_color
|
96
|
-
result = @pdf.common_text_attrs('fill' => '#000000')
|
97
|
-
assert_equal result[:color], '#000000'
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_common_text_attrs_should_return_the_value_of_text_anchor_as_align
|
101
|
-
result = @pdf.common_text_attrs('text-anchor' => 'middle')
|
102
|
-
assert_equal result[:align], :center
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_common_text_attrs_should_return_the_value_of_text_styles_as_styles
|
106
|
-
result = @pdf.common_text_attrs('font-weight' => 'bold')
|
107
|
-
assert_equal result[:styles], [:bold]
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_common_text_attrs_should_return_the_value_of_letter_spacing_as_letter_spacing
|
111
|
-
result = @pdf.common_text_attrs('letter-spacing' => '5')
|
112
|
-
assert_equal result[:letter_spacing], '5'
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_common_text_attrs_should_return_the_value_of_kerning_as_letter_spacing
|
116
|
-
result = @pdf.common_text_attrs('kerning' => '10')
|
117
|
-
assert_equal result[:letter_spacing], '10'
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_common_text_attrs_with_block
|
121
|
-
result = @pdf.common_text_attrs('fill' => '#000000') do |attrs|
|
122
|
-
attrs[:color].gsub!(/0/, 'f')
|
123
|
-
end
|
124
|
-
assert_equal result[:color], '#ffffff'
|
100
|
+
def test_text_overflow
|
101
|
+
assert_equal :truncate, @pdf.text_overflow('truncate')
|
102
|
+
assert_equal :shrink_to_fit, @pdf.text_overflow('fit')
|
103
|
+
assert_equal :expand, @pdf.text_overflow('expand')
|
104
|
+
assert_equal :truncate, @pdf.text_overflow('')
|
105
|
+
assert_equal :truncate, @pdf.text_overflow(nil)
|
125
106
|
end
|
126
107
|
|
127
|
-
def
|
128
|
-
assert_equal @pdf.
|
108
|
+
def test_word_wrap
|
109
|
+
assert_equal :break_word, @pdf.word_wrap('break-word')
|
110
|
+
assert_equal :none, @pdf.word_wrap('none')
|
111
|
+
assert_equal :none, @pdf.word_wrap(nil)
|
129
112
|
end
|
130
113
|
|
131
|
-
def
|
132
|
-
|
114
|
+
def test_line_height
|
115
|
+
assert_equal 20.9, @pdf.line_height(20.9)
|
116
|
+
assert_nil @pdf.line_height('')
|
117
|
+
assert_nil @pdf.line_height(nil)
|
133
118
|
end
|
134
119
|
|
135
|
-
def
|
136
|
-
|
120
|
+
def test_image_position_x
|
121
|
+
assert_equal :left, @pdf.image_position_x('left')
|
122
|
+
assert_equal :center, @pdf.image_position_x('center')
|
123
|
+
assert_equal :right, @pdf.image_position_x('right')
|
124
|
+
assert_equal :left, @pdf.image_position_x('')
|
125
|
+
assert_equal :left, @pdf.image_position_x(nil)
|
137
126
|
end
|
138
127
|
|
139
|
-
def
|
140
|
-
assert_equal @pdf.
|
141
|
-
assert_equal @pdf.
|
142
|
-
assert_equal @pdf.
|
143
|
-
assert_equal @pdf.
|
128
|
+
def test_image_position_y
|
129
|
+
assert_equal :top, @pdf.image_position_y('top')
|
130
|
+
assert_equal :center, @pdf.image_position_y('middle')
|
131
|
+
assert_equal :bottom, @pdf.image_position_y('bottom')
|
132
|
+
assert_equal :top, @pdf.image_position_y('')
|
133
|
+
assert_equal :top, @pdf.image_position_y(nil)
|
144
134
|
end
|
145
135
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class Thinreports::Generator::PDF::Graphics::TestBasic < Minitest::Test
|
5
|
+
include Thinreports::TestHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@pdf = Thinreports::Generator::PDF::Document.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_build_stroke_styles
|
12
|
+
style = {
|
13
|
+
stroke: 'red',
|
14
|
+
stroke_width: 2.0,
|
15
|
+
stroke_type: 'solid'
|
16
|
+
}
|
17
|
+
|
18
|
+
assert_equal(
|
19
|
+
{
|
20
|
+
color: 'ff0000',
|
21
|
+
width: 2.0,
|
22
|
+
dash: nil
|
23
|
+
},
|
24
|
+
@pdf.build_stroke_styles(style)
|
25
|
+
)
|
26
|
+
|
27
|
+
style_stroke_dashed = style.merge(stroke_type: 'dashed')
|
28
|
+
assert_equal [2, 2], @pdf.build_stroke_styles(style_stroke_dashed)[:dash]
|
29
|
+
|
30
|
+
style_stroke_dotted = style.merge(stroke_type: 'dotted')
|
31
|
+
assert_equal [1, 2], @pdf.build_stroke_styles(style_stroke_dotted)[:dash]
|
32
|
+
|
33
|
+
assert_nil @pdf.build_stroke_styles(stroke: nil, stroke_width: 1)
|
34
|
+
assert_nil @pdf.build_stroke_styles(stroke: 'none', stroke_width: 1)
|
35
|
+
|
36
|
+
assert_nil @pdf.build_stroke_styles(stroke_width: nil, stroke: 'red')
|
37
|
+
assert_nil @pdf.build_stroke_styles(stroke_width: 0, stroke: 'red')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_build_fill_styles
|
41
|
+
assert_equal({ color: 'ff0000' }, @pdf.build_fill_styles(fill: 'red'))
|
42
|
+
assert_nil @pdf.build_fill_styles(fill: nil)
|
43
|
+
assert_nil @pdf.build_fill_styles(fill: 'none')
|
44
|
+
end
|
45
|
+
end
|
@@ -58,11 +58,11 @@ class Thinreports::Generator::PDF::Graphics::TestImage < Minitest::Test
|
|
58
58
|
|
59
59
|
image_id = Digest::MD5.hexdigest(base64_normal_image)
|
60
60
|
assert_includes image_registry.keys, image_id
|
61
|
-
assert_equal normalized_image_path, image_registry[image_id]
|
61
|
+
assert_equal normalized_image_path, image_registry[image_id].path
|
62
62
|
|
63
63
|
assert equal_image(data_file(image_file), normalized_image_path)
|
64
64
|
|
65
|
-
|
65
|
+
assert_equal normalized_image_path,
|
66
66
|
test_image.normalize_image_from_base64(image_type, base64_normal_image)
|
67
67
|
end
|
68
68
|
end
|
@@ -81,14 +81,14 @@ class Thinreports::Generator::PDF::Graphics::TestImage < Minitest::Test
|
|
81
81
|
|
82
82
|
image_id = Digest::MD5.hexdigest(base64_palleted_png)
|
83
83
|
assert_includes image_registry.keys, image_id
|
84
|
-
assert_equal normalized_image_path, image_registry[image_id]
|
84
|
+
assert_equal normalized_image_path, image_registry[image_id].path
|
85
85
|
|
86
86
|
refute equal_image(data_file('image_pallete_based.png'), normalized_image_path)
|
87
87
|
|
88
88
|
assert_not_palette_based_transparency_png File.read(normalized_image_path)
|
89
89
|
|
90
90
|
# 2nd time
|
91
|
-
|
91
|
+
assert_equal normalized_image_path,
|
92
92
|
test_image.normalize_image_from_base64('image/png', base64_palleted_png)
|
93
93
|
assert_equal 1, test_image.temp_image_registry.count
|
94
94
|
end
|
@@ -130,7 +130,7 @@ class Thinreports::Generator::PDF::Graphics::TestImage < Minitest::Test
|
|
130
130
|
|
131
131
|
# It should never called in 2nd time or subsequent.
|
132
132
|
TestImage::PNGNormalizer.stubs(:load_file).never
|
133
|
-
|
133
|
+
assert_equal normalized_image_path,
|
134
134
|
test_image.normalize_image_from_file(original_image_path)
|
135
135
|
end
|
136
136
|
|
@@ -11,7 +11,6 @@ class Thinreports::Generator::PDF::TestFont < Minitest::Test
|
|
11
11
|
# Reset font settings
|
12
12
|
Thinreports.configure do |c|
|
13
13
|
c.fallback_fonts = []
|
14
|
-
c.generator.pdf.eudc_fonts = []
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
@@ -22,7 +21,7 @@ class Thinreports::Generator::PDF::TestFont < Minitest::Test
|
|
22
21
|
assert_equal font, pdf.font_families[name]
|
23
22
|
end
|
24
23
|
|
25
|
-
Font::
|
24
|
+
Font::PRAWN_BUINTIN_FONT_ALIASES.each do |alias_font, original_font|
|
26
25
|
assert_equal pdf.font_families[alias_font],
|
27
26
|
pdf.font_families[original_font]
|
28
27
|
end
|
@@ -33,37 +32,32 @@ class Thinreports::Generator::PDF::TestFont < Minitest::Test
|
|
33
32
|
def test_setup_fonts_with_custom_fallback_fonts
|
34
33
|
Thinreports.configure do |c|
|
35
34
|
c.fallback_fonts = []
|
36
|
-
c.generator.pdf.eudc_fonts = []
|
37
35
|
end
|
38
36
|
assert_equal Font::DEFAULT_FALLBACK_FONTS,
|
39
37
|
document.pdf.fallback_fonts
|
40
38
|
|
41
39
|
Thinreports.configure do |c|
|
42
40
|
c.fallback_fonts = 'IPAGothic'
|
43
|
-
c.generator.pdf.eudc_fonts = []
|
44
41
|
end
|
45
42
|
assert_equal ['IPAGothic'] + Font::DEFAULT_FALLBACK_FONTS,
|
46
43
|
document.pdf.fallback_fonts
|
47
44
|
|
48
45
|
Thinreports.configure do |c|
|
49
46
|
c.fallback_fonts = ['IPAMincho']
|
50
|
-
c.generator.pdf.eudc_fonts = [data_file('font.ttf')]
|
51
47
|
end
|
52
|
-
assert_equal ['
|
48
|
+
assert_equal ['IPAMincho'] + Font::DEFAULT_FALLBACK_FONTS,
|
53
49
|
document.pdf.fallback_fonts
|
54
50
|
|
55
51
|
Thinreports.configure do |c|
|
56
|
-
c.
|
57
|
-
c.fallback_fonts = ['IPAMincho', 'IPAMincho', data_file('font.ttf')]
|
52
|
+
c.fallback_fonts = ['IPAMincho', data_file('font.ttf')]
|
58
53
|
end
|
59
|
-
assert_equal ['Custom-fallback-
|
54
|
+
assert_equal ['IPAMincho', 'Custom-fallback-font1'] + Font::DEFAULT_FALLBACK_FONTS,
|
60
55
|
document.pdf.fallback_fonts
|
61
56
|
end
|
62
57
|
|
63
58
|
def test_setup_fonts_with_unknown_custom_fallback_fonts
|
64
59
|
Thinreports.configure do |c|
|
65
60
|
c.fallback_fonts = ['/path/to/unknown.ttf']
|
66
|
-
c.generator.pdf.eudc_fonts = []
|
67
61
|
end
|
68
62
|
|
69
63
|
assert_raises Thinreports::Errors::FontFileNotFound do
|