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
@@ -1,18 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
module PDF::DrawShape
|
8
|
-
# @param [
|
7
|
+
# @param [Thinreports::Core::Shape::TextBlock::Internal] shape
|
9
8
|
def draw_shape_tblock(shape)
|
10
9
|
x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
|
11
|
-
|
10
|
+
|
12
11
|
content = shape.real_value.to_s
|
13
12
|
unless content.empty?
|
14
13
|
attrs = shape_text_attrs(shape)
|
15
|
-
|
14
|
+
|
16
15
|
unless shape.multiple?
|
17
16
|
content = content.gsub(/\n/, ' ')
|
18
17
|
attrs[:single] = true
|
@@ -24,52 +23,52 @@ module ThinReports
|
|
24
23
|
def draw_shape_pageno(shape, page_no, page_count)
|
25
24
|
x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
|
26
25
|
|
27
|
-
text_box(shape.build_format(page_no, page_count), x, y, w, h,
|
26
|
+
text_box(shape.build_format(page_no, page_count), x, y, w, h,
|
28
27
|
common_text_attrs(shape.style.svg_attrs))
|
29
28
|
end
|
30
|
-
|
31
|
-
# @param [
|
29
|
+
|
30
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
32
31
|
def draw_shape_image(shape)
|
33
32
|
x, y, w, h = shape.style.svg_attrs.values_at('x', 'y', 'width', 'height')
|
34
33
|
base64image(extract_base64_string(shape.style.svg_attrs['xlink:href']),
|
35
34
|
x, y, w, h)
|
36
35
|
end
|
37
|
-
|
38
|
-
# @param [
|
36
|
+
|
37
|
+
# @param [Thinreports::Core::Shape::ImageBlock::Internal] shape
|
39
38
|
def draw_shape_iblock(shape)
|
40
39
|
x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
|
41
|
-
unless shape.src
|
40
|
+
unless blank_value?(shape.src)
|
42
41
|
posx = shape.format.position_x
|
43
42
|
posy = shape.format.position_y
|
44
|
-
|
43
|
+
|
45
44
|
image_box(shape.src, x, y, w, h,
|
46
|
-
:
|
47
|
-
:
|
45
|
+
position_x: posx ? posx.to_sym : nil,
|
46
|
+
position_y: posy ? posy.to_sym : nil)
|
48
47
|
end
|
49
48
|
end
|
50
|
-
|
51
|
-
# @param [
|
49
|
+
|
50
|
+
# @param [Thinreports::Core::Shape::Text::Internal] shape
|
52
51
|
def draw_shape_text(shape)
|
53
52
|
x, y, w, h = shape.box.values_at('x', 'y', 'width', 'height')
|
54
|
-
text(shape.text.join("\n"), x, y, w, h,
|
53
|
+
text(shape.text.join("\n"), x, y, w, h,
|
55
54
|
shape_text_attrs(shape))
|
56
55
|
end
|
57
|
-
|
58
|
-
# @param [
|
56
|
+
|
57
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
59
58
|
def draw_shape_ellipse(shape)
|
60
59
|
args = shape.style.svg_attrs.values_at('cx', 'cy', 'rx', 'ry')
|
61
60
|
args << common_graphic_attrs(shape.style.svg_attrs)
|
62
61
|
ellipse(*args)
|
63
62
|
end
|
64
|
-
|
65
|
-
# @param [
|
63
|
+
|
64
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
66
65
|
def draw_shape_line(shape)
|
67
66
|
args = shape.style.svg_attrs.values_at('x1', 'y1', 'x2', 'y2')
|
68
67
|
args << common_graphic_attrs(shape.style.svg_attrs)
|
69
68
|
line(*args)
|
70
69
|
end
|
71
|
-
|
72
|
-
# @param [
|
70
|
+
|
71
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
73
72
|
def draw_shape_rect(shape)
|
74
73
|
args = shape.style.svg_attrs.values_at('x', 'y', 'width', 'height')
|
75
74
|
args << common_graphic_attrs(shape.style.svg_attrs) do |attrs|
|
@@ -77,20 +76,20 @@ module ThinReports
|
|
77
76
|
end
|
78
77
|
rect(*args)
|
79
78
|
end
|
80
|
-
|
79
|
+
|
81
80
|
private
|
82
|
-
|
83
|
-
# @param [
|
81
|
+
|
82
|
+
# @param [Thinreports::Core::Shape::Text::Internal, Thinreports::Core::Shape::TextBlock::Internal] shape
|
84
83
|
# @return [Hash]
|
85
84
|
def shape_text_attrs(shape)
|
86
85
|
format = shape.format
|
87
|
-
|
86
|
+
|
88
87
|
common_text_attrs(shape.style.svg_attrs) do |attrs|
|
89
88
|
# Set the :line_height option.
|
90
|
-
attrs[:line_height] = format.line_height unless format.line_height
|
89
|
+
attrs[:line_height] = format.line_height unless blank_value?(format.line_height)
|
91
90
|
# Set the :valign option.
|
92
91
|
attrs[:valign] = shape.style.valign
|
93
|
-
|
92
|
+
|
94
93
|
if shape.type_of?(:tblock)
|
95
94
|
# Set the :overflow option.
|
96
95
|
attrs[:overflow] = text_overflow(format.overflow)
|
@@ -100,6 +99,6 @@ module ThinReports
|
|
100
99
|
end
|
101
100
|
end
|
102
101
|
end
|
103
|
-
|
102
|
+
|
104
103
|
end
|
105
104
|
end
|
@@ -1,75 +1,84 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
module PDF::Font
|
8
|
-
FONT_STORE = File.join(
|
9
|
-
|
7
|
+
FONT_STORE = File.join(Thinreports::ROOT, 'fonts')
|
8
|
+
|
10
9
|
BUILTIN_FONTS = {
|
11
|
-
'IPAMincho' => {:
|
12
|
-
'IPAPMincho' => {:
|
13
|
-
'IPAGothic' => {:
|
14
|
-
'IPAPGothic' => {:
|
10
|
+
'IPAMincho' => { normal: File.join(FONT_STORE, 'ipam.ttf') },
|
11
|
+
'IPAPMincho' => { normal: File.join(FONT_STORE, 'ipamp.ttf') },
|
12
|
+
'IPAGothic' => { normal: File.join(FONT_STORE, 'ipag.ttf') },
|
13
|
+
'IPAPGothic' => { normal: File.join(FONT_STORE, 'ipagp.ttf') }
|
14
|
+
}
|
15
|
+
|
16
|
+
DEFAULT_FALLBACK_FONTS = %w( Helvetica IPAMincho )
|
17
|
+
|
18
|
+
PRAWN_BUINTIN_FONT_ARIASES = {
|
19
|
+
'Courier New' => 'Courier',
|
20
|
+
'Times New Roman' => 'Times-Roman'
|
15
21
|
}
|
16
|
-
|
17
|
-
private
|
18
|
-
|
22
|
+
|
19
23
|
def setup_fonts
|
20
24
|
# Install built-in fonts.
|
21
25
|
pdf.font_families.update(BUILTIN_FONTS)
|
22
|
-
|
26
|
+
|
27
|
+
# Create aliases from the font list provided by Prawn.
|
28
|
+
PRAWN_BUINTIN_FONT_ARIASES.each do |alias_name, name|
|
29
|
+
pdf.font_families[alias_name] = pdf.font_families[name]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Setup custom fallback fonts
|
23
33
|
fallback_fonts = []
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
+
|
39
|
+
fallback_fonts.map!.with_index do |font, i|
|
40
|
+
unless pdf.font_families.key?(font)
|
41
|
+
install_font "Custom-fallback-font#{i}", font
|
42
|
+
else
|
43
|
+
font
|
44
|
+
end
|
30
45
|
end
|
31
|
-
|
32
|
-
#
|
33
|
-
|
34
|
-
fallback_fonts << 'DefaultFont'
|
35
|
-
|
36
|
-
# Setup fallback fonts.
|
37
|
-
pdf.fallback_fonts(fallback_fonts)
|
38
|
-
|
39
|
-
# Create aliases from the font list provided by Prawn.
|
40
|
-
pdf.font_families.update(
|
41
|
-
'Courier New' => pdf.font_families['Courier'],
|
42
|
-
'Times New Roman' => pdf.font_families['Times-Roman']
|
43
|
-
)
|
46
|
+
|
47
|
+
# Set fallback fonts
|
48
|
+
pdf.fallback_fonts(fallback_fonts + DEFAULT_FALLBACK_FONTS)
|
44
49
|
end
|
45
|
-
|
50
|
+
|
46
51
|
# @param [String] name
|
47
52
|
# @param [String] file
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
# @return [String] installed font name
|
54
|
+
def install_font(name, file)
|
55
|
+
raise Errors::FontFileNotFound unless File.exists?(file)
|
56
|
+
|
57
|
+
pdf.font_families[name] = {normal: file,
|
58
|
+
bold: file,
|
59
|
+
italic: file,
|
60
|
+
bold_italic: file}
|
61
|
+
name
|
53
62
|
end
|
54
|
-
|
63
|
+
|
55
64
|
# @return [String]
|
56
65
|
def default_family
|
57
66
|
'Helvetica'
|
58
67
|
end
|
59
|
-
|
68
|
+
|
60
69
|
# @param [String] family
|
61
70
|
# @return [String]
|
62
71
|
def default_family_if_missing(family)
|
63
72
|
pdf.font_families.key?(family) ? family : default_family
|
64
73
|
end
|
65
|
-
|
74
|
+
|
66
75
|
# @param [String] font
|
67
76
|
# @param [Symbol] style
|
68
77
|
# @return [Boolean]
|
69
78
|
def font_has_style?(font, style)
|
70
79
|
(f = pdf.font_families[font]) && f.key?(style)
|
71
|
-
end
|
80
|
+
end
|
72
81
|
end
|
73
|
-
|
82
|
+
|
74
83
|
end
|
75
|
-
end
|
84
|
+
end
|
@@ -1,38 +1,37 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
module PDF::Graphics
|
8
|
-
|
7
|
+
|
9
8
|
BASE_LINE_WIDTH = 0.9
|
10
|
-
|
9
|
+
|
11
10
|
private
|
12
11
|
|
13
12
|
# Change the default graphic states defined by Prawn.
|
14
13
|
def setup_custom_graphic_states
|
15
14
|
pdf.line_width(BASE_LINE_WIDTH)
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
# @param [Numeric] width
|
19
18
|
def line_width(width)
|
20
19
|
pdf.line_width(width * BASE_LINE_WIDTH)
|
21
20
|
end
|
22
|
-
|
21
|
+
|
23
22
|
# Delegate to Prawn::Document#save_graphic_state
|
24
23
|
# @see Prawn::Document#save_graphics_state
|
25
24
|
def save_graphics_state
|
26
25
|
pdf.save_graphics_state
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
# Delegate to Prawn::Document#restore_graphic_state
|
30
29
|
# @see Prawn::Document#restore_graphics_state
|
31
30
|
def restore_graphics_state
|
32
31
|
pdf.restore_graphics_state
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
@@ -1,23 +1,23 @@
|
|
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 [Hash] svg_attrs
|
8
8
|
# @yield [attrs]
|
9
9
|
# @yieldparam [Hash] attrs
|
10
10
|
# @return [Hash]
|
11
11
|
def common_graphic_attrs(svg_attrs, &block)
|
12
|
-
attrs = {:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
|
12
|
+
attrs = {stroke: svg_attrs['stroke'],
|
13
|
+
stroke_width: svg_attrs['stroke-width'],
|
14
|
+
fill: svg_attrs['fill']}
|
15
|
+
|
16
16
|
# Set 0 to stroke_width if stroke_opacity is '0'.
|
17
17
|
if svg_attrs['stroke-opacity'] == '0'
|
18
18
|
attrs[:stroke_width] = 0
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
# Setting for stroke dash.
|
22
22
|
if (dash = svg_attrs['stroke-dasharray']) && dash != 'none'
|
23
23
|
attrs[:stroke_dash] = dash.split(',')
|
@@ -25,40 +25,40 @@ module ThinReports
|
|
25
25
|
block.call(attrs) if block_given?
|
26
26
|
attrs
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# @param [Hash] svg_attrs
|
30
30
|
# @yield [attrs]
|
31
31
|
# @yieldparam [Hash] attrs
|
32
32
|
# @return [Hash]
|
33
33
|
def common_text_attrs(svg_attrs, &block)
|
34
|
-
attrs = {:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
|
34
|
+
attrs = {font: default_family_if_missing(svg_attrs['font-family']),
|
35
|
+
size: svg_attrs['font-size'],
|
36
|
+
color: svg_attrs['fill'],
|
37
|
+
align: text_align(svg_attrs['text-anchor']),
|
38
|
+
styles: font_styles(svg_attrs)}
|
39
|
+
|
40
40
|
# The Letter Spacing Property.
|
41
|
-
#
|
41
|
+
#
|
42
42
|
# When the version of Layout is
|
43
|
-
# smaller then 0.6.0:
|
43
|
+
# smaller then 0.6.0:
|
44
44
|
# Use letter-spacing attribute (normal is none).
|
45
45
|
# 0.6.0 or more:
|
46
46
|
# Use kerning attribute (auto is none).
|
47
|
-
#
|
47
|
+
#
|
48
48
|
if space = text_letter_spacing(svg_attrs['kerning'] || svg_attrs['letter-spacing'])
|
49
49
|
attrs[:letter_spacing] = space
|
50
50
|
end
|
51
51
|
block.call(attrs) if block_given?
|
52
52
|
attrs
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
# @param [Hash] svg_attrs
|
56
56
|
# @return [Array<Symbol>]
|
57
57
|
def font_styles(svg_attrs)
|
58
58
|
styles = []
|
59
59
|
styles << :bold if svg_attrs['font-weight'] == 'bold'
|
60
60
|
styles << :italic if svg_attrs['font-style'] == 'italic'
|
61
|
-
|
61
|
+
|
62
62
|
if (deco = svg_attrs['text-decoration']) && deco != 'none'
|
63
63
|
deco = deco.split(' ')
|
64
64
|
styles << :underline if deco.include?('underline')
|
@@ -66,13 +66,13 @@ module ThinReports
|
|
66
66
|
end
|
67
67
|
styles
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
# @param [String] space
|
71
71
|
# @return [String, nil]
|
72
72
|
def text_letter_spacing(space)
|
73
73
|
%w( normal auto ).include?(space) ? nil : space
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
# @param [String] svg_align
|
77
77
|
# @return [Symbol]
|
78
78
|
def text_align(svg_align)
|
@@ -83,7 +83,7 @@ module ThinReports
|
|
83
83
|
else :left
|
84
84
|
end
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
# @param [String] svg_valign
|
88
88
|
# @return [Symbol]
|
89
89
|
def text_valign(svg_valign)
|
@@ -94,7 +94,7 @@ module ThinReports
|
|
94
94
|
else :top
|
95
95
|
end
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
# @param [String] overflow
|
99
99
|
# @return [Symbol]
|
100
100
|
def text_overflow(overflow)
|
@@ -114,13 +114,13 @@ module ThinReports
|
|
114
114
|
else :none
|
115
115
|
end
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
# @param [String] xlink
|
119
119
|
# @return [String]
|
120
120
|
def extract_base64_string(xlink)
|
121
121
|
xlink.sub(%r{^data:image/[a-z]+?;base64,}, '')
|
122
122
|
end
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
end
|
126
126
|
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 [Numeric, String] x1
|
8
8
|
# @param [Numeric, String] y1
|
@@ -17,7 +17,7 @@ module ThinReports
|
|
17
17
|
pdf.line(pos(x1, y1), pos(x2, y2))
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
# @param [Numeric, String] x
|
22
22
|
# @param [Numeric, String] y
|
23
23
|
# @param [Numeric, String] w width
|
@@ -31,7 +31,7 @@ module ThinReports
|
|
31
31
|
def rect(x, y, w, h, attrs = {})
|
32
32
|
w, h = s2f(w, h)
|
33
33
|
radius = s2f(attrs[:radius])
|
34
|
-
|
34
|
+
|
35
35
|
with_graphic_styles(attrs) do
|
36
36
|
if radius && !radius.zero?
|
37
37
|
pdf.rounded_rectangle(pos(x, y), w, h, radius)
|
@@ -40,7 +40,7 @@ module ThinReports
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
# @param [Numeric, String] x center-x
|
45
45
|
# @param [Numeric, String] y center-y
|
46
46
|
# @param [Numeric, String] rx
|
@@ -52,30 +52,30 @@ module ThinReports
|
|
52
52
|
# @option attrs [String] :fill
|
53
53
|
def ellipse(x, y, rx, ry, attrs = {})
|
54
54
|
rx, ry = s2f(rx, ry)
|
55
|
-
|
55
|
+
|
56
56
|
with_graphic_styles(attrs) do
|
57
57
|
pdf.ellipse(pos(x, y), rx, ry)
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
private
|
62
|
-
|
62
|
+
|
63
63
|
# @param [Hash] attrs
|
64
64
|
def with_graphic_styles(attrs, &block)
|
65
65
|
stroke = build_stroke_styles(attrs)
|
66
66
|
fill = build_fill_styles(attrs)
|
67
|
-
|
67
|
+
|
68
68
|
# Do not draw if no colors given.
|
69
69
|
return unless fill || stroke
|
70
|
-
|
70
|
+
|
71
71
|
save_graphics_state
|
72
72
|
|
73
73
|
# Apply stroke-dashed.
|
74
74
|
if stroke && stroke[:dash]
|
75
75
|
length, space = stroke[:dash]
|
76
|
-
pdf.dash(length, :
|
76
|
+
pdf.dash(length, space: space)
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
case
|
80
80
|
# Draw with fill and stroke.
|
81
81
|
when fill && stroke
|
@@ -99,34 +99,34 @@ module ThinReports
|
|
99
99
|
block.call
|
100
100
|
}
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
restore_graphics_state
|
104
|
-
end
|
105
|
-
|
104
|
+
end
|
105
|
+
|
106
106
|
# @param [Hash] styles
|
107
107
|
# @return [Hash, nil]
|
108
108
|
def build_stroke_styles(styles)
|
109
109
|
color = styles[:stroke]
|
110
110
|
width = styles[:stroke_width]
|
111
|
-
|
111
|
+
|
112
112
|
if color && color != 'none' && width && width != 0
|
113
|
-
{:
|
114
|
-
:
|
115
|
-
:
|
113
|
+
{color: parse_color(color),
|
114
|
+
width: s2f(width),
|
115
|
+
dash: s2f(*styles[:stroke_dash])}
|
116
116
|
end
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
# @param [Hash] styles
|
120
120
|
# @return [Hash, nil]
|
121
121
|
def build_fill_styles(styles)
|
122
122
|
color = styles[:fill]
|
123
|
-
|
123
|
+
|
124
124
|
if color && color != 'none'
|
125
|
-
{:
|
125
|
+
{color: parse_color(color)}
|
126
126
|
end
|
127
|
-
end
|
128
|
-
|
127
|
+
end
|
128
|
+
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
end
|
132
132
|
end
|