prawn-graph 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +3 -0
- data/Rakefile +34 -0
- data/examples/example_helper.rb +10 -0
- data/examples/graph/advanced_bar_chart.rb +22 -0
- data/examples/graph/bar_chart.rb +18 -0
- data/examples/graph/line_chart.rb +18 -0
- data/lib/prawn/graph.rb +94 -0
- data/lib/prawn/graph/bar.rb +172 -0
- data/lib/prawn/graph/chart.rb +4 -0
- data/lib/prawn/graph/errors.rb +6 -0
- data/lib/prawn/graph/grid.rb +43 -0
- data/lib/prawn/graph/line.rb +43 -0
- data/vendor/prawn-core/COPYING +340 -0
- data/vendor/prawn-core/HACKING +46 -0
- data/vendor/prawn-core/LICENSE +56 -0
- data/vendor/prawn-core/README +138 -0
- data/vendor/prawn-core/Rakefile +75 -0
- data/vendor/prawn-core/bench/afm_text_bench.rb +18 -0
- data/vendor/prawn-core/bench/png_type_6.rb +15 -0
- data/vendor/prawn-core/bench/ttf_text_bench.rb +19 -0
- data/vendor/prawn-core/bugs/indentation_across_pagebreaks.rb +15 -0
- data/vendor/prawn-core/bugs/resolved/canvas_sets_y_to_0.rb +15 -0
- data/vendor/prawn-core/bugs/resolved/png_barcode_issue.rb +11 -0
- data/vendor/prawn-core/bugs/resolved/transaction_page_number_issue_79.rb +21 -0
- data/vendor/prawn-core/bugs/resolved/ttf_fails_in_transactions.rb +24 -0
- data/vendor/prawn-core/data/encodings/win_ansi.txt +29 -0
- data/vendor/prawn-core/data/fonts/Action Man.dfont +0 -0
- data/vendor/prawn-core/data/fonts/Activa.ttf +0 -0
- data/vendor/prawn-core/data/fonts/Chalkboard.ttf +0 -0
- data/vendor/prawn-core/data/fonts/Courier-Bold.afm +342 -0
- data/vendor/prawn-core/data/fonts/Courier-BoldOblique.afm +342 -0
- data/vendor/prawn-core/data/fonts/Courier-Oblique.afm +342 -0
- data/vendor/prawn-core/data/fonts/Courier.afm +342 -0
- data/vendor/prawn-core/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/prawn-core/data/fonts/Dustismo_Roman.ttf +0 -0
- data/vendor/prawn-core/data/fonts/Helvetica-Bold.afm +2827 -0
- data/vendor/prawn-core/data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/vendor/prawn-core/data/fonts/Helvetica-Oblique.afm +3051 -0
- data/vendor/prawn-core/data/fonts/Helvetica.afm +3051 -0
- data/vendor/prawn-core/data/fonts/MustRead.html +19 -0
- data/vendor/prawn-core/data/fonts/Symbol.afm +213 -0
- data/vendor/prawn-core/data/fonts/Times-Bold.afm +2588 -0
- data/vendor/prawn-core/data/fonts/Times-BoldItalic.afm +2384 -0
- data/vendor/prawn-core/data/fonts/Times-Italic.afm +2667 -0
- data/vendor/prawn-core/data/fonts/Times-Roman.afm +2419 -0
- data/vendor/prawn-core/data/fonts/ZapfDingbats.afm +225 -0
- data/vendor/prawn-core/data/fonts/comicsans.ttf +0 -0
- data/vendor/prawn-core/data/fonts/gkai00mp.ttf +0 -0
- data/vendor/prawn-core/data/images/16bit.alpha +0 -0
- data/vendor/prawn-core/data/images/16bit.dat +0 -0
- data/vendor/prawn-core/data/images/16bit.png +0 -0
- data/vendor/prawn-core/data/images/arrow.png +0 -0
- data/vendor/prawn-core/data/images/arrow2.png +0 -0
- data/vendor/prawn-core/data/images/barcode_issue.png +0 -0
- data/vendor/prawn-core/data/images/dice.alpha +0 -0
- data/vendor/prawn-core/data/images/dice.dat +0 -0
- data/vendor/prawn-core/data/images/dice.png +0 -0
- data/vendor/prawn-core/data/images/dice_interlaced.png +0 -0
- data/vendor/prawn-core/data/images/fractal.jpg +0 -0
- data/vendor/prawn-core/data/images/letterhead.jpg +0 -0
- data/vendor/prawn-core/data/images/page_white_text.alpha +0 -0
- data/vendor/prawn-core/data/images/page_white_text.dat +0 -0
- data/vendor/prawn-core/data/images/page_white_text.png +0 -0
- data/vendor/prawn-core/data/images/pigs.jpg +0 -0
- data/vendor/prawn-core/data/images/rails.dat +0 -0
- data/vendor/prawn-core/data/images/rails.png +0 -0
- data/vendor/prawn-core/data/images/ruport.png +0 -0
- data/vendor/prawn-core/data/images/ruport_data.dat +0 -0
- data/vendor/prawn-core/data/images/ruport_transparent.png +0 -0
- data/vendor/prawn-core/data/images/ruport_type0.png +0 -0
- data/vendor/prawn-core/data/images/stef.jpg +0 -0
- data/vendor/prawn-core/data/images/tru256.bmp +0 -0
- data/vendor/prawn-core/data/images/web-links.dat +1 -0
- data/vendor/prawn-core/data/images/web-links.png +0 -0
- data/vendor/prawn-core/data/shift_jis_text.txt +1 -0
- data/vendor/prawn-core/examples/bounding_box/bounding_boxes.rb +43 -0
- data/vendor/prawn-core/examples/bounding_box/indentation.rb +34 -0
- data/vendor/prawn-core/examples/bounding_box/russian_boxes.rb +36 -0
- data/vendor/prawn-core/examples/bounding_box/stretched_nesting.rb +67 -0
- data/vendor/prawn-core/examples/column_box/column_box_example.rb +43 -0
- data/vendor/prawn-core/examples/example_helper.rb +3 -0
- data/vendor/prawn-core/examples/general/background.rb +23 -0
- data/vendor/prawn-core/examples/general/canvas.rb +15 -0
- data/vendor/prawn-core/examples/general/context_sensitive_headers.rb +37 -0
- data/vendor/prawn-core/examples/general/float.rb +11 -0
- data/vendor/prawn-core/examples/general/margin.rb +36 -0
- data/vendor/prawn-core/examples/general/measurement_units.rb +51 -0
- data/vendor/prawn-core/examples/general/metadata-info.rb +16 -0
- data/vendor/prawn-core/examples/general/multi_page_layout.rb +18 -0
- data/vendor/prawn-core/examples/general/outlines.rb +50 -0
- data/vendor/prawn-core/examples/general/page_geometry.rb +31 -0
- data/vendor/prawn-core/examples/general/page_numbering.rb +15 -0
- data/vendor/prawn-core/examples/general/repeaters.rb +47 -0
- data/vendor/prawn-core/examples/general/stamp.rb +41 -0
- data/vendor/prawn-core/examples/graphics/basic_images.rb +23 -0
- data/vendor/prawn-core/examples/graphics/cmyk.rb +12 -0
- data/vendor/prawn-core/examples/graphics/curves.rb +11 -0
- data/vendor/prawn-core/examples/graphics/hexagon.rb +13 -0
- data/vendor/prawn-core/examples/graphics/image_fit.rb +15 -0
- data/vendor/prawn-core/examples/graphics/image_flow.rb +37 -0
- data/vendor/prawn-core/examples/graphics/image_position.rb +17 -0
- data/vendor/prawn-core/examples/graphics/line.rb +32 -0
- data/vendor/prawn-core/examples/graphics/png_types.rb +22 -0
- data/vendor/prawn-core/examples/graphics/polygons.rb +16 -0
- data/vendor/prawn-core/examples/graphics/remote_images.rb +12 -0
- data/vendor/prawn-core/examples/graphics/rounded_polygons.rb +19 -0
- data/vendor/prawn-core/examples/graphics/rounded_rectangle.rb +20 -0
- data/vendor/prawn-core/examples/graphics/ruport_style_helpers.rb +19 -0
- data/vendor/prawn-core/examples/graphics/stroke_bounds.rb +20 -0
- data/vendor/prawn-core/examples/graphics/stroke_cap_and_join.rb +45 -0
- data/vendor/prawn-core/examples/graphics/stroke_dash.rb +42 -0
- data/vendor/prawn-core/examples/graphics/transformations.rb +52 -0
- data/vendor/prawn-core/examples/graphics/transparency.rb +26 -0
- data/vendor/prawn-core/examples/m17n/chinese_text_wrapping.rb +17 -0
- data/vendor/prawn-core/examples/m17n/euro.rb +15 -0
- data/vendor/prawn-core/examples/m17n/sjis.rb +28 -0
- data/vendor/prawn-core/examples/m17n/utf8.rb +13 -0
- data/vendor/prawn-core/examples/m17n/win_ansi_charset.rb +54 -0
- data/vendor/prawn-core/examples/text/alignment.rb +18 -0
- data/vendor/prawn-core/examples/text/dfont.rb +48 -0
- data/vendor/prawn-core/examples/text/family_based_styling.rb +24 -0
- data/vendor/prawn-core/examples/text/font_calculations.rb +91 -0
- data/vendor/prawn-core/examples/text/font_size.rb +33 -0
- data/vendor/prawn-core/examples/text/indent_paragraphs.rb +18 -0
- data/vendor/prawn-core/examples/text/kerning.rb +30 -0
- data/vendor/prawn-core/examples/text/rotated.rb +98 -0
- data/vendor/prawn-core/examples/text/simple_text.rb +17 -0
- data/vendor/prawn-core/examples/text/simple_text_ttf.rb +17 -0
- data/vendor/prawn-core/examples/text/span.rb +29 -0
- data/vendor/prawn-core/examples/text/text_box.rb +88 -0
- data/vendor/prawn-core/examples/text/text_box_returning_excess.rb +51 -0
- data/vendor/prawn-core/examples/text/text_flow.rb +67 -0
- data/vendor/prawn-core/lib/prawn/byte_string.rb +7 -0
- data/vendor/prawn-core/lib/prawn/compatibility.rb +51 -0
- data/vendor/prawn-core/lib/prawn/core.rb +87 -0
- data/vendor/prawn-core/lib/prawn/core/page.rb +88 -0
- data/vendor/prawn-core/lib/prawn/core/text.rb +65 -0
- data/vendor/prawn-core/lib/prawn/document.rb +596 -0
- data/vendor/prawn-core/lib/prawn/document/annotations.rb +65 -0
- data/vendor/prawn-core/lib/prawn/document/bounding_box.rb +402 -0
- data/vendor/prawn-core/lib/prawn/document/column_box.rb +113 -0
- data/vendor/prawn-core/lib/prawn/document/destinations.rb +92 -0
- data/vendor/prawn-core/lib/prawn/document/graphics_state.rb +49 -0
- data/vendor/prawn-core/lib/prawn/document/internals.rb +153 -0
- data/vendor/prawn-core/lib/prawn/document/page_geometry.rb +136 -0
- data/vendor/prawn-core/lib/prawn/document/snapshot.rb +80 -0
- data/vendor/prawn-core/lib/prawn/document/span.rb +55 -0
- data/vendor/prawn-core/lib/prawn/encoding.rb +121 -0
- data/vendor/prawn-core/lib/prawn/errors.rb +83 -0
- data/vendor/prawn-core/lib/prawn/font.rb +329 -0
- data/vendor/prawn-core/lib/prawn/font/afm.rb +217 -0
- data/vendor/prawn-core/lib/prawn/font/dfont.rb +34 -0
- data/vendor/prawn-core/lib/prawn/font/ttf.rb +341 -0
- data/vendor/prawn-core/lib/prawn/graphics.rb +321 -0
- data/vendor/prawn-core/lib/prawn/graphics/cap_style.rb +38 -0
- data/vendor/prawn-core/lib/prawn/graphics/color.rb +205 -0
- data/vendor/prawn-core/lib/prawn/graphics/dash.rb +71 -0
- data/vendor/prawn-core/lib/prawn/graphics/join_style.rb +38 -0
- data/vendor/prawn-core/lib/prawn/graphics/transformation.rb +157 -0
- data/vendor/prawn-core/lib/prawn/graphics/transparency.rb +99 -0
- data/vendor/prawn-core/lib/prawn/images.rb +337 -0
- data/vendor/prawn-core/lib/prawn/images/jpg.rb +46 -0
- data/vendor/prawn-core/lib/prawn/images/png.rb +219 -0
- data/vendor/prawn-core/lib/prawn/literal_string.rb +14 -0
- data/vendor/prawn-core/lib/prawn/measurement_extensions.rb +46 -0
- data/vendor/prawn-core/lib/prawn/measurements.rb +71 -0
- data/vendor/prawn-core/lib/prawn/name_tree.rb +166 -0
- data/vendor/prawn-core/lib/prawn/object_store.rb +93 -0
- data/vendor/prawn-core/lib/prawn/outline.rb +278 -0
- data/vendor/prawn-core/lib/prawn/pdf_object.rb +83 -0
- data/vendor/prawn-core/lib/prawn/reference.rb +92 -0
- data/vendor/prawn-core/lib/prawn/repeater.rb +129 -0
- data/vendor/prawn-core/lib/prawn/stamp.rb +128 -0
- data/vendor/prawn-core/lib/prawn/text.rb +271 -0
- data/vendor/prawn-core/lib/prawn/text/box.rb +414 -0
- data/vendor/prawn-core/meta/Rakefile +36 -0
- data/vendor/prawn-core/meta/lib/prawn.rb +2 -0
- data/vendor/prawn-core/reference_pdfs/alignment.pdf +229 -0
- data/vendor/prawn-core/reference_pdfs/background.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/basic_images.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/bounding_boxes.pdf +128 -0
- data/vendor/prawn-core/reference_pdfs/canvas.pdf +78 -0
- data/vendor/prawn-core/reference_pdfs/chinese_flow.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/cmyk.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/column_box.pdf +3671 -0
- data/vendor/prawn-core/reference_pdfs/context_sensitive_headers.pdf +2331 -0
- data/vendor/prawn-core/reference_pdfs/curves.pdf +62 -0
- data/vendor/prawn-core/reference_pdfs/dfont.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/euro.pdf +75 -0
- data/vendor/prawn-core/reference_pdfs/family_style.pdf +286 -0
- data/vendor/prawn-core/reference_pdfs/flow.pdf +964 -0
- data/vendor/prawn-core/reference_pdfs/font_calculations.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/font_size.pdf +142 -0
- data/vendor/prawn-core/reference_pdfs/hexagon.pdf +61 -0
- data/vendor/prawn-core/reference_pdfs/image-flow.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/image_fit.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/image_position.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/indentation.pdf +124 -0
- data/vendor/prawn-core/reference_pdfs/kerning.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/landscape_a4.pdf +52 -0
- data/vendor/prawn-core/reference_pdfs/landscape_legal.pdf +52 -0
- data/vendor/prawn-core/reference_pdfs/landscape_letter.pdf +52 -0
- data/vendor/prawn-core/reference_pdfs/lines.pdf +116 -0
- data/vendor/prawn-core/reference_pdfs/margin.pdf +3850 -0
- data/vendor/prawn-core/reference_pdfs/measurement_units.pdf +4667 -0
- data/vendor/prawn-core/reference_pdfs/metadata-info.pdf +88 -0
- data/vendor/prawn-core/reference_pdfs/multi-layout.pdf +209 -0
- data/vendor/prawn-core/reference_pdfs/page_with_numbering.pdf +156 -0
- data/vendor/prawn-core/reference_pdfs/png_types.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/portrait_a4.pdf +52 -0
- data/vendor/prawn-core/reference_pdfs/portrait_legal.pdf +52 -0
- data/vendor/prawn-core/reference_pdfs/portrait_letter.pdf +52 -0
- data/vendor/prawn-core/reference_pdfs/pretty_polygons.pdf +122 -0
- data/vendor/prawn-core/reference_pdfs/remote_images.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/ruport.pdf +101 -0
- data/vendor/prawn-core/reference_pdfs/russian_boxes.pdf +2780 -0
- data/vendor/prawn-core/reference_pdfs/simple_text.pdf +136 -0
- data/vendor/prawn-core/reference_pdfs/simple_text_ttf.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/sjis.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/span.pdf +1975 -0
- data/vendor/prawn-core/reference_pdfs/stamp.pdf +649 -0
- data/vendor/prawn-core/reference_pdfs/stretched_nesting.pdf +200 -0
- data/vendor/prawn-core/reference_pdfs/stroke_bounds.pdf +135 -0
- data/vendor/prawn-core/reference_pdfs/stroke_cap_and_join.pdf +80 -0
- data/vendor/prawn-core/reference_pdfs/stroke_dash.pdf +457 -0
- data/vendor/prawn-core/reference_pdfs/text_box.pdf +962 -0
- data/vendor/prawn-core/reference_pdfs/text_box_returning_excess.pdf +271 -0
- data/vendor/prawn-core/reference_pdfs/transparency.pdf +347 -0
- data/vendor/prawn-core/reference_pdfs/utf8.pdf +0 -0
- data/vendor/prawn-core/reference_pdfs/win-ansi.pdf +6172 -0
- data/vendor/prawn-core/spec/annotations_spec.rb +90 -0
- data/vendor/prawn-core/spec/bounding_box_spec.rb +185 -0
- data/vendor/prawn-core/spec/destinations_spec.rb +15 -0
- data/vendor/prawn-core/spec/document_spec.rb +408 -0
- data/vendor/prawn-core/spec/font_spec.rb +314 -0
- data/vendor/prawn-core/spec/graphics_spec.rb +438 -0
- data/vendor/prawn-core/spec/images_spec.rb +79 -0
- data/vendor/prawn-core/spec/jpg_spec.rb +25 -0
- data/vendor/prawn-core/spec/measurement_units_spec.rb +23 -0
- data/vendor/prawn-core/spec/name_tree_spec.rb +112 -0
- data/vendor/prawn-core/spec/object_store_spec.rb +75 -0
- data/vendor/prawn-core/spec/outline_spec.rb +229 -0
- data/vendor/prawn-core/spec/pdf_object_spec.rb +122 -0
- data/vendor/prawn-core/spec/png_spec.rb +236 -0
- data/vendor/prawn-core/spec/reference_spec.rb +82 -0
- data/vendor/prawn-core/spec/repeater_spec.rb +96 -0
- data/vendor/prawn-core/spec/snapshot_spec.rb +138 -0
- data/vendor/prawn-core/spec/span_spec.rb +49 -0
- data/vendor/prawn-core/spec/spec_helper.rb +24 -0
- data/vendor/prawn-core/spec/stamp_spec.rb +108 -0
- data/vendor/prawn-core/spec/stroke_styles_spec.rb +152 -0
- data/vendor/prawn-core/spec/text_at_spec.rb +119 -0
- data/vendor/prawn-core/spec/text_box_spec.rb +603 -0
- data/vendor/prawn-core/spec/text_spec.rb +308 -0
- data/vendor/prawn-core/spec/transparency_spec.rb +75 -0
- data/vendor/prawn-core/vendor/pdf-inspector/README +18 -0
- data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector.rb +26 -0
- data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +18 -0
- data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +131 -0
- data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/page.rb +25 -0
- data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/text.rb +31 -0
- data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +19 -0
- data/vendor/prawn-core/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/prawn-core/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/prawn-core/vendor/ttfunk/example.rb +45 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk.rb +102 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/directory.rb +17 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +88 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +69 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/reader.rb +44 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/resource_file.rb +78 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset.rb +18 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/base.rb +141 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +46 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +48 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +63 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +51 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset_collection.rb +72 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table.rb +46 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/cmap.rb +34 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +54 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +126 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +79 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/glyf.rb +64 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +81 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +37 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/head.rb +44 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/hhea.rb +41 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +47 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/kern.rb +79 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +62 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/loca.rb +43 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/maxp.rb +40 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/name.rb +119 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/os2.rb +78 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post.rb +91 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +43 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +35 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +23 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +17 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +17 -0
- data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/simple.rb +14 -0
- data/vendor/prawn-core/www/index.html +196 -0
- data/vendor/prawn-core/www/media/bounding_boxes.pdf +146 -0
- data/vendor/prawn-core/www/media/bounding_boxes.png +0 -0
- data/vendor/prawn-core/www/media/bounding_boxes_out.png +0 -0
- data/vendor/prawn-core/www/media/fancy_table.pdf +350 -0
- data/vendor/prawn-core/www/media/image.pdf +0 -0
- data/vendor/prawn-core/www/media/images.png +0 -0
- data/vendor/prawn-core/www/media/prawn_logo.png +0 -0
- data/vendor/prawn-core/www/media/tables.png +0 -0
- data/vendor/prawn-core/www/media/utf8.pdf +0 -0
- data/vendor/prawn-core/www/media/utf8.png +0 -0
- data/vendor/prawn-core/www/prawn-Chinese.html +113 -0
- data/vendor/prawn-core/www/prawn.css +86 -0
- data/vendor/prawn-core/www/twilight.css +266 -0
- metadata +374 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# snapshot.rb : Implements transactional rendering for Prawn
|
4
|
+
#
|
5
|
+
# Copyright August 2009, Brad Ediger. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
+
require 'delegate'
|
9
|
+
|
10
|
+
module Prawn
|
11
|
+
class Document
|
12
|
+
module Snapshot
|
13
|
+
|
14
|
+
RollbackTransaction = Class.new(StandardError)
|
15
|
+
|
16
|
+
# Call this within a +transaction+ block to roll back the transaction and
|
17
|
+
# prevent any of its data from being rendered. You must reset the
|
18
|
+
# y-position yourself if you have performed any drawing operations that
|
19
|
+
# modify it.
|
20
|
+
#
|
21
|
+
def rollback
|
22
|
+
raise RollbackTransaction
|
23
|
+
end
|
24
|
+
|
25
|
+
# Run a block of drawing operations, to be completed atomically. If
|
26
|
+
# +rollback+ is called or a RollbackTransaction exception is raised
|
27
|
+
# inside the block, all actions taken inside the block will be rolled
|
28
|
+
# back (with the exception of y-position, which you must restore
|
29
|
+
# yourself).
|
30
|
+
#
|
31
|
+
# Returns true on success, or false if the transaction was rolled back.
|
32
|
+
#
|
33
|
+
def transaction
|
34
|
+
snap = take_snapshot
|
35
|
+
yield
|
36
|
+
true
|
37
|
+
rescue RollbackTransaction
|
38
|
+
restore_snapshot(snap)
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# Takes a current snapshot of the document's state, sufficient to
|
45
|
+
# reconstruct it after it was amended.
|
46
|
+
def take_snapshot
|
47
|
+
{:page_content => Marshal.load(Marshal.dump(page.content)),
|
48
|
+
:current_page => Marshal.load(Marshal.dump(page.dictionary)),
|
49
|
+
:page_number => @page_number,
|
50
|
+
:page_kids => @store.pages.data[:Kids].map{|kid| kid.identifier},
|
51
|
+
:dests => names? &&
|
52
|
+
Marshal.load(Marshal.dump(names.data[:Dests]))}
|
53
|
+
end
|
54
|
+
|
55
|
+
# Rolls the page state back to the state of the given snapshot.
|
56
|
+
def restore_snapshot(shot)
|
57
|
+
# Because these objects are referenced by identifier from the Pages
|
58
|
+
# dictionary, we can't just restore them over the current refs in
|
59
|
+
# page_content and current_page. We have to restore them over the old
|
60
|
+
# ones.
|
61
|
+
page.content = shot[:page_content].identifier
|
62
|
+
page.content.replace shot[:page_content]
|
63
|
+
|
64
|
+
page.dictionary = shot[:current_page].identifier
|
65
|
+
page.dictionary.replace shot[:current_page]
|
66
|
+
page.dictionary.data[:Contents] = page.content
|
67
|
+
|
68
|
+
@page_number = shot[:page_number]
|
69
|
+
|
70
|
+
@store.pages.data[:Kids] = shot[:page_kids].map{|id| @store[id]}
|
71
|
+
@store.pages.data[:Count] = shot[:page_kids].size
|
72
|
+
|
73
|
+
if shot[:dests]
|
74
|
+
names.data[:Dests] = shot[:dests]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# span.rb : Implements text columns
|
4
|
+
#
|
5
|
+
# Copyright September 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
|
+
# A span is a special purpose bounding box that allows a column of
|
12
|
+
# elements to be positioned relative to the margin_box.
|
13
|
+
#
|
14
|
+
# Arguments:
|
15
|
+
# +width+:: The width of the column in PDF points
|
16
|
+
#
|
17
|
+
# Options:
|
18
|
+
# <tt>:position</tt>:: One of :left, :center, :right or an x offset
|
19
|
+
#
|
20
|
+
# This method is typically used for flowing a column of text from one
|
21
|
+
# page to the next.
|
22
|
+
#
|
23
|
+
# span(350, :position => :center) do
|
24
|
+
# text "Here's some centered text in a 350 point column. " * 100
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
def span(width, options={})
|
28
|
+
Prawn.verify_options [:position], options
|
29
|
+
original_position = self.y
|
30
|
+
|
31
|
+
# FIXME: Any way to move this upstream?
|
32
|
+
left_boundary = case(options[:position] || :left)
|
33
|
+
when :left
|
34
|
+
margin_box.absolute_left
|
35
|
+
when :center
|
36
|
+
margin_box.absolute_left + margin_box.width / 2.0 - width /2.0
|
37
|
+
when :right
|
38
|
+
margin_box.absolute_right - width
|
39
|
+
when Numeric
|
40
|
+
margin_box.absolute_left + options[:position]
|
41
|
+
else
|
42
|
+
raise ArgumentError, "Invalid option for :position"
|
43
|
+
end
|
44
|
+
|
45
|
+
# we need to bust out of whatever nested bounding boxes we're in.
|
46
|
+
canvas do
|
47
|
+
bounding_box([left_boundary,
|
48
|
+
margin_box.absolute_top], :width => width) do
|
49
|
+
self.y = original_position
|
50
|
+
yield
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright September 2008, Gregory Brown, James Healy All Rights Reserved.
|
4
|
+
#
|
5
|
+
# This is free software. Please see the LICENSE and COPYING files for details.
|
6
|
+
#
|
7
|
+
module Prawn
|
8
|
+
module Encoding
|
9
|
+
# Map between unicode and WinAnsiEnoding
|
10
|
+
#
|
11
|
+
class WinAnsi #:nodoc:
|
12
|
+
CHARACTERS = %w[
|
13
|
+
.notdef .notdef .notdef .notdef
|
14
|
+
.notdef .notdef .notdef .notdef
|
15
|
+
.notdef .notdef .notdef .notdef
|
16
|
+
.notdef .notdef .notdef .notdef
|
17
|
+
.notdef .notdef .notdef .notdef
|
18
|
+
.notdef .notdef .notdef .notdef
|
19
|
+
.notdef .notdef .notdef .notdef
|
20
|
+
.notdef .notdef .notdef .notdef
|
21
|
+
|
22
|
+
space exclam quotedbl numbersign
|
23
|
+
dollar percent ampersand quotesingle
|
24
|
+
parenleft parenright asterisk plus
|
25
|
+
comma hyphen period slash
|
26
|
+
zero one two three
|
27
|
+
four five six seven
|
28
|
+
eight nine colon semicolon
|
29
|
+
less equal greater question
|
30
|
+
|
31
|
+
at A B C
|
32
|
+
D E F G
|
33
|
+
H I J K
|
34
|
+
L M N O
|
35
|
+
P Q R S
|
36
|
+
T U V W
|
37
|
+
X Y Z bracketleft
|
38
|
+
backslash bracketright asciicircum underscore
|
39
|
+
|
40
|
+
grave a b c
|
41
|
+
d e f g
|
42
|
+
h i j k
|
43
|
+
l m n o
|
44
|
+
p q r s
|
45
|
+
t u v w
|
46
|
+
x y z braceleft
|
47
|
+
bar braceright asciitilde .notdef
|
48
|
+
|
49
|
+
Euro .notdef quotesinglbase florin
|
50
|
+
quotedblbase ellipsis dagger daggerdbl
|
51
|
+
circumflex perthousand Scaron guilsinglleft
|
52
|
+
OE .notdef Zcaron .notdef
|
53
|
+
.notdef quoteleft quoteright quotedblleft
|
54
|
+
quotedblright bullet endash emdash
|
55
|
+
tilde trademark scaron guilsinglright
|
56
|
+
oe .notdef zcaron ydieresis
|
57
|
+
|
58
|
+
space exclamdown cent sterling
|
59
|
+
currency yen brokenbar section
|
60
|
+
dieresis copyright ordfeminine guillemotleft
|
61
|
+
logicalnot hyphen registered macron
|
62
|
+
degree plusminus twosuperior threesuperior
|
63
|
+
acute mu paragraph periodcentered
|
64
|
+
cedilla onesuperior ordmasculine guillemotright
|
65
|
+
onequarter onehalf threequarters questiondown
|
66
|
+
|
67
|
+
Agrave Aacute Acircumflex Atilde
|
68
|
+
Adieresis Aring AE Ccedilla
|
69
|
+
Egrave Eacute Ecircumflex Edieresis
|
70
|
+
Igrave Iacute Icircumflex Idieresis
|
71
|
+
Eth Ntilde Ograve Oacute
|
72
|
+
Ocircumflex Otilde Odieresis multiply
|
73
|
+
Oslash Ugrave Uacute Ucircumflex
|
74
|
+
Udieresis Yacute Thorn germandbls
|
75
|
+
|
76
|
+
agrave aacute acircumflex atilde
|
77
|
+
adieresis aring ae ccedilla
|
78
|
+
egrave eacute ecircumflex edieresis
|
79
|
+
igrave iacute icircumflex idieresis
|
80
|
+
eth ntilde ograve oacute
|
81
|
+
ocircumflex otilde odieresis divide
|
82
|
+
oslash ugrave uacute ucircumflex
|
83
|
+
udieresis yacute thorn ydieresis
|
84
|
+
]
|
85
|
+
|
86
|
+
def initialize
|
87
|
+
@mapping_file = "#{Prawn::BASEDIR}/data/encodings/win_ansi.txt"
|
88
|
+
load_mapping if self.class.mapping.empty?
|
89
|
+
end
|
90
|
+
|
91
|
+
# Converts a Unicode codepoint into a valid WinAnsi single byte character.
|
92
|
+
#
|
93
|
+
# If there is no WinAnsi equivlant for a character, a _ will be substituted.
|
94
|
+
#
|
95
|
+
def [](codepoint)
|
96
|
+
# unicode codepoints < 255 map directly to the single byte value in WinAnsi
|
97
|
+
return codepoint if codepoint <= 255
|
98
|
+
|
99
|
+
# There are a handful of codepoints > 255 that have equivilants in WinAnsi.
|
100
|
+
# Replace anything else with an underscore
|
101
|
+
self.class.mapping[codepoint] || 95
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.mapping
|
105
|
+
@mapping ||= {}
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def load_mapping
|
111
|
+
RUBY_VERSION >= "1.9" ? mode = "r:BINARY" : mode = "r"
|
112
|
+
File.open(@mapping_file, mode) do |f|
|
113
|
+
f.each do |l|
|
114
|
+
m, single_byte, unicode = *l.match(/([0-9A-Za-z]+);([0-9A-F]{4})/)
|
115
|
+
self.class.mapping["0x#{unicode}".hex] = "0x#{single_byte}".hex if single_byte
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# errors.rb : Implements custom error classes for Prawn
|
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
|
+
module Errors
|
11
|
+
|
12
|
+
# This error is raised when Prawn::PdfObject() encounters a Ruby object it
|
13
|
+
# cannot convert to PDF
|
14
|
+
#
|
15
|
+
FailedObjectConversion = Class.new(StandardError)
|
16
|
+
|
17
|
+
# This error is raised when Document#page_layout is set to anything
|
18
|
+
# other than :portrait or :landscape
|
19
|
+
#
|
20
|
+
InvalidPageLayout = Class.new(StandardError)
|
21
|
+
|
22
|
+
# This error is raised when a method requiring a current page is called
|
23
|
+
# without being on a page.
|
24
|
+
#
|
25
|
+
NotOnPage = Class.new(StandardError)
|
26
|
+
|
27
|
+
# This error is raised when Prawn cannot find a specified font
|
28
|
+
#
|
29
|
+
UnknownFont = Class.new(StandardError)
|
30
|
+
|
31
|
+
# Raised when Prawn is asked to draw something into a too-small box
|
32
|
+
#
|
33
|
+
CannotFit = Class.new(StandardError)
|
34
|
+
|
35
|
+
# Raised if group() is called with a block that is too big to be
|
36
|
+
# rendered in the current context.
|
37
|
+
#
|
38
|
+
CannotGroup = Class.new(StandardError)
|
39
|
+
|
40
|
+
# This error is raised when Prawn is being used on a M17N aware VM,
|
41
|
+
# and the user attempts to add text that isn't compatible with UTF-8
|
42
|
+
# to their document
|
43
|
+
#
|
44
|
+
IncompatibleStringEncoding = Class.new(StandardError)
|
45
|
+
|
46
|
+
# This error is raised when Prawn encounters an unknown key in functions
|
47
|
+
# that accept an options hash. This usually means there is a typo in your
|
48
|
+
# code or that the option you are trying to use has a different name than
|
49
|
+
# what you have specified.
|
50
|
+
#
|
51
|
+
UnknownOption = Class.new(StandardError)
|
52
|
+
|
53
|
+
# this error is raised when a user attempts to embed an image of an unsupported
|
54
|
+
# type. This can either a completely unsupported format, or a dialect of a
|
55
|
+
# supported format (ie. some types of PNG)
|
56
|
+
UnsupportedImageType = Class.new(StandardError)
|
57
|
+
|
58
|
+
# This error is raised when a named element has alredy been
|
59
|
+
# created. For example, in the stamp module, stamps must have
|
60
|
+
# unique names within a document
|
61
|
+
NameTaken = Class.new(StandardError)
|
62
|
+
|
63
|
+
# This error is raised when a name is not a valid format
|
64
|
+
InvalidName = Class.new(StandardError)
|
65
|
+
|
66
|
+
# This error is raised when an object is attempted to be
|
67
|
+
# referenced by name, but no such name is associated with an object
|
68
|
+
UndefinedObjectName = Class.new(StandardError)
|
69
|
+
|
70
|
+
# This error is raised when a required option has not been set
|
71
|
+
RequiredOption = Class.new(StandardError)
|
72
|
+
|
73
|
+
# This error is raised when a requested outline item with a given title does not exist
|
74
|
+
UnknownOutlineTitle = Class.new(StandardError)
|
75
|
+
|
76
|
+
# This error is raised when a block is required, but not provided
|
77
|
+
BlockRequired = Class.new(StandardError)
|
78
|
+
|
79
|
+
# This error is rased when a graphics method is called with improper arguments
|
80
|
+
InvalidGraphicsPath = Class.new(StandardError)
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,329 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# font.rb : The Prawn font class
|
4
|
+
#
|
5
|
+
# Copyright May 2008, Gregory Brown / James Healy. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
+
require "prawn/font/afm"
|
9
|
+
require "prawn/font/ttf"
|
10
|
+
require "prawn/font/dfont"
|
11
|
+
|
12
|
+
module Prawn
|
13
|
+
|
14
|
+
class Document
|
15
|
+
# Without arguments, this returns the currently selected font. Otherwise,
|
16
|
+
# it sets the current font. When a block is used, the font is applied
|
17
|
+
# transactionally and is rolled back when the block exits.
|
18
|
+
#
|
19
|
+
# Prawn::Document.generate("font.pdf") do
|
20
|
+
# text "Default font is Helvetica"
|
21
|
+
#
|
22
|
+
# font "Times-Roman"
|
23
|
+
# text "Now using Times-Roman"
|
24
|
+
#
|
25
|
+
# font("Chalkboard.ttf") do
|
26
|
+
# text "Using TTF font from file Chalkboard.ttf"
|
27
|
+
# font "Courier", :style => :bold
|
28
|
+
# text "You see this in bold Courier"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# text "Times-Roman, again"
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# The :name parameter must be a string. It can be one of the 14 built-in
|
35
|
+
# fonts supported by PDF, or the location of a TTF file. The Font::AFM::BUILT_INS
|
36
|
+
# array specifies the valid built in font values.
|
37
|
+
#
|
38
|
+
# If a ttf font is specified, the glyphs necessary to render your document
|
39
|
+
# will be embedded in the rendered PDF. This should be your preferred option
|
40
|
+
# in most cases. It will increase the size of the resulting file, but also
|
41
|
+
# make it more portable.
|
42
|
+
#
|
43
|
+
# The options parameter is an optional hash providing size and style. To use
|
44
|
+
# the :style option you need to map those font styles to their respective font files.
|
45
|
+
# See font_families for more information.
|
46
|
+
#
|
47
|
+
def font(name=nil, options={})
|
48
|
+
return((defined?(@font) && @font) || font("Helvetica")) if name.nil?
|
49
|
+
|
50
|
+
raise Errors::NotOnPage if pages.empty? && !page.in_stamp_stream?
|
51
|
+
new_font = find_font(name, options)
|
52
|
+
|
53
|
+
if block_given?
|
54
|
+
save_font do
|
55
|
+
set_font(new_font, options[:size])
|
56
|
+
yield
|
57
|
+
end
|
58
|
+
else
|
59
|
+
set_font(new_font, options[:size])
|
60
|
+
end
|
61
|
+
|
62
|
+
@font
|
63
|
+
end
|
64
|
+
|
65
|
+
# When called with no argument, returns the current font size.
|
66
|
+
# When called with a single argument but no block, sets the current font
|
67
|
+
# size. When a block is used, the font size is applied transactionally and
|
68
|
+
# is rolled back when the block exits. You may still change the font size
|
69
|
+
# within a transactional block for individual text segments, or nested calls
|
70
|
+
# to font_size.
|
71
|
+
#
|
72
|
+
# Prawn::Document.generate("font_size.pdf") do
|
73
|
+
# font_size 16
|
74
|
+
# text "At size 16"
|
75
|
+
#
|
76
|
+
# font_size(10) do
|
77
|
+
# text "At size 10"
|
78
|
+
# text "At size 6", :size => 6
|
79
|
+
# text "At size 10"
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# text "At size 16"
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# When called without an argument, this method returns the current font
|
86
|
+
# size.
|
87
|
+
#
|
88
|
+
def font_size(points=nil)
|
89
|
+
return @font_size unless points
|
90
|
+
size_before_yield = @font_size
|
91
|
+
@font_size = points
|
92
|
+
block_given? ? yield : return
|
93
|
+
@font_size = size_before_yield
|
94
|
+
end
|
95
|
+
|
96
|
+
# Sets the font directly, given an actual Font object
|
97
|
+
# and size.
|
98
|
+
#
|
99
|
+
def set_font(font, size=nil) # :nodoc:
|
100
|
+
@font = font
|
101
|
+
@font_size = size if size
|
102
|
+
end
|
103
|
+
|
104
|
+
# Saves the current font, and then yields. When the block
|
105
|
+
# finishes, the original font is restored.
|
106
|
+
#
|
107
|
+
def save_font
|
108
|
+
@font ||= find_font("Helvetica")
|
109
|
+
original_font = @font
|
110
|
+
original_size = @font_size
|
111
|
+
|
112
|
+
yield
|
113
|
+
ensure
|
114
|
+
set_font(original_font, original_size) if original_font
|
115
|
+
end
|
116
|
+
|
117
|
+
# Looks up the given font using the given criteria. Once a font has been
|
118
|
+
# found by that matches the criteria, it will be cached to subsequent lookups
|
119
|
+
# for that font will return the same object.
|
120
|
+
#--
|
121
|
+
# Challenges involved: the name alone is not sufficient to uniquely identify
|
122
|
+
# a font (think dfont suitcases that can hold multiple different fonts in a
|
123
|
+
# single file). Thus, the :name key is included in the cache key.
|
124
|
+
#
|
125
|
+
# It is further complicated, however, since fonts in some formats (like the
|
126
|
+
# dfont suitcases) can be identified either by numeric index, OR by their
|
127
|
+
# name within the suitcase, and both should hash to the same font object
|
128
|
+
# (to avoid the font being embedded multiple times). This is not yet implemented,
|
129
|
+
# which means if someone selects a font both by name, and by index, the
|
130
|
+
# font will be embedded twice. Since we do font subsetting, this double
|
131
|
+
# embedding won't be catastrophic, just annoying.
|
132
|
+
# ++
|
133
|
+
def find_font(name, options={}) #:nodoc:
|
134
|
+
if font_families.key?(name)
|
135
|
+
family, name = name, font_families[name][options[:style] || :normal]
|
136
|
+
if name.is_a?(Hash)
|
137
|
+
options = options.merge(name)
|
138
|
+
name = options[:file]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
key = "#{name}:#{options[:font] || 0}"
|
142
|
+
font_registry[key] ||= Font.load(self, name, options.merge(:family => family))
|
143
|
+
end
|
144
|
+
|
145
|
+
# Hash of Font objects keyed by names
|
146
|
+
#
|
147
|
+
def font_registry #:nodoc:
|
148
|
+
@font_registry ||= {}
|
149
|
+
end
|
150
|
+
|
151
|
+
# Hash that maps font family names to their styled individual font names.
|
152
|
+
#
|
153
|
+
# To add support for another font family, append to this hash, e.g:
|
154
|
+
#
|
155
|
+
# pdf.font_families.update(
|
156
|
+
# "MyTrueTypeFamily" => { :bold => "foo-bold.ttf",
|
157
|
+
# :italic => "foo-italic.ttf",
|
158
|
+
# :bold_italic => "foo-bold-italic.ttf",
|
159
|
+
# :normal => "foo.ttf" })
|
160
|
+
#
|
161
|
+
# This will then allow you to use the fonts like so:
|
162
|
+
#
|
163
|
+
# pdf.font("MyTrueTypeFamily", :style => :bold)
|
164
|
+
# pdf.text "Some bold text"
|
165
|
+
# pdf.font("MyTrueTypeFamily")
|
166
|
+
# pdf.text "Some normal text"
|
167
|
+
#
|
168
|
+
# This assumes that you have appropriate TTF fonts for each style you
|
169
|
+
# wish to support.
|
170
|
+
#
|
171
|
+
# By default the styles :bold, :italic, :bold_italic, and :normal are
|
172
|
+
# defined for fonts "Courier", "Times-Roman" and "Helvetica".
|
173
|
+
#
|
174
|
+
# You probably want to provide those four styles, but are free to define
|
175
|
+
# custom ones, like :thin, and use them in font calls.
|
176
|
+
#
|
177
|
+
def font_families
|
178
|
+
@font_families ||= Hash.new { |h,k| h[k] = {} }.merge!(
|
179
|
+
{ "Courier" => { :bold => "Courier-Bold",
|
180
|
+
:italic => "Courier-Oblique",
|
181
|
+
:bold_italic => "Courier-BoldOblique",
|
182
|
+
:normal => "Courier" },
|
183
|
+
|
184
|
+
"Times-Roman" => { :bold => "Times-Bold",
|
185
|
+
:italic => "Times-Italic",
|
186
|
+
:bold_italic => "Times-BoldItalic",
|
187
|
+
:normal => "Times-Roman" },
|
188
|
+
|
189
|
+
"Helvetica" => { :bold => "Helvetica-Bold",
|
190
|
+
:italic => "Helvetica-Oblique",
|
191
|
+
:bold_italic => "Helvetica-BoldOblique",
|
192
|
+
:normal => "Helvetica" }
|
193
|
+
})
|
194
|
+
end
|
195
|
+
|
196
|
+
# Returns the width of the given string using the given font. If :size is not
|
197
|
+
# specified as one of the options, the string is measured using the current
|
198
|
+
# font size. You can also pass :kerning as an option to indicate whether
|
199
|
+
# kerning should be used when measuring the width (defaults to +false+).
|
200
|
+
#
|
201
|
+
# Note that the string _must_ be encoded properly for the font being used.
|
202
|
+
# For AFM fonts, this is WinAnsi. For TTF, make sure the font is encoded as
|
203
|
+
# UTF-8. You can use the Font#normalize_encoding method to make sure strings
|
204
|
+
# are in an encoding appropriate for the current font.
|
205
|
+
#--
|
206
|
+
# For the record, this method used to be a method of Font (and still delegates
|
207
|
+
# to width computations on Font). However, having the primary interface for
|
208
|
+
# calculating string widths exist on Font made it tricky to write extensions
|
209
|
+
# for Prawn in which widths are computed differently (e.g., taking formatting
|
210
|
+
# tags into account, or the like).
|
211
|
+
#
|
212
|
+
# By putting width_of here, on Document itself, extensions may easily override
|
213
|
+
# it and redefine the width calculation behavior.
|
214
|
+
#++
|
215
|
+
def width_of(string, options={})
|
216
|
+
font.compute_width_of(string, options)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# Provides font information and helper functions.
|
221
|
+
#
|
222
|
+
class Font
|
223
|
+
|
224
|
+
# The current font name
|
225
|
+
attr_reader :name
|
226
|
+
|
227
|
+
# The current font family
|
228
|
+
attr_reader :family
|
229
|
+
|
230
|
+
# The options hash used to initialize the font
|
231
|
+
attr_reader :options
|
232
|
+
|
233
|
+
# Shortcut interface for constructing a font object. Filenames of the form
|
234
|
+
# *.ttf will call Font::TTF.new, *.dfont Font::DFont.new, and anything else
|
235
|
+
# will be passed through to Font::AFM.new()
|
236
|
+
#
|
237
|
+
def self.load(document,name,options={})
|
238
|
+
case name
|
239
|
+
when /\.ttf$/ then TTF.new(document, name, options)
|
240
|
+
when /\.dfont$/ then DFont.new(document, name, options)
|
241
|
+
when /\.afm$/ then AFM.new(document, name, options)
|
242
|
+
else AFM.new(document, name, options)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def initialize(document,name,options={}) #:nodoc:
|
247
|
+
@document = document
|
248
|
+
@name = name
|
249
|
+
@options = options
|
250
|
+
|
251
|
+
@family = options[:family]
|
252
|
+
|
253
|
+
@identifier = :"F#{@document.font_registry.size + 1}"
|
254
|
+
|
255
|
+
@references = {}
|
256
|
+
end
|
257
|
+
|
258
|
+
# The size of the font ascender in PDF points
|
259
|
+
#
|
260
|
+
def ascender
|
261
|
+
@ascender / 1000.0 * size
|
262
|
+
end
|
263
|
+
|
264
|
+
# The size of the font descender in PDF points
|
265
|
+
#
|
266
|
+
def descender
|
267
|
+
-@descender / 1000.0 * size
|
268
|
+
end
|
269
|
+
|
270
|
+
# The size of the recommended gap between lines of text in PDF points
|
271
|
+
#
|
272
|
+
def line_gap
|
273
|
+
@line_gap / 1000.0 * size
|
274
|
+
end
|
275
|
+
|
276
|
+
# Normalizes the encoding of the string to an encoding supported by the
|
277
|
+
# font. The string is expected to be UTF-8 going in. It will be re-encoded
|
278
|
+
# and the new string will be returned. For an in-place (destructive)
|
279
|
+
# version, see normalize_encoding!.
|
280
|
+
def normalize_encoding(string)
|
281
|
+
raise NotImplementedError, "subclasses of Prawn::Font must implement #normalize_encoding"
|
282
|
+
end
|
283
|
+
|
284
|
+
# Destructive version of normalize_encoding; normalizes the encoding of a
|
285
|
+
# string in place.
|
286
|
+
#
|
287
|
+
def normalize_encoding!(str)
|
288
|
+
str.replace(normalize_encoding(str))
|
289
|
+
end
|
290
|
+
|
291
|
+
# Gets height of current font in PDF points at the given font size
|
292
|
+
#
|
293
|
+
def height_at(size)
|
294
|
+
@normalized_height ||= (@ascender - @descender + @line_gap) / 1000.0
|
295
|
+
@normalized_height * size
|
296
|
+
end
|
297
|
+
|
298
|
+
# Gets height of current font in PDF points at current font size
|
299
|
+
#
|
300
|
+
def height
|
301
|
+
height_at(size)
|
302
|
+
end
|
303
|
+
|
304
|
+
# Registers the given subset of the current font with the current PDF
|
305
|
+
# page. This is safe to call multiple times for a given font and subset,
|
306
|
+
# as it will only add the font the first time it is called.
|
307
|
+
#
|
308
|
+
def add_to_current_page(subset)
|
309
|
+
@references[subset] ||= register(subset)
|
310
|
+
@document.page.fonts.merge!(identifier_for(subset) => @references[subset])
|
311
|
+
end
|
312
|
+
|
313
|
+
def identifier_for(subset) #:nodoc:
|
314
|
+
"#{@identifier}.#{subset}"
|
315
|
+
end
|
316
|
+
|
317
|
+
def inspect #:nodoc:
|
318
|
+
"#{self.class.name}< #{name}: #{size} >"
|
319
|
+
end
|
320
|
+
|
321
|
+
private
|
322
|
+
|
323
|
+
def size
|
324
|
+
@document.font_size
|
325
|
+
end
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|