thinreports 0.6.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/.yardopts +1 -0
  2. data/README.rdoc +100 -0
  3. data/Rakefile +10 -0
  4. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  5. data/lib/thinreports.rb +11 -0
  6. data/lib/thinreports/core.rb +20 -0
  7. data/lib/thinreports/core/errors.rb +58 -0
  8. data/lib/thinreports/core/events.rb +71 -0
  9. data/lib/thinreports/core/ext.rb +5 -0
  10. data/lib/thinreports/core/ext/array.rb +19 -0
  11. data/lib/thinreports/core/ext/hash.rb +19 -0
  12. data/lib/thinreports/core/ext/object.rb +25 -0
  13. data/lib/thinreports/core/format.rb +14 -0
  14. data/lib/thinreports/core/format/base.rb +93 -0
  15. data/lib/thinreports/core/format/builder.rb +65 -0
  16. data/lib/thinreports/core/ordered_hash.rb +39 -0
  17. data/lib/thinreports/core/page.rb +91 -0
  18. data/lib/thinreports/core/shape.rb +53 -0
  19. data/lib/thinreports/core/shape/base.rb +16 -0
  20. data/lib/thinreports/core/shape/base/interface.rb +38 -0
  21. data/lib/thinreports/core/shape/base/internal.rb +60 -0
  22. data/lib/thinreports/core/shape/basic.rb +15 -0
  23. data/lib/thinreports/core/shape/basic/format.rb +26 -0
  24. data/lib/thinreports/core/shape/basic/interface.rb +57 -0
  25. data/lib/thinreports/core/shape/basic/internal.rb +29 -0
  26. data/lib/thinreports/core/shape/list.rb +25 -0
  27. data/lib/thinreports/core/shape/list/configuration.rb +33 -0
  28. data/lib/thinreports/core/shape/list/events.rb +30 -0
  29. data/lib/thinreports/core/shape/list/format.rb +72 -0
  30. data/lib/thinreports/core/shape/list/manager.rb +209 -0
  31. data/lib/thinreports/core/shape/list/page.rb +118 -0
  32. data/lib/thinreports/core/shape/list/page_state.rb +40 -0
  33. data/lib/thinreports/core/shape/list/section_format.rb +32 -0
  34. data/lib/thinreports/core/shape/list/section_interface.rb +48 -0
  35. data/lib/thinreports/core/shape/list/section_internal.rb +29 -0
  36. data/lib/thinreports/core/shape/list/store.rb +34 -0
  37. data/lib/thinreports/core/shape/manager.rb +14 -0
  38. data/lib/thinreports/core/shape/manager/format.rb +28 -0
  39. data/lib/thinreports/core/shape/manager/internal.rb +87 -0
  40. data/lib/thinreports/core/shape/manager/target.rb +85 -0
  41. data/lib/thinreports/core/shape/tblock.rb +16 -0
  42. data/lib/thinreports/core/shape/tblock/format.rb +36 -0
  43. data/lib/thinreports/core/shape/tblock/formatter.rb +32 -0
  44. data/lib/thinreports/core/shape/tblock/formatter/basic.rb +38 -0
  45. data/lib/thinreports/core/shape/tblock/formatter/datetime.rb +21 -0
  46. data/lib/thinreports/core/shape/tblock/formatter/number.rb +49 -0
  47. data/lib/thinreports/core/shape/tblock/formatter/padding.rb +43 -0
  48. data/lib/thinreports/core/shape/tblock/interface.rb +52 -0
  49. data/lib/thinreports/core/shape/tblock/internal.rb +70 -0
  50. data/lib/thinreports/core/shape/text.rb +15 -0
  51. data/lib/thinreports/core/shape/text/format.rb +25 -0
  52. data/lib/thinreports/core/shape/text/interface.rb +16 -0
  53. data/lib/thinreports/core/shape/text/internal.rb +17 -0
  54. data/lib/thinreports/core/utils.rb +48 -0
  55. data/lib/thinreports/generator.rb +30 -0
  56. data/lib/thinreports/generator/base.rb +49 -0
  57. data/lib/thinreports/generator/pdf.rb +63 -0
  58. data/lib/thinreports/generator/pdf/document.rb +171 -0
  59. data/lib/thinreports/generator/pdf/document/draw_shape.rb +74 -0
  60. data/lib/thinreports/generator/pdf/document/font.rb +59 -0
  61. data/lib/thinreports/generator/pdf/document/graphics.rb +42 -0
  62. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +92 -0
  63. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +132 -0
  64. data/lib/thinreports/generator/pdf/document/graphics/image.rb +51 -0
  65. data/lib/thinreports/generator/pdf/document/graphics/text.rb +130 -0
  66. data/lib/thinreports/generator/pdf/document/parse_color.rb +51 -0
  67. data/lib/thinreports/generator/pdf/document/parse_svg.rb +102 -0
  68. data/lib/thinreports/generator/pdf/drawer.rb +16 -0
  69. data/lib/thinreports/generator/pdf/drawer/base.rb +56 -0
  70. data/lib/thinreports/generator/pdf/drawer/list.rb +39 -0
  71. data/lib/thinreports/generator/pdf/drawer/list_section.rb +46 -0
  72. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -0
  73. data/lib/thinreports/generator/pdf/prawn_ext.rb +36 -0
  74. data/lib/thinreports/generator/pxd.rb +75 -0
  75. data/lib/thinreports/generator/pxd/helper.rb +33 -0
  76. data/lib/thinreports/generator/pxd/list_renderer.rb +58 -0
  77. data/lib/thinreports/generator/pxd/page_renderer.rb +75 -0
  78. data/lib/thinreports/layout.rb +17 -0
  79. data/lib/thinreports/layout/base.rb +78 -0
  80. data/lib/thinreports/layout/configuration.rb +27 -0
  81. data/lib/thinreports/layout/format.rb +77 -0
  82. data/lib/thinreports/layout/version.rb +43 -0
  83. data/lib/thinreports/report.rb +31 -0
  84. data/lib/thinreports/report/base.rb +160 -0
  85. data/lib/thinreports/report/events.rb +32 -0
  86. data/lib/thinreports/report/internal.rb +131 -0
  87. data/resources/fonts/IPA_Font_License_Agreement_v1.0.txt +117 -0
  88. data/resources/fonts/ipag.ttf +0 -0
  89. data/resources/fonts/ipagp.ttf +0 -0
  90. data/resources/fonts/ipam.ttf +0 -0
  91. data/resources/fonts/ipamp.ttf +0 -0
  92. data/tasks/clean.rake +6 -0
  93. data/tasks/doc.rake +13 -0
  94. data/tasks/test.rake +18 -0
  95. data/test/unit/core/ext/array_spec.rb +29 -0
  96. data/test/unit/core/ext/hash_spec.rb +29 -0
  97. data/test/unit/core/ext/object_spec.rb +30 -0
  98. data/test/unit/core/format/test_base.rb +148 -0
  99. data/test/unit/core/format/test_builder.rb +114 -0
  100. data/test/unit/core/ordered_hash_spec.rb +51 -0
  101. data/test/unit/core/shape/base/test_interface.rb +52 -0
  102. data/test/unit/core/shape/base/test_internal.rb +109 -0
  103. data/test/unit/core/shape/basic/test_format.rb +59 -0
  104. data/test/unit/core/shape/basic/test_interface.rb +70 -0
  105. data/test/unit/core/shape/basic/test_internal.rb +42 -0
  106. data/test/unit/core/shape/list/test_configuration.rb +52 -0
  107. data/test/unit/core/shape/list/test_events.rb +28 -0
  108. data/test/unit/core/shape/list/test_format.rb +71 -0
  109. data/test/unit/core/shape/list/test_page.rb +10 -0
  110. data/test/unit/core/shape/list/test_page_state.rb +31 -0
  111. data/test/unit/core/shape/list/test_section_format.rb +46 -0
  112. data/test/unit/core/shape/list/test_section_interface.rb +52 -0
  113. data/test/unit/core/shape/list/test_section_internal.rb +30 -0
  114. data/test/unit/core/shape/list/test_store.rb +41 -0
  115. data/test/unit/core/shape/manager/test_format.rb +40 -0
  116. data/test/unit/core/shape/manager/test_internal.rb +137 -0
  117. data/test/unit/core/shape/manager/test_target.rb +109 -0
  118. data/test/unit/core/shape/tblock/formatter/test_basic.rb +24 -0
  119. data/test/unit/core/shape/tblock/formatter/test_datetime.rb +47 -0
  120. data/test/unit/core/shape/tblock/formatter/test_number.rb +76 -0
  121. data/test/unit/core/shape/tblock/formatter/test_padding.rb +72 -0
  122. data/test/unit/core/shape/tblock/test_format.rb +125 -0
  123. data/test/unit/core/shape/tblock/test_formatter.rb +28 -0
  124. data/test/unit/core/shape/tblock/test_interface.rb +40 -0
  125. data/test/unit/core/shape/tblock/test_internal.rb +139 -0
  126. data/test/unit/core/shape/text/test_format.rb +73 -0
  127. data/test/unit/core/shape/text/test_internal.rb +21 -0
  128. data/test/unit/core/test_events.rb +91 -0
  129. data/test/unit/core/test_shape.rb +35 -0
  130. data/test/unit/core/utils_spec.rb +56 -0
  131. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +103 -0
  132. data/test/unit/generator/pdf/document/test_font.rb +54 -0
  133. data/test/unit/generator/pdf/document/test_graphics.rb +43 -0
  134. data/test/unit/generator/pdf/document/test_parse_color.rb +30 -0
  135. data/test/unit/generator/test_base.rb +51 -0
  136. data/test/unit/helper.rb +37 -0
  137. data/test/unit/layout/test_base.rb +92 -0
  138. data/test/unit/layout/test_configuration.rb +46 -0
  139. data/test/unit/layout/test_format.rb +104 -0
  140. data/test/unit/layout/test_version.rb +62 -0
  141. data/test/unit/report/test_base.rb +187 -0
  142. data/test/unit/report/test_events.rb +22 -0
  143. data/test/unit/report/test_internal.rb +234 -0
  144. data/test/unit/test_layout.rb +12 -0
  145. data/test/unit/test_report.rb +30 -0
  146. metadata +218 -0
@@ -0,0 +1,73 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Text::TestFormat < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ TEST_TEXT_FORMAT = {
9
+ "type" => "s-text",
10
+ "id" => "text_1",
11
+ "display" => "true",
12
+ "text" => ["Text Content1", "Text Content2"],
13
+ "valign" => "top",
14
+ "line-height" => 60,
15
+ "box" => {
16
+ "x" => 100.0,
17
+ "y" => 100.0,
18
+ "width" => 100.0,
19
+ "height" => 100.0
20
+ },
21
+ "svg" => {
22
+ "tag" => "g",
23
+ "attrs" => {
24
+ "stroke-width" => "0",
25
+ "font-weight" => "normal",
26
+ "font-style" => "normal",
27
+ "font-family" => "Arial",
28
+ "font-size" => "12",
29
+ "text-anchor" => "start",
30
+ "fill" => "#000000",
31
+ "fill-opacity" => "1",
32
+ "text-decoration" => "none",
33
+ "letter-spacing" => "normal"
34
+ },
35
+ "content" => "<text class=\"s-text-l0\" xml:space=\"preserve\" " +
36
+ "stroke=\"none\" fill=\"inherit\" fill-opacity=\"1\" " +
37
+ "text-decoration=\"none\" x=\"92\" y=\"93\">" +
38
+ "Text Content1</text>" +
39
+ "<text class=\"s-text-l1\" xml:space=\"preserve\" " +
40
+ "stroke=\"none\" fill=\"inherit\" fill-opacity=\"1\" " +
41
+ "text-decoration=\"none\" x=\"92\" y=\"107\">" +
42
+ "Text Content2</text>"
43
+ }
44
+ }
45
+
46
+ # Alias
47
+ Format = ThinReports::Core::Shape::Text::Format
48
+
49
+ def test_build_format
50
+ build_format
51
+ rescue => e
52
+ flunk exception_details(e, 'Building failed.')
53
+ end
54
+
55
+ def test_config_readers
56
+ format = Format.new(TEST_TEXT_FORMAT)
57
+
58
+ assert_instance_of ::Hash, format.box
59
+ assert_equal format.box['x'], 100.0
60
+
61
+ assert_instance_of ::Array, format.text
62
+ assert_equal format.text.first, 'Text Content1'
63
+
64
+ assert_equal format.valign, 'top'
65
+ assert_equal format.line_height, 60
66
+
67
+ assert_equal format.svg_content, TEST_TEXT_FORMAT['svg']['content']
68
+ end
69
+
70
+ def build_format
71
+ Format.build(TEST_TEXT_FORMAT)
72
+ end
73
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::Shape::Text::TestInternal < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ Text = ThinReports::Core::Shape::Text
9
+
10
+ def setup
11
+ format = flexmock('format')
12
+ format.should_receive(:type => 's-text')
13
+
14
+ @internal = Text::Internal.new(flexmock('parent'), format)
15
+ end
16
+
17
+ def test_type_of?
18
+ assert_equal @internal.type_of?(:text), true
19
+ assert_equal @internal.type_of?(:basic), false
20
+ end
21
+ end
@@ -0,0 +1,91 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::TestEvents < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ Events = ThinReports::Core::Events
10
+
11
+ def setup
12
+ @events = Events.new(:load, :change, :blur)
13
+ end
14
+
15
+ def test_listen
16
+ load1_handler = proc{|e| e.type }
17
+ load2_handler = proc{|e| e.type }
18
+ change_handler = proc{|e| e.target }
19
+
20
+ @events.listen(:load, &load1_handler)
21
+ @events.listen(:change, &change_handler)
22
+ # Overwrite
23
+ @events.listen(:load, &load2_handler)
24
+
25
+ # Using #on method
26
+ @events.on(:blur) do |e|
27
+ e.target
28
+ end
29
+
30
+ assert_equal @events.events.size, 3
31
+ assert_same @events.events[:change], change_handler
32
+ assert_same @events.events[:load], load2_handler
33
+ end
34
+
35
+ def test_listen_raise_error_when_unknown_event_type_is_set
36
+ assert_raises ThinReports::Errors::UnknownEventType do
37
+ @events.listen(:unknown) {|e| e.type }
38
+ end
39
+ end
40
+
41
+ def test_listen_raise_error_when_no_block_is_given
42
+ assert_raises ::ArgumentError do
43
+ @events.listen(:blur)
44
+ end
45
+ end
46
+
47
+ def test_unlisten
48
+ @events.listen(:load) {|e| e.type }
49
+ @events.listen(:change) {|e| e.type }
50
+ @events.listen(:blur) {|e| e.type }
51
+
52
+ @events.unlisten(:load)
53
+ @events.un(:change)
54
+ @events.un(:blur)
55
+
56
+ assert_empty @events.events
57
+ end
58
+
59
+ def test_dispatch
60
+ # Expected returns a true value
61
+ @events.listen(:change) {|e| e.type == :change }
62
+ assert_equal @events.dispatch(Events::Event.new(:change)), true
63
+
64
+ # Expected to reverse the string given as e#target
65
+ @events.on(:blur) {|e| e.target.reverse }
66
+ assert_equal @events.dispatch(Events::Event.new(:blur, '123')), '321'
67
+ end
68
+
69
+ def test_dispatch_raise_error_when_no_event_type_is_given
70
+ assert_raises ::ArgumentError do
71
+ @events.dispatch(Events::Event.new)
72
+ end
73
+ end
74
+
75
+ def test_dispatch_return_nil_when_event_type_is_not_listened
76
+ assert_nil @events.dispatch(Events::Event.new(:load, self))
77
+ end
78
+
79
+ def test_copy
80
+ @events.on(:change) {|e| e.type }
81
+ @events.on(:load) {|e| e.type }
82
+
83
+ copied = @events.copy
84
+
85
+ assert_equal @events.events, copied.events
86
+ refute_same @events.events, copied.events
87
+
88
+ @events.unlisten(:change)
89
+ refute_nil copied.dispatch(Events::Event.new(:change, self))
90
+ end
91
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Core::TestShape < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ ShapeModule = ThinReports::Core::Shape
10
+
11
+ def test_find_by_type
12
+ assert_same ShapeModule.find_by_type('s-tblock'), ShapeModule::Tblock
13
+ assert_same ShapeModule.find_by_type('s-list'), ShapeModule::List
14
+ assert_same ShapeModule.find_by_type('s-text'), ShapeModule::Text
15
+
16
+ assert_same ShapeModule.find_by_type('s-image'), ShapeModule::Basic
17
+ assert_same ShapeModule.find_by_type('s-line'), ShapeModule::Basic
18
+ assert_same ShapeModule.find_by_type('s-rect'), ShapeModule::Basic
19
+ assert_same ShapeModule.find_by_type('s-ellipse'), ShapeModule::Basic
20
+
21
+ assert_raises ThinReports::Errors::UnknownShapeType do
22
+ ShapeModule.find_by_type('unknown')
23
+ end
24
+ end
25
+
26
+ def test_Configuration
27
+ assert_same ShapeModule::Configuration('s-list'),
28
+ ShapeModule::List::Configuration
29
+
30
+ # When shape don't have a Configuration
31
+ assert_raises ThinReports::Errors::NoConfigurationFound do
32
+ ShapeModule::Configuration('s-line')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ include ThinReports::TestHelpers
6
+
7
+ describe '#block_exec_on' do
8
+ it 'should return raw context if not given a block' do
9
+ expected = '123'
10
+ block_exec_on(expected).must_be_same_as expected
11
+ end
12
+
13
+ it 'should be run correctly without receiver if no block argument' do
14
+ block_exec_on('123', &proc{ reverse! }).must_equal '321'
15
+ end
16
+
17
+ it 'should be run correctly with an receiver if block has an argument' do
18
+ block_exec_on([2, 1, 3], &proc{ |a| a.sort! }).must_equal [1, 2, 3]
19
+ end
20
+ end
21
+
22
+ describe '#ruby_18' do
23
+ it 'should not be run and return false if ruby version more than 1.8' do
24
+ skip_if_ruby18
25
+
26
+ ruby_18 {
27
+ flunk '#ruby_18 should not be executed!'
28
+ }.must_equal false
29
+ end
30
+
31
+ it 'should be run if ruby version less than 1.9' do
32
+ skip_if_ruby19
33
+
34
+ ruby_18 {
35
+ pass '#ruby_18 was executed correctly!'; true
36
+ }.must_equal true
37
+ end
38
+ end
39
+
40
+ describe '#ruby_19' do
41
+ it 'should not be run and return false if ruby version less than 1.9' do
42
+ skip_if_ruby19
43
+
44
+ ruby_19 {
45
+ flunk '#ruby_19 should not be executed!'
46
+ }.must_equal false
47
+ end
48
+
49
+ it 'should be run if ruby version more than 1.9' do
50
+ skip_if_ruby18
51
+
52
+ ruby_19 {
53
+ pass '#ruby_19 was executed correctly!'; true
54
+ }.must_equal true
55
+ end
56
+ end
@@ -0,0 +1,103 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Generator::Pdf::Graphics::TestAttributes < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ class TestAttrs
9
+ include ThinReports::Generator::Pdf::Graphics
10
+ end
11
+
12
+ def setup
13
+ @attrs = TestAttrs.new
14
+ end
15
+
16
+ def test_common_graphic_attrs
17
+ result = @attrs.common_graphic_attrs('stroke' => '#ff0000',
18
+ 'stroke-width' => '1',
19
+ 'fill' => '#0000ff')
20
+ assert_equal result.values_at(:stroke, :stroke_width, :fill),
21
+ ['#ff0000', '1', '#0000ff']
22
+ end
23
+
24
+ def test_common_graphic_attrs_with_stroke_dasharray
25
+ result1 = @attrs.common_graphic_attrs('stroke-dasharray' => '3,5')
26
+ result2 = @attrs.common_graphic_attrs('stroke-dasharray' => 'none')
27
+ result3 = @attrs.common_graphic_attrs({})
28
+
29
+ assert_equal result1[:stroke_dash], %w( 3 5 )
30
+ assert_nil result2[:stroke_dash]
31
+ assert_nil result3[:stroke_dash]
32
+ end
33
+
34
+ def test_common_graphic_attrs_set_0_to_stroke_width_when_opacity_is_0
35
+ result = @attrs.common_graphic_attrs('stroke-width' => '1',
36
+ 'stroke-opacity' => '0')
37
+ assert_equal result[:stroke_width], 0
38
+ end
39
+
40
+ def test_common_graphic_attrs_with_block
41
+ result = @attrs.common_graphic_attrs('stroke' => '#ff0000') do |attrs|
42
+ attrs[:stroke].gsub!(/0/, 'f')
43
+ end
44
+ assert_equal result[:stroke], '#ffffff'
45
+ end
46
+
47
+ def test_text_align
48
+ aligns = ['start', 'middle', 'end', nil]
49
+ assert_equal aligns.map {|a| @attrs.text_align(a) },
50
+ [:left, :center, :right, :left]
51
+ end
52
+
53
+ def test_text_valign
54
+ valigns = ['top', 'center', 'bottom', nil]
55
+ assert_equal valigns.map {|a| @attrs.text_valign(a) },
56
+ [:top, :center, :bottom, :top]
57
+ end
58
+
59
+ def test_extract_base64_string
60
+ base64 = 'data:image/png;base64,iVBORw0KGg1+/AAy/plYlzil'
61
+ assert_equal @attrs.extract_base64_string(base64),
62
+ 'iVBORw0KGg1+/AAy/plYlzil'
63
+ end
64
+
65
+ def test_font_styles_with_bold_and_italic
66
+ assert_equal @attrs.font_styles('font-weight' => 'bold'), [:bold]
67
+ assert_equal @attrs.font_styles('font-style' => 'italic'), [:italic]
68
+
69
+ refute_includes @attrs.font_styles('font-weight' => 'normal'), :bold
70
+ refute_includes @attrs.font_styles('font-style' => 'normal'), :italic
71
+ end
72
+
73
+ def test_font_styles_with_underline_and_strikethrough_via_text_decoration
74
+ assert_equal @attrs.font_styles('text-decoration' => 'underline line-through'),
75
+ [:underline, :strikethrough]
76
+ end
77
+
78
+ def common_text_attrs
79
+ result = @attrs.common_text_attrs('font-family' => 'IPAMincho',
80
+ 'font-size' => '12',
81
+ 'fill' => '#000000',
82
+ 'text-anchor' => 'middle',
83
+ 'font-weight' => 'bold',
84
+ 'text-decoration' => 'line-through')
85
+ assert_equal result.values_at(:font, :size, :color, :align, :styles),
86
+ ['IPAMincho', '12', '#000000', :center, [:bold, :strikethrough]]
87
+ end
88
+
89
+ def common_text_attrs_with_letter_spacing
90
+ result1 = @attrs.common_text_attrs('letter-spacing' => '5')
91
+ result2 = @attrs.common_text_attrs('letter-spacing' => 'normal')
92
+
93
+ assert_equal result1[:letter_spacing], '5'
94
+ assert_nil result2[:letter_spacing]
95
+ end
96
+
97
+ def common_text_attrs_with_block
98
+ result = @attrs.common_text_attrs('fill' => '#000000') do |attrs|
99
+ attrs[:color].gsub!(/0/, 'f')
100
+ end
101
+ assert_equal result[:color], '#ffffff'
102
+ end
103
+ end
@@ -0,0 +1,54 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Generator::Pdf::TestFont < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ # Alias
9
+ Font = ThinReports::Generator::Pdf::Font
10
+
11
+ def setup
12
+ @doc = ThinReports::Generator::Pdf::Document.new
13
+ end
14
+
15
+ def test_setup_fonts_install_builtin_fonts
16
+ Font::BUILTIN_FONTS.each_key do |font|
17
+ assert_includes @doc.internal.font_families.keys, font
18
+ end
19
+ end
20
+
21
+ def test_setup_fonts_install_fallback_font
22
+ assert_includes @doc.internal.font_families.keys, 'FallbackFont'
23
+ assert_includes @doc.internal.fallback_fonts, 'FallbackFont'
24
+ end
25
+
26
+ def test_fallback_font_has_all_styles_as_normal_IPAMincho
27
+ ipam = Font::BUILTIN_FONTS['IPAMincho'][:normal]
28
+ [:normal, :bold, :italic, :bold_italic].each do |style|
29
+ assert_same @doc.internal.font_families['FallbackFont'][style], ipam
30
+ end
31
+ end
32
+
33
+ def test_setup_fonts_install_alias_fonts_of_CourierNew_and_TimesNewRoman
34
+ assert_same @doc.internal.font_families['Courier New'],
35
+ @doc.internal.font_families['Courier']
36
+ assert_same @doc.internal.font_families['Times New Roman'],
37
+ @doc.internal.font_families['Times-Roman']
38
+ end
39
+
40
+ def test_default_family
41
+ assert_equal @doc.send(:default_family), 'Helvetica'
42
+ end
43
+
44
+ def test_default_family_if_missing
45
+ assert_equal @doc.send(:default_family_if_missing, 'unknown font'),
46
+ @doc.send(:default_family)
47
+ assert_equal @doc.send(:default_family_if_missing, 'IPAMincho'), 'IPAMincho'
48
+ end
49
+
50
+ def test_font_has_style?
51
+ assert_equal @doc.send(:font_has_style?, 'IPAMincho', :bold), false
52
+ assert_equal @doc.send(:font_has_style?, 'Courier New', :bold), true
53
+ end
54
+ end
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+
3
+ require 'test/unit/helper'
4
+
5
+ class ThinReports::Generator::Pdf::TestGraphics < MiniTest::Unit::TestCase
6
+ include ThinReports::TestHelpers
7
+
8
+ class TestGraphics
9
+ attr_accessor :pdf
10
+ include ThinReports::Generator::Pdf::Graphics
11
+ end
12
+
13
+ def setup
14
+ @g = TestGraphics.new
15
+ @g.pdf = flexmock('pdf')
16
+ end
17
+
18
+ def test_setup_custom_graphic_states
19
+ @g.pdf.
20
+ should_receive(:line_width).
21
+ with(TestGraphics::BASE_LINE_WIDTH).once
22
+
23
+ @g.send(:setup_custom_graphic_states)
24
+ end
25
+
26
+ def test_line_width
27
+ @g.pdf.
28
+ should_receive(:line_width).
29
+ with(10 * TestGraphics::BASE_LINE_WIDTH).once
30
+
31
+ @g.send(:line_width, 10)
32
+ end
33
+
34
+ def test_save_graphics_state
35
+ @g.pdf.should_receive(:save_graphics_state).once
36
+ @g.send(:save_graphics_state)
37
+ end
38
+
39
+ def test_restore_graphics_state
40
+ @g.pdf.should_receive(:restore_graphics_state).once
41
+ @g.send(:restore_graphics_state)
42
+ end
43
+ end