davebenvenuti-prawn 0.11.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/HACKING +50 -0
- data/LICENSE +56 -0
- data/README +141 -0
- data/Rakefile +52 -0
- data/data/encodings/win_ansi.txt +29 -0
- 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/Courier-Bold.afm +342 -0
- data/data/fonts/Courier-BoldOblique.afm +342 -0
- data/data/fonts/Courier-Oblique.afm +342 -0
- data/data/fonts/Courier.afm +342 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/Helvetica-Bold.afm +2827 -0
- data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/data/fonts/Helvetica-Oblique.afm +3051 -0
- data/data/fonts/Helvetica.afm +3051 -0
- data/data/fonts/MustRead.html +19 -0
- data/data/fonts/Symbol.afm +213 -0
- data/data/fonts/Times-Bold.afm +2588 -0
- data/data/fonts/Times-BoldItalic.afm +2384 -0
- data/data/fonts/Times-Italic.afm +2667 -0
- data/data/fonts/Times-Roman.afm +2419 -0
- data/data/fonts/ZapfDingbats.afm +225 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +1 -0
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/hexagon.pdf +61 -0
- data/data/pdfs/indirect_reference.pdf +86 -0
- data/data/pdfs/nested_pages.pdf +118 -0
- data/data/pdfs/page_without_mediabox.pdf +193 -0
- data/data/pdfs/resources_as_indirect_object.pdf +83 -0
- data/data/pdfs/two_hexagons.pdf +90 -0
- data/data/pdfs/version_1_6.pdf +61 -0
- data/data/shift_jis_text.txt +1 -0
- data/examples/bounding_box/bounding_boxes.rb +44 -0
- data/examples/bounding_box/indentation.rb +35 -0
- data/examples/bounding_box/russian_boxes.rb +37 -0
- data/examples/bounding_box/stretched_nesting.rb +68 -0
- data/examples/example_helper.rb +8 -0
- data/examples/general/background.rb +24 -0
- data/examples/general/canvas.rb +16 -0
- data/examples/general/context_sensitive_headers.rb +38 -0
- data/examples/general/float.rb +12 -0
- data/examples/general/margin.rb +37 -0
- data/examples/general/measurement_units.rb +52 -0
- data/examples/general/metadata-info.rb +17 -0
- data/examples/general/multi_page_layout.rb +19 -0
- data/examples/general/outlines.rb +67 -0
- data/examples/general/page_geometry.rb +32 -0
- data/examples/general/page_numbering.rb +16 -0
- data/examples/general/repeaters.rb +48 -0
- data/examples/general/stamp.rb +42 -0
- data/examples/general/templates.rb +14 -0
- data/examples/graphics/basic_images.rb +24 -0
- data/examples/graphics/cmyk.rb +13 -0
- data/examples/graphics/curves.rb +12 -0
- data/examples/graphics/hexagon.rb +14 -0
- data/examples/graphics/image_fit.rb +16 -0
- data/examples/graphics/image_flow.rb +38 -0
- data/examples/graphics/image_position.rb +18 -0
- data/examples/graphics/line.rb +33 -0
- data/examples/graphics/png_types.rb +23 -0
- data/examples/graphics/polygons.rb +17 -0
- data/examples/graphics/remote_images.rb +13 -0
- data/examples/graphics/rounded_polygons.rb +20 -0
- data/examples/graphics/rounded_rectangle.rb +21 -0
- data/examples/graphics/ruport_style_helpers.rb +20 -0
- data/examples/graphics/stroke_bounds.rb +21 -0
- data/examples/graphics/stroke_cap_and_join.rb +46 -0
- data/examples/graphics/stroke_dash.rb +43 -0
- data/examples/graphics/transformations.rb +53 -0
- data/examples/graphics/transparency.rb +27 -0
- data/examples/grid/bounding_boxes.rb +22 -0
- data/examples/grid/column_gutter_grid.rb +21 -0
- data/examples/grid/multi_boxes.rb +52 -0
- data/examples/grid/show_grid.rb +14 -0
- data/examples/grid/simple_grid.rb +21 -0
- data/examples/m17n/chinese_text_wrapping.rb +18 -0
- data/examples/m17n/euro.rb +16 -0
- data/examples/m17n/sjis.rb +29 -0
- data/examples/m17n/utf8.rb +14 -0
- data/examples/m17n/win_ansi_charset.rb +55 -0
- data/examples/security/hello_foo.rb +9 -0
- data/examples/table/bill.rb +54 -0
- data/examples/table/cell.rb +13 -0
- data/examples/table/checkerboard.rb +23 -0
- data/examples/table/header.rb +15 -0
- data/examples/table/inline_format_table.rb +13 -0
- data/examples/table/multi_page_table.rb +10 -0
- data/examples/table/simple_table.rb +25 -0
- data/examples/table/subtable.rb +13 -0
- data/examples/table/widths.rb +21 -0
- data/examples/text/alignment.rb +19 -0
- data/examples/text/character_spacing.rb +13 -0
- data/examples/text/dfont.rb +49 -0
- data/examples/text/family_based_styling.rb +25 -0
- data/examples/text/font_calculations.rb +92 -0
- data/examples/text/font_size.rb +34 -0
- data/examples/text/hyphenation.rb +46 -0
- data/examples/text/indent_paragraphs.rb +23 -0
- data/examples/text/inline_format.rb +104 -0
- data/examples/text/kerning.rb +31 -0
- data/examples/text/rotated.rb +99 -0
- data/examples/text/shaped_text_box.rb +32 -0
- data/examples/text/simple_text.rb +18 -0
- data/examples/text/simple_text_ttf.rb +18 -0
- data/examples/text/span.rb +30 -0
- data/examples/text/text_box.rb +89 -0
- data/examples/text/text_box_returning_excess.rb +52 -0
- data/examples/text/text_flow.rb +68 -0
- data/lib/prawn.rb +26 -0
- data/lib/prawn/compatibility.rb +51 -0
- data/lib/prawn/core.rb +85 -0
- data/lib/prawn/core/annotations.rb +61 -0
- data/lib/prawn/core/byte_string.rb +9 -0
- data/lib/prawn/core/destinations.rb +90 -0
- data/lib/prawn/core/document_state.rb +78 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +165 -0
- data/lib/prawn/core/object_store.rb +236 -0
- data/lib/prawn/core/page.rb +199 -0
- data/lib/prawn/core/pdf_object.rb +108 -0
- data/lib/prawn/core/reference.rb +112 -0
- data/lib/prawn/core/text.rb +140 -0
- data/lib/prawn/core/text/formatted/arranger.rb +266 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +127 -0
- data/lib/prawn/core/text/formatted/wrap.rb +112 -0
- data/lib/prawn/core/text/line_wrap.rb +211 -0
- data/lib/prawn/core/text/wrap.rb +82 -0
- data/lib/prawn/document.rb +575 -0
- data/lib/prawn/document/bounding_box.rb +428 -0
- data/lib/prawn/document/graphics_state.rb +48 -0
- data/lib/prawn/document/internals.rb +170 -0
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +87 -0
- data/lib/prawn/document/span.rb +55 -0
- data/lib/prawn/encoding.rb +121 -0
- data/lib/prawn/errors.rb +86 -0
- data/lib/prawn/font.rb +368 -0
- data/lib/prawn/font/afm.rb +225 -0
- data/lib/prawn/font/dfont.rb +42 -0
- data/lib/prawn/font/ttf.rb +350 -0
- data/lib/prawn/graphics.rb +325 -0
- data/lib/prawn/graphics/cap_style.rb +38 -0
- data/lib/prawn/graphics/color.rb +205 -0
- data/lib/prawn/graphics/dash.rb +71 -0
- data/lib/prawn/graphics/join_style.rb +38 -0
- data/lib/prawn/graphics/transformation.rb +156 -0
- data/lib/prawn/graphics/transparency.rb +99 -0
- data/lib/prawn/images.rb +217 -0
- data/lib/prawn/images/jpg.rb +85 -0
- data/lib/prawn/images/png.rb +356 -0
- data/lib/prawn/layout.rb +20 -0
- data/lib/prawn/layout/grid.rb +259 -0
- data/lib/prawn/measurement_extensions.rb +46 -0
- data/lib/prawn/measurements.rb +71 -0
- data/lib/prawn/outline.rb +326 -0
- data/lib/prawn/repeater.rb +129 -0
- data/lib/prawn/security.rb +262 -0
- data/lib/prawn/security/arcfour.rb +51 -0
- data/lib/prawn/stamp.rb +126 -0
- data/lib/prawn/table.rb +451 -0
- data/lib/prawn/table/cell.rb +395 -0
- data/lib/prawn/table/cell/in_table.rb +27 -0
- data/lib/prawn/table/cell/subtable.rb +65 -0
- data/lib/prawn/table/cell/text.rb +135 -0
- data/lib/prawn/table/cells.rb +206 -0
- data/lib/prawn/text.rb +449 -0
- data/lib/prawn/text/box.rb +397 -0
- data/lib/prawn/text/formatted.rb +4 -0
- data/lib/prawn/text/formatted/box.rb +222 -0
- data/lib/prawn/text/formatted/fragment.rb +181 -0
- data/lib/prawn/text/formatted/parser.rb +213 -0
- data/prawn.gemspec +28 -0
- data/spec/annotations_spec.rb +90 -0
- data/spec/bounding_box_spec.rb +190 -0
- data/spec/cell_spec.rb +430 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +476 -0
- data/spec/extensions/mocha.rb +32 -0
- data/spec/font_spec.rb +324 -0
- data/spec/formatted_text_arranger_spec.rb +426 -0
- data/spec/formatted_text_box_spec.rb +756 -0
- data/spec/formatted_text_fragment_spec.rb +211 -0
- data/spec/graphics_spec.rb +446 -0
- data/spec/grid_spec.rb +85 -0
- data/spec/images_spec.rb +119 -0
- data/spec/inline_formatted_text_parser_spec.rb +502 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/line_wrap_spec.rb +341 -0
- data/spec/measurement_units_spec.rb +23 -0
- data/spec/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +160 -0
- data/spec/outline_spec.rb +404 -0
- data/spec/pdf_object_spec.rb +170 -0
- data/spec/png_spec.rb +237 -0
- data/spec/reference_spec.rb +82 -0
- data/spec/repeater_spec.rb +96 -0
- data/spec/security_spec.rb +120 -0
- data/spec/snapshot_spec.rb +154 -0
- data/spec/span_spec.rb +49 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/stamp_spec.rb +108 -0
- data/spec/stroke_styles_spec.rb +163 -0
- data/spec/table_spec.rb +687 -0
- data/spec/template_spec.rb +165 -0
- data/spec/text_at_spec.rb +125 -0
- data/spec/text_box_spec.rb +777 -0
- data/spec/text_spacing_spec.rb +75 -0
- data/spec/text_spec.rb +349 -0
- data/spec/text_with_inline_formatting_spec.rb +193 -0
- data/spec/transparency_spec.rb +89 -0
- data/vendor/pdf-inspector/README +18 -0
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +26 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +18 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +131 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +25 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +46 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +19 -0
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +45 -0
- data/vendor/ttfunk/lib/ttfunk.rb +102 -0
- data/vendor/ttfunk/lib/ttfunk/directory.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +88 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +69 -0
- data/vendor/ttfunk/lib/ttfunk/reader.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/subset.rb +18 -0
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +141 -0
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +50 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +63 -0
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +55 -0
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +72 -0
- data/vendor/ttfunk/lib/ttfunk/table.rb +46 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +34 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +54 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +126 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +79 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +64 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +81 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +37 -0
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +41 -0
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +47 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +79 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +62 -0
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +40 -0
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +125 -0
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +91 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +35 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +23 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +14 -0
- metadata +379 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
2
|
+
|
3
|
+
module TransparencyHelper
|
4
|
+
def make_transparent(opacity, stroke_opacity=opacity)
|
5
|
+
@pdf.transparent(opacity, stroke_opacity) do
|
6
|
+
yield if block_given?
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "Document with transparency" do
|
12
|
+
include TransparencyHelper
|
13
|
+
|
14
|
+
it "the PDF version should be at least 1.4" do
|
15
|
+
create_pdf
|
16
|
+
make_transparent(0.5)
|
17
|
+
str = @pdf.render
|
18
|
+
str[0,8].should == "%PDF-1.4"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "a new extended graphics state should be created for "+
|
22
|
+
"each unique transparency setting" do
|
23
|
+
create_pdf
|
24
|
+
make_transparent(0.5, 0.2) do
|
25
|
+
make_transparent(0.5, 0.75)
|
26
|
+
end
|
27
|
+
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
28
|
+
extgstates.length.should == 2
|
29
|
+
end
|
30
|
+
|
31
|
+
it "a new extended graphics state should not be created for "+
|
32
|
+
"each duplicate transparency setting" do
|
33
|
+
create_pdf
|
34
|
+
make_transparent(0.5, 0.75) do
|
35
|
+
make_transparent(0.5, 0.75)
|
36
|
+
end
|
37
|
+
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
38
|
+
extgstates.length.should == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
it "setting the transparency with only one parameter sets the transparency"+
|
42
|
+
" for both the fill and the stroke" do
|
43
|
+
create_pdf
|
44
|
+
make_transparent(0.5)
|
45
|
+
extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates[0]
|
46
|
+
extgstate[:opacity].should == 0.5
|
47
|
+
extgstate[:stroke_opacity].should == 0.5
|
48
|
+
end
|
49
|
+
|
50
|
+
it "setting the transparency with a numerical parameter and "+
|
51
|
+
"a :stroke should set the fill transparency to the numerical parameter "+
|
52
|
+
"and the stroke transparency to the option" do
|
53
|
+
create_pdf
|
54
|
+
make_transparent(0.5, 0.2)
|
55
|
+
extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates[0]
|
56
|
+
extgstate[:opacity].should == 0.5
|
57
|
+
extgstate[:stroke_opacity].should == 0.2
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should enforce the valid range of 0.0 to 1.0" do
|
61
|
+
create_pdf
|
62
|
+
make_transparent(-0.5, -0.2)
|
63
|
+
extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates[0]
|
64
|
+
extgstate[:opacity].should == 0.0
|
65
|
+
extgstate[:stroke_opacity].should == 0.0
|
66
|
+
|
67
|
+
create_pdf
|
68
|
+
make_transparent(2.0, 3.0)
|
69
|
+
extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates[0]
|
70
|
+
extgstate[:opacity].should == 1.0
|
71
|
+
extgstate[:stroke_opacity].should == 1.0
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "with more than one page" do
|
75
|
+
include TransparencyHelper
|
76
|
+
|
77
|
+
it "the extended graphic state resource should be added to both pages" do
|
78
|
+
create_pdf
|
79
|
+
make_transparent(0.5, 0.2)
|
80
|
+
@pdf.start_new_page
|
81
|
+
make_transparent(0.5, 0.2)
|
82
|
+
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
83
|
+
extgstate = extgstates[0]
|
84
|
+
extgstates.length.should == 2
|
85
|
+
extgstate[:opacity].should == 0.5
|
86
|
+
extgstate[:stroke_opacity].should == 0.2
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
PDF::Inspector : A tool for analyzing PDF output
|
2
|
+
|
3
|
+
This library provides a number of PDF::Reader[0] based tools for use in testing
|
4
|
+
PDF output. Presently, the primary purpose of this tool is to support the
|
5
|
+
tests found in Prawn[1], a pure Ruby PDF generation library.
|
6
|
+
|
7
|
+
However, it may be useful to others, so we have made it available on Github[2]
|
8
|
+
|
9
|
+
Questions can be directed to the Prawn mailing list[3], but please remember
|
10
|
+
that this code is not necessarily suitable for production and has no officially
|
11
|
+
planned release date.
|
12
|
+
|
13
|
+
That having been said, patches are welcome!
|
14
|
+
|
15
|
+
[0] http://github.com/yob/pdf-reader
|
16
|
+
[1] http://github.com/sandal/prawn
|
17
|
+
[2] http://github.com/sandal/pdf-inspector
|
18
|
+
[3] http://groups.google.com/group/prawn-ruby
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "pdf/reader"
|
3
|
+
require "pdf/inspector/text"
|
4
|
+
require "pdf/inspector/xobject"
|
5
|
+
require "pdf/inspector/extgstate"
|
6
|
+
require "pdf/inspector/graphics"
|
7
|
+
require "pdf/inspector/page"
|
8
|
+
|
9
|
+
module PDF
|
10
|
+
class Inspector
|
11
|
+
def self.analyze(output,*args,&block)
|
12
|
+
obs = self.new(*args, &block)
|
13
|
+
PDF::Reader.string(output,obs)
|
14
|
+
obs
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.analyze_file(filename,*args,&block)
|
18
|
+
analyze(File.open(filename, "rb") { |f| f.read },*args,&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse(obj)
|
22
|
+
PDF::Reader::Parser.new(
|
23
|
+
PDF::Reader::Buffer.new(StringIO.new(obj)), nil).parse_token
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PDF
|
2
|
+
class Inspector
|
3
|
+
class ExtGState < Inspector
|
4
|
+
attr_accessor :extgstates
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@extgstates = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def resource_extgstate(*params)
|
11
|
+
@extgstates << {
|
12
|
+
:opacity => params[1][:ca],
|
13
|
+
:stroke_opacity => params[1][:CA]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module PDF
|
2
|
+
class Inspector
|
3
|
+
module Graphics
|
4
|
+
class Line < Inspector
|
5
|
+
attr_accessor :points, :widths
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@points = []
|
9
|
+
@widths = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def append_line(*params)
|
13
|
+
@points << params
|
14
|
+
end
|
15
|
+
|
16
|
+
def begin_new_subpath(*params)
|
17
|
+
@points << params
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_line_width(params)
|
21
|
+
@widths << params
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class Rectangle < Inspector
|
27
|
+
attr_reader :rectangles
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@rectangles = []
|
31
|
+
end
|
32
|
+
|
33
|
+
def append_rectangle(*params)
|
34
|
+
@rectangles << { :point => params[0..1],
|
35
|
+
:width => params[2],
|
36
|
+
:height => params[3] }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Curve < Inspector
|
41
|
+
|
42
|
+
attr_reader :coords
|
43
|
+
|
44
|
+
def initialize
|
45
|
+
@coords = []
|
46
|
+
end
|
47
|
+
|
48
|
+
def begin_new_subpath(*params)
|
49
|
+
@coords += params
|
50
|
+
end
|
51
|
+
|
52
|
+
def append_curved_segment(*params)
|
53
|
+
@coords += params
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
class Color < Inspector
|
59
|
+
attr_reader :stroke_color, :fill_color, :stroke_color_count,
|
60
|
+
:fill_color_count
|
61
|
+
|
62
|
+
def initialize
|
63
|
+
@stroke_color_count = 0
|
64
|
+
@fill_color_count = 0
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_color_for_stroking_and_special(*params)
|
68
|
+
@stroke_color_count += 1
|
69
|
+
@stroke_color = params
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_color_for_nonstroking_and_special(*params)
|
73
|
+
@fill_color_count += 1
|
74
|
+
@fill_color = params
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Dash < Inspector
|
79
|
+
attr_reader :stroke_dash, :stroke_dash_count
|
80
|
+
|
81
|
+
def initialize
|
82
|
+
@stroke_dash_count = 0
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_line_dash(*params)
|
86
|
+
@stroke_dash_count += 1
|
87
|
+
@stroke_dash = params
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class CapStyle < Inspector
|
92
|
+
attr_reader :cap_style, :cap_style_count
|
93
|
+
|
94
|
+
def initialize
|
95
|
+
@cap_style_count = 0
|
96
|
+
end
|
97
|
+
|
98
|
+
def set_line_cap_style(*params)
|
99
|
+
@cap_style_count += 1
|
100
|
+
@cap_style = params[0]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class JoinStyle < Inspector
|
105
|
+
attr_reader :join_style, :join_style_count
|
106
|
+
|
107
|
+
def initialize
|
108
|
+
@join_style_count = 0
|
109
|
+
end
|
110
|
+
|
111
|
+
def set_line_join_style(*params)
|
112
|
+
@join_style_count += 1
|
113
|
+
@join_style = params[0]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class Matrix < Inspector
|
118
|
+
attr_reader :matrices
|
119
|
+
|
120
|
+
def initialize
|
121
|
+
@matrices = []
|
122
|
+
end
|
123
|
+
|
124
|
+
def concatenate_matrix(*values)
|
125
|
+
@matrices << values
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PDF
|
2
|
+
class Inspector
|
3
|
+
class Page < Inspector
|
4
|
+
attr_reader :pages
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@pages = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def begin_page(params)
|
11
|
+
@pages << {:size => params[:MediaBox][-2..-1], :strings => []}
|
12
|
+
end
|
13
|
+
|
14
|
+
def show_text(*params)
|
15
|
+
@pages.last[:strings] << params[0]
|
16
|
+
end
|
17
|
+
|
18
|
+
def show_text_with_positioning(*params)
|
19
|
+
# ignore kerning information
|
20
|
+
@pages.last[:strings] << params[0].reject { |e| Numeric === e }.join
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module PDF
|
2
|
+
class Inspector
|
3
|
+
class Text < Inspector
|
4
|
+
attr_accessor :font_settings, :size, :strings
|
5
|
+
attr_accessor :character_spacing, :word_spacing
|
6
|
+
attr_accessor :kerned
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@font_settings = []
|
10
|
+
@fonts = {}
|
11
|
+
@strings = []
|
12
|
+
@character_spacing = []
|
13
|
+
@word_spacing = []
|
14
|
+
@kerned = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def resource_font(*params)
|
18
|
+
@fonts[params[0]] = params[1].basefont
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_text_font_and_size(*params)
|
22
|
+
@font_settings << { :name => @fonts[params[0]], :size => params[1] }
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_text(*params)
|
26
|
+
@kerned << false
|
27
|
+
@strings << params[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
def show_text_with_positioning(*params)
|
31
|
+
@kerned << true
|
32
|
+
# ignore kerning information
|
33
|
+
@strings << params[0].reject { |e| Numeric === e }.join
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_character_spacing(*params)
|
37
|
+
@character_spacing << params[0]
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_word_spacing(*params)
|
41
|
+
@word_spacing << params[0]
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PDF
|
2
|
+
class Inspector
|
3
|
+
class XObject < Inspector
|
4
|
+
attr_accessor :page_xobjects
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@page_xobjects = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def resource_xobject(*params)
|
11
|
+
@page_xobjects.last << params.first
|
12
|
+
end
|
13
|
+
|
14
|
+
def begin_page(*params)
|
15
|
+
@page_xobjects << []
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,45 @@
|
|
1
|
+
$LOAD_PATH << "#{File.dirname(__FILE__)}/lib"
|
2
|
+
require "ttfunk"
|
3
|
+
|
4
|
+
def character_lookup(file, character)
|
5
|
+
puts "character : #{character}"
|
6
|
+
|
7
|
+
character_code = character.unpack("U*").first
|
8
|
+
puts "character code: #{character_code}"
|
9
|
+
|
10
|
+
glyph_id = file.cmap.unicode.first[character_code]
|
11
|
+
puts "glyph id : #{glyph_id}"
|
12
|
+
|
13
|
+
glyph = file.glyph_outlines.for(glyph_id)
|
14
|
+
puts "glyph type : %s" % glyph.class.name.split(/::/).last.downcase
|
15
|
+
puts "glyph size : %db" % glyph.raw.length
|
16
|
+
puts "glyph bbox : (%d,%d)-(%d,%d)" % [glyph.x_min, glyph.y_min, glyph.x_max, glyph.y_max]
|
17
|
+
|
18
|
+
if glyph.compound?
|
19
|
+
puts "components : %d %s" % [glyph.glyph_ids.length, glyph.glyph_ids.inspect]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
file = TTFunk::File.open(ARGV.first || "data/fonts/DejaVuSans.ttf")
|
24
|
+
|
25
|
+
puts "-- FONT ------------------------------------"
|
26
|
+
|
27
|
+
puts "revision : %08x" % file.header.font_revision
|
28
|
+
puts "name : #{file.name.font_name.join(', ')}"
|
29
|
+
puts "family : #{file.name.font_family.join(', ')}"
|
30
|
+
puts "subfamily : #{file.name.font_subfamily.join(', ')}"
|
31
|
+
puts "postscript: #{file.name.postscript_name}"
|
32
|
+
|
33
|
+
puts "-- FONT METRICS ----------------------------"
|
34
|
+
|
35
|
+
puts "units/em : #{file.header.units_per_em}"
|
36
|
+
puts "ascent : #{file.ascent}"
|
37
|
+
puts "descent : #{file.descent}"
|
38
|
+
puts "line gap : #{file.line_gap}"
|
39
|
+
puts "bbox : (%d,%d)-(%d,%d)" % file.bbox
|
40
|
+
|
41
|
+
puts "-- SIMPLE CHARACTER -> GLYPH LOOKUP --------"
|
42
|
+
character_lookup(file, "\xE2\x98\x9C")
|
43
|
+
|
44
|
+
puts "-- COMPOUND CHARACTER -> GLYPH LOOKUP ------"
|
45
|
+
character_lookup(file, "ë")
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require 'ttfunk/directory'
|
3
|
+
require 'ttfunk/resource_file'
|
4
|
+
|
5
|
+
module TTFunk
|
6
|
+
class File
|
7
|
+
attr_reader :contents
|
8
|
+
attr_reader :directory
|
9
|
+
|
10
|
+
def self.open(file)
|
11
|
+
new(::File.open(file, "rb") { |f| f.read })
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_dfont(file, which=0)
|
15
|
+
new(ResourceFile.open(file) { |dfont| dfont["sfnt", which] })
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(contents)
|
19
|
+
@contents = StringIO.new(contents)
|
20
|
+
@directory = Directory.new(@contents)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def ascent
|
25
|
+
@ascent ||= os2.exists? && os2.ascent || horizontal_header.ascent
|
26
|
+
end
|
27
|
+
|
28
|
+
def descent
|
29
|
+
@descent ||= os2.exists? && os2.descent || horizontal_header.descent
|
30
|
+
end
|
31
|
+
|
32
|
+
def line_gap
|
33
|
+
@line_gap ||= os2.exists? && os2.line_gap || horizontal_header.line_gap
|
34
|
+
end
|
35
|
+
|
36
|
+
def bbox
|
37
|
+
[header.x_min, header.y_min, header.x_max, header.y_max]
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def directory_info(tag)
|
42
|
+
directory.tables[tag.to_s]
|
43
|
+
end
|
44
|
+
|
45
|
+
def header
|
46
|
+
@header ||= TTFunk::Table::Head.new(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
def cmap
|
50
|
+
@cmap ||= TTFunk::Table::Cmap.new(self)
|
51
|
+
end
|
52
|
+
|
53
|
+
def horizontal_header
|
54
|
+
@horizontal_header ||= TTFunk::Table::Hhea.new(self)
|
55
|
+
end
|
56
|
+
|
57
|
+
def horizontal_metrics
|
58
|
+
@horizontal_metrics ||= TTFunk::Table::Hmtx.new(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def maximum_profile
|
62
|
+
@maximum_profile ||= TTFunk::Table::Maxp.new(self)
|
63
|
+
end
|
64
|
+
|
65
|
+
def kerning
|
66
|
+
@kerning ||= TTFunk::Table::Kern.new(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
def name
|
70
|
+
@name ||= TTFunk::Table::Name.new(self)
|
71
|
+
end
|
72
|
+
|
73
|
+
def os2
|
74
|
+
@os2 ||= TTFunk::Table::OS2.new(self)
|
75
|
+
end
|
76
|
+
|
77
|
+
def postscript
|
78
|
+
@postscript ||= TTFunk::Table::Post.new(self)
|
79
|
+
end
|
80
|
+
|
81
|
+
def glyph_locations
|
82
|
+
@glyph_locations ||= TTFunk::Table::Loca.new(self)
|
83
|
+
end
|
84
|
+
|
85
|
+
def glyph_outlines
|
86
|
+
@glyph_outlines ||= TTFunk::Table::Glyf.new(self)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
require "ttfunk/table/cmap"
|
92
|
+
require "ttfunk/table/glyf"
|
93
|
+
require "ttfunk/table/head"
|
94
|
+
require "ttfunk/table/hhea"
|
95
|
+
require "ttfunk/table/hmtx"
|
96
|
+
require "ttfunk/table/kern"
|
97
|
+
require "ttfunk/table/loca"
|
98
|
+
require "ttfunk/table/maxp"
|
99
|
+
require "ttfunk/table/name"
|
100
|
+
require "ttfunk/table/os2"
|
101
|
+
require "ttfunk/table/post"
|
102
|
+
|