thinreports 0.9.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +39 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +59 -2
- data/Dockerfile +12 -0
- data/Gemfile +7 -4
- data/README.md +44 -22
- data/Rakefile +14 -31
- data/lib/thinreports.rb +16 -15
- data/lib/thinreports/config.rb +2 -24
- data/lib/thinreports/core/errors.rb +6 -17
- data/lib/thinreports/core/format/base.rb +62 -61
- data/lib/thinreports/core/shape.rb +10 -12
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +34 -32
- data/lib/thinreports/core/shape/base/internal.rb +45 -43
- data/lib/thinreports/core/shape/basic.rb +12 -12
- data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
- data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
- data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
- data/lib/thinreports/core/shape/basic/format.rb +11 -9
- data/lib/thinreports/core/shape/basic/interface.rb +79 -77
- data/lib/thinreports/core/shape/basic/internal.rb +17 -14
- data/lib/thinreports/core/shape/image_block.rb +9 -9
- data/lib/thinreports/core/shape/image_block/format.rb +7 -5
- data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
- data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
- data/lib/thinreports/core/shape/list.rb +13 -13
- data/lib/thinreports/core/shape/list/format.rb +83 -77
- data/lib/thinreports/core/shape/list/manager.rb +179 -176
- data/lib/thinreports/core/shape/list/page.rb +91 -93
- data/lib/thinreports/core/shape/list/page_state.rb +42 -40
- data/lib/thinreports/core/shape/list/section_format.rb +28 -26
- data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
- data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
- data/lib/thinreports/core/shape/manager.rb +4 -13
- data/lib/thinreports/core/shape/manager/format.rb +21 -19
- data/lib/thinreports/core/shape/manager/internal.rb +87 -84
- data/lib/thinreports/core/shape/manager/target.rb +93 -95
- data/lib/thinreports/core/shape/page_number.rb +9 -9
- data/lib/thinreports/core/shape/page_number/format.rb +20 -18
- data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
- data/lib/thinreports/core/shape/page_number/internal.rb +46 -44
- data/lib/thinreports/core/shape/style.rb +5 -14
- data/lib/thinreports/core/shape/style/base.rb +121 -120
- data/lib/thinreports/core/shape/style/basic.rb +12 -10
- data/lib/thinreports/core/shape/style/graphic.rb +35 -33
- data/lib/thinreports/core/shape/style/text.rb +113 -107
- data/lib/thinreports/core/shape/text.rb +9 -9
- data/lib/thinreports/core/shape/text/format.rb +10 -9
- data/lib/thinreports/core/shape/text/interface.rb +13 -11
- data/lib/thinreports/core/shape/text/internal.rb +14 -12
- data/lib/thinreports/core/shape/text_block.rb +10 -10
- data/lib/thinreports/core/shape/text_block/format.rb +35 -33
- data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +52 -34
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
- data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
- data/lib/thinreports/core/shape/text_block/internal.rb +66 -68
- data/lib/thinreports/core/utils.rb +7 -3
- data/lib/thinreports/generator/pdf.rb +24 -25
- data/lib/thinreports/generator/pdf/document.rb +109 -110
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +57 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +50 -47
- data/lib/thinreports/generator/pdf/document/font.rb +67 -58
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +121 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +112 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +149 -137
- data/lib/thinreports/generator/pdf/document/page.rb +60 -64
- data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
- data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
- data/lib/thinreports/generator/pdf/drawer/list.rb +56 -54
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
- data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +32 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +35 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -9
- data/lib/thinreports/layout/format.rb +17 -13
- data/lib/thinreports/layout/legacy_schema.rb +17 -13
- data/lib/thinreports/layout/version.rb +22 -25
- data/lib/thinreports/report.rb +4 -6
- data/lib/thinreports/report/base.rb +24 -51
- data/lib/thinreports/report/internal.rb +13 -15
- data/lib/thinreports/report/page.rb +5 -11
- data/lib/thinreports/version.rb +2 -2
- data/thinreports.gemspec +10 -19
- metadata +13 -288
- data/.travis.yml +0 -19
- data/examples/character_spacing/character_spacing.rb +0 -8
- data/examples/character_spacing/character_spacing.tlf +0 -293
- data/examples/dynamic_image/dynamic_image.rb +0 -31
- data/examples/dynamic_image/dynamic_image.tlf +0 -661
- data/examples/dynamic_image/img200x100.png +0 -0
- data/examples/dynamic_image/img50x50.png +0 -0
- data/examples/dynamic_style/dynamic_style.rb +0 -150
- data/examples/dynamic_style/dynamic_style.tlf +0 -1835
- data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
- data/examples/dynamic_style/image.png +0 -0
- data/examples/eudc/eudc.rb +0 -20
- data/examples/eudc/eudc.tlf +0 -180
- data/examples/eudc/eudc.ttf +0 -0
- data/examples/helper.rb +0 -50
- data/examples/hidden_shapes/hidden_shapes.rb +0 -9
- data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
- data/examples/list_events/list_events.rb +0 -32
- data/examples/list_events/list_events.tlf +0 -361
- data/examples/list_manual_generation/list_manual_generation.rb +0 -22
- data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
- data/examples/list_page_number/list_page_number.rb +0 -17
- data/examples/list_page_number/list_page_number.tlf +0 -254
- data/examples/page_number/page_number.rb +0 -33
- data/examples/page_number/page_number.tlf +0 -215
- data/examples/palleted_png/palleted_png.png +0 -0
- data/examples/palleted_png/palleted_png.rb +0 -11
- data/examples/palleted_png/palleted_png.tlf +0 -47
- data/examples/password_setting/password_setting.rb +0 -10
- data/examples/password_setting/password_setting.tlf +0 -45
- data/examples/report_callbacks/report_callbacks.rb +0 -14
- data/examples/report_callbacks/report_callbacks.tlf +0 -147
- data/examples/single_line_tblock/single_line_tblock.rb +0 -13
- data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
- data/examples/tblock_overflow/tblock_overflow.rb +0 -20
- data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
- data/examples/tblock_styles/font_size.tlf +0 -383
- data/examples/tblock_styles/tblock_styles.rb +0 -43
- data/examples/tblock_styles/tblock_styles.tlf +0 -889
- data/examples/text_align/text_align.rb +0 -8
- data/examples/text_align/text_align.tlf +0 -241
- data/examples/typeB_page_size/B4_ISO.tlf +0 -45
- data/examples/typeB_page_size/B4_JIS.tlf +0 -45
- data/examples/typeB_page_size/typeB_page_size.rb +0 -17
- data/examples/word_wrap/word_wrap.rb +0 -26
- data/examples/word_wrap/word_wrap.tlf +0 -297
- data/lib/thinreports/generator.rb +0 -29
- data/lib/thinreports/generator/base.rb +0 -40
- data/lib/thinreports/generator/configuration.rb +0 -31
- data/lib/thinreports/report/events.rb +0 -32
- data/test/data/font.ttf +0 -0
- data/test/data/image_normal.jpg +0 -0
- data/test/data/image_normal.png +0 -0
- data/test/data/image_normal_jpg_noext +0 -0
- data/test/data/image_normal_png_noext +0 -0
- data/test/data/image_pallete_based.png +0 -0
- data/test/data/legacy_layout/all-items.tlf +0 -1
- data/test/schema_helper.rb +0 -121
- data/test/test_helper.rb +0 -42
- data/test/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +0 -152
- data/test/unit/core/shape/base/test_internal.rb +0 -87
- data/test/unit/core/shape/basic/test_block_format.rb +0 -23
- data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
- data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
- data/test/unit/core/shape/basic/test_format.rb +0 -37
- data/test/unit/core/shape/basic/test_interface.rb +0 -108
- data/test/unit/core/shape/basic/test_internal.rb +0 -55
- data/test/unit/core/shape/image_block/test_interface.rb +0 -24
- data/test/unit/core/shape/image_block/test_internal.rb +0 -31
- data/test/unit/core/shape/list/test_format.rb +0 -111
- data/test/unit/core/shape/list/test_manager.rb +0 -67
- data/test/unit/core/shape/list/test_page.rb +0 -82
- data/test/unit/core/shape/list/test_page_state.rb +0 -31
- data/test/unit/core/shape/list/test_section_format.rb +0 -36
- data/test/unit/core/shape/list/test_section_interface.rb +0 -75
- data/test/unit/core/shape/list/test_section_internal.rb +0 -50
- data/test/unit/core/shape/manager/test_format.rb +0 -38
- data/test/unit/core/shape/manager/test_internal.rb +0 -132
- data/test/unit/core/shape/manager/test_target.rb +0 -140
- data/test/unit/core/shape/page_number/test_format.rb +0 -55
- data/test/unit/core/shape/page_number/test_interface.rb +0 -33
- data/test/unit/core/shape/page_number/test_internal.rb +0 -81
- data/test/unit/core/shape/styles/test_base.rb +0 -191
- data/test/unit/core/shape/styles/test_basic.rb +0 -24
- data/test/unit/core/shape/styles/test_graphic.rb +0 -50
- data/test/unit/core/shape/styles/test_text.rb +0 -97
- data/test/unit/core/shape/text/test_format.rb +0 -44
- data/test/unit/core/shape/text/test_internal.rb +0 -20
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
- data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
- data/test/unit/core/shape/text_block/test_format.rb +0 -169
- data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
- data/test/unit/core/shape/text_block/test_interface.rb +0 -63
- data/test/unit/core/shape/text_block/test_internal.rb +0 -128
- data/test/unit/core/test_shape.rb +0 -52
- data/test/unit/core/test_utils.rb +0 -68
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -45
- data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -150
- data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
- data/test/unit/generator/pdf/document/test_font.rb +0 -84
- data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
- data/test/unit/generator/pdf/document/test_page.rb +0 -122
- data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
- data/test/unit/generator/pdf/test_document.rb +0 -20
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
- data/test/unit/generator/test_pdf.rb +0 -24
- data/test/unit/layout/test_base.rb +0 -41
- data/test/unit/layout/test_format.rb +0 -100
- data/test/unit/layout/test_legacy_schema.rb +0 -574
- data/test/unit/layout/test_version.rb +0 -95
- data/test/unit/report/test_base.rb +0 -262
- data/test/unit/report/test_internal.rb +0 -206
- data/test/unit/test_config.rb +0 -51
- data/test/unit/test_layout.rb +0 -12
- data/test/unit/test_report.rb +0 -18
@@ -1,79 +1,85 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
4
|
module Generator
|
5
|
+
class PDF
|
6
|
+
module DrawShape
|
7
|
+
# @param [Thinreports::Core::Shape::TextBlock::Internal] shape
|
8
|
+
def draw_shape_tblock(shape)
|
9
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
def draw_shape_tblock(shape)
|
9
|
-
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
11
|
+
content = shape.real_value.to_s
|
12
|
+
return if content.empty?
|
10
13
|
|
11
|
-
content = shape.real_value.to_s
|
12
|
-
unless content.empty?
|
13
14
|
attrs = build_text_attributes(shape.style.finalized_styles)
|
14
15
|
|
15
16
|
unless shape.multiple?
|
16
|
-
content = content.
|
17
|
+
content = content.tr("\n", ' ')
|
17
18
|
attrs[:single] = true
|
18
19
|
end
|
20
|
+
|
19
21
|
text_box(content, x, y, w, h, attrs)
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
def draw_shape_pageno(shape, page_no, page_count)
|
25
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
attrs = build_text_attributes(shape.style.finalized_styles)
|
28
|
+
text_box(shape.build_format(page_no, page_count), x, y, w, h, attrs)
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
32
|
+
def draw_shape_image(shape)
|
33
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
image_data = shape.format.attributes['data']
|
36
|
+
base64image(image_data['base64'], x, y, w, h)
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
# @param [Thinreports::Core::Shape::ImageBlock::Internal] shape
|
40
|
+
def draw_shape_iblock(shape)
|
41
|
+
return if blank_value?(shape.src)
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
44
|
+
style = shape.style.finalized_styles
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
image_box(
|
47
|
+
shape.src, x, y, w, h,
|
48
|
+
position_x: image_position_x(style['position-x']),
|
49
|
+
position_y: image_position_y(style['position-y'])
|
50
|
+
)
|
51
|
+
end
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
# @param [Thinreports::Core::Shape::Text::Internal] shape
|
54
|
+
def draw_shape_text(shape)
|
55
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
56
|
+
text(
|
57
|
+
shape.texts.join("\n"), x, y, w, h,
|
58
|
+
build_text_attributes(shape.style.finalized_styles)
|
59
|
+
)
|
60
|
+
end
|
55
61
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
62
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
63
|
+
def draw_shape_ellipse(shape)
|
64
|
+
cx, cy, rx, ry = shape.format.attributes.values_at('cx', 'cy', 'rx', 'ry')
|
65
|
+
ellipse(cx, cy, rx, ry, build_graphic_attributes(shape.style.finalized_styles))
|
66
|
+
end
|
61
67
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
68
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
69
|
+
def draw_shape_line(shape)
|
70
|
+
x1, y1, x2, y2 = shape.format.attributes.values_at('x1', 'y1', 'x2', 'y2')
|
71
|
+
line(x1, y1, x2, y2, build_graphic_attributes(shape.style.finalized_styles))
|
72
|
+
end
|
67
73
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
74
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
75
|
+
def draw_shape_rect(shape)
|
76
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
77
|
+
rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs|
|
78
|
+
attrs[:radius] = shape.format.attributes['border-radius']
|
79
|
+
end
|
80
|
+
rect(x, y, w, h, rect_attributes)
|
73
81
|
end
|
74
|
-
rect(x, y, w, h, rect_attributes)
|
75
82
|
end
|
76
83
|
end
|
77
|
-
|
78
84
|
end
|
79
85
|
end
|
@@ -1,66 +1,69 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
4
|
module Generator
|
5
|
+
class PDF
|
6
|
+
module DrawTemplateItems
|
7
|
+
# @param [Array<Hash>] items
|
8
|
+
def draw_template_items(items)
|
9
|
+
items.each do |item_attributes|
|
10
|
+
next unless drawable?(item_attributes)
|
5
11
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
when 'text' then draw_text(item_attributes)
|
14
|
-
when 'image' then draw_image(item_attributes)
|
15
|
-
when 'rect' then draw_rect(item_attributes)
|
16
|
-
when 'ellipse' then draw_ellipse(item_attributes)
|
17
|
-
when 'line' then draw_line(item_attributes)
|
12
|
+
case item_attributes['type']
|
13
|
+
when 'text' then draw_text(item_attributes)
|
14
|
+
when 'image' then draw_image(item_attributes)
|
15
|
+
when 'rect' then draw_rect(item_attributes)
|
16
|
+
when 'ellipse' then draw_ellipse(item_attributes)
|
17
|
+
when 'line' then draw_line(item_attributes)
|
18
|
+
end
|
18
19
|
end
|
19
20
|
end
|
20
|
-
end
|
21
21
|
|
22
|
-
|
22
|
+
private
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
# @param [Hash] item_attributes
|
25
|
+
def draw_rect(item_attributes)
|
26
|
+
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
27
|
+
graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
|
28
|
+
attrs[:radius] = item_attributes['border-radius']
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
rect(x, y, w, h, graphic_attributes)
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
# @see #draw_rect
|
35
|
+
def draw_ellipse(item_attributes)
|
36
|
+
x, y, rx, ry = item_attributes.values_at('cx', 'cy', 'rx', 'ry')
|
37
|
+
ellipse(x, y, rx, ry, build_graphic_attributes(item_attributes['style']))
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
# @see #draw_rect
|
41
|
+
def draw_line(item_attributes)
|
42
|
+
x1, y1, x2, y2 = item_attributes.values_at('x1', 'y1', 'x2', 'y2')
|
43
|
+
line(x1, y1, x2, y2, build_graphic_attributes(item_attributes['style']))
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
# @see #draw_rect
|
47
|
+
def draw_text(item_attributes)
|
48
|
+
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
49
|
+
text(
|
50
|
+
item_attributes['texts'].join("\n"), x, y, w, h,
|
51
|
+
build_text_attributes(item_attributes['style'])
|
52
|
+
)
|
53
|
+
end
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
# @see #draw_rect
|
56
|
+
def draw_image(item_attributes)
|
57
|
+
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
58
|
+
image_data = item_attributes['data']
|
56
59
|
|
57
|
-
|
58
|
-
|
60
|
+
base64image(image_data['base64'], x, y, w, h)
|
61
|
+
end
|
59
62
|
|
60
|
-
|
61
|
-
|
63
|
+
def drawable?(item_attributes)
|
64
|
+
item_attributes['id'].empty? && item_attributes['display']
|
65
|
+
end
|
62
66
|
end
|
63
67
|
end
|
64
|
-
|
65
68
|
end
|
66
69
|
end
|
@@ -1,79 +1,88 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
4
|
module Generator
|
5
|
+
class PDF
|
6
|
+
module Font
|
7
|
+
FONT_STORE = Thinreports.root.join('fonts')
|
5
8
|
|
6
|
-
|
7
|
-
|
9
|
+
BUILTIN_FONTS = {
|
10
|
+
'IPAMincho' => FONT_STORE.join('ipam.ttf').to_s,
|
11
|
+
'IPAPMincho' => FONT_STORE.join('ipamp.ttf').to_s,
|
12
|
+
'IPAGothic' => FONT_STORE.join('ipag.ttf').to_s,
|
13
|
+
'IPAPGothic' => FONT_STORE.join('ipagp.ttf').to_s
|
14
|
+
}.freeze
|
8
15
|
|
9
|
-
|
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
|
-
}
|
16
|
+
DEFAULT_FALLBACK_FONTS = %w[IPAMincho].freeze
|
15
17
|
|
16
|
-
|
18
|
+
PRAWN_BUINTIN_FONT_ALIASES = {
|
19
|
+
'Courier New' => 'Courier',
|
20
|
+
'Times New Roman' => 'Times-Roman'
|
21
|
+
}.freeze
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def setup_fonts
|
24
|
-
# Install built-in fonts.
|
25
|
-
pdf.font_families.update(BUILTIN_FONTS)
|
23
|
+
def setup_fonts
|
24
|
+
# Install built-in fonts.
|
25
|
+
BUILTIN_FONTS.each do |font_name, font_path|
|
26
|
+
install_font(font_name, font_path)
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
# Create aliases from the font list provided by Prawn.
|
30
|
+
PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name|
|
31
|
+
pdf.font_families[alias_name] = pdf.font_families[name]
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
# Setup custom fallback fonts
|
35
|
+
fallback_fonts = Thinreports.config.fallback_fonts.uniq
|
36
|
+
fallback_fonts.map!.with_index do |font, i|
|
37
|
+
if pdf.font_families.key?(font)
|
38
|
+
font
|
39
|
+
else
|
40
|
+
install_font "Custom-fallback-font#{i}", font
|
41
|
+
end
|
39
42
|
end
|
43
|
+
|
44
|
+
# Set fallback fonts
|
45
|
+
pdf.fallback_fonts(fallback_fonts + DEFAULT_FALLBACK_FONTS)
|
40
46
|
end
|
41
47
|
|
42
|
-
#
|
43
|
-
|
44
|
-
|
48
|
+
# @param [String] name
|
49
|
+
# @param [String] file
|
50
|
+
# @return [String] installed font name
|
51
|
+
def install_font(name, file)
|
52
|
+
raise Errors::FontFileNotFound unless File.exist?(file)
|
45
53
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
54
|
+
pdf.font_families[name] = {
|
55
|
+
normal: file,
|
56
|
+
bold: file,
|
57
|
+
italic: file,
|
58
|
+
bold_italic: file
|
59
|
+
}
|
60
|
+
name
|
61
|
+
end
|
51
62
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
name
|
57
|
-
end
|
63
|
+
# @return [String]
|
64
|
+
def default_family
|
65
|
+
'Helvetica'
|
66
|
+
end
|
58
67
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
68
|
+
# @param [String] family
|
69
|
+
# @return [String]
|
70
|
+
def default_family_if_missing(family)
|
71
|
+
pdf.font_families.key?(family) ? family : default_family
|
72
|
+
end
|
63
73
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
74
|
+
# @param [String] font_name
|
75
|
+
# @param [:bold, :italic] font_style
|
76
|
+
# @return [Boolean]
|
77
|
+
def font_has_style?(font_name, font_style)
|
78
|
+
font = pdf.font_families[font_name]
|
69
79
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
80
|
+
return false unless font
|
81
|
+
return false unless font.key?(font_style)
|
82
|
+
|
83
|
+
font[font_style] != font[:normal]
|
84
|
+
end
|
75
85
|
end
|
76
86
|
end
|
77
|
-
|
78
87
|
end
|
79
88
|
end
|
@@ -1,41 +1,40 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
4
|
module Generator
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
5
|
+
class PDF
|
6
|
+
module Graphics
|
7
|
+
BASE_LINE_WIDTH = 0.9
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
# Change the default graphic states defined by Prawn.
|
12
|
+
def setup_custom_graphic_states
|
13
|
+
pdf.line_width(BASE_LINE_WIDTH)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [Numeric] width
|
17
|
+
def line_width(width)
|
18
|
+
pdf.line_width(width * BASE_LINE_WIDTH)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Delegate to Prawn::Document#save_graphic_state
|
22
|
+
# @see Prawn::Document#save_graphics_state
|
23
|
+
def save_graphics_state
|
24
|
+
pdf.save_graphics_state
|
25
|
+
end
|
26
|
+
|
27
|
+
# Delegate to Prawn::Document#restore_graphic_state
|
28
|
+
# @see Prawn::Document#restore_graphics_state
|
29
|
+
def restore_graphics_state
|
30
|
+
pdf.restore_graphics_state
|
31
|
+
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
require_relative 'graphics/attributes'
|
38
|
+
require_relative 'graphics/basic'
|
39
|
+
require_relative 'graphics/image'
|
40
|
+
require_relative 'graphics/text'
|