prawn 0.11.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +10 -0
- data/COPYING +2 -2
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/Gemfile +11 -0
- data/LICENSE +1 -1
- data/Rakefile +29 -38
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn/document/bounding_box.rb +87 -12
- data/lib/prawn/document/column_box.rb +57 -28
- data/lib/prawn/document/graphics_state.rb +11 -74
- data/lib/prawn/document/internals.rb +25 -23
- data/lib/prawn/document/snapshot.rb +11 -8
- data/lib/prawn/document/span.rb +12 -10
- data/lib/prawn/document.rb +250 -194
- data/lib/prawn/encoding.rb +9 -10
- data/lib/prawn/errors.rb +18 -29
- data/lib/prawn/font/afm.rb +52 -41
- data/lib/prawn/font/dfont.rb +4 -3
- data/lib/prawn/font/ttf.rb +44 -48
- data/lib/prawn/font.rb +138 -88
- data/lib/prawn/font_metric_cache.rb +47 -0
- data/lib/prawn/graphics/cap_style.rb +4 -3
- data/lib/prawn/graphics/color.rb +13 -5
- data/lib/prawn/graphics/dash.rb +53 -31
- data/lib/prawn/graphics/join_style.rb +9 -7
- data/lib/prawn/graphics/patterns.rb +138 -0
- data/lib/prawn/graphics/transformation.rb +10 -9
- data/lib/prawn/graphics/transparency.rb +3 -1
- data/lib/prawn/graphics.rb +316 -61
- data/lib/prawn/image_handler.rb +36 -0
- data/lib/prawn/images/image.rb +49 -0
- data/lib/prawn/images/jpg.rb +21 -15
- data/lib/prawn/images/png.rb +62 -119
- data/lib/prawn/images.rb +89 -108
- data/lib/prawn/layout/grid.rb +66 -54
- data/lib/prawn/layout.rb +10 -15
- data/lib/prawn/measurement_extensions.rb +10 -6
- data/lib/prawn/measurements.rb +27 -21
- data/lib/prawn/outline.rb +6 -308
- data/lib/prawn/repeater.rb +11 -9
- data/lib/prawn/security/arcfour.rb +1 -0
- data/lib/prawn/security.rb +55 -33
- data/lib/prawn/soft_mask.rb +96 -0
- data/lib/prawn/stamp.rb +5 -3
- data/lib/prawn/table/cell/image.rb +69 -0
- data/lib/prawn/table/cell/in_table.rb +4 -2
- data/lib/prawn/table/cell/span_dummy.rb +93 -0
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +44 -26
- data/lib/prawn/table/cell.rb +302 -50
- data/lib/prawn/table/cells.rb +147 -49
- data/lib/prawn/table/column_width_calculator.rb +61 -0
- data/lib/prawn/table.rb +297 -118
- data/lib/prawn/text/box.rb +21 -5
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +103 -59
- data/lib/prawn/text/formatted/fragment.rb +34 -23
- data/lib/prawn/text/formatted/line_wrap.rb +266 -0
- data/lib/prawn/text/formatted/parser.rb +15 -5
- data/lib/prawn/text/formatted/wrap.rb +150 -0
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text.rb +38 -24
- data/lib/prawn/utilities.rb +46 -0
- data/lib/prawn.rb +85 -20
- data/manual/basic_concepts/adding_pages.rb +27 -0
- data/manual/basic_concepts/basic_concepts.rb +34 -0
- data/manual/basic_concepts/creation.rb +39 -0
- data/manual/basic_concepts/cursor.rb +33 -0
- data/manual/basic_concepts/measurement.rb +25 -0
- data/manual/basic_concepts/origin.rb +38 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
- data/manual/bounding_box/bounding_box.rb +39 -0
- data/manual/bounding_box/bounds.rb +49 -0
- data/manual/bounding_box/canvas.rb +24 -0
- data/manual/bounding_box/creation.rb +23 -0
- data/manual/bounding_box/indentation.rb +46 -0
- data/manual/bounding_box/nesting.rb +45 -0
- data/manual/bounding_box/russian_boxes.rb +40 -0
- data/manual/bounding_box/stretchy.rb +31 -0
- data/manual/document_and_page_options/background.rb +27 -0
- data/manual/document_and_page_options/document_and_page_options.rb +32 -0
- data/manual/document_and_page_options/metadata.rb +23 -0
- data/manual/document_and_page_options/page_margins.rb +38 -0
- data/manual/document_and_page_options/page_size.rb +34 -0
- data/manual/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_file.rb +111 -0
- data/manual/example_helper.rb +411 -0
- data/manual/example_package.rb +53 -0
- data/manual/example_section.rb +46 -0
- data/manual/graphics/circle_and_ellipse.rb +22 -0
- data/manual/graphics/color.rb +24 -0
- data/manual/graphics/common_lines.rb +30 -0
- data/manual/graphics/fill_and_stroke.rb +42 -0
- data/manual/graphics/fill_rules.rb +37 -0
- data/manual/graphics/gradients.rb +37 -0
- data/manual/graphics/graphics.rb +58 -0
- data/manual/graphics/helper.rb +24 -0
- data/manual/graphics/line_width.rb +35 -0
- data/manual/graphics/lines_and_curves.rb +41 -0
- data/manual/graphics/polygon.rb +29 -0
- data/manual/graphics/rectangle.rb +21 -0
- data/manual/graphics/rotate.rb +28 -0
- data/manual/graphics/scale.rb +41 -0
- data/manual/graphics/soft_masks.rb +46 -0
- data/manual/graphics/stroke_cap.rb +31 -0
- data/manual/graphics/stroke_dash.rb +48 -0
- data/manual/graphics/stroke_join.rb +30 -0
- data/manual/graphics/translate.rb +29 -0
- data/manual/graphics/transparency.rb +35 -0
- data/manual/images/absolute_position.rb +23 -0
- data/manual/images/fit.rb +21 -0
- data/manual/images/horizontal.rb +25 -0
- data/manual/images/images.rb +40 -0
- data/manual/images/plain_image.rb +18 -0
- data/manual/images/scale.rb +22 -0
- data/manual/images/vertical.rb +28 -0
- data/manual/images/width_and_height.rb +25 -0
- data/manual/layout/boxes.rb +27 -0
- data/manual/layout/content.rb +25 -0
- data/manual/layout/layout.rb +28 -0
- data/manual/layout/simple_grid.rb +23 -0
- data/manual/manual/cover.rb +36 -0
- data/manual/manual/foreword.rb +85 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +34 -0
- data/manual/outline/add_subsection_to.rb +61 -0
- data/manual/outline/insert_section_after.rb +47 -0
- data/manual/outline/outline.rb +32 -0
- data/manual/outline/sections_and_pages.rb +67 -0
- data/manual/repeatable_content/page_numbering.rb +54 -0
- data/manual/repeatable_content/repeatable_content.rb +31 -0
- data/manual/repeatable_content/repeater.rb +55 -0
- data/manual/repeatable_content/stamp.rb +41 -0
- data/manual/security/encryption.rb +31 -0
- data/manual/security/permissions.rb +38 -0
- data/manual/security/security.rb +28 -0
- data/manual/syntax_highlight.rb +52 -0
- data/manual/table/basic_block.rb +53 -0
- data/manual/table/before_rendering_page.rb +26 -0
- data/manual/table/cell_border_lines.rb +24 -0
- data/manual/table/cell_borders_and_bg.rb +31 -0
- data/manual/table/cell_dimensions.rb +30 -0
- data/manual/table/cell_text.rb +38 -0
- data/manual/table/column_widths.rb +30 -0
- data/manual/table/content_and_subtables.rb +39 -0
- data/manual/table/creation.rb +27 -0
- data/manual/table/filtering.rb +36 -0
- data/manual/table/flow_and_header.rb +17 -0
- data/manual/table/image_cells.rb +33 -0
- data/manual/table/position.rb +29 -0
- data/manual/table/row_colors.rb +20 -0
- data/manual/table/span.rb +30 -0
- data/manual/table/style.rb +22 -0
- data/manual/table/table.rb +52 -0
- data/manual/table/width.rb +27 -0
- data/manual/text/alignment.rb +44 -0
- data/manual/text/color.rb +24 -0
- data/manual/text/column_box.rb +32 -0
- data/manual/text/fallback_fonts.rb +37 -0
- data/manual/text/font.rb +41 -0
- data/manual/text/font_size.rb +45 -0
- data/manual/text/font_style.rb +23 -0
- data/manual/text/formatted_callbacks.rb +60 -0
- data/manual/text/formatted_text.rb +54 -0
- data/manual/text/free_flowing_text.rb +51 -0
- data/manual/text/group.rb +31 -0
- data/manual/text/inline.rb +43 -0
- data/manual/text/kerning_and_character_spacing.rb +39 -0
- data/manual/text/leading.rb +25 -0
- data/manual/text/line_wrapping.rb +41 -0
- data/manual/text/paragraph_indentation.rb +26 -0
- data/manual/text/positioned_text.rb +38 -0
- data/manual/text/registering_families.rb +48 -0
- data/manual/text/rendering_and_color.rb +37 -0
- data/manual/text/right_to_left_text.rb +43 -0
- data/manual/text/rotation.rb +43 -0
- data/manual/text/single_usage.rb +37 -0
- data/manual/text/text.rb +75 -0
- data/manual/text/text_box_excess.rb +32 -0
- data/manual/text/text_box_extensions.rb +45 -0
- data/manual/text/text_box_overflow.rb +44 -0
- data/manual/text/utf8.rb +28 -0
- data/{examples/m17n → manual/text}/win_ansi_charset.rb +14 -10
- data/prawn.gemspec +27 -17
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +284 -2
- data/spec/cell_spec.rb +169 -38
- data/spec/column_box_spec.rb +65 -0
- data/spec/data/curves.pdf +66 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +212 -113
- data/spec/extensions/encoding_helpers.rb +9 -0
- data/spec/extensions/mocha.rb +2 -3
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +205 -95
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +63 -24
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +175 -68
- data/spec/grid_spec.rb +26 -15
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +58 -30
- data/spec/inline_formatted_text_parser_spec.rb +73 -19
- data/spec/jpg_spec.rb +4 -4
- data/spec/line_wrap_spec.rb +28 -28
- data/spec/measurement_units_spec.rb +6 -6
- data/spec/object_store_spec.rb +17 -106
- data/spec/outline_spec.rb +103 -63
- data/spec/png_spec.rb +25 -25
- data/spec/reference_spec.rb +8 -65
- data/spec/repeater_spec.rb +25 -11
- data/spec/security_spec.rb +44 -12
- data/spec/snapshot_spec.rb +38 -6
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +10 -15
- data/spec/spec_helper.rb +32 -8
- data/spec/stamp_spec.rb +29 -30
- data/spec/stroke_styles_spec.rb +36 -18
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +850 -104
- data/spec/text_at_spec.rb +19 -33
- data/spec/text_box_spec.rb +117 -64
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +20 -2
- data/spec/text_spec.rb +111 -59
- data/spec/transparency_spec.rb +5 -5
- metadata +477 -328
- data/HACKING +0 -50
- data/README +0 -141
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/examples/bounding_box/bounding_boxes.rb +0 -44
- data/examples/bounding_box/indentation.rb +0 -35
- data/examples/bounding_box/russian_boxes.rb +0 -37
- data/examples/bounding_box/stretched_nesting.rb +0 -68
- data/examples/example_helper.rb +0 -8
- data/examples/general/background.rb +0 -24
- data/examples/general/canvas.rb +0 -16
- data/examples/general/context_sensitive_headers.rb +0 -38
- data/examples/general/float.rb +0 -12
- data/examples/general/margin.rb +0 -37
- data/examples/general/measurement_units.rb +0 -52
- data/examples/general/metadata-info.rb +0 -17
- data/examples/general/multi_page_layout.rb +0 -19
- data/examples/general/outlines.rb +0 -67
- data/examples/general/page_geometry.rb +0 -32
- data/examples/general/page_numbering.rb +0 -40
- data/examples/general/page_templates.rb +0 -20
- data/examples/general/repeaters.rb +0 -48
- data/examples/general/stamp.rb +0 -42
- data/examples/general/templates.rb +0 -14
- data/examples/graphics/basic_images.rb +0 -24
- data/examples/graphics/cmyk.rb +0 -13
- data/examples/graphics/curves.rb +0 -12
- data/examples/graphics/gradient.rb +0 -23
- data/examples/graphics/hexagon.rb +0 -14
- data/examples/graphics/image_fit.rb +0 -16
- data/examples/graphics/image_flow.rb +0 -38
- data/examples/graphics/image_position.rb +0 -18
- data/examples/graphics/line.rb +0 -33
- data/examples/graphics/png_types.rb +0 -23
- data/examples/graphics/polygons.rb +0 -17
- data/examples/graphics/remote_images.rb +0 -13
- data/examples/graphics/rounded_polygons.rb +0 -20
- data/examples/graphics/rounded_rectangle.rb +0 -21
- data/examples/graphics/ruport_style_helpers.rb +0 -20
- data/examples/graphics/stroke_bounds.rb +0 -21
- data/examples/graphics/stroke_cap_and_join.rb +0 -46
- data/examples/graphics/stroke_dash.rb +0 -43
- data/examples/graphics/transformations.rb +0 -53
- data/examples/graphics/transparency.rb +0 -27
- data/examples/grid/bounding_boxes.rb +0 -22
- data/examples/grid/column_gutter_grid.rb +0 -21
- data/examples/grid/multi_boxes.rb +0 -52
- data/examples/grid/show_grid.rb +0 -14
- data/examples/grid/simple_grid.rb +0 -21
- data/examples/m17n/chinese_text_wrapping.rb +0 -18
- data/examples/m17n/euro.rb +0 -16
- data/examples/m17n/full_win_ansi_character_list.rb +0 -20
- data/examples/m17n/sjis.rb +0 -29
- data/examples/m17n/utf8.rb +0 -14
- data/examples/security/hello_foo.rb +0 -9
- data/examples/table/bill.rb +0 -54
- data/examples/table/borders.rb +0 -25
- data/examples/table/cell.rb +0 -13
- data/examples/table/checkerboard.rb +0 -23
- data/examples/table/header.rb +0 -15
- data/examples/table/inline_format_table.rb +0 -13
- data/examples/table/multi_page_table.rb +0 -10
- data/examples/table/simple_table.rb +0 -25
- data/examples/table/subtable.rb +0 -13
- data/examples/table/widths.rb +0 -21
- data/examples/text/alignment.rb +0 -19
- data/examples/text/character_spacing.rb +0 -13
- data/examples/text/dfont.rb +0 -49
- data/examples/text/family_based_styling.rb +0 -25
- data/examples/text/font_calculations.rb +0 -92
- data/examples/text/font_size.rb +0 -34
- data/examples/text/hyphenation.rb +0 -45
- data/examples/text/indent_paragraphs.rb +0 -24
- data/examples/text/inline_format.rb +0 -104
- data/examples/text/kerning.rb +0 -31
- data/examples/text/rendering_mode.rb +0 -21
- data/examples/text/rotated.rb +0 -99
- data/examples/text/shaped_text_box.rb +0 -32
- data/examples/text/simple_text.rb +0 -18
- data/examples/text/simple_text_ttf.rb +0 -18
- data/examples/text/span.rb +0 -30
- data/examples/text/text_box.rb +0 -90
- data/examples/text/text_box_returning_excess.rb +0 -52
- data/examples/text/text_flow.rb +0 -68
- data/lib/prawn/compatibility.rb +0 -51
- data/lib/prawn/core/annotations.rb +0 -61
- data/lib/prawn/core/byte_string.rb +0 -9
- data/lib/prawn/core/destinations.rb +0 -90
- data/lib/prawn/core/document_state.rb +0 -78
- data/lib/prawn/core/literal_string.rb +0 -16
- data/lib/prawn/core/name_tree.rb +0 -165
- data/lib/prawn/core/object_store.rb +0 -264
- data/lib/prawn/core/page.rb +0 -213
- data/lib/prawn/core/pdf_object.rb +0 -108
- data/lib/prawn/core/reference.rb +0 -112
- data/lib/prawn/core/text/formatted/arranger.rb +0 -293
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -272
- data/lib/prawn/core/text/formatted/wrap.rb +0 -149
- data/lib/prawn/core/text.rb +0 -268
- data/lib/prawn/core.rb +0 -85
- data/lib/prawn/document/page_geometry.rb +0 -136
- data/lib/prawn/graphics/gradient.rb +0 -84
- data/spec/name_tree_spec.rb +0 -112
- data/spec/pdf_object_spec.rb +0 -170
- data/spec/template_spec.rb +0 -291
data/lib/prawn/core/text.rb
DELETED
@@ -1,268 +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 Prawn
|
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 @default_kerning.nil?
|
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
|
-
return 0 if @default_leading.nil?
|
85
|
-
@default_leading
|
86
|
-
else
|
87
|
-
@default_leading = number
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
alias_method :default_leading=, :default_leading
|
92
|
-
|
93
|
-
# Call with no argument to retrieve the current text direction.
|
94
|
-
#
|
95
|
-
# Call with a symbol to set the document-wide text direction. This can be
|
96
|
-
# overridden using the :direction text option when drawing text or a text
|
97
|
-
# box.
|
98
|
-
#
|
99
|
-
# pdf.text_direction = :rtl
|
100
|
-
# pdf.text("hello world") # prints "dlrow olleh"
|
101
|
-
# pdf.text("hello world", :direction => :ltr) # prints "hello world"
|
102
|
-
#
|
103
|
-
# Valid directions are:
|
104
|
-
#
|
105
|
-
# * :ltr - left-to-right (default)
|
106
|
-
# * :rtl - right-to-left
|
107
|
-
#
|
108
|
-
# Side effects:
|
109
|
-
#
|
110
|
-
# * When printing left-to-right, the default text alignment is :left
|
111
|
-
# * When printing right-to-left, the default text alignment is :right
|
112
|
-
#
|
113
|
-
def text_direction(direction=nil)
|
114
|
-
if direction.nil?
|
115
|
-
return :ltr if @text_direction.nil?
|
116
|
-
@text_direction
|
117
|
-
else
|
118
|
-
@text_direction = direction
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
alias_method :text_direction=, :text_direction
|
123
|
-
|
124
|
-
# Call with no argument to retrieve the current fallback fonts.
|
125
|
-
#
|
126
|
-
# Call with an array of font names. Each name must be the name of an AFM
|
127
|
-
# font or the name that was used to register a family of TTF fonts (see
|
128
|
-
# Prawn::Document#font_families). If present, then each glyph will be
|
129
|
-
# rendered using the first font that includes the glyph, starting with the
|
130
|
-
# current font and then moving through :fallback_fonts from left to right.
|
131
|
-
#
|
132
|
-
# Call with an empty array to turn off fallback fonts
|
133
|
-
#
|
134
|
-
# file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
135
|
-
# font_families["Kai"] = {
|
136
|
-
# :normal => { :file => file, :font => "Kai" }
|
137
|
-
# }
|
138
|
-
# file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
|
139
|
-
# font_families["Action Man"] = {
|
140
|
-
# :normal => { :file => file, :font => "ActionMan" },
|
141
|
-
# }
|
142
|
-
# fallback_fonts ["Times-Roman", "Kai"]
|
143
|
-
# font "Action Man"
|
144
|
-
# text "hello ƒ 你好"
|
145
|
-
# > hello prints in Action Man
|
146
|
-
# > ƒ prints in Times-Roman
|
147
|
-
# > 你好 prints in Kai
|
148
|
-
#
|
149
|
-
# fallback_fonts [] # clears document-wide fallback fonts
|
150
|
-
#
|
151
|
-
# Side effects:
|
152
|
-
#
|
153
|
-
# * Increased overhead when fallback fonts are declared as each glyph is
|
154
|
-
# checked to see whether it exists in the current font
|
155
|
-
#
|
156
|
-
def fallback_fonts(fallback_fonts=nil)
|
157
|
-
if fallback_fonts.nil?
|
158
|
-
return [] if @fallback_fonts.nil?
|
159
|
-
@fallback_fonts
|
160
|
-
else
|
161
|
-
@fallback_fonts = fallback_fonts
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
alias_method :fallback_fonts=, :fallback_fonts
|
166
|
-
|
167
|
-
# Call with no argument to retrieve the current text rendering mode.
|
168
|
-
#
|
169
|
-
# Call with a symbol and block to temporarily change the current
|
170
|
-
# text rendering mode.
|
171
|
-
#
|
172
|
-
# pdf.text_rendering_mode(:stroke) do
|
173
|
-
# pdf.text("Outlined Text")
|
174
|
-
# end
|
175
|
-
#
|
176
|
-
# Valid modes are:
|
177
|
-
#
|
178
|
-
# * :fill - fill text (default)
|
179
|
-
# * :stroke - stroke text
|
180
|
-
# * :fill_stroke - fill, then stroke text
|
181
|
-
# * :invisible - invisible text
|
182
|
-
# * :fill_clip - fill text then add to path for clipping
|
183
|
-
# * :stroke_clip - stroke text then add to path for clipping
|
184
|
-
# * :fill_stroke_clip - fill then stroke text, then add to path for clipping
|
185
|
-
# * :clip - add text to path for clipping
|
186
|
-
#
|
187
|
-
def text_rendering_mode(mode=nil)
|
188
|
-
return @text_rendering_mode || :fill if mode.nil?
|
189
|
-
unless MODES.keys.include?(mode)
|
190
|
-
raise ArgumentError, "mode must be between one of #{MODES.keys.join(', ')} (#{mode})"
|
191
|
-
end
|
192
|
-
original_mode = text_rendering_mode
|
193
|
-
if original_mode == mode
|
194
|
-
yield
|
195
|
-
else
|
196
|
-
@text_rendering_mode = mode
|
197
|
-
add_content "\n#{MODES[mode]} Tr"
|
198
|
-
yield
|
199
|
-
add_content "\n#{MODES[original_mode]} Tr"
|
200
|
-
@text_rendering_mode = original_mode
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
# Increases or decreases the space between characters.
|
205
|
-
# For horizontal text, a positive value will increase the space.
|
206
|
-
# For veritical text, a positive value will decrease the space.
|
207
|
-
#
|
208
|
-
def character_spacing(amount=nil)
|
209
|
-
return @character_spacing || 0 if amount.nil?
|
210
|
-
original_character_spacing = character_spacing
|
211
|
-
if original_character_spacing == amount
|
212
|
-
yield
|
213
|
-
else
|
214
|
-
@character_spacing = amount
|
215
|
-
add_content "\n%.3f Tc" % amount
|
216
|
-
yield
|
217
|
-
add_content "\n%.3f Tc" % original_character_spacing
|
218
|
-
@character_spacing = original_character_spacing
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
# Increases or decreases the space between words.
|
223
|
-
# For horizontal text, a positive value will increase the space.
|
224
|
-
# For veritical text, a positive value will decrease the space.
|
225
|
-
#
|
226
|
-
def word_spacing(amount=nil)
|
227
|
-
return @word_spacing || 0 if amount.nil?
|
228
|
-
original_word_spacing = word_spacing
|
229
|
-
if original_word_spacing == amount
|
230
|
-
yield
|
231
|
-
else
|
232
|
-
@word_spacing = amount
|
233
|
-
add_content "\n%.3f Tw" % amount
|
234
|
-
yield
|
235
|
-
add_content "\n%.3f Tw" % original_word_spacing
|
236
|
-
@word_spacing = original_word_spacing
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
private
|
241
|
-
|
242
|
-
def add_text_content(text, x, y, options)
|
243
|
-
chunks = font.encode_text(text,options)
|
244
|
-
|
245
|
-
add_content "\nBT"
|
246
|
-
|
247
|
-
if options[:rotate]
|
248
|
-
rad = options[:rotate].to_f * Math::PI / 180
|
249
|
-
arr = [ Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), x, y ]
|
250
|
-
add_content "%.3f %.3f %.3f %.3f %.3f %.3f Tm" % arr
|
251
|
-
else
|
252
|
-
add_content "#{x} #{y} Td"
|
253
|
-
end
|
254
|
-
|
255
|
-
chunks.each do |(subset, string)|
|
256
|
-
font.add_to_current_page(subset)
|
257
|
-
add_content "/#{font.identifier_for(subset)} #{font_size} Tf"
|
258
|
-
|
259
|
-
operation = options[:kerning] && string.is_a?(Array) ? "TJ" : "Tj"
|
260
|
-
add_content Prawn::Core::PdfObject(string, true) << " " << operation
|
261
|
-
end
|
262
|
-
|
263
|
-
add_content "ET\n"
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
end
|
268
|
-
end
|
data/lib/prawn/core.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# Prawn : A library for PDF generation in Ruby
|
3
|
-
#
|
4
|
-
# Copyright April 2008, Gregory Brown. All Rights Reserved.
|
5
|
-
#
|
6
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
7
|
-
|
8
|
-
require "set"
|
9
|
-
|
10
|
-
%w[ttfunk/lib].each do |dep|
|
11
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../../vendor/#{dep}")
|
12
|
-
end
|
13
|
-
|
14
|
-
begin
|
15
|
-
require 'ttfunk'
|
16
|
-
rescue LoadError
|
17
|
-
puts "Failed to load ttfunk. If you are running Prawn from git:"
|
18
|
-
puts " git submodule init"
|
19
|
-
puts " git submodule update"
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
|
23
|
-
module Prawn
|
24
|
-
extend self
|
25
|
-
|
26
|
-
file = __FILE__
|
27
|
-
file = File.readlink(file) if File.symlink?(file)
|
28
|
-
dir = File.dirname(file)
|
29
|
-
|
30
|
-
# The base source directory for Prawn as installed on the system
|
31
|
-
#
|
32
|
-
BASEDIR = File.expand_path(File.join(dir, '..', '..'))
|
33
|
-
|
34
|
-
# Whe set to true, Prawn will verify hash options to ensure only valid keys
|
35
|
-
# are used. Off by default.
|
36
|
-
#
|
37
|
-
# Example:
|
38
|
-
# >> Prawn::Document.new(:tomato => "Juicy")
|
39
|
-
# Prawn::Errors::UnknownOption:
|
40
|
-
# Detected unknown option(s): [:tomato]
|
41
|
-
# Accepted options are: [:page_size, :page_layout, :left_margin, ...]
|
42
|
-
#
|
43
|
-
attr_accessor :debug
|
44
|
-
|
45
|
-
def verify_options(accepted, actual) #:nodoc:
|
46
|
-
return unless debug || $DEBUG
|
47
|
-
unless (act=Set[*actual.keys]).subset?(acc=Set[*accepted])
|
48
|
-
raise Prawn::Errors::UnknownOption,
|
49
|
-
"\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" <<
|
50
|
-
"Accepted options are: #{accepted.inspect}"
|
51
|
-
end
|
52
|
-
yield if block_given?
|
53
|
-
end
|
54
|
-
|
55
|
-
module Configurable #:nodoc:
|
56
|
-
def configuration(*args)
|
57
|
-
@config ||= Marshal.load(Marshal.dump(default_configuration))
|
58
|
-
if Hash === args[0]
|
59
|
-
@config.update(args[0])
|
60
|
-
elsif args.length > 1
|
61
|
-
@config.values_at(*args)
|
62
|
-
elsif args.length == 1
|
63
|
-
@config[args[0]]
|
64
|
-
else
|
65
|
-
@config
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
alias_method :C, :configuration
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
require "prawn/compatibility"
|
74
|
-
require "prawn/errors"
|
75
|
-
require "prawn/core/pdf_object"
|
76
|
-
require "prawn/core/reference"
|
77
|
-
require "prawn/core/page"
|
78
|
-
require "prawn/core/object_store"
|
79
|
-
require "prawn/core/document_state"
|
80
|
-
require "prawn/core/literal_string"
|
81
|
-
require "prawn/core/byte_string"
|
82
|
-
require "prawn/core/name_tree"
|
83
|
-
require "prawn/core/annotations"
|
84
|
-
require "prawn/core/destinations"
|
85
|
-
|
@@ -1,136 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# page_geometry.rb : Describes PDF page geometries
|
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
|
-
module Prawn
|
10
|
-
class Document
|
11
|
-
|
12
|
-
# Dimensions pulled from PDF::Writer, rubyforge.org/projects/ruby-pdf
|
13
|
-
#
|
14
|
-
# All of these dimensions are in PDF Points, see Prawn::Measurements for
|
15
|
-
# conversion utilities.
|
16
|
-
#
|
17
|
-
# Additionally, if the size you are after is not listed below, you can always
|
18
|
-
# specify your size by passing an array of width and height to Prawn::Document.new
|
19
|
-
# like:
|
20
|
-
#
|
21
|
-
# Prawn::Document.new(:page_size => [1000, 20000])
|
22
|
-
#
|
23
|
-
# The sizes below can be used by passing the appropriate string to :size:
|
24
|
-
#
|
25
|
-
# Prawn::Document.new(:page_size => '2A0')
|
26
|
-
#
|
27
|
-
# ===Inbuilt Sizes:
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# 4A0:: => 4767.87 x 6740.79
|
31
|
-
# 2A0:: => 3370.39 x 4767.87
|
32
|
-
# A0:: => 2383.94 x 3370.39
|
33
|
-
# A1:: => 1683.78 x 2383.94
|
34
|
-
# A2:: => 1190.55 x 1683.78
|
35
|
-
# A3:: => 841.89 x 1190.55
|
36
|
-
# A4:: => 595.28 x 841.89
|
37
|
-
# A5:: => 419.53 x 595.28
|
38
|
-
# A6:: => 297.64 x 419.53
|
39
|
-
# A7:: => 209.76 x 297.64
|
40
|
-
# A8:: => 147.40 x 209.76
|
41
|
-
# A9:: => 104.88 x 147.40
|
42
|
-
# A10:: => 73.70 x 104.88
|
43
|
-
# B0:: => 2834.65 x 4008.19
|
44
|
-
# B1:: => 2004.09 x 2834.65
|
45
|
-
# B2:: => 1417.32 x 2004.09
|
46
|
-
# B3:: => 1000.63 x 1417.32
|
47
|
-
# B4:: => 708.66 x 1000.63
|
48
|
-
# B5:: => 498.90 x 708.66
|
49
|
-
# B6:: => 354.33 x 498.90
|
50
|
-
# B7:: => 249.45 x 354.33
|
51
|
-
# B8:: => 175.75 x 249.45
|
52
|
-
# B9:: => 124.72 x 175.75
|
53
|
-
# B10:: => 87.87 x 124.72
|
54
|
-
# C0:: => 2599.37 x 3676.54
|
55
|
-
# C1:: => 1836.85 x 2599.37
|
56
|
-
# C2:: => 1298.27 x 1836.85
|
57
|
-
# C3:: => 918.43 x 1298.27
|
58
|
-
# C4:: => 649.13 x 918.43
|
59
|
-
# C5:: => 459.21 x 649.13
|
60
|
-
# C6:: => 323.15 x 459.21
|
61
|
-
# C7:: => 229.61 x 323.15
|
62
|
-
# C8:: => 161.57 x 229.61
|
63
|
-
# C9:: => 113.39 x 161.57
|
64
|
-
# C10:: => 79.37 x 113.39
|
65
|
-
# RA0:: => 2437.80 x 3458.27
|
66
|
-
# RA1:: => 1729.13 x 2437.80
|
67
|
-
# RA2:: => 1218.90 x 1729.13
|
68
|
-
# RA3:: => 864.57 x 1218.90
|
69
|
-
# RA4:: => 609.45 x 864.57
|
70
|
-
# SRA0:: => 2551.18 x 3628.35
|
71
|
-
# SRA1:: => 1814.17 x 2551.18
|
72
|
-
# SRA2:: => 1275.59 x 1814.17
|
73
|
-
# SRA3:: => 907.09 x 1275.59
|
74
|
-
# SRA4:: => 637.80 x 907.09
|
75
|
-
# EXECUTIVE:: => 521.86 x 756.00
|
76
|
-
# FOLIO:: => 612.00 x 936.00
|
77
|
-
# LEGAL:: => 612.00 x 1008.00
|
78
|
-
# LETTER:: => 612.00 x 792.00
|
79
|
-
# TABLOID:: => 792.00 x 1224.00
|
80
|
-
#
|
81
|
-
module PageGeometry
|
82
|
-
|
83
|
-
SIZES = { "4A0" => [4767.87, 6740.79],
|
84
|
-
"2A0" => [3370.39, 4767.87],
|
85
|
-
"A0" => [2383.94, 3370.39],
|
86
|
-
"A1" => [1683.78, 2383.94],
|
87
|
-
"A2" => [1190.55, 1683.78],
|
88
|
-
"A3" => [841.89, 1190.55],
|
89
|
-
"A4" => [595.28, 841.89],
|
90
|
-
"A5" => [419.53, 595.28],
|
91
|
-
"A6" => [297.64, 419.53],
|
92
|
-
"A7" => [209.76, 297.64],
|
93
|
-
"A8" => [147.40, 209.76],
|
94
|
-
"A9" => [104.88, 147.40],
|
95
|
-
"A10" => [73.70, 104.88],
|
96
|
-
"B0" => [2834.65, 4008.19],
|
97
|
-
"B1" => [2004.09, 2834.65],
|
98
|
-
"B2" => [1417.32, 2004.09],
|
99
|
-
"B3" => [1000.63, 1417.32],
|
100
|
-
"B4" => [708.66, 1000.63],
|
101
|
-
"B5" => [498.90, 708.66],
|
102
|
-
"B6" => [354.33, 498.90],
|
103
|
-
"B7" => [249.45, 354.33],
|
104
|
-
"B8" => [175.75, 249.45],
|
105
|
-
"B9" => [124.72, 175.75],
|
106
|
-
"B10" => [87.87, 124.72],
|
107
|
-
"C0" => [2599.37, 3676.54],
|
108
|
-
"C1" => [1836.85, 2599.37],
|
109
|
-
"C2" => [1298.27, 1836.85],
|
110
|
-
"C3" => [918.43, 1298.27],
|
111
|
-
"C4" => [649.13, 918.43],
|
112
|
-
"C5" => [459.21, 649.13],
|
113
|
-
"C6" => [323.15, 459.21],
|
114
|
-
"C7" => [229.61, 323.15],
|
115
|
-
"C8" => [161.57, 229.61],
|
116
|
-
"C9" => [113.39, 161.57],
|
117
|
-
"C10" => [79.37, 113.39],
|
118
|
-
"RA0" => [2437.80, 3458.27],
|
119
|
-
"RA1" => [1729.13, 2437.80],
|
120
|
-
"RA2" => [1218.90, 1729.13],
|
121
|
-
"RA3" => [864.57, 1218.90],
|
122
|
-
"RA4" => [609.45, 864.57],
|
123
|
-
"SRA0" => [2551.18, 3628.35],
|
124
|
-
"SRA1" => [1814.17, 2551.18],
|
125
|
-
"SRA2" => [1275.59, 1814.17],
|
126
|
-
"SRA3" => [907.09, 1275.59],
|
127
|
-
"SRA4" => [637.80, 907.09],
|
128
|
-
"EXECUTIVE" => [521.86, 756.00],
|
129
|
-
"FOLIO" => [612.00, 936.00],
|
130
|
-
"LEGAL" => [612.00, 1008.00],
|
131
|
-
"LETTER" => [612.00, 792.00],
|
132
|
-
"TABLOID" => [792.00, 1224.00] }
|
133
|
-
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# gradient.rb : Implements axial gradient
|
4
|
-
#
|
5
|
-
# Contributed by Wojciech Piekutowski. November, 2009
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
#
|
9
|
-
module Prawn
|
10
|
-
module Graphics
|
11
|
-
module Gradient
|
12
|
-
# Sets the fill gradient from color1 to color2.
|
13
|
-
#
|
14
|
-
# It accepts CMYK and RGB colors, like #fill_color. Both colors must be
|
15
|
-
# of the same type.
|
16
|
-
#
|
17
|
-
# point, width and height define a bounding box in which the gradient
|
18
|
-
# will be rendered. For example, if you want to have page full of text
|
19
|
-
# with gradually changing color:
|
20
|
-
#
|
21
|
-
# pdf.fill_gradient [0, pdf.bounds.height], pdf.bounds.width,
|
22
|
-
# pdf.bounds.height, 'FF0000', '0000FF'
|
23
|
-
# pdf.text 'lots of text'*1000
|
24
|
-
#
|
25
|
-
# <tt>:stroke_bounds</tt> - draw gradient bounds
|
26
|
-
def fill_gradient(point, width, height, color1, color2, options = {})
|
27
|
-
set_gradient(:fill, point, width, height, color1, color2, options)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Sets the stroke gradient from color1 to color2.
|
31
|
-
#
|
32
|
-
# See #fill_gradient for details.
|
33
|
-
def stroke_gradient(point, width, height, color1, color2, options = {})
|
34
|
-
set_gradient(:stroke, point, width, height, color1, color2, options)
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def set_gradient(type, point, width, height, color1, color2, options)
|
40
|
-
if options[:stroke_bounds]
|
41
|
-
stroke_color 0, 0, 0, 100
|
42
|
-
stroke_rectangle point, width, height
|
43
|
-
end
|
44
|
-
|
45
|
-
if color_type(color1) != color_type(color2)
|
46
|
-
raise ArgumentError, 'both colors must be of the same type: RGB or CMYK'
|
47
|
-
end
|
48
|
-
|
49
|
-
process_color color1
|
50
|
-
process_color color2
|
51
|
-
|
52
|
-
shader = ref!({
|
53
|
-
:FunctionType => 2,
|
54
|
-
:Domain => [0.0, 1.0],
|
55
|
-
:C0 => normalize_color(color1),
|
56
|
-
:C1 => normalize_color(color2),
|
57
|
-
:N => 1,
|
58
|
-
})
|
59
|
-
|
60
|
-
shading = ref!({
|
61
|
-
:ShadingType => 2, # axial shading
|
62
|
-
:ColorSpace => color_type(color1) == :RGB ? :DeviceRGB : :DeviceCMYK,
|
63
|
-
:Coords => [0.0, 0.0, 1.0, 0.0],
|
64
|
-
:Function => shader,
|
65
|
-
:Extend => [true, true],
|
66
|
-
})
|
67
|
-
|
68
|
-
x, y = *point
|
69
|
-
shading_pattern = ref!({
|
70
|
-
:PatternType => 2, # shading pattern
|
71
|
-
:Shading => shading,
|
72
|
-
:Matrix => [0,-height, -width, 0, x, y],
|
73
|
-
})
|
74
|
-
|
75
|
-
patterns = page.resources[:Pattern] ||= {}
|
76
|
-
id = patterns.empty? ? 'SP1' : patterns.keys.sort.last.succ
|
77
|
-
patterns[id] = shading_pattern
|
78
|
-
|
79
|
-
set_color type, id, :pattern => true
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
data/spec/name_tree_spec.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
2
|
-
|
3
|
-
def tree_dump(tree)
|
4
|
-
if tree.is_a?(Prawn::Core::NameTree::Node)
|
5
|
-
"[" + tree.children.map { |child| tree_dump(child) }.join(",") + "]"
|
6
|
-
else
|
7
|
-
"#{tree.name}=#{tree.value}"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def tree_add(tree, *args)
|
12
|
-
args.each do |(name, value)|
|
13
|
-
tree.add(name, value)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def tree_value(name, value)
|
18
|
-
Prawn::Core::NameTree::Value.new(name, value)
|
19
|
-
end
|
20
|
-
|
21
|
-
class RefExposingDocument < Prawn::Document
|
22
|
-
def object_store
|
23
|
-
state.store
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "Name Tree" do
|
28
|
-
before(:each) { create_pdf(RefExposingDocument) }
|
29
|
-
|
30
|
-
it "should have no children when first initialized" do
|
31
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
32
|
-
node.children.length.should == 0
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should have no subtrees while child limit is not reached" do
|
36
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
37
|
-
tree_add(node, ["one", 1], ["two", 2], ["three", 3])
|
38
|
-
tree_dump(node).should == "[one=1,three=3,two=2]"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should split into subtrees when limit is exceeded" do
|
42
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
43
|
-
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
44
|
-
tree_dump(node).should == "[[four=4,one=1],[three=3,two=2]]"
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should create a two new references when root is split" do
|
48
|
-
ref_count = @pdf.object_store.length
|
49
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
50
|
-
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
51
|
-
@pdf.object_store.length.should.equal ref_count+2
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should create a one new reference when subtree is split" do
|
55
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
56
|
-
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
57
|
-
|
58
|
-
ref_count = @pdf.object_store.length # save when root is split
|
59
|
-
tree_add(node, ["five", 5], ["six", 6], ["seven", 7])
|
60
|
-
tree_dump(node).should == "[[five=5,four=4,one=1],[seven=7,six=6],[three=3,two=2]]"
|
61
|
-
@pdf.object_store.length.should.equal ref_count+1
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should keep tree balanced when subtree split cascades to root" do
|
65
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
66
|
-
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
67
|
-
tree_add(node, ["five", 5], ["six", 6], ["seven", 7], ["eight", 8])
|
68
|
-
tree_dump(node).should == "[[[eight=8,five=5],[four=4,one=1]],[[seven=7,six=6],[three=3,two=2]]]"
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should maintain order of already properly ordered nodes" do
|
72
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
73
|
-
tree_add(node, ["eight", 8], ["five", 5], ["four", 4], ["one", 1])
|
74
|
-
tree_add(node, ['seven', 7], ['six', 6], ['three', 3], ['two', 2])
|
75
|
-
tree_dump(node).should == "[[[eight=8,five=5],[four=4,one=1]],[[seven=7,six=6],[three=3,two=2]]]"
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should emit only :Names key with to_hash if root is only node" do
|
79
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
80
|
-
tree_add(node, ["one", 1], ["two", 2], ["three", 3])
|
81
|
-
node.to_hash.should.equal(
|
82
|
-
{ :Names => [tree_value("one", 1), tree_value("three", 3), tree_value("two", 2)] }
|
83
|
-
)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should emit only :Kids key with to_hash if root has children" do
|
87
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
88
|
-
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
89
|
-
node.to_hash.should.equal({ :Kids => node.children.map { |child| child.ref } })
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should emit :Limits and :Names keys with to_hash for leaf node" do
|
93
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
94
|
-
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
95
|
-
node.children.first.to_hash.should.equal(
|
96
|
-
{ :Limits => %w(four one),
|
97
|
-
:Names => [tree_value("four", 4), tree_value("one", 1)] }
|
98
|
-
)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should emit :Limits and :Kids keys with to_hash for inner node" do
|
102
|
-
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
103
|
-
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
104
|
-
tree_add(node, ["five", 5], ["six", 6], ["seven", 7], ["eight", 8])
|
105
|
-
tree_add(node, ["nine", 9], ["ten", 10], ["eleven", 11], ["twelve", 12])
|
106
|
-
tree_add(node, ["thirteen", 13], ["fourteen", 14], ["fifteen", 15], ["sixteen", 16])
|
107
|
-
node.children.first.to_hash.should.equal(
|
108
|
-
{ :Limits => %w(eight one),
|
109
|
-
:Kids => node.children.first.children.map { |child| child.ref } }
|
110
|
-
)
|
111
|
-
end
|
112
|
-
end
|