prawn 1.0.0.rc2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/COPYING +2 -2
  4. data/Gemfile +8 -15
  5. data/LICENSE +1 -1
  6. data/Rakefile +25 -16
  7. data/data/images/16bit.alpha +0 -0
  8. data/data/images/16bit.color +0 -0
  9. data/data/images/dice.alpha +0 -0
  10. data/data/images/dice.color +0 -0
  11. data/data/images/indexed_color.dat +0 -0
  12. data/data/images/indexed_color.png +0 -0
  13. data/data/images/license.md +8 -0
  14. data/data/images/page_white_text.alpha +0 -0
  15. data/data/images/page_white_text.color +0 -0
  16. data/lib/prawn.rb +85 -23
  17. data/lib/prawn/document.rb +134 -116
  18. data/lib/prawn/document/bounding_box.rb +33 -4
  19. data/lib/prawn/document/column_box.rb +18 -6
  20. data/lib/prawn/document/graphics_state.rb +11 -74
  21. data/lib/prawn/document/internals.rb +24 -23
  22. data/lib/prawn/document/span.rb +12 -10
  23. data/lib/prawn/encoding.rb +8 -9
  24. data/lib/prawn/errors.rb +13 -32
  25. data/lib/prawn/font.rb +137 -105
  26. data/lib/prawn/font/afm.rb +76 -32
  27. data/lib/prawn/font/dfont.rb +4 -3
  28. data/lib/prawn/font/ttf.rb +33 -25
  29. data/lib/prawn/font_metric_cache.rb +47 -0
  30. data/lib/prawn/graphics.rb +177 -57
  31. data/lib/prawn/graphics/cap_style.rb +4 -3
  32. data/lib/prawn/graphics/color.rb +5 -4
  33. data/lib/prawn/graphics/dash.rb +53 -31
  34. data/lib/prawn/graphics/join_style.rb +9 -7
  35. data/lib/prawn/graphics/patterns.rb +4 -15
  36. data/lib/prawn/graphics/transformation.rb +10 -9
  37. data/lib/prawn/graphics/transparency.rb +3 -1
  38. data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
  39. data/lib/prawn/image_handler.rb +42 -0
  40. data/lib/prawn/images.rb +58 -54
  41. data/lib/prawn/images/image.rb +6 -22
  42. data/lib/prawn/images/jpg.rb +20 -14
  43. data/lib/prawn/images/png.rb +58 -121
  44. data/lib/prawn/layout.rb +12 -15
  45. data/lib/prawn/measurement_extensions.rb +10 -6
  46. data/lib/prawn/measurements.rb +27 -21
  47. data/lib/prawn/outline.rb +108 -147
  48. data/lib/prawn/repeater.rb +10 -8
  49. data/lib/prawn/security.rb +59 -40
  50. data/lib/prawn/security/arcfour.rb +52 -0
  51. data/lib/prawn/soft_mask.rb +4 -4
  52. data/lib/prawn/stamp.rb +5 -3
  53. data/lib/prawn/table.rb +83 -60
  54. data/lib/prawn/table/cell.rb +17 -21
  55. data/lib/prawn/table/cell/image.rb +2 -3
  56. data/lib/prawn/table/cell/in_table.rb +8 -2
  57. data/lib/prawn/table/cell/span_dummy.rb +5 -0
  58. data/lib/prawn/table/cell/subtable.rb +3 -2
  59. data/lib/prawn/table/cell/text.rb +14 -12
  60. data/lib/prawn/table/cells.rb +58 -14
  61. data/lib/prawn/table/column_width_calculator.rb +61 -0
  62. data/lib/prawn/text.rb +27 -26
  63. data/lib/prawn/text/box.rb +12 -6
  64. data/lib/prawn/text/formatted.rb +5 -4
  65. data/lib/prawn/text/formatted/arranger.rb +290 -0
  66. data/lib/prawn/text/formatted/box.rb +85 -57
  67. data/lib/prawn/text/formatted/fragment.rb +11 -11
  68. data/lib/prawn/text/formatted/line_wrap.rb +266 -0
  69. data/lib/prawn/text/formatted/parser.rb +11 -4
  70. data/lib/prawn/text/formatted/wrap.rb +156 -0
  71. data/lib/prawn/utilities.rb +5 -3
  72. data/manual/document_and_page_options/document_and_page_options.rb +2 -1
  73. data/manual/document_and_page_options/metadata.rb +3 -3
  74. data/manual/document_and_page_options/page_size.rb +2 -2
  75. data/manual/document_and_page_options/print_scaling.rb +20 -0
  76. data/manual/example_file.rb +2 -7
  77. data/manual/example_helper.rb +62 -81
  78. data/manual/graphics/common_lines.rb +2 -0
  79. data/manual/graphics/helper.rb +11 -4
  80. data/manual/graphics/stroke_dash.rb +19 -14
  81. data/manual/manual/cover.rb +16 -0
  82. data/manual/manual/manual.rb +1 -5
  83. data/manual/text/fallback_fonts.rb +4 -4
  84. data/manual/text/formatted_text.rb +5 -5
  85. data/manual/text/inline.rb +2 -4
  86. data/manual/text/registering_families.rb +12 -12
  87. data/manual/text/single_usage.rb +4 -4
  88. data/manual/text/text.rb +0 -2
  89. data/prawn.gemspec +21 -13
  90. data/spec/acceptance/png.rb +23 -0
  91. data/spec/annotations_spec.rb +16 -32
  92. data/spec/bounding_box_spec.rb +22 -5
  93. data/spec/cell_spec.rb +49 -5
  94. data/spec/column_box_spec.rb +32 -0
  95. data/spec/destinations_spec.rb +5 -5
  96. data/spec/document_spec.rb +112 -118
  97. data/spec/extensions/encoding_helpers.rb +5 -2
  98. data/spec/font_metric_cache_spec.rb +52 -0
  99. data/spec/font_spec.rb +121 -120
  100. data/spec/formatted_text_arranger_spec.rb +24 -24
  101. data/spec/formatted_text_box_spec.rb +31 -32
  102. data/spec/formatted_text_fragment_spec.rb +2 -2
  103. data/spec/graphics_spec.rb +63 -45
  104. data/spec/grid_spec.rb +24 -13
  105. data/spec/image_handler_spec.rb +54 -0
  106. data/spec/images_spec.rb +34 -21
  107. data/spec/inline_formatted_text_parser_spec.rb +69 -20
  108. data/spec/jpg_spec.rb +3 -3
  109. data/spec/line_wrap_spec.rb +25 -14
  110. data/spec/measurement_units_spec.rb +5 -5
  111. data/spec/outline_spec.rb +68 -64
  112. data/spec/png_spec.rb +15 -18
  113. data/spec/reference_spec.rb +2 -82
  114. data/spec/repeater_spec.rb +1 -1
  115. data/spec/security_spec.rb +41 -9
  116. data/spec/soft_mask_spec.rb +0 -40
  117. data/spec/span_spec.rb +6 -11
  118. data/spec/spec_helper.rb +20 -2
  119. data/spec/stamp_spec.rb +19 -20
  120. data/spec/stroke_styles_spec.rb +31 -13
  121. data/spec/table/span_dummy_spec.rb +17 -0
  122. data/spec/table_spec.rb +268 -43
  123. data/spec/text_at_spec.rb +13 -27
  124. data/spec/text_box_spec.rb +35 -30
  125. data/spec/text_spec.rb +56 -40
  126. data/spec/transparency_spec.rb +5 -5
  127. metadata +214 -217
  128. data/README.md +0 -98
  129. data/data/fonts/Action Man.dfont +0 -0
  130. data/data/fonts/Activa.ttf +0 -0
  131. data/data/fonts/Chalkboard.ttf +0 -0
  132. data/data/fonts/DejaVuSans.ttf +0 -0
  133. data/data/fonts/Dustismo_Roman.ttf +0 -0
  134. data/data/fonts/comicsans.ttf +0 -0
  135. data/data/fonts/gkai00mp.ttf +0 -0
  136. data/data/images/16bit.dat +0 -0
  137. data/data/images/barcode_issue.png +0 -0
  138. data/data/images/dice.dat +0 -0
  139. data/data/images/page_white_text.dat +0 -0
  140. data/data/images/rails.dat +0 -0
  141. data/data/images/rails.png +0 -0
  142. data/lib/prawn/compatibility.rb +0 -87
  143. data/lib/prawn/core.rb +0 -87
  144. data/lib/prawn/core/annotations.rb +0 -61
  145. data/lib/prawn/core/byte_string.rb +0 -9
  146. data/lib/prawn/core/destinations.rb +0 -90
  147. data/lib/prawn/core/document_state.rb +0 -79
  148. data/lib/prawn/core/literal_string.rb +0 -16
  149. data/lib/prawn/core/name_tree.rb +0 -177
  150. data/lib/prawn/core/object_store.rb +0 -320
  151. data/lib/prawn/core/page.rb +0 -212
  152. data/lib/prawn/core/pdf_object.rb +0 -125
  153. data/lib/prawn/core/reference.rb +0 -119
  154. data/lib/prawn/core/text.rb +0 -268
  155. data/lib/prawn/core/text/formatted/arranger.rb +0 -294
  156. data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
  157. data/lib/prawn/core/text/formatted/wrap.rb +0 -153
  158. data/lib/prawn/document/page_geometry.rb +0 -136
  159. data/lib/prawn/document/snapshot.rb +0 -89
  160. data/manual/manual/foreword.rb +0 -13
  161. data/manual/templates/full_template.rb +0 -23
  162. data/manual/templates/page_template.rb +0 -47
  163. data/manual/templates/templates.rb +0 -26
  164. data/manual/text/group.rb +0 -29
  165. data/spec/name_tree_spec.rb +0 -112
  166. data/spec/object_store_spec.rb +0 -170
  167. data/spec/pdf_object_spec.rb +0 -172
  168. data/spec/snapshot_spec.rb +0 -186
  169. data/spec/template_spec.rb +0 -351
data/README.md DELETED
@@ -1,98 +0,0 @@
1
- # Prawn: Fast, Nimble PDF Generation For Ruby
2
-
3
- [![Build Status](https://secure.travis-ci.org/prawnpdf/prawn.png)](http://travis-ci.org/prawnpdf/prawn)
4
-
5
- Prawn is a pure Ruby PDF generation library that provides a lot of great functionality while trying to remain simple and reasonably performant. Here are some of the important features we provide:
6
-
7
- * Vector drawing support, including lines, polygons, curves, ellipses, etc.
8
- * Extensive text rendering support, including flowing text and limited inline formatting options.
9
- * Support for both PDF builtin fonts as well as embedded TrueType fonts
10
- * A variety of low level tools for basic layout needs, including a simple grid system
11
- * PNG and JPG image embedding, with flexible scaling options
12
- * Reporting tools for rendering complex data tables, with pagination support
13
- * Security features including encryption and password protection
14
- * Tools for rendering repeatable content (i.e headers, footers, and page numbers)
15
- * Comprehensive internationalization features, including full support for UTF-8 based fonts, right-to-left text rendering, fallback font support, and extension points for customizable text wrapping.
16
- * Support for PDF outlines for document navigation
17
- * Low level PDF features, allowing users to create custom extensions by dropping down all the way to the PDF object tree layer. (Mostly useful to those with knowledge of the PDF specification)
18
- * Lots of other stuff!
19
-
20
- ## Should You Use Prawn?
21
-
22
- If you are looking for a highly flexible PDF document generation system, Prawn might be the tool for you. It is not a reporting tool or a publishing toolchain, though it could be fairly easily used to build those things.
23
-
24
- One thing Prawn is not, and will never be, is an HTML to PDF generator. For those needs, consider looking into FlyingSaucer via JRuby, or one of the webkit based tools, like Wicked or PDFKit. We do have basic support for inline styling but it is limited to a very small subset of functionality and is not suitable for rendering rich HTML documents.
25
-
26
- ## Supported Ruby Versions and Implementations
27
-
28
- Because Prawn is pure Ruby and virtually all of its dependencies are maintained by our core team, it should run pretty much anywhere, including Rubinius, JRuby, MacRuby, etc. While we officially support MRI 1.8.7 and 1.9.2 only, we will accept patches to fix problems on other Ruby platforms if they aren't too invasive.
29
-
30
- ## Installing Prawn
31
-
32
- Prawn is distributed via RubyGems, and can be installed the usual way that you install gems: by simply typing `gem install prawn` on the command line.
33
-
34
- You can also install from git if you'd like, the _master_ branch contains the latest developments, and _stable_ represents the latest bug fixes to the currently released version of Prawn. If you go this route, using Bundler is encouraged.
35
-
36
- ## Release Policies
37
-
38
- We may introduce backwards incompatible changes each time our minor version number is bumped, but that any tiny version number bump should be bug fixes and internal changes only. Be sure to read the release notes each time we cut a new release and lock your gems accordingly. You can find the project CHANGELOG at: https://github.com/prawnpdf/prawn/wiki/CHANGELOG
39
-
40
- ## Hello World!
41
-
42
- If the following code runs and produces a working PDF file, you've successfully installed Prawn.
43
-
44
- require "prawn"
45
-
46
- Prawn::Document.generate("hello.pdf") do
47
- text "Hello World!"
48
- end
49
-
50
- Of course, you'll probably want to do more interesting things than that...
51
-
52
- ## Manual
53
-
54
- Mendicant University student Felipe Doria provided us with a beautiful system for generating a user manual from our examples. This can be generated from the prawn source or you can download a pre-generated snapshot of it at http://prawn.majesticseacreature.com/manual.pdf
55
-
56
- Note that while we will try to keep the downloadable manual up to date, that it's provided as a convenience only and you should generate the manual yourself if you want to be sure the code in it actually runs and works as expected. To build the manual, here's what you need to do:
57
-
58
- 1. clone the repository
59
- 2. switch to the stable branch (optional, stay on master for development version)
60
- 3. install bundler if necessay
61
- 4. run `bundle install`
62
- 5. run `bundle exec rake manual`, which will generate _manual.pdf_ in the project root
63
-
64
- ## Support
65
-
66
- The easiest way to get help with Prawn is to post a message to our mailing list:
67
-
68
- <http://groups.google.com/group/prawn-ruby>
69
-
70
- Feel free to post any Prawn related question there, our community is very responsive and will be happy to help you figure out how to use Prawn, or help you determine whether it's the right tool for the task you are working on.
71
-
72
- Please make your posts to the list as specific as possible, including code samples and output where relevant. Do not post any information that should not be shared publicly, and be sure to reduce your example code as much as possible so that those who are responding to your question can more easily see what the issue might be.
73
-
74
- ## Contributing
75
-
76
- If you've found a bug, want to submit a patch, or have a feature request, please enter a ticket into our github tracker:
77
-
78
- <http://github.com/prawnpdf/prawn/issues>
79
-
80
- We strongly encourage bug reports to come with failing tests or at least a reduced example that demonstrates the problem. Similarly, patches should include tests, API documentation, and an update to the manual where relevant. Feel free to send a pull request early though, if you just want some feedback or a code review before preparing your code to be merged.
81
-
82
- If you are unsure about whether or not you've found a bug, or want to check to see whether we'd be interested in the feature you want to add before you start working on it, feel free to post to our mailing list.
83
-
84
- ## Authorship
85
-
86
- Prawn was originally developed by Gregory Brown, under the auspices of the Ruby Mendicant Project, a grassroots initiative in which the Ruby community collectively provided funding so that Gregory could take several months off of work to focus on this project.
87
-
88
- Over the last several years, we've received code contributions from over 50 people, which is amazing considering the low-level nature of this project. In 2010, Gregory officially handed the project off to the Prawn core team. Currently active maintainers include Brad Ediger, Daniel Nelson, James Healy, and Jonathan Greenberg.
89
-
90
- While he was only with us for a short time before moving on to other things, we'd also like to thank Prawn core team emeritus Jamis Buck for his contributions. He was responsible for introducing font subsetting as well as the first implementation of our inline formatting support.
91
-
92
- You can find the full list of folks who have at least one patch accepted to Prawn on github at https://github.com/prawnpdf/prawn/contributors
93
-
94
- ## License
95
-
96
- Prawn is released under a slightly modified form of the License of Ruby, allowing you to choose between Matz's terms, the GPLv2, or GPLv3. For details, please see the LICENSE, GPLv2, and GPLv3 files.
97
-
98
- If you wish to contribute to Prawn, you will retain your own copyright but must agree to license your code under the same terms as the project itself.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,87 +0,0 @@
1
- # coding: utf-8
2
- #
3
- # Compatibility layer to smooth over differences between Ruby implementations
4
- # The oldest version of Ruby which is supported is MRI 1.8.7
5
- # Ideally, all version-specific or implementation-specific code should be
6
- # kept in this file (but that ideal has not been attained yet)
7
-
8
- class String #:nodoc:
9
- def first_line
10
- self.each_line { |line| return line }
11
- end
12
-
13
- unless "".respond_to?(:codepoints)
14
- def codepoints(&block)
15
- if block_given?
16
- unpack("U*").each(&block)
17
- else
18
- unpack("U*")
19
- end
20
- end
21
- end
22
-
23
- if "".respond_to?(:encode)
24
- def normalize_to_utf8
25
- begin
26
- encode(Encoding::UTF_8)
27
- rescue
28
- raise Prawn::Errors::IncompatibleStringEncoding, "Encoding " +
29
- "#{text.encoding} can not be transparently converted to UTF-8. " +
30
- "Please ensure the encoding of the string you are attempting " +
31
- "to use is set correctly"
32
- end
33
- end
34
- alias :unicode_characters :each_char
35
- alias :unicode_length :length
36
-
37
- else
38
- def normalize_to_utf8
39
- begin
40
- # use unpack as a hackish way to verify the string is valid utf-8
41
- unpack("U*")
42
- return dup
43
- rescue
44
- raise Prawn::Errors::IncompatibleStringEncoding, "The string you " +
45
- "are attempting to render is not encoded in valid UTF-8."
46
- end
47
- end
48
- def unicode_characters
49
- if block_given?
50
- unpack("U*").each { |c| yield [c].pack("U") }
51
- else
52
- unpack("U*").map { |c| [c].pack("U") }
53
- end
54
- end
55
- def unicode_length
56
- unpack("U*").length
57
- end
58
- end
59
- end
60
-
61
- unless File.respond_to?(:binread)
62
- def File.binread(file) #:nodoc:
63
- File.open(file,"rb") { |f| f.read }
64
- end
65
- end
66
-
67
- if RUBY_VERSION < "1.9"
68
-
69
- def ruby_18 #:nodoc:
70
- yield
71
- end
72
-
73
- def ruby_19 #:nodoc:
74
- false
75
- end
76
-
77
- else
78
-
79
- def ruby_18 #:nodoc:
80
- false
81
- end
82
-
83
- def ruby_19 #:nodoc:
84
- yield
85
- end
86
-
87
- end
@@ -1,87 +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
- #
33
- BASEDIR = File.expand_path(File.join(dir, '..','..'))
34
- DATADIR = File.expand_path(File.join(dir, '..', '..', 'data'))
35
-
36
- # Whe set to true, Prawn will verify hash options to ensure only valid keys
37
- # are used. Off by default.
38
- #
39
- # Example:
40
- # >> Prawn::Document.new(:tomato => "Juicy")
41
- # Prawn::Errors::UnknownOption:
42
- # Detected unknown option(s): [:tomato]
43
- # Accepted options are: [:page_size, :page_layout, :left_margin, ...]
44
- #
45
- attr_accessor :debug
46
-
47
- def verify_options(accepted, actual) #:nodoc:
48
- return unless debug || $DEBUG
49
- unless (act=Set[*actual.keys]).subset?(acc=Set[*accepted])
50
- raise Prawn::Errors::UnknownOption,
51
- "\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" <<
52
- "Accepted options are: #{accepted.inspect}"
53
- end
54
- yield if block_given?
55
- end
56
-
57
- module Configurable #:nodoc:
58
- def configuration(*args)
59
- @config ||= Marshal.load(Marshal.dump(default_configuration))
60
- if Hash === args[0]
61
- @config.update(args[0])
62
- elsif args.length > 1
63
- @config.values_at(*args)
64
- elsif args.length == 1
65
- @config[args[0]]
66
- else
67
- @config
68
- end
69
- end
70
-
71
- alias_method :C, :configuration
72
- end
73
- end
74
-
75
- require "prawn/compatibility"
76
- require "prawn/errors"
77
- require "prawn/core/pdf_object"
78
- require "prawn/core/reference"
79
- require "prawn/core/page"
80
- require "prawn/core/object_store"
81
- require "prawn/core/document_state"
82
- require "prawn/core/literal_string"
83
- require "prawn/core/byte_string"
84
- require "prawn/core/name_tree"
85
- require "prawn/core/annotations"
86
- require "prawn/core/destinations"
87
-
@@ -1,61 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # annotations.rb : Implements low-level annotation support for PDF
4
- #
5
- # Copyright November 2008, Jamis Buck. 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
-
12
- # Provides very low-level support for annotations.
13
- #
14
- module Annotations #:nodoc:
15
-
16
- # Adds a new annotation (section 8.4 in PDF spec) to the current page.
17
- # +options+ must be a Hash describing the annotation.
18
- #
19
- def annotate(options)
20
- state.page.dictionary.data[:Annots] ||= []
21
- options = sanitize_annotation_hash(options)
22
- state.page.dictionary.data[:Annots] << ref!(options)
23
- return options
24
- end
25
-
26
- # A convenience method for creating Text annotations. +rect+ must be an array
27
- # of four numbers, describing the bounds of the annotation. +contents+ should
28
- # be a string, to be shown when the annotation is activated.
29
- #
30
- def text_annotation(rect, contents, options={})
31
- options = options.merge(:Subtype => :Text, :Rect => rect, :Contents => contents)
32
- annotate(options)
33
- end
34
-
35
- # A convenience method for creating Link annotations. +rect+ must be an array
36
- # of four numbers, describing the bounds of the annotation. The +options+ hash
37
- # should include either :Dest (describing the target destination, usually as a
38
- # string that has been recorded in the document's Dests tree), or :A (describing
39
- # an action to perform on clicking the link), or :PA (for describing a URL to
40
- # link to).
41
- #
42
- def link_annotation(rect, options={})
43
- options = options.merge(:Subtype => :Link, :Rect => rect)
44
- annotate(options)
45
- end
46
-
47
- private
48
-
49
- def sanitize_annotation_hash(options)
50
- options = options.merge(:Type => :Annot)
51
-
52
- if options[:Dest].is_a?(String)
53
- options[:Dest] = Prawn::Core::LiteralString.new(options[:Dest])
54
- end
55
-
56
- options
57
- end
58
-
59
- end
60
- end
61
- end
@@ -1,9 +0,0 @@
1
- # encoding: utf-8
2
- module Prawn
3
- module Core
4
- # This is used to differentiate strings that must be encoded as
5
- # a byte string, such as binary data from encrypted strings.
6
- class ByteString < String #:nodoc:
7
- end
8
- end
9
- end
@@ -1,90 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # prawn/core/destinations.rb : Implements destination support for PDF
4
- #
5
- # Copyright November 2008, Jamis Buck. 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 Destinations #:nodoc:
12
-
13
- # The maximum number of children to fit into a single node in the Dests tree.
14
- NAME_TREE_CHILDREN_LIMIT = 20 #:nodoc:
15
-
16
- # The Dests name tree in the Name dictionary (see Prawn::Document::Internal#names).
17
- # This name tree is used to store named destinations (PDF spec 8.2.1).
18
- # (For more on name trees, see section 3.8.4 in the PDF spec.)
19
- #
20
- def dests
21
- names.data[:Dests] ||= ref!(Prawn::Core::NameTree::Node.new(self, NAME_TREE_CHILDREN_LIMIT))
22
- end
23
-
24
- # Adds a new destination to the dests name tree (see #dests). The
25
- # +reference+ parameter will be converted into a Prawn::Reference if
26
- # it is not already one.
27
- #
28
- def add_dest(name, reference)
29
- reference = ref!(reference) unless reference.is_a?(Prawn::Core::Reference)
30
- dests.data.add(name, reference)
31
- end
32
-
33
- # Return a Dest specification for a specific location (and optional zoom
34
- # level).
35
- #
36
- def dest_xyz(left, top, zoom=nil, dest_page=page)
37
- [dest_page.dictionary, :XYZ, left, top, zoom]
38
- end
39
-
40
- # Return a Dest specification that will fit the given page into the
41
- # viewport.
42
- #
43
- def dest_fit(dest_page=page)
44
- [dest_page.dictionary, :Fit]
45
- end
46
-
47
- # Return a Dest specification that will fit the given page horizontally
48
- # into the viewport, aligned vertically at the given top coordinate.
49
- #
50
- def dest_fit_horizontally(top, dest_page=page)
51
- [dest_page.dictionary, :FitH, top]
52
- end
53
-
54
- # Return a Dest specification that will fit the given page vertically
55
- # into the viewport, aligned horizontally at the given left coordinate.
56
- #
57
- def dest_fit_vertically(left, dest_page=page)
58
- [dest_page.dictionary, :FitV, left]
59
- end
60
-
61
- # Return a Dest specification that will fit the given rectangle into the
62
- # viewport, for the given page.
63
- #
64
- def dest_fit_rect(left, bottom, right, top, dest_page=page)
65
- [dest_page.dictionary, :FitR, left, bottom, right, top]
66
- end
67
-
68
- # Return a Dest specfication that will fit the given page's bounding box
69
- # into the viewport.
70
- #
71
- def dest_fit_bounds(dest_page=page)
72
- [dest_page.dictionary, :FitB]
73
- end
74
-
75
- # Same as #dest_fit_horizontally, but works on the page's bounding box
76
- # instead of the entire page.
77
- #
78
- def dest_fit_bounds_horizontally(top, dest_page=page)
79
- [dest_page.dictionary, :FitBH, top]
80
- end
81
-
82
- # Same as #dest_fit_vertically, but works on the page's bounding box
83
- # instead of the entire page.
84
- #
85
- def dest_fit_bounds_vertically(left, dest_page=page)
86
- [dest_page.dictionary, :FitBV, left]
87
- end
88
- end
89
- end
90
- end