thinreports 0.7.7 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -6
- data/.travis.yml +4 -10
- data/CHANGELOG.md +220 -0
- data/Gemfile +3 -3
- data/MIT-LICENSE +1 -1
- data/README.md +286 -0
- data/Rakefile +38 -8
- data/examples/character_spacing/character_spacing.rb +8 -0
- data/examples/character_spacing/character_spacing.tlf +1 -0
- data/examples/dynamic_image/dynamic_image.rb +31 -0
- data/examples/dynamic_image/dynamic_image.tlf +1 -0
- data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
- data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
- data/examples/dynamic_style/dynamic_style.rb +150 -0
- data/examples/dynamic_style/dynamic_style.tlf +1 -0
- data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
- data/{test/case → examples}/dynamic_style/image.png +0 -0
- data/examples/eudc/eudc.rb +20 -0
- data/examples/eudc/eudc.tlf +1 -0
- data/{test/case → examples}/eudc/eudc.ttf +0 -0
- data/{test/case → examples}/helper.rb +14 -12
- data/examples/hidden_shapes/hidden_shapes.rb +9 -0
- data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
- data/examples/list_events/list_events.rb +59 -0
- data/examples/list_events/list_events_0_7_7.tlf +1 -0
- data/examples/list_events/list_events_0_8.tlf +1 -0
- data/{test/case → examples}/list_manual_generation/list_manual_generation.rb +4 -4
- data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
- data/{test/case → examples}/list_page_number/list_page_number.rb +3 -3
- data/examples/list_page_number/list_page_number.tlf +1 -0
- data/examples/page_number/page_number.rb +33 -0
- data/examples/page_number/page_number.tlf +1 -0
- data/examples/password_setting/password_setting.rb +10 -0
- data/examples/password_setting/password_setting.tlf +1 -0
- data/examples/report_callbacks/report_callbacks.rb +31 -0
- data/examples/report_callbacks/report_callbacks.tlf +1 -0
- data/{test/case → examples}/single_line_tblock/single_line_tblock.rb +2 -2
- data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
- data/examples/tblock_overflow/tblock_overflow.rb +20 -0
- data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
- data/examples/tblock_styles/font_size.tlf +1 -0
- data/examples/tblock_styles/tblock_styles.rb +43 -0
- data/examples/tblock_styles/tblock_styles.tlf +1 -0
- data/examples/text_align/text_align.rb +8 -0
- data/examples/text_align/text_align.tlf +1 -0
- data/examples/typeB_page_size/B4_ISO.tlf +1 -0
- data/examples/typeB_page_size/B4_JIS.tlf +1 -0
- data/{test/case → examples}/typeB_page_size/typeB_page_size.rb +3 -3
- data/examples/word_wrap/word_wrap.rb +26 -0
- data/examples/word_wrap/word_wrap.tlf +1 -0
- data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
- data/{resources/fonts → fonts}/ipag.ttf +0 -0
- data/{resources/fonts → fonts}/ipagp.ttf +0 -0
- data/{resources/fonts → fonts}/ipam.ttf +0 -0
- data/{resources/fonts → fonts}/ipamp.ttf +0 -0
- data/lib/thinreports.rb +14 -2
- data/lib/thinreports/config.rb +30 -10
- data/lib/thinreports/core/errors.rb +23 -20
- data/lib/thinreports/core/events.rb +18 -19
- data/lib/thinreports/core/format/base.rb +20 -20
- data/lib/thinreports/core/format/builder.rb +14 -22
- data/lib/thinreports/core/shape.rb +9 -13
- data/lib/thinreports/core/shape/base.rb +4 -5
- data/lib/thinreports/core/shape/base/interface.rb +15 -15
- data/lib/thinreports/core/shape/base/internal.rb +15 -20
- data/lib/thinreports/core/shape/basic.rb +1 -1
- data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
- data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
- data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
- data/lib/thinreports/core/shape/basic/format.rb +11 -10
- data/lib/thinreports/core/shape/basic/interface.rb +3 -3
- data/lib/thinreports/core/shape/basic/internal.rb +4 -5
- data/lib/thinreports/core/shape/image_block.rb +1 -1
- data/lib/thinreports/core/shape/image_block/format.rb +5 -6
- data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
- data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
- data/lib/thinreports/core/shape/list.rb +1 -1
- data/lib/thinreports/core/shape/list/configuration.rb +30 -15
- data/lib/thinreports/core/shape/list/events.rb +11 -11
- data/lib/thinreports/core/shape/list/format.rb +27 -28
- data/lib/thinreports/core/shape/list/manager.rb +128 -95
- data/lib/thinreports/core/shape/list/page.rb +54 -50
- data/lib/thinreports/core/shape/list/page_state.rb +15 -16
- data/lib/thinreports/core/shape/list/section_format.rb +14 -15
- data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
- data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
- data/lib/thinreports/core/shape/list/store.rb +10 -11
- data/lib/thinreports/core/shape/manager.rb +1 -1
- data/lib/thinreports/core/shape/manager/format.rb +10 -11
- data/lib/thinreports/core/shape/manager/internal.rb +21 -20
- data/lib/thinreports/core/shape/manager/target.rb +63 -34
- data/lib/thinreports/core/shape/page_number.rb +1 -1
- data/lib/thinreports/core/shape/page_number/format.rb +3 -3
- data/lib/thinreports/core/shape/page_number/interface.rb +2 -2
- data/lib/thinreports/core/shape/page_number/internal.rb +3 -3
- data/lib/thinreports/core/shape/style.rb +1 -1
- data/lib/thinreports/core/shape/style/base.rb +29 -29
- data/lib/thinreports/core/shape/style/basic.rb +1 -1
- data/lib/thinreports/core/shape/style/graphic.rb +10 -25
- data/lib/thinreports/core/shape/style/text.rb +36 -30
- data/lib/thinreports/core/shape/text.rb +1 -1
- data/lib/thinreports/core/shape/text/format.rb +8 -9
- data/lib/thinreports/core/shape/text/interface.rb +2 -2
- data/lib/thinreports/core/shape/text/internal.rb +6 -7
- data/lib/thinreports/core/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape/text_block/format.rb +17 -18
- data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
- data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
- data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
- data/lib/thinreports/core/utils.rb +33 -32
- data/lib/thinreports/generator.rb +6 -8
- data/lib/thinreports/generator/base.rb +15 -24
- data/lib/thinreports/generator/configuration.rb +10 -9
- data/lib/thinreports/generator/pdf.rb +27 -30
- data/lib/thinreports/generator/pdf/configuration.rb +11 -6
- data/lib/thinreports/generator/pdf/document.rb +28 -28
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +30 -31
- data/lib/thinreports/generator/pdf/document/font.rb +53 -44
- data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +25 -25
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +40 -41
- data/lib/thinreports/generator/pdf/document/page.rb +20 -21
- data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
- data/lib/thinreports/generator/pdf/drawer/base.rb +13 -14
- data/lib/thinreports/generator/pdf/drawer/list.rb +13 -14
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +13 -14
- data/lib/thinreports/generator/pdf/drawer/page.rb +16 -17
- data/lib/thinreports/generator/pdf/prawn_ext.rb +17 -33
- data/lib/thinreports/layout.rb +2 -2
- data/lib/thinreports/layout/base.rb +22 -36
- data/lib/thinreports/layout/configuration.rb +11 -9
- data/lib/thinreports/layout/format.rb +26 -27
- data/lib/thinreports/layout/version.rb +8 -9
- data/lib/thinreports/report.rb +10 -14
- data/lib/thinreports/report/base.rb +104 -126
- data/lib/thinreports/report/events.rb +5 -5
- data/lib/thinreports/report/internal.rb +41 -33
- data/lib/thinreports/{core → report}/page.rb +38 -30
- data/lib/thinreports/version.rb +2 -3
- data/test/data/font.ttf +0 -0
- data/test/data/layout_block.tlf +1 -0
- data/test/data/layout_list.tlf +1 -0
- data/test/data/layout_list_noheader.tlf +1 -0
- data/test/data/layout_text1.tlf +1 -0
- data/test/data/layout_text2.tlf +1 -0
- data/test/test_helper.rb +74 -0
- data/test/{unit/tmp → tmp}/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +14 -14
- data/test/unit/core/format/test_builder.rb +19 -23
- data/test/unit/core/shape/base/test_internal.rb +34 -37
- data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
- data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
- data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
- data/test/unit/core/shape/basic/test_format.rb +4 -4
- data/test/unit/core/shape/basic/test_interface.rb +36 -46
- data/test/unit/core/shape/basic/test_internal.rb +23 -20
- data/test/unit/core/shape/image_block/test_format.rb +5 -5
- data/test/unit/core/shape/image_block/test_interface.rb +17 -16
- data/test/unit/core/shape/image_block/test_internal.rb +19 -16
- data/test/unit/core/shape/list/test_configuration.rb +45 -33
- data/test/unit/core/shape/list/test_events.rb +7 -7
- data/test/unit/core/shape/list/test_format.rb +16 -18
- data/test/unit/core/shape/list/test_manager.rb +5 -5
- data/test/unit/core/shape/list/test_page.rb +80 -22
- data/test/unit/core/shape/list/test_page_state.rb +12 -12
- data/test/unit/core/shape/list/test_section_format.rb +16 -17
- data/test/unit/core/shape/list/test_section_interface.rb +30 -22
- data/test/unit/core/shape/list/test_section_internal.rb +21 -19
- data/test/unit/core/shape/list/test_store.rb +7 -7
- data/test/unit/core/shape/manager/test_format.rb +11 -15
- data/test/unit/core/shape/manager/test_internal.rb +9 -9
- data/test/unit/core/shape/manager/test_target.rb +85 -57
- data/test/unit/core/shape/page_number/test_format.rb +4 -4
- data/test/unit/core/shape/page_number/test_interface.rb +11 -8
- data/test/unit/core/shape/page_number/test_internal.rb +5 -5
- data/test/unit/core/shape/styles/test_base.rb +9 -9
- data/test/unit/core/shape/styles/test_basic.rb +5 -5
- data/test/unit/core/shape/styles/test_graphic.rb +19 -33
- data/test/unit/core/shape/styles/test_text.rb +18 -7
- data/test/unit/core/shape/text/test_format.rb +6 -6
- data/test/unit/core/shape/text/test_internal.rb +11 -12
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +4 -4
- data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
- data/test/unit/core/shape/text_block/test_format.rb +8 -8
- data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
- data/test/unit/core/shape/text_block/test_interface.rb +37 -20
- data/test/unit/core/shape/text_block/test_internal.rb +38 -38
- data/test/unit/core/test_events.rb +5 -5
- data/test/unit/core/test_shape.rb +6 -6
- data/test/unit/core/test_utils.rb +68 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +4 -4
- data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
- data/test/unit/generator/pdf/document/test_draw_shape.rb +9 -7
- data/test/unit/generator/pdf/document/test_font.rb +79 -58
- data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
- data/test/unit/generator/pdf/document/test_page.rb +44 -45
- data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
- data/test/unit/generator/pdf/test_configuration.rb +16 -9
- data/test/unit/generator/pdf/test_document.rb +8 -16
- data/test/unit/generator/test_base.rb +31 -42
- data/test/unit/generator/test_configuration.rb +6 -6
- data/test/unit/generator/test_pdf.rb +17 -14
- data/test/unit/layout/test_base.rb +34 -79
- data/test/unit/layout/test_configuration.rb +12 -37
- data/test/unit/layout/test_format.rb +36 -39
- data/test/unit/layout/test_version.rb +4 -4
- data/test/unit/report/test_base.rb +134 -213
- data/test/unit/report/test_events.rb +4 -4
- data/test/unit/report/test_internal.rb +84 -86
- data/test/unit/test_config.rb +31 -12
- data/test/unit/test_layout.rb +7 -7
- data/test/unit/test_report.rb +12 -24
- data/thinreports.gemspec +18 -22
- metadata +101 -200
- data/LICENSE +0 -1
- data/README.rdoc +0 -166
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- data/lib/thinreports/core.rb +0 -20
- data/lib/thinreports/core/ext.rb +0 -5
- data/lib/thinreports/core/ext/array.rb +0 -19
- data/lib/thinreports/core/ext/hash.rb +0 -19
- data/lib/thinreports/core/ext/object.rb +0 -25
- data/lib/thinreports/core/format.rb +0 -14
- data/lib/thinreports/core/ordered_hash.rb +0 -39
- data/lib/thinreports/generator/pdf/drawer.rb +0 -16
- data/tasks/doc.rake +0 -12
- data/tasks/test.rake +0 -56
- data/test/benchmark/basic_estimate.tlf +0 -1
- data/test/benchmark/bench_basic_estimate.rb +0 -95
- data/test/case/character_spacing/character_spacing.rb +0 -8
- data/test/case/character_spacing/character_spacing.tlf +0 -1
- data/test/case/dynamic_image/dynamic_image.rb +0 -41
- data/test/case/dynamic_image/dynamic_image.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style.rb +0 -154
- data/test/case/dynamic_style/dynamic_style.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
- data/test/case/eudc/eudc.rb +0 -20
- data/test/case/eudc/eudc.tlf +0 -1
- data/test/case/hidden_shapes/hidden_shapes.rb +0 -9
- data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
- data/test/case/list_events/list_events.rb +0 -32
- data/test/case/list_events/list_events.tlf +0 -1
- data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
- data/test/case/list_page_number/list_page_number.tlf +0 -1
- data/test/case/page_number/page_number.rb +0 -33
- data/test/case/page_number/page_number.tlf +0 -1
- data/test/case/password_setting/password_setting.rb +0 -10
- data/test/case/password_setting/password_setting.tlf +0 -1
- data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
- data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
- data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
- data/test/case/tblock_styles/tblock_styles.rb +0 -27
- data/test/case/tblock_styles/tblock_styles.tlf +0 -1
- data/test/case/text_align/text_align.rb +0 -8
- data/test/case/text_align/text_align.tlf +0 -1
- data/test/case/typeB_page_size/B4_ISO.tlf +0 -1
- data/test/case/typeB_page_size/B4_JIS.tlf +0 -1
- data/test/case/word_wrap/word_wrap.rb +0 -26
- data/test/case/word_wrap/word_wrap.tlf +0 -1
- data/test/unit/core/ext/array_spec.rb +0 -29
- data/test/unit/core/ext/hash_spec.rb +0 -29
- data/test/unit/core/ext/object_spec.rb +0 -30
- data/test/unit/core/ordered_hash_spec.rb +0 -51
- data/test/unit/core/shape/base/test_interface.rb +0 -52
- data/test/unit/core/utils_spec.rb +0 -56
- data/test/unit/data/basic_layout1.tlf +0 -1
- data/test/unit/data/basic_layout2.tlf +0 -1
- data/test/unit/data/basic_list_layout.tlf +0 -1
- data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
- data/test/unit/helper.rb +0 -87
@@ -3,9 +3,9 @@
|
|
3
3
|
require 'tempfile'
|
4
4
|
require 'base64'
|
5
5
|
|
6
|
-
module
|
6
|
+
module Thinreports
|
7
7
|
module Generator
|
8
|
-
|
8
|
+
|
9
9
|
module PDF::Graphics
|
10
10
|
# @param [String] filename
|
11
11
|
# @param [Numeric, Strng] x
|
@@ -14,9 +14,9 @@ module ThinReports
|
|
14
14
|
# @param [Numeric, Strng] h
|
15
15
|
def image(filename, x, y, w, h)
|
16
16
|
w, h = s2f(w, h)
|
17
|
-
pdf.image(filename, :
|
17
|
+
pdf.image(filename, at: pos(x, y), width: w, height: h)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
# @param [String] base64
|
21
21
|
# @param [Numeric, Strng] x
|
22
22
|
# @param [Numeric, Strng] y
|
@@ -26,7 +26,7 @@ module ThinReports
|
|
26
26
|
image = create_temp_imagefile(base64)
|
27
27
|
image(image.path, x, y, w, h)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# @param file (see Prawn#image)
|
31
31
|
# @param [Numeric, Strng] x
|
32
32
|
# @param [Numeric, Strng] y
|
@@ -37,23 +37,23 @@ module ThinReports
|
|
37
37
|
# @option options [:top, :center, :bottom] :position_y (:top)
|
38
38
|
def image_box(file, x, y, w, h, options = {})
|
39
39
|
w, h = s2f(w, h)
|
40
|
-
pdf.bounding_box(pos(x, y), :
|
41
|
-
pdf.image(file, :
|
42
|
-
:
|
43
|
-
:
|
40
|
+
pdf.bounding_box(pos(x, y), width: w, height: h) do
|
41
|
+
pdf.image(file, position: options[:position_x] || :left,
|
42
|
+
vposition: options[:position_y] || :top,
|
43
|
+
auto_fit: [w, h])
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
private
|
48
|
-
|
48
|
+
|
49
49
|
def clean_temp_images
|
50
50
|
temp_image_registry.each {|tmp| tmp.unlink }
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def temp_image_registry
|
54
54
|
@temp_image_registry ||= []
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# @param [String] base64
|
58
58
|
# @return [Tempfile]
|
59
59
|
def create_temp_imagefile(base64)
|
@@ -64,8 +64,8 @@ module ThinReports
|
|
64
64
|
file
|
65
65
|
ensure
|
66
66
|
file.close
|
67
|
-
end
|
67
|
+
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
end
|
71
71
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
5
|
+
|
6
6
|
module PDF::Graphics
|
7
7
|
# @param [String] content
|
8
8
|
# @param [Numeric, String] x
|
@@ -24,32 +24,31 @@ module ThinReports
|
|
24
24
|
# @option attrs [:none, :break_word] :word_wrap (:none)
|
25
25
|
def text_box(content, x, y, w, h, attrs = {})
|
26
26
|
w, h = s2f(w, h)
|
27
|
-
box_attrs = text_box_attrs(x, y, w, h, :
|
28
|
-
:
|
27
|
+
box_attrs = text_box_attrs(x, y, w, h, single: attrs.delete(:single),
|
28
|
+
overflow: attrs[:overflow])
|
29
29
|
# Do not break by word unless :word_wrap is :break_word
|
30
30
|
content = text_without_line_wrap(content) if attrs[:word_wrap] == :none
|
31
|
-
|
31
|
+
|
32
32
|
with_text_styles(attrs) do |built_attrs, font_styles|
|
33
|
-
pdf.formatted_text_box([{:
|
34
|
-
|
35
|
-
built_attrs.merge(box_attrs))
|
33
|
+
pdf.formatted_text_box([{ text: content, styles: font_styles }],
|
34
|
+
built_attrs.merge(box_attrs))
|
36
35
|
end
|
37
36
|
rescue Prawn::Errors::CannotFit => e
|
38
37
|
# Nothing to do.
|
39
|
-
#
|
38
|
+
#
|
40
39
|
# When the area is too small compared
|
41
40
|
# with the content and the style of the text.
|
42
41
|
# (See prawn/core/text/formatted/line_wrap.rb#L185)
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
# @see #text_box
|
46
45
|
def text(content, x, y, w, h, attrs = {})
|
47
46
|
# Set the :overflow property to :shirink_to_fit.
|
48
|
-
text_box(content, x, y, w, h, {:
|
47
|
+
text_box(content, x, y, w, h, { overflow: :shirink_to_fit }.merge(attrs))
|
49
48
|
end
|
50
|
-
|
49
|
+
|
51
50
|
private
|
52
|
-
|
51
|
+
|
53
52
|
# @param x (see #text_box)
|
54
53
|
# @param y (see #text_box)
|
55
54
|
# @param w (see #text_box)
|
@@ -59,15 +58,15 @@ module ThinReports
|
|
59
58
|
# @option states [Symbold] :overflow
|
60
59
|
# @return [Hash]
|
61
60
|
def text_box_attrs(x, y, w, h, states = {})
|
62
|
-
attrs = {:
|
63
|
-
:
|
61
|
+
attrs = {at: pos(x, y),
|
62
|
+
width: s2f(w)}
|
64
63
|
if states[:single]
|
65
|
-
states[:overflow] != :expand ? attrs.merge(:
|
64
|
+
states[:overflow] != :expand ? attrs.merge(single_line: true) : attrs
|
66
65
|
else
|
67
|
-
attrs.merge(:
|
66
|
+
attrs.merge(height: s2f(h))
|
68
67
|
end
|
69
68
|
end
|
70
|
-
|
69
|
+
|
71
70
|
# @param attrs (see #text)
|
72
71
|
# @yield [built_attrs, font_styles]
|
73
72
|
# @yieldparam [Hash] built_attrs The finalized attributes.
|
@@ -75,48 +74,48 @@ module ThinReports
|
|
75
74
|
def with_text_styles(attrs, &block)
|
76
75
|
# When no color is given, do not draw.
|
77
76
|
return unless attrs.key?(:color) && attrs[:color] != 'none'
|
78
|
-
|
77
|
+
|
79
78
|
save_graphics_state
|
80
|
-
|
81
|
-
fontinfo = {:
|
82
|
-
:
|
83
|
-
:
|
84
|
-
|
79
|
+
|
80
|
+
fontinfo = {name: attrs.delete(:font).to_s,
|
81
|
+
color: parse_color(attrs.delete(:color)),
|
82
|
+
size: s2f(attrs.delete(:size))}
|
83
|
+
|
85
84
|
# Add the specified value to :leading option.
|
86
85
|
if line_height = attrs.delete(:line_height)
|
87
86
|
attrs[:leading] = text_line_leading(s2f(line_height),
|
88
|
-
:
|
89
|
-
:
|
87
|
+
name: fontinfo[:name],
|
88
|
+
size: fontinfo[:size])
|
90
89
|
end
|
91
|
-
|
90
|
+
|
92
91
|
# Set the :character_spacing option.
|
93
92
|
if space = attrs.delete(:letter_spacing)
|
94
93
|
attrs[:character_spacing] = s2f(space)
|
95
94
|
end
|
96
|
-
|
95
|
+
|
97
96
|
# Or... with_font_styles(attrs, fontinfo, &block)
|
98
97
|
with_font_styles(attrs, fontinfo) do |modified_attrs, styles|
|
99
98
|
block.call(modified_attrs, styles)
|
100
99
|
end
|
101
|
-
|
100
|
+
|
102
101
|
restore_graphics_state
|
103
102
|
end
|
104
|
-
|
103
|
+
|
105
104
|
# @param [Numeric] line_height
|
106
105
|
# @param [Hash] font
|
107
106
|
# @option font [String] :name Name of font.
|
108
107
|
# @option font [Numeric] :size Size of font.
|
109
108
|
# @return [Numeric]
|
110
109
|
def text_line_leading(line_height, font)
|
111
|
-
line_height - pdf.font(font[:name], :
|
110
|
+
line_height - pdf.font(font[:name], size: font[:size]).height
|
112
111
|
end
|
113
|
-
|
112
|
+
|
114
113
|
# @param [String] content
|
115
114
|
# @return [String]
|
116
115
|
def text_without_line_wrap(content)
|
117
116
|
content.gsub(/ /, Prawn::Text::NBSP)
|
118
117
|
end
|
119
|
-
|
118
|
+
|
120
119
|
# @param [Hash] attrs
|
121
120
|
# @param [Hash] font
|
122
121
|
# @option font [String] :color
|
@@ -132,29 +131,29 @@ module ThinReports
|
|
132
131
|
[:bold, :italic].include?(style) && !font_has_style?(font[:name], style)
|
133
132
|
end
|
134
133
|
end
|
135
|
-
|
134
|
+
|
136
135
|
# Emulate bold style.
|
137
136
|
if manual && manual.include?(:bold)
|
138
137
|
pdf.stroke_color(font[:color])
|
139
138
|
pdf.line_width(font[:size] * 0.025)
|
140
|
-
|
139
|
+
|
141
140
|
# Change rendering mode to :fill_stroke.
|
142
141
|
attrs[:mode] = :fill_stroke
|
143
142
|
end
|
144
|
-
|
143
|
+
|
145
144
|
# Emulate italic style.
|
146
145
|
if manual && manual.include?(:italic)
|
147
146
|
# FIXME
|
148
147
|
# pdf.transformation_matrix(1, 0, 0.26, 1, 0, 0)
|
149
148
|
end
|
150
|
-
|
151
|
-
pdf.font(font[:name], :
|
149
|
+
|
150
|
+
pdf.font(font[:name], size: font[:size]) do
|
152
151
|
pdf.fill_color(font[:color])
|
153
152
|
block.call(attrs, styles || [])
|
154
153
|
end
|
155
|
-
end
|
156
|
-
|
154
|
+
end
|
155
|
+
|
157
156
|
end
|
158
|
-
|
157
|
+
|
159
158
|
end
|
160
159
|
end
|
@@ -1,22 +1,21 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
module PDF::Page
|
8
7
|
# Add JIS-B4,B5 page geometry
|
9
|
-
|
8
|
+
::PDF::Core::PageGeometry::SIZES.update(
|
10
9
|
'B4_JIS' => [728.5, 1031.8],
|
11
10
|
'B5_JIS' => [515.9, 728.5]
|
12
11
|
)
|
13
|
-
|
14
|
-
# @param [
|
12
|
+
|
13
|
+
# @param [Thinreports::Layout::Format] format
|
15
14
|
def start_new_page(format)
|
16
15
|
format_id = if change_page_format?(format)
|
17
16
|
pdf.start_new_page(new_basic_page_options(format))
|
18
17
|
@current_page_format = format
|
19
|
-
|
18
|
+
|
20
19
|
unless format_stamp_registry.include?(format.identifier)
|
21
20
|
create_format_stamp(format)
|
22
21
|
end
|
@@ -25,43 +24,43 @@ module ThinReports
|
|
25
24
|
pdf.start_new_page(new_basic_page_options(current_page_format))
|
26
25
|
current_page_format.identifier
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
stamp(format_id.to_s)
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
def add_blank_page
|
33
|
-
pdf.start_new_page(pdf.page_count.zero? ? {:
|
32
|
+
pdf.start_new_page(pdf.page_count.zero? ? {size: 'A4'} : {})
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
private
|
37
|
-
|
38
|
-
# @return [
|
36
|
+
|
37
|
+
# @return [Thinreports::Layout::Format]
|
39
38
|
attr_reader :current_page_format
|
40
39
|
|
41
|
-
# @param [
|
40
|
+
# @param [Thinreports::Layout::Format] new_format
|
42
41
|
# @return [Boolean]
|
43
42
|
def change_page_format?(new_format)
|
44
43
|
!current_page_format ||
|
45
44
|
current_page_format.identifier != new_format.identifier
|
46
45
|
end
|
47
|
-
|
48
|
-
# @param [
|
46
|
+
|
47
|
+
# @param [Thinreports::Layout::Format] format
|
49
48
|
def create_format_stamp(format)
|
50
49
|
create_stamp(format.identifier.to_s) do
|
51
50
|
parse_svg(format.layout, '/svg/g')
|
52
51
|
end
|
53
52
|
format_stamp_registry << format.identifier
|
54
53
|
end
|
55
|
-
|
54
|
+
|
56
55
|
# @return [Array]
|
57
56
|
def format_stamp_registry
|
58
57
|
@format_stamp_registry ||= []
|
59
58
|
end
|
60
|
-
|
61
|
-
# @param [
|
59
|
+
|
60
|
+
# @param [Thinreports::Layout::Format] format
|
62
61
|
# @return [Hash]
|
63
62
|
def new_basic_page_options(format)
|
64
|
-
options = {:
|
63
|
+
options = {layout: format.page_orientation.to_sym}
|
65
64
|
|
66
65
|
options[:size] = if format.user_paper_type?
|
67
66
|
[format.page_width.to_f, format.page_height.to_f]
|
@@ -80,6 +79,6 @@ module ThinReports
|
|
80
79
|
options
|
81
80
|
end
|
82
81
|
end
|
83
|
-
|
82
|
+
|
84
83
|
end
|
85
84
|
end
|
@@ -1,24 +1,23 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
module PDF::ParseColor
|
8
7
|
# @param [String] color
|
9
8
|
# @return [String]
|
10
9
|
def parse_color(color)
|
11
10
|
color = color.downcase
|
12
|
-
|
11
|
+
|
13
12
|
unless color =~ /^#?[\da-f]{6}$/
|
14
13
|
find_color_from_name(color)
|
15
14
|
else
|
16
15
|
color.delete('#')
|
17
16
|
end
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
private
|
21
|
-
|
20
|
+
|
22
21
|
# Supported only SAFE COLORS.
|
23
22
|
SUPPORTED_COLOR_NAMES = {
|
24
23
|
'red' => 'ff0000',
|
@@ -38,14 +37,14 @@ module ThinReports
|
|
38
37
|
'silver' => 'c0c0c0',
|
39
38
|
'white' => 'ffffff'
|
40
39
|
}
|
41
|
-
|
40
|
+
|
42
41
|
def find_color_from_name(name)
|
43
42
|
unless color = SUPPORTED_COLOR_NAMES[name]
|
44
|
-
raise
|
43
|
+
raise Thinreports::Errors::UnsupportedColorName, name
|
45
44
|
end
|
46
45
|
color
|
47
46
|
end
|
48
47
|
end
|
49
|
-
|
48
|
+
|
50
49
|
end
|
51
|
-
end
|
50
|
+
end
|
@@ -2,16 +2,15 @@
|
|
2
2
|
|
3
3
|
require 'rexml/document'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Thinreports
|
6
6
|
module Generator
|
7
|
-
|
8
|
-
# @private
|
7
|
+
|
9
8
|
module PDF::ParseSVG
|
10
9
|
# @param [String] source
|
11
10
|
# @param [String] base_path
|
12
11
|
def parse_svg(source, base_path)
|
13
12
|
svg = REXML::Document.new(clean_svg(source))
|
14
|
-
|
13
|
+
|
15
14
|
svg.elements[base_path].each do |elm|
|
16
15
|
case elm.attributes['class']
|
17
16
|
when 's-text' then draw_svg_text(elm)
|
@@ -23,15 +22,15 @@ module ThinReports
|
|
23
22
|
end
|
24
23
|
svg = nil
|
25
24
|
end
|
26
|
-
|
25
|
+
|
27
26
|
private
|
28
|
-
|
27
|
+
|
29
28
|
# @param [String] source
|
30
29
|
# @return [String]
|
31
30
|
def clean_svg(source)
|
32
31
|
source.gsub(/<%.+?%>/, '')
|
33
32
|
end
|
34
|
-
|
33
|
+
|
35
34
|
# @param [REXML::Element] elm
|
36
35
|
# @param [Array<String>] keys
|
37
36
|
# @return [Array<String>]
|
@@ -41,7 +40,7 @@ module ThinReports
|
|
41
40
|
values << attrs[key]
|
42
41
|
end
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
# @param [REXML::Element] elm
|
46
45
|
def draw_svg_rect(elm)
|
47
46
|
x, y, w, h = element_attributes_values_at(elm, 'x', 'y', 'width', 'height')
|
@@ -50,21 +49,21 @@ module ThinReports
|
|
50
49
|
end
|
51
50
|
rect(x, y, w, h, attributes)
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
# @see #draw_svg_rect
|
55
54
|
def draw_svg_ellipse(elm)
|
56
55
|
x, y, rx, ry = element_attributes_values_at(elm, 'cx', 'cy', 'rx', 'ry')
|
57
56
|
ellipse(x, y, rx, ry,
|
58
57
|
common_graphic_attrs(elm.attributes))
|
59
58
|
end
|
60
|
-
|
59
|
+
|
61
60
|
# @see #draw_svg_rect
|
62
61
|
def draw_svg_line(elm)
|
63
62
|
x1, y1, x2, y2 = element_attributes_values_at(elm, 'x1', 'y1', 'x2', 'y2')
|
64
63
|
line(x1, y1, x2, y2,
|
65
64
|
common_graphic_attrs(elm.attributes))
|
66
65
|
end
|
67
|
-
|
66
|
+
|
68
67
|
# @see #draw_svg_rect
|
69
68
|
def draw_svg_text(elm)
|
70
69
|
x, y, w, h = element_attributes_values_at(elm, 'x-left', 'x-top',
|
@@ -75,14 +74,14 @@ module ThinReports
|
|
75
74
|
end
|
76
75
|
text(content.join("\n"), x, y, w, h, svg_text_attrs(elm.attributes))
|
77
76
|
end
|
78
|
-
|
77
|
+
|
79
78
|
# @see #draw_svg_rect
|
80
79
|
def draw_svg_image(elm)
|
81
80
|
x, y, w, h = element_attributes_values_at(elm, 'x', 'y', 'width', 'height')
|
82
81
|
base64image(extract_base64_string(elm.attributes['xlink:href']),
|
83
82
|
x, y, w, h)
|
84
83
|
end
|
85
|
-
|
84
|
+
|
86
85
|
# @param [Hash] attributes
|
87
86
|
# @return [Hash]
|
88
87
|
def svg_text_attrs(attributes)
|
@@ -95,8 +94,8 @@ module ThinReports
|
|
95
94
|
attrs[:valign] = text_valign(attributes['x-valign'])
|
96
95
|
end
|
97
96
|
end
|
98
|
-
|
97
|
+
|
99
98
|
end
|
100
|
-
|
99
|
+
|
101
100
|
end
|
102
101
|
end
|