alphasights-prawn 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +50 -3
@@ -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
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TTFunk
|
2
|
+
class Directory
|
3
|
+
attr_reader :tables
|
4
|
+
attr_reader :scaler_type
|
5
|
+
|
6
|
+
def initialize(io)
|
7
|
+
@scaler_type, table_count, search_range,
|
8
|
+
entry_selector, range_shift = io.read(12).unpack("Nn*")
|
9
|
+
|
10
|
+
@tables = {}
|
11
|
+
table_count.times do
|
12
|
+
tag, checksum, offset, length = io.read(16).unpack("a4N*")
|
13
|
+
@tables[tag] = { :tag => tag, :checksum => checksum, :offset => offset, :length => length }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|