prawn 2.2.2 → 2.3.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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +2 -0
- data/Rakefile +10 -3
- data/lib/prawn.rb +9 -3
- data/lib/prawn/document.rb +40 -18
- data/lib/prawn/document/bounding_box.rb +9 -4
- data/lib/prawn/document/column_box.rb +2 -0
- data/lib/prawn/document/internals.rb +6 -4
- data/lib/prawn/document/span.rb +2 -0
- data/lib/prawn/encoding.rb +4 -1
- data/lib/prawn/errors.rb +2 -0
- data/lib/prawn/font.rb +34 -17
- data/lib/prawn/font_metric_cache.rb +8 -3
- data/lib/prawn/{font → fonts}/afm.rb +14 -7
- data/lib/prawn/{font → fonts}/dfont.rb +3 -1
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/{font → fonts}/ttc.rb +3 -1
- data/lib/prawn/{font → fonts}/ttf.rb +23 -12
- data/lib/prawn/graphics.rb +24 -26
- data/lib/prawn/graphics/blend_mode.rb +2 -0
- data/lib/prawn/graphics/cap_style.rb +2 -0
- data/lib/prawn/graphics/color.rb +8 -3
- data/lib/prawn/graphics/dash.rb +3 -1
- data/lib/prawn/graphics/join_style.rb +2 -0
- data/lib/prawn/graphics/patterns.rb +7 -2
- data/lib/prawn/graphics/transformation.rb +5 -1
- data/lib/prawn/graphics/transparency.rb +2 -0
- data/lib/prawn/grid.rb +39 -38
- data/lib/prawn/image_handler.rb +2 -0
- data/lib/prawn/images.rb +21 -19
- data/lib/prawn/images/image.rb +2 -0
- data/lib/prawn/images/jpg.rb +2 -0
- data/lib/prawn/images/png.rb +9 -9
- data/lib/prawn/measurement_extensions.rb +2 -0
- data/lib/prawn/measurements.rb +5 -0
- data/lib/prawn/outline.rb +2 -0
- data/lib/prawn/repeater.rb +2 -0
- data/lib/prawn/security.rb +26 -24
- data/lib/prawn/security/arcfour.rb +2 -0
- data/lib/prawn/soft_mask.rb +3 -1
- data/lib/prawn/stamp.rb +4 -1
- data/lib/prawn/text.rb +14 -12
- data/lib/prawn/text/box.rb +3 -1
- data/lib/prawn/text/formatted.rb +2 -0
- data/lib/prawn/text/formatted/arranger.rb +12 -12
- data/lib/prawn/text/formatted/box.rb +23 -13
- data/lib/prawn/text/formatted/fragment.rb +2 -0
- data/lib/prawn/text/formatted/line_wrap.rb +10 -8
- data/lib/prawn/text/formatted/parser.rb +8 -10
- data/lib/prawn/text/formatted/wrap.rb +4 -2
- data/lib/prawn/transformation_stack.rb +5 -2
- data/lib/prawn/utilities.rb +2 -2
- data/lib/prawn/version.rb +3 -1
- data/lib/prawn/view.rb +15 -7
- data/manual/basic_concepts/adding_pages.rb +2 -0
- data/manual/basic_concepts/basic_concepts.rb +4 -2
- data/manual/basic_concepts/creation.rb +2 -0
- data/manual/basic_concepts/cursor.rb +2 -0
- data/manual/basic_concepts/measurement.rb +3 -1
- data/manual/basic_concepts/origin.rb +2 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +2 -0
- data/manual/basic_concepts/view.rb +2 -0
- data/manual/bounding_box/bounding_box.rb +4 -2
- data/manual/bounding_box/bounds.rb +6 -4
- data/manual/bounding_box/canvas.rb +2 -0
- data/manual/bounding_box/creation.rb +2 -0
- data/manual/bounding_box/indentation.rb +2 -0
- data/manual/bounding_box/nesting.rb +2 -0
- data/manual/bounding_box/russian_boxes.rb +6 -4
- data/manual/bounding_box/stretchy.rb +2 -0
- data/manual/contents.rb +2 -0
- data/manual/cover.rb +10 -7
- data/manual/document_and_page_options/background.rb +2 -0
- data/manual/document_and_page_options/document_and_page_options.rb +4 -2
- data/manual/document_and_page_options/metadata.rb +2 -0
- data/manual/document_and_page_options/page_margins.rb +2 -0
- data/manual/document_and_page_options/page_size.rb +2 -0
- data/manual/document_and_page_options/print_scaling.rb +2 -0
- data/manual/example_helper.rb +5 -2
- data/manual/graphics/blend_mode.rb +6 -4
- data/manual/graphics/circle_and_ellipse.rb +2 -0
- data/manual/graphics/color.rb +2 -0
- data/manual/graphics/common_lines.rb +2 -0
- data/manual/graphics/fill_and_stroke.rb +2 -0
- data/manual/graphics/fill_rules.rb +2 -0
- data/manual/graphics/gradients.rb +2 -0
- data/manual/graphics/graphics.rb +4 -2
- data/manual/graphics/helper.rb +2 -0
- data/manual/graphics/line_width.rb +3 -0
- data/manual/graphics/lines_and_curves.rb +2 -0
- data/manual/graphics/polygon.rb +2 -0
- data/manual/graphics/rectangle.rb +2 -0
- data/manual/graphics/rotate.rb +2 -0
- data/manual/graphics/scale.rb +2 -0
- data/manual/graphics/soft_masks.rb +2 -0
- data/manual/graphics/stroke_cap.rb +3 -1
- data/manual/graphics/stroke_dash.rb +2 -0
- data/manual/graphics/stroke_join.rb +3 -1
- data/manual/graphics/translate.rb +2 -0
- data/manual/graphics/transparency.rb +2 -0
- data/manual/how_to_read_this_manual.rb +2 -0
- data/manual/images/absolute_position.rb +2 -0
- data/manual/images/fit.rb +2 -0
- data/manual/images/horizontal.rb +3 -1
- data/manual/images/images.rb +4 -2
- data/manual/images/plain_image.rb +2 -0
- data/manual/images/scale.rb +2 -0
- data/manual/images/vertical.rb +3 -1
- data/manual/images/width_and_height.rb +2 -0
- data/manual/layout/boxes.rb +2 -0
- data/manual/layout/content.rb +2 -0
- data/manual/layout/layout.rb +4 -2
- data/manual/layout/simple_grid.rb +2 -0
- data/manual/outline/add_subsection_to.rb +2 -0
- data/manual/outline/insert_section_after.rb +2 -0
- data/manual/outline/outline.rb +4 -2
- data/manual/outline/sections_and_pages.rb +2 -0
- data/manual/repeatable_content/alternate_page_numbering.rb +2 -0
- data/manual/repeatable_content/page_numbering.rb +2 -0
- data/manual/repeatable_content/repeatable_content.rb +4 -2
- data/manual/repeatable_content/repeater.rb +2 -0
- data/manual/repeatable_content/stamp.rb +2 -0
- data/manual/security/encryption.rb +2 -0
- data/manual/security/permissions.rb +2 -0
- data/manual/security/security.rb +4 -2
- data/manual/table.rb +2 -0
- data/manual/text/alignment.rb +2 -0
- data/manual/text/color.rb +2 -0
- data/manual/text/column_box.rb +4 -2
- data/manual/text/fallback_fonts.rb +4 -2
- data/manual/text/font.rb +2 -0
- data/manual/text/font_size.rb +2 -0
- data/manual/text/font_style.rb +4 -2
- data/manual/text/formatted_callbacks.rb +2 -0
- data/manual/text/formatted_text.rb +3 -1
- data/manual/text/free_flowing_text.rb +2 -0
- data/manual/text/inline.rb +2 -0
- data/manual/text/kerning_and_character_spacing.rb +2 -0
- data/manual/text/leading.rb +2 -0
- data/manual/text/line_wrapping.rb +4 -1
- data/manual/text/paragraph_indentation.rb +2 -0
- data/manual/text/positioned_text.rb +2 -0
- data/manual/text/registering_families.rb +4 -2
- data/manual/text/rendering_and_color.rb +2 -0
- data/manual/text/right_to_left_text.rb +2 -0
- data/manual/text/rotation.rb +3 -1
- data/manual/text/single_usage.rb +2 -0
- data/manual/text/text.rb +4 -3
- data/manual/text/text_box_excess.rb +2 -0
- data/manual/text/text_box_extensions.rb +2 -0
- data/manual/text/text_box_overflow.rb +3 -1
- data/manual/text/utf8.rb +3 -1
- data/manual/text/win_ansi_charset.rb +6 -3
- data/prawn.gemspec +14 -11
- data/spec/extensions/encoding_helpers.rb +4 -2
- data/spec/prawn/document/bounding_box_spec.rb +8 -8
- data/spec/prawn/document/column_box_spec.rb +2 -0
- data/spec/prawn/document/security_spec.rb +12 -9
- data/spec/prawn/document_annotations_spec.rb +2 -0
- data/spec/prawn/document_destinations_spec.rb +2 -0
- data/spec/prawn/document_grid_spec.rb +3 -0
- data/spec/prawn/document_reference_spec.rb +2 -0
- data/spec/prawn/document_span_spec.rb +2 -0
- data/spec/prawn/document_spec.rb +59 -14
- data/spec/prawn/font_metric_cache_spec.rb +2 -0
- data/spec/prawn/font_spec.rb +45 -16
- data/spec/prawn/graphics/blend_mode_spec.rb +4 -2
- data/spec/prawn/graphics/transparency_spec.rb +2 -0
- data/spec/prawn/graphics_spec.rb +40 -20
- data/spec/prawn/graphics_stroke_styles_spec.rb +2 -0
- data/spec/prawn/image_handler_spec.rb +2 -0
- data/spec/prawn/images/jpg_spec.rb +2 -0
- data/spec/prawn/images/png_spec.rb +2 -0
- data/spec/prawn/images_spec.rb +56 -2
- data/spec/prawn/measurements_extensions_spec.rb +2 -0
- data/spec/prawn/outline_spec.rb +6 -2
- data/spec/prawn/repeater_spec.rb +6 -4
- data/spec/prawn/soft_mask_spec.rb +2 -0
- data/spec/prawn/stamp_spec.rb +11 -7
- data/spec/prawn/text/box_spec.rb +26 -27
- data/spec/prawn/text/formatted/arranger_spec.rb +30 -28
- data/spec/prawn/text/formatted/box_spec.rb +78 -57
- data/spec/prawn/text/formatted/fragment_spec.rb +10 -8
- data/spec/prawn/text/formatted/line_wrap_spec.rb +8 -5
- data/spec/prawn/text/formatted/parser_spec.rb +32 -2
- data/spec/prawn/text_draw_text_spec.rb +5 -3
- data/spec/prawn/text_rendering_mode_spec.rb +7 -1
- data/spec/prawn/text_spacing_spec.rb +6 -4
- data/spec/prawn/text_spec.rb +9 -7
- data/spec/prawn/text_with_inline_formatting_spec.rb +3 -1
- data/spec/prawn/transformation_stack_spec.rb +2 -0
- data/spec/prawn/view_spec.rb +18 -0
- data/spec/{manual_spec.rb → prawn_manual_spec.rb} +6 -4
- data/spec/spec_helper.rb +9 -10
- metadata +86 -73
- metadata.gz.sig +4 -2
data/manual/text/font_style.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Most font families come with some styles other than normal. Most common are
|
2
4
|
# <code>bold</code>, <code>italic</code> and <code>bold_italic</code>.
|
3
5
|
#
|
@@ -9,10 +11,10 @@ require_relative '../example_helper'
|
|
9
11
|
|
10
12
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
11
13
|
Prawn::ManualBuilder::Example.generate(filename) do
|
12
|
-
[
|
14
|
+
%w[Courier Helvetica Times-Roman].each do |example_font|
|
13
15
|
move_down 20
|
14
16
|
|
15
|
-
[
|
17
|
+
%i[bold bold_italic italic normal].each do |style|
|
16
18
|
font example_font, style: style
|
17
19
|
text "I'm writing in #{example_font} (#{style})"
|
18
20
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# There are two other text methods available: <code>formatted_text</code> and
|
2
4
|
# <code>formatted_text_box</code>.
|
3
5
|
#
|
@@ -25,7 +27,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
25
27
|
formatted_text [
|
26
28
|
{ text: 'Some bold. ', styles: [:bold] },
|
27
29
|
{ text: 'Some italic. ', styles: [:italic] },
|
28
|
-
{ text: 'Bold italic. ', styles: [
|
30
|
+
{ text: 'Bold italic. ', styles: %i[bold italic] },
|
29
31
|
{ text: 'Bigger Text. ', size: 20 },
|
30
32
|
{ text: 'More spacing. ', character_spacing: 3 },
|
31
33
|
{ text: 'Different Font. ', font: 'Courier' },
|
data/manual/text/inline.rb
CHANGED
data/manual/text/leading.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Line wrapping happens on white space or hyphens. Soft hyphens can be used to
|
2
4
|
# indicate where words can be hyphenated. Non-breaking spaces can be used to
|
3
5
|
# display space without allowing for a break.
|
4
6
|
#
|
5
7
|
# For writing styles that do not make use of spaces, the zero width space serves
|
6
|
-
# to mark word boundaries. Zero width spaces are available only with
|
8
|
+
# to mark word boundaries. Zero width spaces are available only with external
|
9
|
+
# fonts.
|
7
10
|
|
8
11
|
require_relative '../example_helper'
|
9
12
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Registering font families will help you when you want to use a font over and
|
2
4
|
# over or if you would like to take advantage of the <code>:style</code> option
|
3
5
|
# of the text methods and the <code>b</code> and <code>i</code> tags when using
|
@@ -10,7 +12,7 @@ require_relative '../example_helper'
|
|
10
12
|
|
11
13
|
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
12
14
|
Prawn::ManualBuilder::Example.generate(filename) do
|
13
|
-
# Registering a single
|
15
|
+
# Registering a single external font
|
14
16
|
font_families.update(
|
15
17
|
'DejaVu Sans' => {
|
16
18
|
normal: "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
|
@@ -41,7 +43,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
41
43
|
inline_format: true
|
42
44
|
move_down 20
|
43
45
|
|
44
|
-
[
|
46
|
+
%i[bold bold_italic italic normal].each do |style|
|
45
47
|
text "Using the #{style} style option.",
|
46
48
|
style: style
|
47
49
|
move_down 10
|
data/manual/text/rotation.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Rotating text is best avoided on free flowing text, so this example
|
2
4
|
# will only use the <code>text_box</code> method as we can have much more
|
3
5
|
# control over its output.
|
@@ -29,7 +31,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
29
31
|
rotate: angle, rotate_around: :center
|
30
32
|
)
|
31
33
|
|
32
|
-
[
|
34
|
+
%i[lower_left upper_left lower_right upper_right]
|
33
35
|
.each_with_index do |corner, index|
|
34
36
|
y -= 100 if index == 2
|
35
37
|
stroke_rectangle [x + (index % 2) * 200, y], width, height
|
data/manual/text/single_usage.rb
CHANGED
data/manual/text/text.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Examples for text rendering.
|
2
4
|
|
3
5
|
require '../example_helper'
|
4
6
|
|
5
|
-
# rubocop: disable Metrics/LineLength
|
6
7
|
Prawn::ManualBuilder::Example.generate('text.pdf', page_size: 'FOLIO') do
|
7
8
|
package 'text' do |p|
|
8
9
|
p.section 'Basics' do |s|
|
@@ -47,14 +48,14 @@ Prawn::ManualBuilder::Example.generate('text.pdf', page_size: 'FOLIO') do
|
|
47
48
|
end
|
48
49
|
|
49
50
|
p.intro do
|
50
|
-
prose <<-
|
51
|
+
prose <<-TEXT
|
51
52
|
This is probably the feature people will use the most. There is no
|
52
53
|
shortage of options when it comes to text. You'll be hard pressed to
|
53
54
|
find a use case that is not covered by one of the text methods and
|
54
55
|
configurable options.
|
55
56
|
|
56
57
|
The examples show:
|
57
|
-
|
58
|
+
TEXT
|
58
59
|
|
59
60
|
list(
|
60
61
|
'Text that flows from page to page automatically starting new pages when necessary',
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# The <code>text_box</code> method accepts both <code>:width</code> and
|
2
4
|
# <code>:height</code> options. So what happens if the text doesn't fit the box?
|
3
5
|
#
|
@@ -24,7 +26,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
24
26
|
text string
|
25
27
|
|
26
28
|
y_position = cursor - 20
|
27
|
-
[
|
29
|
+
%i[truncate expand shrink_to_fit].each_with_index do |mode, i|
|
28
30
|
text_box string, at: [i * 150, y_position],
|
29
31
|
width: 100,
|
30
32
|
height: 50,
|
data/manual/text/utf8.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Multilingualization isn't much of a problem on Prawn as its default encoding
|
2
4
|
# is UTF-8. The only thing you need to worry about is if the font support the
|
3
5
|
# glyphs of your language.
|
@@ -15,7 +17,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
15
17
|
|
16
18
|
move_down 20
|
17
19
|
|
18
|
-
text 'For full internationalized text support, we need to use
|
20
|
+
text 'For full internationalized text support, we need to use external fonts:'
|
19
21
|
move_down 20
|
20
22
|
|
21
23
|
font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Prints a list of all of the glyphs that can be rendered by Adobe's built
|
2
4
|
# in fonts, along with their character widths and WinAnsi codes. Be sure
|
3
5
|
# to pass these glyphs as UTF-8, and Prawn will transcode them for you.
|
@@ -22,6 +24,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
22
24
|
|
23
25
|
Prawn::Encoding::WinAnsi::CHARACTERS.each_with_index do |name, index|
|
24
26
|
next if name == '.notdef'
|
27
|
+
|
25
28
|
y -= FONT_SIZE
|
26
29
|
|
27
30
|
if y < FONT_SIZE
|
@@ -29,11 +32,11 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
29
32
|
x += 170
|
30
33
|
end
|
31
34
|
|
32
|
-
code = format('
|
35
|
+
code = format('%<index>d.', index: index)
|
33
36
|
char = index.chr.force_encoding(::Encoding::Windows_1252)
|
34
37
|
|
35
38
|
width = 1000 * width_of(char, size: FONT_SIZE) / FONT_SIZE
|
36
|
-
size = format('
|
39
|
+
size = format('%<width>d', width: width)
|
37
40
|
|
38
41
|
data = [code, nil, char, size, nil, name]
|
39
42
|
dx = x
|
@@ -48,7 +51,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
|
|
48
51
|
end
|
49
52
|
|
50
53
|
text_box(
|
51
|
-
field.force_encoding('windows-1252').encode('UTF-8'),
|
54
|
+
field.dup.force_encoding('windows-1252').encode('UTF-8'),
|
52
55
|
at: [dx + offset, y]
|
53
56
|
)
|
54
57
|
end
|
data/prawn.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
basedir = __dir__
|
2
4
|
|
3
5
|
require "#{basedir}/lib/prawn/version"
|
4
6
|
|
@@ -10,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
10
12
|
|
11
13
|
spec.cert_chain = ['certs/pointlessone.pem']
|
12
14
|
if $PROGRAM_NAME.end_with? 'gem'
|
13
|
-
spec.signing_key = File.expand_path('~/.
|
15
|
+
spec.signing_key = File.expand_path('~/.gem/gem-private_key.pem')
|
14
16
|
end
|
15
17
|
|
16
18
|
spec.files = Dir.glob('{examples,lib,spec,manual}/**/**/*') +
|
@@ -21,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
21
23
|
'.yardopts'
|
22
24
|
]
|
23
25
|
spec.require_path = 'lib'
|
24
|
-
spec.required_ruby_version = '~> 2.
|
26
|
+
spec.required_ruby_version = '~> 2.5'
|
25
27
|
spec.required_rubygems_version = '>= 1.3.6'
|
26
28
|
|
27
29
|
spec.authors = [
|
@@ -34,18 +36,19 @@ Gem::Specification.new do |spec|
|
|
34
36
|
]
|
35
37
|
spec.licenses = %w[PRAWN GPL-2.0 GPL-3.0]
|
36
38
|
|
37
|
-
spec.add_dependency('
|
38
|
-
spec.add_dependency('
|
39
|
+
spec.add_dependency('pdf-core', '~> 0.8.1')
|
40
|
+
spec.add_dependency('ttfunk', '~> 1.6')
|
39
41
|
|
40
42
|
spec.add_development_dependency('pdf-inspector', '>= 1.2.1', '< 2.0.a')
|
41
|
-
spec.add_development_dependency('
|
42
|
-
spec.add_development_dependency('
|
43
|
+
spec.add_development_dependency('pdf-reader', ['~> 1.4', '>= 1.4.1'])
|
44
|
+
spec.add_development_dependency('prawn-manual_builder', '>= 0.3.0')
|
43
45
|
spec.add_development_dependency('rake', '~> 12.0')
|
46
|
+
spec.add_development_dependency('rspec', '~> 3.0')
|
47
|
+
spec.add_development_dependency('rubocop', '~> 0.84.0')
|
48
|
+
spec.add_development_dependency('rubocop-performance', '~> 1.1')
|
49
|
+
spec.add_development_dependency('rubocop-rspec', '~> 1.32')
|
44
50
|
spec.add_development_dependency('simplecov')
|
45
|
-
spec.add_development_dependency('
|
46
|
-
spec.add_development_dependency('pdf-reader', ['~> 1.4', '>= 1.4.1'])
|
47
|
-
spec.add_development_dependency('rubocop', '~> 0.47.1')
|
48
|
-
spec.add_development_dependency('rubocop-rspec', '~> 1.10')
|
51
|
+
spec.add_development_dependency('yard')
|
49
52
|
|
50
53
|
spec.homepage = 'http://prawnpdf.org'
|
51
54
|
spec.description = <<END_DESC
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module EncodingHelpers
|
2
4
|
def win1252_string(str)
|
3
|
-
str.force_encoding(Encoding::Windows_1252)
|
5
|
+
str.dup.force_encoding(Encoding::Windows_1252)
|
4
6
|
end
|
5
7
|
|
6
8
|
def bin_string(str)
|
7
|
-
str.force_encoding(Encoding::ASCII_8BIT)
|
9
|
+
str.dup.force_encoding(Encoding::ASCII_8BIT)
|
8
10
|
end
|
9
11
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Prawn::Document::BoundingBox do
|
@@ -183,8 +185,8 @@ describe Prawn::Document::BoundingBox do
|
|
183
185
|
expect(pdf.y).to be_within(0.001).of(orig_y - pdf.height_of('hello'))
|
184
186
|
end
|
185
187
|
|
186
|
-
it '
|
187
|
-
|
188
|
+
it 'does not advance y-position of a stretchy bbox if it would stretch '\
|
189
|
+
'the bbox further' do
|
188
190
|
bottom = pdf.y = pdf.margin_box.absolute_bottom
|
189
191
|
pdf.bounding_box [0, pdf.margin_box.top], width: pdf.bounds.width do
|
190
192
|
pdf.y = bottom
|
@@ -224,12 +226,10 @@ describe Prawn::Document::BoundingBox do
|
|
224
226
|
|
225
227
|
it 'restores the x coordinate and width on error' do
|
226
228
|
pdf.bounding_box([100, 100], width: 200) do
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
expect(pdf.bounds.width).to eq(200)
|
232
|
-
end
|
229
|
+
pdf.indent(20) { raise }
|
230
|
+
rescue StandardError
|
231
|
+
expect(pdf.bounds.absolute_left).to eq(100)
|
232
|
+
expect(pdf.bounds.width).to eq(200)
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'tempfile'
|
3
5
|
|
@@ -17,7 +19,7 @@ describe Prawn::Document::Security do
|
|
17
19
|
padded = pad_password(pw)
|
18
20
|
expect(padded.length).to eq(32)
|
19
21
|
expect(padded).to eq(
|
20
|
-
pw + Prawn::Document::Security::
|
22
|
+
pw + Prawn::Document::Security::PASSWORD_PADDING[0, 28]
|
21
23
|
)
|
22
24
|
end
|
23
25
|
|
@@ -25,7 +27,7 @@ describe Prawn::Document::Security do
|
|
25
27
|
pw = ''
|
26
28
|
padded = pad_password(pw)
|
27
29
|
expect(padded.length).to eq(32)
|
28
|
-
expect(padded).to eq(Prawn::Document::Security::
|
30
|
+
expect(padded).to eq(Prawn::Document::Security::PASSWORD_PADDING)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -33,10 +35,11 @@ describe Prawn::Document::Security do
|
|
33
35
|
def doc_with_permissions(permissions)
|
34
36
|
pdf = Prawn::Document.new
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
# Make things easier to test
|
39
|
+
pdf.singleton_class.send :public, :permissions_value
|
40
|
+
# class << pdf
|
41
|
+
# public :permissions_value
|
42
|
+
# end
|
40
43
|
|
41
44
|
pdf.encrypt_document(permissions: permissions)
|
42
45
|
pdf
|
@@ -90,17 +93,17 @@ describe Prawn::Document::Security do
|
|
90
93
|
end
|
91
94
|
|
92
95
|
it 'calculates the correct owner hash' do
|
93
|
-
expect(pdf.owner_password_hash.
|
96
|
+
expect(pdf.owner_password_hash.unpack1('H*'))
|
94
97
|
.to match(/^61CA855012/i)
|
95
98
|
end
|
96
99
|
|
97
100
|
it 'calculates the correct user hash' do
|
98
|
-
expect(pdf.user_password_hash.
|
101
|
+
expect(pdf.user_password_hash.unpack1('H*'))
|
99
102
|
.to match(/^6BC8C51031/i)
|
100
103
|
end
|
101
104
|
|
102
105
|
it 'calculates the correct user_encryption_key' do
|
103
|
-
expect(pdf.user_encryption_key.
|
106
|
+
expect(pdf.user_encryption_key.unpack1('H*').upcase)
|
104
107
|
.to eq('B100AB6429')
|
105
108
|
end
|
106
109
|
end
|