prawn 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +0 -0
- data/Gemfile +1 -9
- data/Rakefile +12 -22
- data/lib/prawn.rb +29 -48
- data/lib/prawn/document.rb +148 -123
- data/lib/prawn/document/bounding_box.rb +33 -26
- data/lib/prawn/document/column_box.rb +5 -7
- data/lib/prawn/document/internals.rb +6 -6
- data/lib/prawn/document/span.rb +20 -17
- data/lib/prawn/encoding.rb +65 -67
- data/lib/prawn/errors.rb +10 -7
- data/lib/prawn/font.rb +78 -62
- data/lib/prawn/font/afm.rb +93 -66
- data/lib/prawn/font/dfont.rb +2 -10
- data/lib/prawn/font/ttc.rb +34 -0
- data/lib/prawn/font/ttf.rb +73 -65
- data/lib/prawn/font_metric_cache.rb +9 -8
- data/lib/prawn/graphics.rb +110 -70
- data/lib/prawn/graphics/blend_mode.rb +7 -8
- data/lib/prawn/graphics/cap_style.rb +2 -4
- data/lib/prawn/graphics/color.rb +23 -26
- data/lib/prawn/graphics/dash.rb +22 -12
- data/lib/prawn/graphics/join_style.rb +8 -4
- data/lib/prawn/graphics/patterns.rb +185 -96
- data/lib/prawn/graphics/transformation.rb +11 -9
- data/lib/prawn/graphics/transparency.rb +15 -13
- data/lib/prawn/grid.rb +20 -20
- data/lib/prawn/image_handler.rb +4 -6
- data/lib/prawn/images.rb +22 -15
- data/lib/prawn/images/image.rb +0 -1
- data/lib/prawn/images/jpg.rb +26 -22
- data/lib/prawn/images/png.rb +60 -57
- data/lib/prawn/measurement_extensions.rb +8 -9
- data/lib/prawn/measurements.rb +14 -15
- data/lib/prawn/outline.rb +96 -78
- data/lib/prawn/repeater.rb +12 -10
- data/lib/prawn/security.rb +66 -48
- data/lib/prawn/security/arcfour.rb +1 -3
- data/lib/prawn/soft_mask.rb +23 -25
- data/lib/prawn/stamp.rb +16 -12
- data/lib/prawn/text.rb +59 -45
- data/lib/prawn/text/box.rb +9 -8
- data/lib/prawn/text/formatted.rb +4 -6
- data/lib/prawn/text/formatted/arranger.rb +51 -30
- data/lib/prawn/text/formatted/box.rb +112 -88
- data/lib/prawn/text/formatted/fragment.rb +10 -15
- data/lib/prawn/text/formatted/line_wrap.rb +118 -61
- data/lib/prawn/text/formatted/parser.rb +134 -110
- data/lib/prawn/text/formatted/wrap.rb +42 -32
- data/lib/prawn/transformation_stack.rb +3 -4
- data/lib/prawn/utilities.rb +6 -21
- data/lib/prawn/version.rb +1 -3
- data/lib/prawn/view.rb +4 -2
- data/manual/basic_concepts/adding_pages.rb +4 -7
- data/manual/basic_concepts/basic_concepts.rb +29 -22
- data/manual/basic_concepts/creation.rb +8 -11
- data/manual/basic_concepts/cursor.rb +2 -5
- data/manual/basic_concepts/measurement.rb +3 -6
- data/manual/basic_concepts/origin.rb +3 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +9 -12
- data/manual/basic_concepts/view.rb +20 -16
- data/manual/bounding_box/bounding_box.rb +27 -24
- data/manual/bounding_box/bounds.rb +9 -12
- data/manual/bounding_box/canvas.rb +2 -5
- data/manual/bounding_box/creation.rb +4 -7
- data/manual/bounding_box/indentation.rb +12 -15
- data/manual/bounding_box/nesting.rb +22 -17
- data/manual/bounding_box/russian_boxes.rb +8 -9
- data/manual/bounding_box/stretchy.rb +10 -13
- data/manual/contents.rb +26 -22
- data/manual/cover.rb +22 -20
- data/manual/document_and_page_options/background.rb +9 -13
- data/manual/document_and_page_options/document_and_page_options.rb +23 -20
- data/manual/document_and_page_options/metadata.rb +16 -16
- data/manual/document_and_page_options/page_margins.rb +16 -20
- data/manual/document_and_page_options/page_size.rb +11 -12
- data/manual/document_and_page_options/print_scaling.rb +15 -15
- data/manual/example_helper.rb +2 -4
- data/manual/graphics/blend_mode.rb +10 -9
- data/manual/graphics/circle_and_ellipse.rb +2 -5
- data/manual/graphics/color.rb +5 -9
- data/manual/graphics/common_lines.rb +5 -8
- data/manual/graphics/fill_and_stroke.rb +2 -5
- data/manual/graphics/fill_rules.rb +7 -10
- data/manual/graphics/gradients.rb +25 -21
- data/manual/graphics/graphics.rb +49 -43
- data/manual/graphics/helper.rb +10 -9
- data/manual/graphics/line_width.rb +5 -7
- data/manual/graphics/lines_and_curves.rb +5 -8
- data/manual/graphics/polygon.rb +4 -8
- data/manual/graphics/rectangle.rb +2 -5
- data/manual/graphics/rotate.rb +4 -7
- data/manual/graphics/scale.rb +12 -15
- data/manual/graphics/soft_masks.rb +1 -4
- data/manual/graphics/stroke_cap.rb +3 -6
- data/manual/graphics/stroke_dash.rb +9 -12
- data/manual/graphics/stroke_join.rb +2 -5
- data/manual/graphics/translate.rb +7 -10
- data/manual/graphics/transparency.rb +5 -8
- data/manual/how_to_read_this_manual.rb +4 -6
- data/manual/images/absolute_position.rb +4 -7
- data/manual/images/fit.rb +5 -8
- data/manual/images/horizontal.rb +6 -9
- data/manual/images/images.rb +25 -23
- data/manual/images/plain_image.rb +3 -6
- data/manual/images/scale.rb +7 -10
- data/manual/images/vertical.rb +10 -13
- data/manual/images/width_and_height.rb +8 -11
- data/manual/layout/boxes.rb +3 -6
- data/manual/layout/content.rb +5 -8
- data/manual/layout/layout.rb +16 -16
- data/manual/layout/simple_grid.rb +4 -7
- data/manual/outline/add_subsection_to.rb +18 -21
- data/manual/outline/insert_section_after.rb +13 -16
- data/manual/outline/outline.rb +19 -17
- data/manual/outline/sections_and_pages.rb +15 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +19 -17
- data/manual/repeatable_content/page_numbering.rb +15 -16
- data/manual/repeatable_content/repeatable_content.rb +23 -19
- data/manual/repeatable_content/repeater.rb +12 -15
- data/manual/repeatable_content/stamp.rb +12 -15
- data/manual/security/encryption.rb +7 -10
- data/manual/security/permissions.rb +17 -14
- data/manual/security/security.rb +17 -16
- data/manual/table.rb +2 -4
- data/manual/text/alignment.rb +14 -17
- data/manual/text/color.rb +10 -11
- data/manual/text/column_box.rb +5 -8
- data/manual/text/fallback_fonts.rb +23 -21
- data/manual/text/font.rb +9 -12
- data/manual/text/font_size.rb +11 -14
- data/manual/text/font_style.rb +4 -7
- data/manual/text/formatted_callbacks.rb +23 -21
- data/manual/text/formatted_text.rb +31 -25
- data/manual/text/free_flowing_text.rb +18 -21
- data/manual/text/inline.rb +16 -19
- data/manual/text/kerning_and_character_spacing.rb +12 -15
- data/manual/text/leading.rb +5 -8
- data/manual/text/line_wrapping.rb +33 -17
- data/manual/text/paragraph_indentation.rb +11 -14
- data/manual/text/positioned_text.rb +13 -16
- data/manual/text/registering_families.rb +16 -19
- data/manual/text/rendering_and_color.rb +7 -10
- data/manual/text/right_to_left_text.rb +24 -19
- data/manual/text/rotation.rb +26 -23
- data/manual/text/single_usage.rb +6 -9
- data/manual/text/text.rb +56 -52
- data/manual/text/text_box_excess.rb +18 -17
- data/manual/text/text_box_extensions.rb +16 -15
- data/manual/text/text_box_overflow.rb +15 -18
- data/manual/text/utf8.rb +9 -12
- data/manual/text/win_ansi_charset.rb +18 -19
- data/prawn.gemspec +37 -27
- data/spec/extensions/encoding_helpers.rb +0 -2
- data/spec/manual_spec.rb +33 -0
- data/spec/prawn/document/bounding_box_spec.rb +546 -0
- data/spec/prawn/document/column_box_spec.rb +73 -0
- data/spec/prawn/document/security_spec.rb +173 -0
- data/spec/prawn/document_annotations_spec.rb +74 -0
- data/spec/prawn/document_destinations_spec.rb +13 -0
- data/spec/prawn/document_grid_spec.rb +96 -0
- data/spec/prawn/document_reference_spec.rb +25 -0
- data/spec/prawn/document_span_spec.rb +34 -0
- data/spec/prawn/document_spec.rb +751 -0
- data/spec/prawn/font_metric_cache_spec.rb +52 -0
- data/spec/prawn/font_spec.rb +513 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +61 -0
- data/spec/prawn/graphics/transparency_spec.rb +79 -0
- data/spec/prawn/graphics_spec.rb +817 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +227 -0
- data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +13 -15
- data/spec/prawn/images/jpg_spec.rb +18 -0
- data/spec/prawn/images/png_spec.rb +281 -0
- data/spec/prawn/images_spec.rb +170 -0
- data/spec/prawn/measurements_extensions_spec.rb +22 -0
- data/spec/prawn/outline_spec.rb +408 -0
- data/spec/prawn/repeater_spec.rb +163 -0
- data/spec/prawn/soft_mask_spec.rb +72 -0
- data/spec/prawn/stamp_spec.rb +168 -0
- data/spec/prawn/text/box_spec.rb +1113 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +464 -0
- data/spec/prawn/text/formatted/box_spec.rb +825 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +341 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +491 -0
- data/spec/prawn/text/formatted/parser_spec.rb +667 -0
- data/spec/prawn/text_draw_text_spec.rb +147 -0
- data/spec/prawn/text_rendering_mode_spec.rb +42 -0
- data/spec/prawn/text_spacing_spec.rb +93 -0
- data/spec/prawn/text_spec.rb +601 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +33 -0
- data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +21 -20
- data/spec/prawn/view_spec.rb +45 -0
- data/spec/spec_helper.rb +16 -16
- metadata +96 -151
- metadata.gz.sig +1 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/blend_modes_bottom_layer.jpg +0 -0
- data/data/images/blend_modes_top_layer.jpg +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/indexed_transparency.png +0 -0
- data/data/images/indexed_transparency_alpha.dat +0 -0
- data/data/images/indexed_transparency_color.dat +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +0 -8
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +0 -1
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +1 -819
- data/data/pdfs/hexagon.pdf +0 -61
- data/data/pdfs/indirect_reference.pdf +0 -86
- data/data/pdfs/multipage_template.pdf +0 -127
- data/data/pdfs/nested_pages.pdf +0 -118
- data/data/pdfs/page_without_mediabox.pdf +0 -193
- data/data/pdfs/resources_as_indirect_object.pdf +0 -83
- data/data/pdfs/two_hexagons.pdf +0 -90
- data/data/pdfs/version_1_6.pdf +0 -61
- data/data/shift_jis_text.txt +0 -1
- data/spec/acceptance/png_spec.rb +0 -35
- data/spec/annotations_spec.rb +0 -67
- data/spec/blend_mode_spec.rb +0 -71
- data/spec/bounding_box_spec.rb +0 -501
- data/spec/column_box_spec.rb +0 -59
- data/spec/destinations_spec.rb +0 -13
- data/spec/document_spec.rb +0 -738
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -475
- data/spec/formatted_text_arranger_spec.rb +0 -452
- data/spec/formatted_text_box_spec.rb +0 -716
- data/spec/formatted_text_fragment_spec.rb +0 -299
- data/spec/graphics_spec.rb +0 -705
- data/spec/grid_spec.rb +0 -95
- data/spec/images_spec.rb +0 -167
- data/spec/inline_formatted_text_parser_spec.rb +0 -568
- data/spec/jpg_spec.rb +0 -23
- data/spec/line_wrap_spec.rb +0 -366
- data/spec/measurement_units_spec.rb +0 -22
- data/spec/outline_spec.rb +0 -409
- data/spec/png_spec.rb +0 -257
- data/spec/reference_spec.rb +0 -25
- data/spec/repeater_spec.rb +0 -154
- data/spec/security_spec.rb +0 -151
- data/spec/soft_mask_spec.rb +0 -78
- data/spec/span_spec.rb +0 -43
- data/spec/stamp_spec.rb +0 -179
- data/spec/stroke_styles_spec.rb +0 -208
- data/spec/text_at_spec.rb +0 -142
- data/spec/text_box_spec.rb +0 -1042
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -543
- data/spec/text_with_inline_formatting_spec.rb +0 -35
- data/spec/transparency_spec.rb +0 -91
- data/spec/view_spec.rb +0 -42
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# Kerning is the process of adjusting the spacing between characters in a
|
4
2
|
# proportional font. It is usually done with specific letter pairs. We can
|
5
3
|
# switch it on and off if it is available with the current font. Just pass a
|
@@ -8,32 +6,31 @@
|
|
8
6
|
# Character Spacing is the space between characters. It can be increased or
|
9
7
|
# decreased and will have effect on the whole text. Just pass a number to the
|
10
8
|
# <code>:character_spacing</code> option from the text methods.
|
11
|
-
|
12
|
-
|
13
|
-
%w[.. example_helper]))
|
9
|
+
|
10
|
+
require_relative '../example_helper'
|
14
11
|
|
15
12
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
16
13
|
Prawn::ManualBuilder::Example.generate(filename) do
|
17
14
|
font_size(30) do
|
18
|
-
text_box
|
19
|
-
text_box
|
15
|
+
text_box 'With kerning:', kerning: true, at: [0, y - 40]
|
16
|
+
text_box 'Without kerning:', kerning: false, at: [0, y - 80]
|
20
17
|
|
21
|
-
text_box
|
22
|
-
text_box
|
18
|
+
text_box 'Tomato', kerning: true, at: [250, y - 40]
|
19
|
+
text_box 'Tomato', kerning: false, at: [250, y - 80]
|
23
20
|
|
24
|
-
text_box
|
25
|
-
text_box
|
21
|
+
text_box 'WAR', kerning: true, at: [400, y - 40]
|
22
|
+
text_box 'WAR', kerning: false, at: [400, y - 80]
|
26
23
|
|
27
|
-
text_box
|
28
|
-
text_box
|
24
|
+
text_box 'F.', kerning: true, at: [500, y - 40]
|
25
|
+
text_box 'F.', kerning: false, at: [500, y - 80]
|
29
26
|
end
|
30
27
|
|
31
28
|
move_down 80
|
32
29
|
|
33
|
-
string =
|
30
|
+
string = 'What have you done to the space between the characters?'
|
34
31
|
[-2, -1, 0, 0.5, 1, 2].each do |spacing|
|
35
32
|
move_down 20
|
36
33
|
text "#{string} (character_spacing: #{spacing})",
|
37
|
-
|
34
|
+
character_spacing: spacing
|
38
35
|
end
|
39
36
|
end
|
data/manual/text/leading.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# Leading is the additional space between lines of text.
|
4
2
|
#
|
5
3
|
# The leading can be set using the <code>default_leading</code> method which
|
@@ -7,19 +5,18 @@
|
|
7
5
|
# text methods with the <code>:leading</code> option.
|
8
6
|
#
|
9
7
|
# The default leading is <code>0</code>.
|
10
|
-
|
11
|
-
|
12
|
-
%w[.. example_helper]))
|
8
|
+
|
9
|
+
require_require '../example_helper'
|
13
10
|
|
14
11
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
15
12
|
Prawn::ManualBuilder::Example.generate(filename) do
|
16
|
-
string =
|
17
|
-
text string, :
|
13
|
+
string = 'Hey, what did you do with the space between my lines? ' * 10
|
14
|
+
text string, leading: 0
|
18
15
|
|
19
16
|
move_down 20
|
20
17
|
default_leading 5
|
21
18
|
text string
|
22
19
|
|
23
20
|
move_down 20
|
24
|
-
text string, :
|
21
|
+
text string, leading: 10
|
25
22
|
end
|
@@ -1,41 +1,57 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# Line wrapping happens on white space or hyphens. Soft hyphens can be used to
|
4
2
|
# indicate where words can be hyphenated. Non-breaking spaces can be used to
|
5
3
|
# display space without allowing for a break.
|
6
4
|
#
|
7
5
|
# For writing styles that do not make use of spaces, the zero width space serves
|
8
6
|
# to mark word boundaries. Zero width spaces are available only with TTF fonts.
|
9
|
-
|
10
|
-
|
11
|
-
%w[.. example_helper]))
|
7
|
+
|
8
|
+
require_relative '../example_helper'
|
12
9
|
|
13
10
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
14
11
|
Prawn::ManualBuilder::Example.generate(filename) do
|
15
|
-
text "Hard hyphens:\n"
|
16
|
-
|
17
|
-
|
12
|
+
text "Hard hyphens:\n" \
|
13
|
+
'Slip-sliding away, slip sliding awaaaay. You know the ' \
|
14
|
+
"nearer your destination the more you're slip-sliding away."
|
18
15
|
move_down 20
|
19
16
|
|
20
17
|
shy = Prawn::Text::SHY
|
21
|
-
text "Soft hyphens:\n"
|
22
|
-
|
23
|
-
|
18
|
+
text "Soft hyphens:\n" \
|
19
|
+
"Slip slid#{shy}ing away, slip slid#{shy}ing away. You know the " \
|
20
|
+
"nearer your destinat#{shy}ion the more you're slip slid#{shy}ing away."
|
24
21
|
move_down 20
|
25
22
|
|
26
23
|
nbsp = Prawn::Text::NBSP
|
27
|
-
text "Non-breaking spaces:\n"
|
28
|
-
|
29
|
-
|
24
|
+
text "Non-breaking spaces:\n" \
|
25
|
+
"Slip#{nbsp}sliding away, slip#{nbsp}sliding awaaaay. You know the " \
|
26
|
+
"nearer your destination the more you're slip#{nbsp}sliding away."
|
30
27
|
move_down 20
|
31
28
|
|
32
|
-
font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", :
|
33
|
-
long_text = "No word boundaries:\n
|
29
|
+
font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", size: 16) do
|
30
|
+
long_text = "No word boundaries:\n更可怕的是,"\
|
31
|
+
'同质化竞争对手可以按照URL中后面这个ID来遍历您的DB中的内容,'\
|
32
|
+
'写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,'\
|
33
|
+
'这样的话,你就非常被动了。更可怕的是,'\
|
34
|
+
'同质化竞争对手可以按照URL中后面这个ID来遍历您的DB中的内容,'\
|
35
|
+
'写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,'\
|
36
|
+
'这样的话,你就非常被动了。'
|
34
37
|
text long_text
|
35
38
|
move_down 20
|
36
39
|
|
37
40
|
zwsp = Prawn::Text::ZWSP
|
38
|
-
long_text = "Invisible word boundaries:\n更#{zwsp}可怕的#{zwsp}
|
41
|
+
long_text = "Invisible word boundaries:\n更#{zwsp}可怕的#{zwsp}是,"\
|
42
|
+
"#{zwsp}同质化#{zwsp}竞争#{zwsp}对#{zwsp}手#{zwsp}可以#{zwsp}按照#{zwsp}"\
|
43
|
+
"URL#{zwsp}中#{zwsp}后面#{zwsp}这个#{zwsp}ID#{zwsp}来#{zwsp}遍历#{zwsp}"\
|
44
|
+
"您的#{zwsp}DB#{zwsp}中的#{zwsp}内容,#{zwsp}写个#{zwsp}小爬虫#{zwsp}把"\
|
45
|
+
"#{zwsp}你的#{zwsp}页面#{zwsp}上的#{zwsp}关#{zwsp}键#{zwsp}信#{zwsp}息顺"\
|
46
|
+
"#{zwsp}次#{zwsp}爬#{zwsp}下来#{zwsp}也#{zwsp}不是#{zwsp}什么#{zwsp}"\
|
47
|
+
"难事,#{zwsp}这样的话,#{zwsp}你#{zwsp}就#{zwsp}非常#{zwsp}被动了。"\
|
48
|
+
"#{zwsp}更#{zwsp}可怕的#{zwsp}是,#{zwsp}同质化#{zwsp}竞争#{zwsp}对"\
|
49
|
+
"#{zwsp}手#{zwsp}可以#{zwsp}按照#{zwsp}URL#{zwsp}中#{zwsp}后面#{zwsp}"\
|
50
|
+
"这个#{zwsp}ID#{zwsp}来#{zwsp}遍历#{zwsp}您的#{zwsp}DB#{zwsp}中的#{zwsp}"\
|
51
|
+
"内容,#{zwsp}写个#{zwsp}小爬虫#{zwsp}把#{zwsp}你的#{zwsp}页面#{zwsp}"\
|
52
|
+
"上的#{zwsp}关#{zwsp}键#{zwsp}信#{zwsp}息顺#{zwsp}次#{zwsp}爬#{zwsp}下来"\
|
53
|
+
"#{zwsp}也#{zwsp}不是#{zwsp}什么#{zwsp}难事,#{zwsp}这样的话,#{zwsp}你"\
|
54
|
+
"#{zwsp}就#{zwsp}非常#{zwsp}被动了。"
|
39
55
|
text long_text
|
40
56
|
end
|
41
57
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# Prawn strips all whitespace from the beginning and the end of strings so there
|
4
2
|
# are two ways to indent paragraphs:
|
5
3
|
#
|
@@ -9,25 +7,24 @@
|
|
9
7
|
# The other is to use the <code>:indent_paragraphs</code> option with the text
|
10
8
|
# methods. Just pass a number with the space to indent the first line in each
|
11
9
|
# paragraph.
|
12
|
-
|
13
|
-
|
14
|
-
%w[.. example_helper]))
|
10
|
+
|
11
|
+
require_relative '../example_helper'
|
15
12
|
|
16
13
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
17
14
|
Prawn::ManualBuilder::Example.generate(filename) do
|
18
15
|
# Using non-breaking spaces
|
19
|
-
text
|
20
|
-
|
16
|
+
text ' ' * 10 + "This paragraph won't be indented. " * 10 +
|
17
|
+
"\n#{Prawn::Text::NBSP * 10}" + 'This one will with NBSP. ' * 10
|
21
18
|
|
22
19
|
move_down 20
|
23
|
-
text
|
24
|
-
|
25
|
-
|
20
|
+
text 'This paragraph will be indented. ' * 10 +
|
21
|
+
"\n" + 'This one will too. ' * 10,
|
22
|
+
indent_paragraphs: 60
|
26
23
|
|
27
24
|
move_down 20
|
28
25
|
|
29
|
-
text
|
30
|
-
text
|
31
|
-
|
32
|
-
|
26
|
+
text 'FROM RIGHT TO LEFT:'
|
27
|
+
text 'This paragraph will be indented. ' * 10 +
|
28
|
+
"\n" + 'This one will too. ' * 10,
|
29
|
+
indent_paragraphs: 60, direction: :rtl
|
33
30
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# Sometimes we want the text on a specific position on the page. The
|
4
2
|
# <code>text</code> method just won't help us.
|
5
3
|
#
|
@@ -16,23 +14,22 @@
|
|
16
14
|
# will flow to a new line if it reaches the right border.
|
17
15
|
#
|
18
16
|
# Given that, <code>text_box</code> is the better option available.
|
19
|
-
|
20
|
-
|
21
|
-
%w[.. example_helper]))
|
17
|
+
|
18
|
+
require_relative '../example_helper'
|
22
19
|
|
23
20
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
24
21
|
Prawn::ManualBuilder::Example.generate(filename) do
|
25
|
-
draw_text "This draw_text line is absolute positioned. However don't "
|
26
|
-
|
27
|
-
|
22
|
+
draw_text "This draw_text line is absolute positioned. However don't " \
|
23
|
+
'expect it to flow even if it hits the document border',
|
24
|
+
at: [200, 300]
|
28
25
|
|
29
|
-
text_box
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
text_box 'This is a text box, you can control where it will flow by ' \
|
27
|
+
'specifying the :height and :width options',
|
28
|
+
at: [100, 250],
|
29
|
+
height: 100,
|
30
|
+
width: 100
|
34
31
|
|
35
|
-
text_box
|
36
|
-
|
37
|
-
|
32
|
+
text_box 'Another text box with no :width option passed, so it will ' \
|
33
|
+
'flow to a new line whenever it reaches the right margin. ',
|
34
|
+
at: [200, 100]
|
38
35
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# Registering font families will help you when you want to use a font over and
|
4
2
|
# over or if you would like to take advantage of the <code>:style</code> option
|
5
3
|
# of the text methods and the <code>b</code> and <code>i</code> tags when using
|
@@ -7,46 +5,45 @@
|
|
7
5
|
#
|
8
6
|
# To register a font family update the <code>font_families</code>
|
9
7
|
# hash with the font path for each style you want to use.
|
10
|
-
|
11
|
-
|
12
|
-
%w[.. example_helper]))
|
8
|
+
|
9
|
+
require_relative '../example_helper'
|
13
10
|
|
14
11
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
15
12
|
Prawn::ManualBuilder::Example.generate(filename) do
|
16
13
|
# Registering a single TTF font
|
17
14
|
font_families.update(
|
18
|
-
|
19
|
-
:
|
15
|
+
'DejaVu Sans' => {
|
16
|
+
normal: "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
|
20
17
|
}
|
21
18
|
)
|
22
19
|
|
23
|
-
font(
|
24
|
-
text
|
20
|
+
font('DejaVu Sans') do
|
21
|
+
text 'Using the DejaVu Sans font providing only its name to the font method'
|
25
22
|
end
|
26
23
|
move_down 20
|
27
24
|
|
28
25
|
# Registering a DFONT package
|
29
26
|
font_path = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
|
30
27
|
font_families.update(
|
31
|
-
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
28
|
+
'Panic Sans' => {
|
29
|
+
normal: { file: font_path, font: 'PanicSans' },
|
30
|
+
italic: { file: font_path, font: 'PanicSans-Italic' },
|
31
|
+
bold: { file: font_path, font: 'PanicSans-Bold' },
|
32
|
+
bold_italic: { file: font_path, font: 'PanicSans-BoldItalic' }
|
36
33
|
}
|
37
34
|
)
|
38
35
|
|
39
|
-
font
|
40
|
-
text
|
36
|
+
font 'Panic Sans'
|
37
|
+
text 'Also using Panic Sans by providing only its name'
|
41
38
|
move_down 20
|
42
39
|
|
43
|
-
text
|
44
|
-
|
40
|
+
text 'Taking <b>advantage</b> of the <i>inline formatting</i>',
|
41
|
+
inline_format: true
|
45
42
|
move_down 20
|
46
43
|
|
47
44
|
[:bold, :bold_italic, :italic, :normal].each do |style|
|
48
45
|
text "Using the #{style} style option.",
|
49
|
-
|
46
|
+
style: style
|
50
47
|
move_down 10
|
51
48
|
end
|
52
49
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# You have already seen how to set the text color using both inline formatting
|
4
2
|
# and the format text methods. There is another way by using the graphics
|
5
3
|
# methods <code>fill_color</code> and <code>stroke_color</code>.
|
@@ -11,27 +9,26 @@
|
|
11
9
|
# being filled (the default mode) or just stroked or both filled and stroked.
|
12
10
|
# This can be set using the <code>text_rendering_mode</code> method or the
|
13
11
|
# <code>:mode</code> option on the text methods.
|
14
|
-
|
15
|
-
|
16
|
-
%w[.. example_helper]))
|
12
|
+
|
13
|
+
require_relative '../example_helper'
|
17
14
|
|
18
15
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
19
16
|
Prawn::ManualBuilder::Example.generate(filename) do
|
20
|
-
fill_color
|
21
|
-
stroke_color
|
17
|
+
fill_color '00ff00'
|
18
|
+
stroke_color '0000ff'
|
22
19
|
|
23
20
|
font_size(40) do
|
24
21
|
# normal rendering mode: fill
|
25
|
-
text
|
22
|
+
text 'This text is filled with green.'
|
26
23
|
move_down 20
|
27
24
|
|
28
25
|
# inline rendering mode: stroke
|
29
|
-
text
|
26
|
+
text 'This text is stroked with blue', mode: :stroke
|
30
27
|
move_down 20
|
31
28
|
|
32
29
|
# block rendering mode: fill and stroke
|
33
30
|
text_rendering_mode(:fill_stroke) do
|
34
|
-
text
|
31
|
+
text 'This text is filled with green and stroked with blue'
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# Prawn can be used with right-to-left text. The direction can be set
|
4
2
|
# document-wide, on particular text, or on a text-box. Setting the direction to
|
5
3
|
# <code>:rtl</code> automatically changes the default alignment to
|
@@ -13,35 +11,42 @@
|
|
13
11
|
# languages is easy using the <code>bidi</code> Ruby Gem and its
|
14
12
|
# <code>render_visual</code> function. See https://github.com/elad/ruby-bidi for
|
15
13
|
# instructions and an example using Prawn.
|
16
|
-
|
17
|
-
|
14
|
+
|
15
|
+
require_relative '../example_helper'
|
18
16
|
|
19
17
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
20
18
|
Prawn::ManualBuilder::Example.generate(filename) do
|
21
19
|
# set the direction document-wide
|
22
20
|
self.text_direction = :rtl
|
23
21
|
|
24
|
-
font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", :
|
25
|
-
long_text =
|
22
|
+
font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", size: 16) do
|
23
|
+
long_text = '写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个'\
|
24
|
+
'小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个小爬虫把你的页'\
|
25
|
+
'面上的关键信息顺次爬下来也不是什么难事写个小'
|
26
26
|
text long_text
|
27
27
|
move_down 20
|
28
28
|
|
29
|
-
text
|
29
|
+
text 'You can override the document direction.', direction: :ltr
|
30
30
|
move_down 20
|
31
31
|
|
32
|
-
formatted_text [
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
formatted_text [
|
33
|
+
{ text: '更可怕的是,同质化竞争对手可以按照' },
|
34
|
+
{ text: 'URL', direction: :ltr },
|
35
|
+
{ text: '中后面这个' },
|
36
|
+
{ text: 'ID', direction: :ltr },
|
37
|
+
{ text: '来遍历您的' },
|
38
|
+
{ text: 'DB', direction: :ltr },
|
39
|
+
{ text: '中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么'\
|
40
|
+
'难事,这样的话,你就非常被动了。' }
|
41
|
+
]
|
39
42
|
move_down 20
|
40
43
|
|
41
|
-
formatted_text [
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
formatted_text [
|
45
|
+
{ text: '更可怕的是,同质化竞争对手可以按照' },
|
46
|
+
{ text: 'this', direction: :ltr },
|
47
|
+
{ text: "won't", direction: :ltr, size: 24 },
|
48
|
+
{ text: 'work', direction: :ltr },
|
49
|
+
{ text: '中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事' }
|
50
|
+
]
|
46
51
|
end
|
47
52
|
end
|
data/manual/text/rotation.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
# Rotating text is best avoided on free flowing text, so this example
|
4
2
|
# will only use the <code>text_box</code> method as we can have much more
|
5
3
|
# control over its output.
|
@@ -7,36 +5,41 @@
|
|
7
5
|
# To rotate text all we need to do is use the <code>:rotate</code> option
|
8
6
|
# passing an angle in degrees and an optional <code>:rotate_around</code> to
|
9
7
|
# indicate the origin of the rotation (the default is <code>:upper_left</code>).
|
10
|
-
|
11
|
-
|
12
|
-
%w[.. example_helper]))
|
8
|
+
|
9
|
+
require_relative '../example_helper'
|
13
10
|
|
14
11
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
15
12
|
Prawn::ManualBuilder::Example.generate(filename) do
|
16
|
-
width
|
13
|
+
width = 100
|
17
14
|
height = 60
|
18
|
-
angle
|
19
|
-
x
|
20
|
-
y
|
15
|
+
angle = 30
|
16
|
+
x = 200
|
17
|
+
y = cursor - 30
|
21
18
|
|
22
19
|
stroke_rectangle [0, y], width, height
|
23
|
-
text_box(
|
24
|
-
|
20
|
+
text_box(
|
21
|
+
'This text was not rotated',
|
22
|
+
at: [0, y], width: width, height: height
|
23
|
+
)
|
25
24
|
|
26
25
|
stroke_rectangle [0, y - 100], width, height
|
27
|
-
text_box(
|
28
|
-
|
29
|
-
|
26
|
+
text_box(
|
27
|
+
'This text was rotated around the center',
|
28
|
+
at: [0, y - 100], width: width, height: height,
|
29
|
+
rotate: angle, rotate_around: :center
|
30
|
+
)
|
30
31
|
|
31
|
-
[:lower_left, :upper_left,
|
32
|
-
|
33
|
-
y
|
32
|
+
[:lower_left, :upper_left, :lower_right, :upper_right]
|
33
|
+
.each_with_index do |corner, index|
|
34
|
+
y -= 100 if index == 2
|
34
35
|
stroke_rectangle [x + (index % 2) * 200, y], width, height
|
35
|
-
text_box(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
text_box(
|
37
|
+
"This text was rotated around the #{corner} corner.",
|
38
|
+
at: [x + (index % 2) * 200, y],
|
39
|
+
width: width,
|
40
|
+
height: height,
|
41
|
+
rotate: angle,
|
42
|
+
rotate_around: corner
|
43
|
+
)
|
41
44
|
end
|
42
45
|
end
|