prawn 0.13.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +10 -0
- data/GPLv2 +20 -21
- data/Gemfile +3 -16
- data/Rakefile +17 -39
- data/lib/prawn/document/bounding_box.rb +85 -42
- data/lib/prawn/document/column_box.rb +21 -11
- data/lib/prawn/document/internals.rb +40 -147
- data/lib/prawn/document/span.rb +25 -17
- data/lib/prawn/document.rb +286 -245
- data/lib/prawn/encoding.rb +68 -101
- data/lib/prawn/errors.rb +47 -43
- data/lib/prawn/font.rb +204 -155
- data/lib/prawn/font_metric_cache.rb +25 -21
- data/lib/prawn/fonts/afm.rb +292 -0
- data/lib/prawn/{font → fonts}/dfont.rb +7 -13
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/fonts/ttc.rb +36 -0
- data/lib/prawn/{font → fonts}/ttf.rb +142 -80
- data/lib/prawn/graphics/blend_mode.rb +65 -0
- data/lib/prawn/graphics/cap_style.rb +6 -5
- data/lib/prawn/graphics/color.rb +47 -44
- data/lib/prawn/graphics/dash.rb +30 -13
- data/lib/prawn/graphics/join_style.rb +13 -6
- data/lib/prawn/graphics/patterns.rb +221 -90
- data/lib/prawn/graphics/transformation.rb +21 -12
- data/lib/prawn/graphics/transparency.rb +21 -17
- data/lib/prawn/graphics.rb +155 -128
- data/lib/prawn/{layout/grid.rb → grid.rb} +110 -47
- data/lib/prawn/image_handler.rb +16 -2
- data/lib/prawn/images/image.rb +4 -2
- data/lib/prawn/images/jpg.rb +39 -30
- data/lib/prawn/images/png.rb +132 -169
- data/lib/prawn/images.rb +70 -62
- data/lib/prawn/measurement_extensions.rb +15 -10
- data/lib/prawn/measurements.rb +22 -23
- data/lib/prawn/outline.rb +301 -13
- data/lib/prawn/repeater.rb +19 -17
- data/lib/prawn/security/arcfour.rb +54 -0
- data/lib/prawn/security.rb +108 -86
- data/lib/prawn/soft_mask.rb +40 -41
- data/lib/prawn/stamp.rb +29 -12
- data/lib/prawn/text/box.rb +27 -29
- data/lib/prawn/text/formatted/arranger.rb +110 -67
- data/lib/prawn/text/formatted/box.rb +233 -165
- data/lib/prawn/text/formatted/fragment.rb +27 -27
- data/lib/prawn/text/formatted/line_wrap.rb +137 -97
- data/lib/prawn/text/formatted/parser.rb +149 -127
- data/lib/prawn/text/formatted/wrap.rb +57 -37
- data/lib/prawn/text/formatted.rb +6 -4
- data/lib/prawn/text.rb +105 -73
- data/lib/prawn/transformation_stack.rb +44 -0
- data/lib/prawn/utilities.rb +11 -21
- data/lib/prawn/version.rb +5 -0
- data/lib/prawn/view.rb +101 -0
- data/lib/prawn.rb +42 -68
- data/{data/images/fractal.jpg → manual/absolute_position.pdf} +0 -0
- data/manual/basic_concepts/adding_pages.rb +9 -10
- data/manual/basic_concepts/basic_concepts.rb +33 -24
- data/manual/basic_concepts/creation.rb +10 -11
- data/manual/basic_concepts/cursor.rb +9 -10
- data/manual/basic_concepts/measurement.rb +10 -11
- data/manual/basic_concepts/origin.rb +8 -9
- data/manual/basic_concepts/other_cursor_helpers.rb +17 -18
- data/manual/basic_concepts/view.rb +48 -0
- data/manual/bounding_box/bounding_box.rb +31 -29
- data/manual/bounding_box/bounds.rb +17 -18
- data/manual/bounding_box/canvas.rb +8 -9
- data/manual/bounding_box/creation.rb +8 -9
- data/manual/bounding_box/indentation.rb +22 -23
- data/manual/bounding_box/nesting.rb +32 -25
- data/manual/bounding_box/russian_boxes.rb +19 -19
- data/manual/bounding_box/stretchy.rb +18 -20
- data/manual/contents.rb +35 -0
- data/manual/cover.rb +43 -0
- data/manual/document_and_page_options/background.rb +16 -14
- data/manual/document_and_page_options/document_and_page_options.rb +26 -23
- data/manual/document_and_page_options/metadata.rb +21 -19
- data/manual/document_and_page_options/page_margins.rb +20 -22
- data/manual/document_and_page_options/page_size.rb +15 -15
- data/manual/document_and_page_options/print_scaling.rb +23 -0
- data/manual/example_helper.rb +5 -408
- data/manual/graphics/blend_mode.rb +52 -0
- data/manual/graphics/circle_and_ellipse.rb +8 -9
- data/manual/graphics/color.rb +11 -13
- data/manual/graphics/common_lines.rb +13 -12
- data/manual/graphics/fill_and_stroke.rb +10 -11
- data/manual/graphics/fill_rules.rb +13 -12
- data/manual/graphics/gradients.rb +28 -22
- data/manual/graphics/graphics.rb +52 -46
- data/manual/graphics/helper.rb +20 -10
- data/manual/graphics/line_width.rb +13 -12
- data/manual/graphics/lines_and_curves.rb +13 -14
- data/manual/graphics/polygon.rb +10 -12
- data/manual/graphics/rectangle.rb +7 -8
- data/manual/graphics/rotate.rb +9 -12
- data/manual/graphics/scale.rb +19 -18
- data/manual/graphics/soft_masks.rb +5 -7
- data/manual/graphics/stroke_cap.rb +10 -11
- data/manual/graphics/stroke_dash.rb +16 -17
- data/manual/graphics/stroke_join.rb +10 -11
- data/manual/graphics/translate.rb +13 -13
- data/manual/graphics/transparency.rb +11 -13
- data/manual/{manual/how_to_read_this_manual.rb → how_to_read_this_manual.rb} +23 -25
- data/manual/images/absolute_position.rb +9 -10
- data/manual/images/fit.rb +9 -10
- data/manual/images/horizontal.rb +13 -14
- data/manual/images/images.rb +31 -30
- data/manual/images/plain_image.rb +6 -7
- data/manual/images/scale.rb +12 -13
- data/manual/images/vertical.rb +19 -17
- data/manual/images/width_and_height.rb +13 -14
- data/manual/layout/boxes.rb +14 -15
- data/manual/layout/content.rb +12 -13
- data/manual/layout/layout.rb +19 -20
- data/manual/layout/simple_grid.rb +8 -9
- data/manual/outline/add_subsection_to.rb +26 -27
- data/manual/outline/insert_section_after.rb +19 -20
- data/manual/outline/outline.rb +23 -22
- data/manual/outline/sections_and_pages.rb +24 -25
- data/manual/repeatable_content/alternate_page_numbering.rb +36 -0
- data/manual/repeatable_content/page_numbering.rb +20 -19
- data/manual/repeatable_content/repeatable_content.rb +26 -22
- data/manual/repeatable_content/repeater.rb +18 -19
- data/manual/repeatable_content/stamp.rb +18 -19
- data/manual/security/encryption.rb +8 -11
- data/manual/security/permissions.rb +20 -15
- data/manual/security/security.rb +20 -20
- data/manual/table.rb +16 -0
- data/manual/text/alignment.rb +17 -18
- data/manual/text/color.rb +13 -13
- data/manual/text/column_box.rb +10 -12
- data/manual/text/fallback_fonts.rb +29 -25
- data/manual/text/font.rb +17 -18
- data/manual/text/font_size.rb +21 -22
- data/manual/text/font_style.rb +12 -10
- data/manual/text/formatted_callbacks.rb +36 -26
- data/manual/text/formatted_text.rb +41 -34
- data/manual/text/free_flowing_text.rb +28 -29
- data/manual/text/inline.rb +23 -26
- data/manual/text/kerning_and_character_spacing.rb +20 -21
- data/manual/text/leading.rb +10 -11
- data/manual/text/line_wrapping.rb +40 -21
- data/manual/text/paragraph_indentation.rb +17 -12
- data/manual/text/positioned_text.rb +19 -20
- data/manual/text/registering_families.rb +33 -30
- data/manual/text/rendering_and_color.rb +11 -12
- data/manual/text/right_to_left_text.rb +31 -20
- data/manual/text/rotation.rb +36 -27
- data/manual/text/single_usage.rb +13 -14
- data/manual/text/text.rb +62 -62
- data/manual/text/text_box_excess.rb +22 -19
- data/manual/text/text_box_extensions.rb +21 -18
- data/manual/text/text_box_overflow.rb +28 -21
- data/manual/text/utf8.rb +16 -17
- data/manual/text/win_ansi_charset.rb +29 -26
- data/prawn.gemspec +45 -43
- data/spec/extensions/encoding_helpers.rb +4 -3
- data/spec/prawn/document/bounding_box_spec.rb +550 -0
- data/spec/prawn/document/column_box_spec.rb +75 -0
- data/spec/prawn/document/security_spec.rb +176 -0
- data/spec/prawn/document_annotations_spec.rb +76 -0
- data/spec/prawn/document_destinations_spec.rb +15 -0
- data/spec/prawn/document_grid_spec.rb +99 -0
- data/spec/prawn/document_reference_spec.rb +27 -0
- data/spec/prawn/document_span_spec.rb +44 -0
- data/spec/prawn/document_spec.rb +805 -0
- data/spec/prawn/font_metric_cache_spec.rb +54 -0
- data/spec/prawn/font_spec.rb +544 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
- data/spec/prawn/graphics/transparency_spec.rb +81 -0
- data/spec/prawn/graphics_spec.rb +872 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
- data/spec/prawn/image_handler_spec.rb +53 -0
- data/spec/prawn/images/jpg_spec.rb +20 -0
- data/spec/prawn/images/png_spec.rb +283 -0
- data/spec/prawn/images_spec.rb +229 -0
- data/spec/prawn/measurements_extensions_spec.rb +24 -0
- data/spec/prawn/outline_spec.rb +512 -0
- data/spec/prawn/repeater_spec.rb +166 -0
- data/spec/prawn/soft_mask_spec.rb +74 -0
- data/spec/prawn/stamp_spec.rb +173 -0
- data/spec/prawn/text/box_spec.rb +1110 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
- data/spec/prawn/text/formatted/box_spec.rb +849 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +495 -0
- data/spec/prawn/text/formatted/parser_spec.rb +697 -0
- data/spec/prawn/text_draw_text_spec.rb +150 -0
- data/spec/prawn/text_rendering_mode_spec.rb +48 -0
- data/spec/prawn/text_spacing_spec.rb +95 -0
- data/spec/prawn/text_spec.rb +603 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
- data/spec/prawn/transformation_stack_spec.rb +66 -0
- data/spec/prawn/view_spec.rb +63 -0
- data/spec/prawn_manual_spec.rb +35 -0
- data/spec/spec_helper.rb +22 -21
- data.tar.gz.sig +0 -0
- metadata +168 -307
- metadata.gz.sig +0 -0
- data/README.md +0 -109
- data/data/encodings/win_ansi.txt +0 -29
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.dat +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/barcode_issue.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.dat +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/lib/pdf/core/annotations.rb +0 -60
- data/lib/pdf/core/byte_string.rb +0 -9
- data/lib/pdf/core/destinations.rb +0 -90
- data/lib/pdf/core/document_state.rb +0 -78
- data/lib/pdf/core/filter_list.rb +0 -51
- data/lib/pdf/core/filters.rb +0 -36
- data/lib/pdf/core/graphics_state.rb +0 -68
- data/lib/pdf/core/literal_string.rb +0 -16
- data/lib/pdf/core/name_tree.rb +0 -177
- data/lib/pdf/core/object_store.rb +0 -320
- data/lib/pdf/core/outline.rb +0 -315
- data/lib/pdf/core/page.rb +0 -212
- data/lib/pdf/core/page_geometry.rb +0 -126
- data/lib/pdf/core/pdf_object.rb +0 -124
- data/lib/pdf/core/reference.rb +0 -103
- data/lib/pdf/core/stream.rb +0 -98
- data/lib/pdf/core/text.rb +0 -275
- data/lib/pdf/core.rb +0 -35
- data/lib/prawn/compatibility.rb +0 -91
- data/lib/prawn/document/graphics_state.rb +0 -73
- data/lib/prawn/document/snapshot.rb +0 -89
- data/lib/prawn/font/afm.rb +0 -203
- data/lib/prawn/layout.rb +0 -20
- data/lib/prawn/table/cell/image.rb +0 -70
- data/lib/prawn/table/cell/in_table.rb +0 -27
- data/lib/prawn/table/cell/span_dummy.rb +0 -92
- data/lib/prawn/table/cell/subtable.rb +0 -65
- data/lib/prawn/table/cell/text.rb +0 -153
- data/lib/prawn/table/cell.rb +0 -770
- data/lib/prawn/table/cells.rb +0 -295
- data/lib/prawn/table.rb +0 -643
- data/manual/example_file.rb +0 -116
- data/manual/example_package.rb +0 -53
- data/manual/example_section.rb +0 -46
- data/manual/manual/cover.rb +0 -35
- data/manual/manual/foreword.rb +0 -85
- data/manual/manual/manual.rb +0 -35
- data/manual/syntax_highlight.rb +0 -52
- data/manual/table/basic_block.rb +0 -53
- data/manual/table/before_rendering_page.rb +0 -26
- data/manual/table/cell_border_lines.rb +0 -24
- data/manual/table/cell_borders_and_bg.rb +0 -31
- data/manual/table/cell_dimensions.rb +0 -30
- data/manual/table/cell_text.rb +0 -38
- data/manual/table/column_widths.rb +0 -30
- data/manual/table/content_and_subtables.rb +0 -39
- data/manual/table/creation.rb +0 -27
- data/manual/table/filtering.rb +0 -36
- data/manual/table/flow_and_header.rb +0 -17
- data/manual/table/image_cells.rb +0 -33
- data/manual/table/position.rb +0 -29
- data/manual/table/row_colors.rb +0 -20
- data/manual/table/span.rb +0 -30
- data/manual/table/style.rb +0 -22
- data/manual/table/table.rb +0 -52
- data/manual/table/width.rb +0 -27
- data/manual/templates/full_template.rb +0 -25
- data/manual/templates/page_template.rb +0 -48
- data/manual/templates/templates.rb +0 -27
- data/manual/text/group.rb +0 -29
- data/spec/acceptance/png.rb +0 -23
- data/spec/annotations_spec.rb +0 -74
- data/spec/bounding_box_spec.rb +0 -493
- data/spec/cell_spec.rb +0 -628
- data/spec/column_box_spec.rb +0 -33
- data/spec/destinations_spec.rb +0 -15
- data/spec/document_spec.rb +0 -761
- data/spec/extensions/mocha.rb +0 -44
- data/spec/filters_spec.rb +0 -34
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -464
- data/spec/formatted_text_arranger_spec.rb +0 -421
- data/spec/formatted_text_box_spec.rb +0 -650
- data/spec/formatted_text_fragment_spec.rb +0 -298
- data/spec/graphics_spec.rb +0 -651
- data/spec/grid_spec.rb +0 -85
- data/spec/image_handler_spec.rb +0 -42
- data/spec/images_spec.rb +0 -157
- data/spec/inline_formatted_text_parser_spec.rb +0 -564
- data/spec/jpg_spec.rb +0 -25
- data/spec/line_wrap_spec.rb +0 -333
- data/spec/measurement_units_spec.rb +0 -23
- data/spec/name_tree_spec.rb +0 -112
- data/spec/object_store_spec.rb +0 -170
- data/spec/outline_spec.rb +0 -448
- data/spec/pdf_object_spec.rb +0 -172
- data/spec/png_spec.rb +0 -240
- data/spec/reference_spec.rb +0 -82
- data/spec/repeater_spec.rb +0 -158
- data/spec/security_spec.rb +0 -158
- data/spec/snapshot_spec.rb +0 -186
- data/spec/soft_mask_spec.rb +0 -117
- data/spec/span_spec.rb +0 -44
- data/spec/stamp_spec.rb +0 -158
- data/spec/stream_spec.rb +0 -58
- data/spec/stroke_styles_spec.rb +0 -211
- data/spec/table/span_dummy_spec.rb +0 -17
- data/spec/table_spec.rb +0 -1355
- data/spec/template_spec.rb +0 -351
- data/spec/text_at_spec.rb +0 -130
- data/spec/text_box_spec.rb +0 -1030
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -425
- data/spec/text_with_inline_formatting_spec.rb +0 -35
- data/spec/transparency_spec.rb +0 -89
data/lib/pdf/core/pdf_object.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# pdf_object.rb : Handles Ruby to PDF object serialization
|
4
|
-
#
|
5
|
-
# Copyright April 2008, Gregory Brown. All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
|
9
|
-
# Top level Module
|
10
|
-
#
|
11
|
-
module PDF
|
12
|
-
module Core
|
13
|
-
module_function
|
14
|
-
|
15
|
-
if "".respond_to?(:encode)
|
16
|
-
# Ruby 1.9+
|
17
|
-
def utf8_to_utf16(str)
|
18
|
-
"\xFE\xFF".force_encoding("UTF-16BE") + str.encode("UTF-16BE")
|
19
|
-
end
|
20
|
-
|
21
|
-
# encodes any string into a hex representation. The result is a string
|
22
|
-
# with only 0-9 and a-f characters. That result is valid ASCII so tag
|
23
|
-
# it as such to account for behaviour of different ruby VMs
|
24
|
-
def string_to_hex(str)
|
25
|
-
str.unpack("H*").first.force_encoding("ascii")
|
26
|
-
end
|
27
|
-
else
|
28
|
-
# Ruby 1.8
|
29
|
-
def utf8_to_utf16(str)
|
30
|
-
utf16 = "\xFE\xFF"
|
31
|
-
|
32
|
-
str.codepoints do |cp|
|
33
|
-
if cp < 0x10000 # Basic Multilingual Plane
|
34
|
-
utf16 << [cp].pack("n")
|
35
|
-
else
|
36
|
-
# pull out high/low 10 bits
|
37
|
-
hi, lo = (cp - 0x10000).divmod(2**10)
|
38
|
-
# encode a surrogate pair
|
39
|
-
utf16 << [0xD800 + hi, 0xDC00 + lo].pack("n*")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
utf16
|
44
|
-
end
|
45
|
-
|
46
|
-
def string_to_hex(str)
|
47
|
-
str.unpack("H*").first
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Serializes Ruby objects to their PDF equivalents. Most primitive objects
|
52
|
-
# will work as expected, but please note that Name objects are represented
|
53
|
-
# by Ruby Symbol objects and Dictionary objects are represented by Ruby hashes
|
54
|
-
# (keyed by symbols)
|
55
|
-
#
|
56
|
-
# Examples:
|
57
|
-
#
|
58
|
-
# PdfObject(true) #=> "true"
|
59
|
-
# PdfObject(false) #=> "false"
|
60
|
-
# PdfObject(1.2124) #=> "1.2124"
|
61
|
-
# PdfObject("foo bar") #=> "(foo bar)"
|
62
|
-
# PdfObject(:Symbol) #=> "/Symbol"
|
63
|
-
# PdfObject(["foo",:bar, [1,2]]) #=> "[foo /bar [1 2]]"
|
64
|
-
#
|
65
|
-
def PdfObject(obj, in_content_stream = false)
|
66
|
-
case(obj)
|
67
|
-
when NilClass then "null"
|
68
|
-
when TrueClass then "true"
|
69
|
-
when FalseClass then "false"
|
70
|
-
when Numeric
|
71
|
-
if (str = String(obj)) =~ /e/i
|
72
|
-
# scientific notation is not supported in PDF
|
73
|
-
sprintf("%.16f", obj).gsub(/\.?0+\z/, "")
|
74
|
-
else
|
75
|
-
str
|
76
|
-
end
|
77
|
-
when Array
|
78
|
-
"[" << obj.map { |e| PdfObject(e, in_content_stream) }.join(' ') << "]"
|
79
|
-
when PDF::Core::LiteralString
|
80
|
-
obj = obj.gsub(/[\\\n\r\t\b\f\(\)]/n) { |m| "\\#{m}" }
|
81
|
-
"(#{obj})"
|
82
|
-
when Time
|
83
|
-
obj = obj.strftime("D:%Y%m%d%H%M%S%z").chop.chop + "'00'"
|
84
|
-
obj = obj.gsub(/[\\\n\r\t\b\f\(\)]/n) { |m| "\\#{m}" }
|
85
|
-
"(#{obj})"
|
86
|
-
when PDF::Core::ByteString
|
87
|
-
"<" << obj.unpack("H*").first << ">"
|
88
|
-
when String
|
89
|
-
obj = utf8_to_utf16(obj) unless in_content_stream
|
90
|
-
"<" << string_to_hex(obj) << ">"
|
91
|
-
when Symbol
|
92
|
-
"/" + obj.to_s.unpack("C*").map { |n|
|
93
|
-
if n < 33 || n > 126 || [35,40,41,47,60,62].include?(n)
|
94
|
-
"#" + n.to_s(16).upcase
|
95
|
-
else
|
96
|
-
[n].pack("C*")
|
97
|
-
end
|
98
|
-
}.join
|
99
|
-
when ::Hash
|
100
|
-
output = "<< "
|
101
|
-
obj.each do |k,v|
|
102
|
-
unless String === k || Symbol === k
|
103
|
-
raise PDF::Core::Errors::FailedObjectConversion,
|
104
|
-
"A PDF Dictionary must be keyed by names"
|
105
|
-
end
|
106
|
-
output << PdfObject(k.to_sym, in_content_stream) << " " <<
|
107
|
-
PdfObject(v, in_content_stream) << "\n"
|
108
|
-
end
|
109
|
-
output << ">>"
|
110
|
-
when PDF::Core::Reference
|
111
|
-
obj.to_s
|
112
|
-
when PDF::Core::NameTree::Node
|
113
|
-
PdfObject(obj.to_hash)
|
114
|
-
when PDF::Core::NameTree::Value
|
115
|
-
PdfObject(obj.name) + " " + PdfObject(obj.value)
|
116
|
-
when PDF::Core::OutlineRoot, PDF::Core::OutlineItem
|
117
|
-
PdfObject(obj.to_hash)
|
118
|
-
else
|
119
|
-
raise PDF::Core::Errors::FailedObjectConversion,
|
120
|
-
"This object cannot be serialized to PDF (#{obj.inspect})"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
data/lib/pdf/core/reference.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# reference.rb : Implementation of PDF indirect objects
|
4
|
-
#
|
5
|
-
# Copyright April 2008, Gregory Brown. All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
|
9
|
-
|
10
|
-
module PDF
|
11
|
-
module Core
|
12
|
-
class Reference #:nodoc:
|
13
|
-
|
14
|
-
attr_accessor :gen, :data, :offset, :stream, :live, :identifier
|
15
|
-
|
16
|
-
def initialize(id, data)
|
17
|
-
@identifier = id
|
18
|
-
@gen = 0
|
19
|
-
@data = data
|
20
|
-
@stream = Stream.new
|
21
|
-
end
|
22
|
-
|
23
|
-
def object
|
24
|
-
output = "#{@identifier} #{gen} obj\n"
|
25
|
-
unless @stream.empty?
|
26
|
-
output << PDF::Core::PdfObject(data.merge @stream.data) << "\n" << @stream.object
|
27
|
-
else
|
28
|
-
output << PDF::Core::PdfObject(data) << "\n"
|
29
|
-
end
|
30
|
-
|
31
|
-
output << "endobj\n"
|
32
|
-
end
|
33
|
-
|
34
|
-
def <<(io)
|
35
|
-
raise "Cannot attach stream to non-dictionary object" unless @data.is_a?(::Hash)
|
36
|
-
(@stream ||= Stream.new) << io
|
37
|
-
end
|
38
|
-
|
39
|
-
def to_s
|
40
|
-
"#{@identifier} #{gen} R"
|
41
|
-
end
|
42
|
-
|
43
|
-
# Creates a deep copy of this ref. If +share+ is provided, shares the
|
44
|
-
# given dictionary entries between the old ref and the new.
|
45
|
-
#
|
46
|
-
def deep_copy(share=[])
|
47
|
-
r = dup
|
48
|
-
|
49
|
-
case r.data
|
50
|
-
when ::Hash
|
51
|
-
# Copy each entry not in +share+.
|
52
|
-
(r.data.keys - share).each do |k|
|
53
|
-
r.data[k] = Marshal.load(Marshal.dump(r.data[k]))
|
54
|
-
end
|
55
|
-
when PDF::Core::NameTree::Node
|
56
|
-
r.data = r.data.deep_copy
|
57
|
-
else
|
58
|
-
r.data = Marshal.load(Marshal.dump(r.data))
|
59
|
-
end
|
60
|
-
|
61
|
-
r.stream = Marshal.load(Marshal.dump(r.stream))
|
62
|
-
r
|
63
|
-
end
|
64
|
-
|
65
|
-
# Replaces the data and stream with that of other_ref.
|
66
|
-
def replace(other_ref)
|
67
|
-
@data = other_ref.data
|
68
|
-
@stream = other_ref.stream
|
69
|
-
end
|
70
|
-
|
71
|
-
# Marks this and all referenced objects live, recursively.
|
72
|
-
def mark_live
|
73
|
-
return if defined?(@live) && @live
|
74
|
-
@live = true
|
75
|
-
referenced_objects.each { |o| o.mark_live }
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
# All objects referenced by this one. Used for GC.
|
81
|
-
def referenced_objects(obj=@data)
|
82
|
-
case obj
|
83
|
-
when self.class
|
84
|
-
[]
|
85
|
-
when ::Hash
|
86
|
-
obj.values.map{|v| [v] + referenced_objects(v) }
|
87
|
-
when Array
|
88
|
-
obj.map{|v| [v] + referenced_objects(v) }
|
89
|
-
when PDF::Core::OutlineRoot, PDF::Core::OutlineItem
|
90
|
-
referenced_objects(obj.to_hash)
|
91
|
-
else []
|
92
|
-
end.flatten.grep(self.class)
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
module_function
|
98
|
-
|
99
|
-
def Reference(*args, &block) #:nodoc:
|
100
|
-
Reference.new(*args, &block)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
data/lib/pdf/core/stream.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# prawn/core/stream.rb : Implements Stream objects
|
4
|
-
#
|
5
|
-
# Copyright February 2013, Alexander Mankuta. All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
|
9
|
-
module PDF
|
10
|
-
module Core
|
11
|
-
class Stream
|
12
|
-
attr_reader :filters
|
13
|
-
|
14
|
-
def initialize(io = nil)
|
15
|
-
@filtered_stream = ''
|
16
|
-
@stream = io
|
17
|
-
@filters = FilterList.new
|
18
|
-
end
|
19
|
-
|
20
|
-
def <<(io)
|
21
|
-
(@stream ||= '') << io
|
22
|
-
@filtered_stream = nil
|
23
|
-
self
|
24
|
-
end
|
25
|
-
|
26
|
-
def compress!
|
27
|
-
unless @filters.names.include? :FlateDecode
|
28
|
-
@filtered_stream = nil
|
29
|
-
@filters << :FlateDecode
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def compressed?
|
34
|
-
@filters.names.include? :FlateDecode
|
35
|
-
end
|
36
|
-
|
37
|
-
def empty?
|
38
|
-
@stream.nil?
|
39
|
-
end
|
40
|
-
|
41
|
-
def filtered_stream
|
42
|
-
if @stream
|
43
|
-
if @filtered_stream.nil?
|
44
|
-
@filtered_stream = @stream.dup
|
45
|
-
|
46
|
-
@filters.each do |(filter_name, params)|
|
47
|
-
if filter = PDF::Core::Filters.const_get(filter_name)
|
48
|
-
@filtered_stream = filter.encode @filtered_stream, params
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
@filtered_stream
|
54
|
-
# XXX Fillter stream
|
55
|
-
else
|
56
|
-
nil
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def length
|
61
|
-
@stream.length
|
62
|
-
end
|
63
|
-
|
64
|
-
def object
|
65
|
-
if filtered_stream
|
66
|
-
"stream\n#{filtered_stream}\nendstream\n"
|
67
|
-
else
|
68
|
-
''
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def data
|
73
|
-
if @stream
|
74
|
-
filter_names = @filters.names
|
75
|
-
filter_params = @filters.decode_params
|
76
|
-
|
77
|
-
d = {
|
78
|
-
:Length => filtered_stream.length
|
79
|
-
}
|
80
|
-
if filter_names.any?
|
81
|
-
d[:Filter] = filter_names
|
82
|
-
end
|
83
|
-
if filter_params.any? {|f| !f.nil? }
|
84
|
-
d[:DecodeParms] = filter_params
|
85
|
-
end
|
86
|
-
|
87
|
-
d
|
88
|
-
else
|
89
|
-
{}
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def inspect
|
94
|
-
"#<#{self.class.name}:0x#{'%014x' % object_id} @stream=#{@stream.inspect}, @filters=#{@filters.inspect}>"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
data/lib/pdf/core/text.rb
DELETED
@@ -1,275 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# prawn/core/text.rb : Implements low level text helpers for Prawn
|
4
|
-
#
|
5
|
-
# Copyright January 2010, Daniel Nelson. All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
|
9
|
-
module PDF
|
10
|
-
module Core
|
11
|
-
module Text #:nodoc:
|
12
|
-
|
13
|
-
# These should be used as a base. Extensions may build on this list
|
14
|
-
#
|
15
|
-
VALID_OPTIONS = [:kerning, :size, :style]
|
16
|
-
MODES = { :fill => 0, :stroke => 1, :fill_stroke => 2, :invisible => 3,
|
17
|
-
:fill_clip => 4, :stroke_clip => 5, :fill_stroke_clip => 6,
|
18
|
-
:clip => 7 }
|
19
|
-
|
20
|
-
attr_reader :skip_encoding
|
21
|
-
|
22
|
-
# Low level text placement method. All font and size alterations
|
23
|
-
# should already be set
|
24
|
-
#
|
25
|
-
def draw_text!(text, options)
|
26
|
-
x,y = map_to_absolute(options[:at])
|
27
|
-
add_text_content(text,x,y,options)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Low level call to set the current font style and extract text options from
|
31
|
-
# an options hash. Should be called from within a save_font block
|
32
|
-
#
|
33
|
-
def process_text_options(options)
|
34
|
-
if options[:style]
|
35
|
-
raise "Bad font family" unless font.family
|
36
|
-
font(font.family, :style => options[:style])
|
37
|
-
end
|
38
|
-
|
39
|
-
# must compare against false to keep kerning on as default
|
40
|
-
unless options[:kerning] == false
|
41
|
-
options[:kerning] = font.has_kerning_data?
|
42
|
-
end
|
43
|
-
|
44
|
-
options[:size] ||= font_size
|
45
|
-
end
|
46
|
-
|
47
|
-
# Retrieve the current default kerning setting.
|
48
|
-
#
|
49
|
-
# Defaults to true
|
50
|
-
#
|
51
|
-
def default_kerning?
|
52
|
-
return true if !defined?(@default_kerning)
|
53
|
-
@default_kerning
|
54
|
-
end
|
55
|
-
|
56
|
-
# Call with a boolean to set the document-wide kerning setting. This can be
|
57
|
-
# overridden using the :kerning text option when drawing text or a text
|
58
|
-
# box.
|
59
|
-
#
|
60
|
-
# pdf.default_kerning = false
|
61
|
-
# pdf.text("hello world") # text is not kerned
|
62
|
-
# pdf.text("hello world", :kerning => true) # text is kerned
|
63
|
-
#
|
64
|
-
def default_kerning(boolean)
|
65
|
-
@default_kerning = boolean
|
66
|
-
end
|
67
|
-
|
68
|
-
alias_method :default_kerning=, :default_kerning
|
69
|
-
|
70
|
-
# Call with no argument to retrieve the current default leading.
|
71
|
-
#
|
72
|
-
# Call with a number to set the document-wide text leading. This can be
|
73
|
-
# overridden using the :leading text option when drawing text or a text
|
74
|
-
# box.
|
75
|
-
#
|
76
|
-
# pdf.default_leading = 7
|
77
|
-
# pdf.text("hello world") # a leading of 7 is used
|
78
|
-
# pdf.text("hello world", :leading => 0) # a leading of 0 is used
|
79
|
-
#
|
80
|
-
# Defaults to 0
|
81
|
-
#
|
82
|
-
def default_leading(number=nil)
|
83
|
-
if number.nil?
|
84
|
-
defined?(@default_leading) && @default_leading || 0
|
85
|
-
else
|
86
|
-
@default_leading = number
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
alias_method :default_leading=, :default_leading
|
91
|
-
|
92
|
-
# Call with no argument to retrieve the current text direction.
|
93
|
-
#
|
94
|
-
# Call with a symbol to set the document-wide text direction. This can be
|
95
|
-
# overridden using the :direction text option when drawing text or a text
|
96
|
-
# box.
|
97
|
-
#
|
98
|
-
# pdf.text_direction = :rtl
|
99
|
-
# pdf.text("hello world") # prints "dlrow olleh"
|
100
|
-
# pdf.text("hello world", :direction => :ltr) # prints "hello world"
|
101
|
-
#
|
102
|
-
# Valid directions are:
|
103
|
-
#
|
104
|
-
# * :ltr - left-to-right (default)
|
105
|
-
# * :rtl - right-to-left
|
106
|
-
#
|
107
|
-
# Side effects:
|
108
|
-
#
|
109
|
-
# * When printing left-to-right, the default text alignment is :left
|
110
|
-
# * When printing right-to-left, the default text alignment is :right
|
111
|
-
#
|
112
|
-
def text_direction(direction=nil)
|
113
|
-
if direction.nil?
|
114
|
-
defined?(@text_direction) && @text_direction || :ltr
|
115
|
-
else
|
116
|
-
@text_direction = direction
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
alias_method :text_direction=, :text_direction
|
121
|
-
|
122
|
-
# Call with no argument to retrieve the current fallback fonts.
|
123
|
-
#
|
124
|
-
# Call with an array of font names. Each name must be the name of an AFM
|
125
|
-
# font or the name that was used to register a family of TTF fonts (see
|
126
|
-
# Prawn::Document#font_families). If present, then each glyph will be
|
127
|
-
# rendered using the first font that includes the glyph, starting with the
|
128
|
-
# current font and then moving through :fallback_fonts from left to right.
|
129
|
-
#
|
130
|
-
# Call with an empty array to turn off fallback fonts
|
131
|
-
#
|
132
|
-
# file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
133
|
-
# font_families["Kai"] = {
|
134
|
-
# :normal => { :file => file, :font => "Kai" }
|
135
|
-
# }
|
136
|
-
# file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
|
137
|
-
# font_families["Action Man"] = {
|
138
|
-
# :normal => { :file => file, :font => "ActionMan" },
|
139
|
-
# }
|
140
|
-
# fallback_fonts ["Times-Roman", "Kai"]
|
141
|
-
# font "Action Man"
|
142
|
-
# text "hello ƒ 你好"
|
143
|
-
# > hello prints in Action Man
|
144
|
-
# > ƒ prints in Times-Roman
|
145
|
-
# > 你好 prints in Kai
|
146
|
-
#
|
147
|
-
# fallback_fonts [] # clears document-wide fallback fonts
|
148
|
-
#
|
149
|
-
# Side effects:
|
150
|
-
#
|
151
|
-
# * Increased overhead when fallback fonts are declared as each glyph is
|
152
|
-
# checked to see whether it exists in the current font
|
153
|
-
#
|
154
|
-
def fallback_fonts(fallback_fonts=nil)
|
155
|
-
if fallback_fonts.nil?
|
156
|
-
defined?(@fallback_fonts) && @fallback_fonts || []
|
157
|
-
else
|
158
|
-
@fallback_fonts = fallback_fonts
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
alias_method :fallback_fonts=, :fallback_fonts
|
163
|
-
|
164
|
-
# Call with no argument to retrieve the current text rendering mode.
|
165
|
-
#
|
166
|
-
# Call with a symbol and block to temporarily change the current
|
167
|
-
# text rendering mode.
|
168
|
-
#
|
169
|
-
# pdf.text_rendering_mode(:stroke) do
|
170
|
-
# pdf.text("Outlined Text")
|
171
|
-
# end
|
172
|
-
#
|
173
|
-
# Valid modes are:
|
174
|
-
#
|
175
|
-
# * :fill - fill text (default)
|
176
|
-
# * :stroke - stroke text
|
177
|
-
# * :fill_stroke - fill, then stroke text
|
178
|
-
# * :invisible - invisible text
|
179
|
-
# * :fill_clip - fill text then add to path for clipping
|
180
|
-
# * :stroke_clip - stroke text then add to path for clipping
|
181
|
-
# * :fill_stroke_clip - fill then stroke text, then add to path for clipping
|
182
|
-
# * :clip - add text to path for clipping
|
183
|
-
#
|
184
|
-
# There's the special mode :unknown which only occurs when we're working
|
185
|
-
# with templates. If left in :unknown, the first text command will force
|
186
|
-
# an assertion to :fill.
|
187
|
-
def text_rendering_mode(mode=nil)
|
188
|
-
return (defined?(@text_rendering_mode) && @text_rendering_mode || :fill) if mode.nil?
|
189
|
-
unless MODES.key?(mode)
|
190
|
-
raise ArgumentError, "mode must be between one of #{MODES.keys.join(', ')} (#{mode})"
|
191
|
-
end
|
192
|
-
original_mode = self.text_rendering_mode
|
193
|
-
if original_mode == :unknown
|
194
|
-
original_mode = :fill
|
195
|
-
add_content "\n#{MODES[:fill]} Tr"
|
196
|
-
end
|
197
|
-
if original_mode == mode
|
198
|
-
yield
|
199
|
-
else
|
200
|
-
@text_rendering_mode = mode
|
201
|
-
add_content "\n#{MODES[mode]} Tr"
|
202
|
-
yield
|
203
|
-
add_content "\n#{MODES[original_mode]} Tr"
|
204
|
-
@text_rendering_mode = original_mode
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
def forget_text_rendering_mode!
|
209
|
-
@text_rendering_mode = :unknown
|
210
|
-
end
|
211
|
-
|
212
|
-
# Increases or decreases the space between characters.
|
213
|
-
# For horizontal text, a positive value will increase the space.
|
214
|
-
# For veritical text, a positive value will decrease the space.
|
215
|
-
#
|
216
|
-
def character_spacing(amount=nil)
|
217
|
-
return defined?(@character_spacing) && @character_spacing || 0 if amount.nil?
|
218
|
-
original_character_spacing = character_spacing
|
219
|
-
if original_character_spacing == amount
|
220
|
-
yield
|
221
|
-
else
|
222
|
-
@character_spacing = amount
|
223
|
-
add_content "\n%.3f Tc" % amount
|
224
|
-
yield
|
225
|
-
add_content "\n%.3f Tc" % original_character_spacing
|
226
|
-
@character_spacing = original_character_spacing
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
# Increases or decreases the space between words.
|
231
|
-
# For horizontal text, a positive value will increase the space.
|
232
|
-
# For veritical text, a positive value will decrease the space.
|
233
|
-
#
|
234
|
-
def word_spacing(amount=nil)
|
235
|
-
return defined?(@word_spacing) && @word_spacing || 0 if amount.nil?
|
236
|
-
original_word_spacing = word_spacing
|
237
|
-
if original_word_spacing == amount
|
238
|
-
yield
|
239
|
-
else
|
240
|
-
@word_spacing = amount
|
241
|
-
add_content "\n%.3f Tw" % amount
|
242
|
-
yield
|
243
|
-
add_content "\n%.3f Tw" % original_word_spacing
|
244
|
-
@word_spacing = original_word_spacing
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
private
|
249
|
-
|
250
|
-
def add_text_content(text, x, y, options)
|
251
|
-
chunks = font.encode_text(text,options)
|
252
|
-
|
253
|
-
add_content "\nBT"
|
254
|
-
|
255
|
-
if options[:rotate]
|
256
|
-
rad = options[:rotate].to_f * Math::PI / 180
|
257
|
-
arr = [ Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), x, y ]
|
258
|
-
add_content "%.3f %.3f %.3f %.3f %.3f %.3f Tm" % arr
|
259
|
-
else
|
260
|
-
add_content "#{x} #{y} Td"
|
261
|
-
end
|
262
|
-
|
263
|
-
chunks.each do |(subset, string)|
|
264
|
-
font.add_to_current_page(subset)
|
265
|
-
add_content "/#{font.identifier_for(subset)} #{font_size} Tf"
|
266
|
-
|
267
|
-
operation = options[:kerning] && string.is_a?(Array) ? "TJ" : "Tj"
|
268
|
-
add_content PDF::Core::PdfObject(string, true) << " " << operation
|
269
|
-
end
|
270
|
-
|
271
|
-
add_content "ET\n"
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
data/lib/pdf/core.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require_relative "core/pdf_object"
|
2
|
-
require_relative "core/annotations"
|
3
|
-
require_relative "core/byte_string"
|
4
|
-
require_relative "core/destinations"
|
5
|
-
require_relative "core/filters"
|
6
|
-
require_relative "core/stream"
|
7
|
-
require_relative "core/reference"
|
8
|
-
require_relative "core/literal_string"
|
9
|
-
require_relative "core/filter_list"
|
10
|
-
require_relative "core/page"
|
11
|
-
require_relative "core/object_store"
|
12
|
-
require_relative "core/document_state"
|
13
|
-
require_relative "core/name_tree"
|
14
|
-
require_relative "core/graphics_state"
|
15
|
-
require_relative "core/page_geometry"
|
16
|
-
require_relative "core/outline"
|
17
|
-
|
18
|
-
module PDF
|
19
|
-
module Core
|
20
|
-
module Errors
|
21
|
-
# This error is raised when PdfObject() fails
|
22
|
-
FailedObjectConversion = Class.new(StandardError)
|
23
|
-
|
24
|
-
# This error is raised when object store fails to load a template file
|
25
|
-
TemplateError = Class.new(StandardError)
|
26
|
-
|
27
|
-
# This error is raise when trying to restore a graphic state that
|
28
|
-
EmptyGraphicStateStack = Class.new(StandardError)
|
29
|
-
|
30
|
-
# This error is raised when Document#page_layout is set to anything
|
31
|
-
# other than :portrait or :landscape
|
32
|
-
InvalidPageLayout = Class.new(StandardError)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|