thinreports 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +41 -0
- data/.travis.yml +4 -6
- data/CHANGELOG.md +21 -2
- data/Gemfile +2 -4
- data/README.md +4 -5
- data/Rakefile +7 -8
- data/examples/character_spacing/character_spacing.rb +1 -1
- data/examples/dynamic_image/dynamic_image.rb +3 -3
- data/examples/dynamic_style/dynamic_style.rb +1 -1
- data/examples/eudc/eudc.rb +1 -1
- data/examples/helper.rb +2 -2
- data/examples/hidden_shapes/hidden_shapes.rb +1 -1
- data/examples/list_events/list_events.rb +1 -1
- data/examples/list_manual_generation/list_manual_generation.rb +1 -1
- data/examples/list_page_number/list_page_number.rb +1 -1
- data/examples/page_number/page_number.rb +1 -1
- data/examples/palleted_png/palleted_png.rb +1 -3
- data/examples/password_setting/password_setting.rb +1 -1
- data/examples/report_callbacks/report_callbacks.rb +1 -1
- data/examples/single_line_tblock/single_line_tblock.rb +1 -1
- data/examples/tblock_overflow/tblock_overflow.rb +1 -1
- data/examples/tblock_styles/tblock_styles.rb +1 -1
- data/examples/text_align/text_align.rb +1 -1
- data/examples/typeB_page_size/typeB_page_size.rb +1 -1
- data/examples/word_wrap/word_wrap.rb +1 -1
- 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 +13 -14
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +35 -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 +182 -176
- data/lib/thinreports/core/shape/list/page.rb +94 -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 +88 -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 +47 -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 +45 -39
- 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 +68 -68
- data/lib/thinreports/core/utils.rb +4 -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 +58 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +51 -47
- data/lib/thinreports/generator/pdf/document/font.rb +62 -59
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +122 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +113 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +152 -137
- data/lib/thinreports/generator/pdf/document/page.rb +63 -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 +48 -45
- 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 +34 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +29 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -7
- data/lib/thinreports/layout/format.rb +18 -13
- data/lib/thinreports/layout/legacy_schema.rb +18 -10
- 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 +9 -11
- data/lib/thinreports/report/page.rb +5 -6
- data/lib/thinreports/version.rb +2 -2
- data/test/schema_helper.rb +4 -3
- data/test/test_helper.rb +9 -3
- data/test/unit/core/format/test_base.rb +1 -1
- data/test/unit/core/shape/base/test_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_block_format.rb +1 -1
- data/test/unit/core/shape/basic/test_block_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_block_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_format.rb +1 -1
- data/test/unit/core/shape/basic/test_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_internal.rb +1 -1
- data/test/unit/core/shape/image_block/test_interface.rb +1 -1
- data/test/unit/core/shape/image_block/test_internal.rb +1 -1
- data/test/unit/core/shape/list/test_format.rb +1 -1
- data/test/unit/core/shape/list/test_manager.rb +4 -4
- data/test/unit/core/shape/list/test_page.rb +1 -1
- data/test/unit/core/shape/list/test_page_state.rb +1 -1
- data/test/unit/core/shape/list/test_section_format.rb +1 -1
- data/test/unit/core/shape/list/test_section_interface.rb +2 -2
- data/test/unit/core/shape/list/test_section_internal.rb +1 -1
- data/test/unit/core/shape/manager/test_format.rb +2 -2
- data/test/unit/core/shape/manager/test_internal.rb +3 -3
- data/test/unit/core/shape/manager/test_target.rb +1 -1
- data/test/unit/core/shape/page_number/test_format.rb +1 -1
- data/test/unit/core/shape/page_number/test_interface.rb +1 -1
- data/test/unit/core/shape/page_number/test_internal.rb +1 -1
- data/test/unit/core/shape/styles/test_base.rb +1 -1
- data/test/unit/core/shape/styles/test_basic.rb +1 -1
- data/test/unit/core/shape/styles/test_graphic.rb +1 -1
- data/test/unit/core/shape/styles/test_text.rb +1 -1
- data/test/unit/core/shape/text/test_format.rb +1 -1
- data/test/unit/core/shape/text/test_internal.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_number.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +2 -2
- data/test/unit/core/shape/text_block/test_format.rb +1 -1
- data/test/unit/core/shape/text_block/test_formatter.rb +1 -1
- data/test/unit/core/shape/text_block/test_interface.rb +1 -1
- data/test/unit/core/shape/text_block/test_internal.rb +3 -3
- data/test/unit/core/test_shape.rb +1 -1
- data/test/unit/core/test_utils.rb +2 -2
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +1 -1
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +2 -1
- data/test/unit/generator/pdf/document/graphics/test_image.rb +27 -131
- data/test/unit/generator/pdf/document/graphics/test_text.rb +1 -1
- data/test/unit/generator/pdf/document/test_font.rb +2 -2
- data/test/unit/generator/pdf/document/test_graphics.rb +1 -1
- data/test/unit/generator/pdf/document/test_page.rb +7 -7
- data/test/unit/generator/pdf/document/test_parse_color.rb +1 -1
- data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +41 -0
- data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +22 -0
- data/test/unit/generator/pdf/test_document.rb +8 -6
- data/test/unit/generator/test_pdf.rb +12 -10
- data/test/unit/layout/test_base.rb +1 -1
- data/test/unit/layout/test_format.rb +2 -2
- data/test/unit/layout/test_legacy_schema.rb +4 -4
- data/test/unit/layout/test_version.rb +11 -80
- data/test/unit/report/test_base.rb +45 -59
- data/test/unit/report/test_internal.rb +1 -1
- data/test/unit/test_config.rb +1 -16
- data/test/unit/test_layout.rb +1 -1
- data/test/unit/test_report.rb +1 -1
- data/thinreports.gemspec +11 -14
- metadata +42 -103
- 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/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
@@ -1,79 +1,86 @@
|
|
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
|
+
# rubocop:disable Metrics/AbcSize
|
9
|
+
def draw_shape_tblock(shape)
|
10
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
5
11
|
|
6
|
-
|
7
|
-
|
8
|
-
def draw_shape_tblock(shape)
|
9
|
-
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
12
|
+
content = shape.real_value.to_s
|
13
|
+
return if content.empty?
|
10
14
|
|
11
|
-
content = shape.real_value.to_s
|
12
|
-
unless content.empty?
|
13
15
|
attrs = build_text_attributes(shape.style.finalized_styles)
|
14
16
|
|
15
17
|
unless shape.multiple?
|
16
|
-
content = content.
|
18
|
+
content = content.tr("\n", ' ')
|
17
19
|
attrs[:single] = true
|
18
20
|
end
|
21
|
+
|
19
22
|
text_box(content, x, y, w, h, attrs)
|
20
23
|
end
|
21
|
-
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
def draw_shape_pageno(shape, page_no, page_count)
|
26
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
attrs = build_text_attributes(shape.style.finalized_styles)
|
29
|
+
text_box(shape.build_format(page_no, page_count), x, y, w, h, attrs)
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
33
|
+
def draw_shape_image(shape)
|
34
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
image_data = shape.format.attributes['data']
|
37
|
+
base64image(image_data['base64'], x, y, w, h)
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
# @param [Thinreports::Core::Shape::ImageBlock::Internal] shape
|
41
|
+
def draw_shape_iblock(shape)
|
42
|
+
return if blank_value?(shape.src)
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
45
|
+
style = shape.style.finalized_styles
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
image_box(
|
48
|
+
shape.src, x, y, w, h,
|
49
|
+
position_x: image_position_x(style['position-x']),
|
50
|
+
position_y: image_position_y(style['position-y'])
|
51
|
+
)
|
52
|
+
end
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
# @param [Thinreports::Core::Shape::Text::Internal] shape
|
55
|
+
def draw_shape_text(shape)
|
56
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
57
|
+
text(
|
58
|
+
shape.texts.join("\n"), x, y, w, h,
|
59
|
+
build_text_attributes(shape.style.finalized_styles)
|
60
|
+
)
|
61
|
+
end
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
64
|
+
def draw_shape_ellipse(shape)
|
65
|
+
cx, cy, rx, ry = shape.format.attributes.values_at('cx', 'cy', 'rx', 'ry')
|
66
|
+
ellipse(cx, cy, rx, ry, build_graphic_attributes(shape.style.finalized_styles))
|
67
|
+
end
|
61
68
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
69
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
70
|
+
def draw_shape_line(shape)
|
71
|
+
x1, y1, x2, y2 = shape.format.attributes.values_at('x1', 'y1', 'x2', 'y2')
|
72
|
+
line(x1, y1, x2, y2, build_graphic_attributes(shape.style.finalized_styles))
|
73
|
+
end
|
67
74
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
75
|
+
# @param [Thinreports::Core::Shape::Basic::Internal] shape
|
76
|
+
def draw_shape_rect(shape)
|
77
|
+
x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
|
78
|
+
rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs|
|
79
|
+
attrs[:radius] = shape.format.attributes['rx']
|
80
|
+
end
|
81
|
+
rect(x, y, w, h, rect_attributes)
|
73
82
|
end
|
74
|
-
rect(x, y, w, h, rect_attributes)
|
75
83
|
end
|
76
84
|
end
|
77
|
-
|
78
85
|
end
|
79
86
|
end
|
@@ -1,66 +1,70 @@
|
|
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
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
9
|
+
def draw_template_items(items)
|
10
|
+
items.each do |item_attributes|
|
11
|
+
next unless drawable?(item_attributes)
|
5
12
|
|
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)
|
13
|
+
case item_attributes['type']
|
14
|
+
when 'text' then draw_text(item_attributes)
|
15
|
+
when 'image' then draw_image(item_attributes)
|
16
|
+
when 'rect' then draw_rect(item_attributes)
|
17
|
+
when 'ellipse' then draw_ellipse(item_attributes)
|
18
|
+
when 'line' then draw_line(item_attributes)
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
+
private
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
# @param [Hash] item_attributes
|
26
|
+
def draw_rect(item_attributes)
|
27
|
+
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
28
|
+
graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
|
29
|
+
attrs[:radius] = item_attributes['rx']
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
rect(x, y, w, h, graphic_attributes)
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
# @see #draw_rect
|
36
|
+
def draw_ellipse(item_attributes)
|
37
|
+
x, y, rx, ry = item_attributes.values_at('cx', 'cy', 'rx', 'ry')
|
38
|
+
ellipse(x, y, rx, ry, build_graphic_attributes(item_attributes['style']))
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
# @see #draw_rect
|
42
|
+
def draw_line(item_attributes)
|
43
|
+
x1, y1, x2, y2 = item_attributes.values_at('x1', 'y1', 'x2', 'y2')
|
44
|
+
line(x1, y1, x2, y2, build_graphic_attributes(item_attributes['style']))
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
# @see #draw_rect
|
48
|
+
def draw_text(item_attributes)
|
49
|
+
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
50
|
+
text(
|
51
|
+
item_attributes['texts'].join("\n"), x, y, w, h,
|
52
|
+
build_text_attributes(item_attributes['style'])
|
53
|
+
)
|
54
|
+
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
# @see #draw_rect
|
57
|
+
def draw_image(item_attributes)
|
58
|
+
x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
|
59
|
+
image_data = item_attributes['data']
|
56
60
|
|
57
|
-
|
58
|
-
|
61
|
+
base64image(image_data['base64'], x, y, w, h)
|
62
|
+
end
|
59
63
|
|
60
|
-
|
61
|
-
|
64
|
+
def drawable?(item_attributes)
|
65
|
+
item_attributes['id'].empty? && item_attributes['display']
|
66
|
+
end
|
62
67
|
end
|
63
68
|
end
|
64
|
-
|
65
69
|
end
|
66
70
|
end
|
@@ -1,79 +1,82 @@
|
|
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' => { normal: FONT_STORE.join('ipam.ttf').to_s },
|
11
|
+
'IPAPMincho' => { normal: FONT_STORE.join('ipamp.ttf').to_s },
|
12
|
+
'IPAGothic' => { normal: FONT_STORE.join('ipag.ttf').to_s },
|
13
|
+
'IPAPGothic' => { normal: 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
|
-
|
23
|
+
# rubocop:disable Metrics/AbcSize
|
24
|
+
def setup_fonts
|
25
|
+
# Install built-in fonts.
|
26
|
+
pdf.font_families.update(BUILTIN_FONTS)
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# Create aliases from the font list provided by Prawn.
|
28
|
-
PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name|
|
29
|
-
pdf.font_families[alias_name] = pdf.font_families[name]
|
30
|
-
end
|
28
|
+
# Create aliases from the font list provided by Prawn.
|
29
|
+
PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name|
|
30
|
+
pdf.font_families[alias_name] = pdf.font_families[name]
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
# Setup custom fallback fonts
|
34
|
+
fallback_fonts = Thinreports.config.fallback_fonts.uniq
|
35
|
+
fallback_fonts.map!.with_index do |font, i|
|
36
|
+
if pdf.font_families.key?(font)
|
37
|
+
font
|
38
|
+
else
|
39
|
+
install_font "Custom-fallback-font#{i}", font
|
40
|
+
end
|
39
41
|
end
|
40
|
-
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
# Set fallback fonts
|
44
|
+
pdf.fallback_fonts(fallback_fonts + DEFAULT_FALLBACK_FONTS)
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
# @param [String] name
|
48
|
+
# @param [String] file
|
49
|
+
# @return [String] installed font name
|
50
|
+
def install_font(name, file)
|
51
|
+
raise Errors::FontFileNotFound unless File.exist?(file)
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
pdf.font_families[name] = {
|
54
|
+
normal: file,
|
55
|
+
bold: file,
|
56
|
+
italic: file,
|
57
|
+
bold_italic: file
|
58
|
+
}
|
59
|
+
name
|
60
|
+
end
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
# @return [String]
|
63
|
+
def default_family
|
64
|
+
'Helvetica'
|
65
|
+
end
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
# @param [String] family
|
68
|
+
# @return [String]
|
69
|
+
def default_family_if_missing(family)
|
70
|
+
pdf.font_families.key?(family) ? family : default_family
|
71
|
+
end
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
# @param [String] font
|
74
|
+
# @param [Symbol] style
|
75
|
+
# @return [Boolean]
|
76
|
+
def font_has_style?(font, style)
|
77
|
+
(f = pdf.font_families[font]) && f.key?(style)
|
78
|
+
end
|
75
79
|
end
|
76
80
|
end
|
77
|
-
|
78
81
|
end
|
79
82
|
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'
|