eideticpdf 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/fonts/AntiqueOlive-Bold.afm +406 -0
- data/fonts/AntiqueOlive-Bold.inf +27 -0
- data/fonts/AntiqueOlive-Compact.afm +401 -0
- data/fonts/AntiqueOlive-Compact.inf +27 -0
- data/fonts/AntiqueOlive-Italic.afm +401 -0
- data/fonts/AntiqueOlive-Italic.inf +27 -0
- data/fonts/AntiqueOlive-Roman.afm +409 -0
- data/fonts/AntiqueOlive-Roman.inf +27 -0
- data/fonts/AvantGarde-Book.afm +667 -0
- data/fonts/AvantGarde-Book.inf +26 -0
- data/fonts/AvantGarde-BookOblique.afm +667 -0
- data/fonts/AvantGarde-BookOblique.inf +26 -0
- data/fonts/AvantGarde-Demi.afm +673 -0
- data/fonts/AvantGarde-Demi.inf +26 -0
- data/fonts/AvantGarde-DemiOblique.afm +673 -0
- data/fonts/AvantGarde-DemiOblique.inf +26 -0
- data/fonts/Bookman-Demi.afm +669 -0
- data/fonts/Bookman-Demi.inf +25 -0
- data/fonts/Bookman-DemiItalic.afm +669 -0
- data/fonts/Bookman-DemiItalic.inf +25 -0
- data/fonts/Bookman-Light.afm +643 -0
- data/fonts/Bookman-Light.inf +25 -0
- data/fonts/Bookman-LightItalic.afm +620 -0
- data/fonts/Bookman-LightItalic.inf +25 -0
- data/fonts/Clarendon-Bold.afm +412 -0
- data/fonts/Clarendon-Bold.inf +27 -0
- data/fonts/Clarendon-Light.afm +410 -0
- data/fonts/Clarendon-Light.inf +27 -0
- data/fonts/Clarendon.afm +410 -0
- data/fonts/Clarendon.inf +27 -0
- data/fonts/CooperBlack-Italic.afm +421 -0
- data/fonts/CooperBlack-Italic.inf +26 -0
- data/fonts/CooperBlack.afm +427 -0
- data/fonts/CooperBlack.inf +26 -0
- data/fonts/Coronet-Regular.afm +327 -0
- data/fonts/Coronet-Regular.inf +25 -0
- data/fonts/Courier-Bold.afm +342 -0
- data/fonts/Courier-Bold.inf +26 -0
- data/fonts/Courier-BoldOblique.afm +342 -0
- data/fonts/Courier-BoldOblique.inf +26 -0
- data/fonts/Courier-Oblique.afm +342 -0
- data/fonts/Courier-Oblique.inf +26 -0
- data/fonts/Courier.afm +342 -0
- data/fonts/Courier.inf +26 -0
- data/fonts/Eurostile.afm +419 -0
- data/fonts/Eurostile.inf +27 -0
- data/fonts/Goudy-ExtraBold.afm +412 -0
- data/fonts/Goudy-ExtraBold.inf +27 -0
- data/fonts/Helvetica-Bold.afm +2827 -0
- data/fonts/Helvetica-Bold.inf +26 -0
- data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/fonts/Helvetica-BoldOblique.inf +26 -0
- data/fonts/Helvetica-Condensed-Bold.afm +623 -0
- data/fonts/Helvetica-Condensed-Bold.inf +25 -0
- data/fonts/Helvetica-Condensed-BoldObl.afm +623 -0
- data/fonts/Helvetica-Condensed-BoldObl.inf +25 -0
- data/fonts/Helvetica-Condensed-Oblique.afm +528 -0
- data/fonts/Helvetica-Condensed-Oblique.inf +25 -0
- data/fonts/Helvetica-Condensed.afm +528 -0
- data/fonts/Helvetica-Condensed.inf +25 -0
- data/fonts/Helvetica-Narrow-Bold.afm +1439 -0
- data/fonts/Helvetica-Narrow-Bold.inf +26 -0
- data/fonts/Helvetica-Narrow-BoldOblique.afm +1439 -0
- data/fonts/Helvetica-Narrow-BoldOblique.inf +26 -0
- data/fonts/Helvetica-Narrow-Oblique.afm +1556 -0
- data/fonts/Helvetica-Narrow-Oblique.inf +26 -0
- data/fonts/Helvetica-Narrow.afm +1556 -0
- data/fonts/Helvetica-Narrow.inf +26 -0
- data/fonts/Helvetica-Oblique.afm +3051 -0
- data/fonts/Helvetica-Oblique.inf +26 -0
- data/fonts/Helvetica.afm +3051 -0
- data/fonts/Helvetica.inf +26 -0
- data/fonts/LetterGothic-Bold.afm +443 -0
- data/fonts/LetterGothic-Bold.inf +26 -0
- data/fonts/LetterGothic-BoldSlanted.afm +443 -0
- data/fonts/LetterGothic-BoldSlanted.inf +26 -0
- data/fonts/LetterGothic-Slanted.afm +443 -0
- data/fonts/LetterGothic-Slanted.inf +26 -0
- data/fonts/LetterGothic.afm +443 -0
- data/fonts/LetterGothic.inf +26 -0
- data/fonts/LubalinGraph-Book.afm +351 -0
- data/fonts/LubalinGraph-Book.inf +25 -0
- data/fonts/LubalinGraph-BookOblique.afm +351 -0
- data/fonts/LubalinGraph-BookOblique.inf +25 -0
- data/fonts/LubalinGraph-Demi.afm +351 -0
- data/fonts/LubalinGraph-Demi.inf +25 -0
- data/fonts/LubalinGraph-DemiOblique.afm +351 -0
- data/fonts/LubalinGraph-DemiOblique.inf +25 -0
- data/fonts/Marigold.afm +491 -0
- data/fonts/Marigold.inf +27 -0
- data/fonts/MonaLisa-Recut.afm +663 -0
- data/fonts/MonaLisa-Recut.inf +27 -0
- data/fonts/NewCenturySchlbk-Bold.afm +886 -0
- data/fonts/NewCenturySchlbk-Bold.inf +25 -0
- data/fonts/NewCenturySchlbk-BoldItalic.afm +1521 -0
- data/fonts/NewCenturySchlbk-BoldItalic.inf +26 -0
- data/fonts/NewCenturySchlbk-Italic.afm +1113 -0
- data/fonts/NewCenturySchlbk-Italic.inf +26 -0
- data/fonts/NewCenturySchlbk-Roman.afm +1067 -0
- data/fonts/NewCenturySchlbk-Roman.inf +26 -0
- data/fonts/Optima-Bold.afm +515 -0
- data/fonts/Optima-Bold.inf +27 -0
- data/fonts/Optima-BoldItalic.afm +712 -0
- data/fonts/Optima-BoldItalic.inf +26 -0
- data/fonts/Optima-Italic.afm +737 -0
- data/fonts/Optima-Italic.inf +26 -0
- data/fonts/Optima.afm +501 -0
- data/fonts/Optima.inf +27 -0
- data/fonts/Palatino-Bold.afm +675 -0
- data/fonts/Palatino-Bold.inf +26 -0
- data/fonts/Palatino-BoldItalic.afm +702 -0
- data/fonts/Palatino-BoldItalic.inf +26 -0
- data/fonts/Palatino-Italic.afm +700 -0
- data/fonts/Palatino-Italic.inf +26 -0
- data/fonts/Palatino-Roman.afm +718 -0
- data/fonts/Palatino-Roman.inf +26 -0
- data/fonts/StempelGaramond-Bold.afm +412 -0
- data/fonts/StempelGaramond-Bold.inf +27 -0
- data/fonts/StempelGaramond-BoldItalic.afm +413 -0
- data/fonts/StempelGaramond-BoldItalic.inf +27 -0
- data/fonts/StempelGaramond-Italic.afm +413 -0
- data/fonts/StempelGaramond-Italic.inf +27 -0
- data/fonts/StempelGaramond-Roman.afm +412 -0
- data/fonts/StempelGaramond-Roman.inf +27 -0
- data/fonts/Symbol.afm +213 -0
- data/fonts/Symbol.inf +27 -0
- data/fonts/Times-Bold.afm +2588 -0
- data/fonts/Times-Bold.inf +26 -0
- data/fonts/Times-BoldItalic.afm +2384 -0
- data/fonts/Times-BoldItalic.inf +26 -0
- data/fonts/Times-Italic.afm +2667 -0
- data/fonts/Times-Italic.inf +26 -0
- data/fonts/Times-Roman.afm +2419 -0
- data/fonts/Times-Roman.inf +26 -0
- data/fonts/Univers-Bold.afm +712 -0
- data/fonts/Univers-Bold.inf +27 -0
- data/fonts/Univers-BoldOblique.afm +712 -0
- data/fonts/Univers-BoldOblique.inf +27 -0
- data/fonts/Univers-Condensed.afm +403 -0
- data/fonts/Univers-Condensed.inf +27 -0
- data/fonts/Univers-CondensedOblique.afm +403 -0
- data/fonts/Univers-CondensedOblique.inf +27 -0
- data/fonts/Univers-Light.afm +737 -0
- data/fonts/Univers-Light.inf +27 -0
- data/fonts/Univers-LightOblique.afm +737 -0
- data/fonts/Univers-LightOblique.inf +27 -0
- data/fonts/Univers-Oblique.afm +656 -0
- data/fonts/Univers-Oblique.inf +27 -0
- data/fonts/Univers.afm +656 -0
- data/fonts/Univers.inf +27 -0
- data/fonts/ZapfChancery-MediumItalic.afm +842 -0
- data/fonts/ZapfChancery-MediumItalic.inf +26 -0
- data/fonts/ZapfDingbats.afm +225 -0
- data/fonts/ZapfDingbats.inf +26 -0
- data/lib/epdfafm.rb +334 -0
- data/lib/epdfdw.rb +710 -0
- data/lib/epdfk.rb +3142 -0
- data/lib/epdfo.rb +882 -0
- data/lib/epdfpw.rb +1749 -0
- data/lib/epdfs.rb +101 -0
- data/lib/epdfsw.rb +267 -0
- data/lib/epdft.rb +145 -0
- data/lib/epdftt.rb +458 -0
- data/test/pdf_tests.rb +16 -0
- data/test/test.rb +816 -0
- data/test/test_epdfafm.rb +202 -0
- data/test/test_epdfdw.rb +369 -0
- data/test/test_epdfk.rb +47 -0
- data/test/test_epdfo.rb +762 -0
- data/test/test_epdfpw.rb +129 -0
- data/test/test_epdfs.rb +54 -0
- data/test/test_epdfsw.rb +314 -0
- data/test/test_epdft.rb +198 -0
- data/test/test_epdftt.rb +34 -0
- data/test/test_helpers.rb +18 -0
- data/test/testimg.jpg +0 -0
- metadata +247 -0
@@ -0,0 +1,202 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Brent Rowland on 2007-12-18.
|
4
|
+
# Copyright (c) 2007, Eidetic Software. All rights reserved.
|
5
|
+
|
6
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
7
|
+
require 'test/unit'
|
8
|
+
require 'epdfafm'
|
9
|
+
|
10
|
+
include EideticPDF::AFM
|
11
|
+
|
12
|
+
class AdobeFontMetricsTestCases < Test::Unit::TestCase
|
13
|
+
FontDir = File.join(File.dirname(__FILE__), '..', 'fonts')
|
14
|
+
CourierAfmFile = File.join(FontDir, 'Courier.afm')
|
15
|
+
|
16
|
+
def test_from_array
|
17
|
+
courier_ary = IO.readlines(CourierAfmFile)
|
18
|
+
afm = AdobeFontMetrics.new.load_afm(courier_ary)
|
19
|
+
ch = afm.chars_by_name['space']
|
20
|
+
assert_equal('space', ch.name)
|
21
|
+
assert_equal(32, ch.code)
|
22
|
+
assert_equal(600, ch.width)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_from_file
|
26
|
+
afm = AdobeFontMetrics.load(CourierAfmFile)
|
27
|
+
ch = afm.chars_by_name['space']
|
28
|
+
assert_equal('space', ch.name)
|
29
|
+
assert_equal(32, ch.code)
|
30
|
+
assert_equal(600, ch.width)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_afm_cache
|
34
|
+
assert_equal(77, AdobeFontMetrics.afm_cache.size)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_find_font
|
38
|
+
afm = AdobeFontMetrics.find_font('Helvetica-BoldOblique')
|
39
|
+
assert_not_nil(afm)
|
40
|
+
assert_equal('Helvetica-BoldOblique', afm.font_name, "font_name")
|
41
|
+
assert_equal('Helvetica Bold Oblique', afm.full_name, "full_name")
|
42
|
+
assert_equal('Helvetica', afm.family_name, "family_name")
|
43
|
+
assert_equal('Bold', afm.weight, "weight")
|
44
|
+
assert_equal(-12, afm.italic_angle, "italic_angle")
|
45
|
+
assert_equal(false, afm.is_fixed_pitch, "is_fixed_pitch")
|
46
|
+
assert_equal(0x40060, afm.flags, "flags")
|
47
|
+
assert_equal([-174, -228, 1114, 962], afm.font_b_box, "font_b_box")
|
48
|
+
assert_equal(-100, afm.underline_position, "underline_position")
|
49
|
+
assert_equal(50, afm.underline_thickness, "underline_thickness")
|
50
|
+
assert_equal('002.000', afm.version, "version")
|
51
|
+
assert_equal('Copyright (c) 1985, 1987, 1989, 1990, 1997 Adobe Systems Incorporated. All Rights Reserved.Helvetica is a trademark of Linotype-Hell AG and/or its subsidiaries.', afm.notice)
|
52
|
+
assert_equal('ExtendedRoman', afm.character_set, "character_set")
|
53
|
+
assert_equal('AdobeStandardEncoding', afm.encoding_scheme, "encoding_scheme")
|
54
|
+
assert_equal(718, afm.cap_height, "cap_height")
|
55
|
+
assert_equal(532, afm.x_height, "x_height")
|
56
|
+
assert_equal(718, afm.ascender, "ascender")
|
57
|
+
assert_equal(-207, afm.descender, "descender")
|
58
|
+
assert_equal(118, afm.std_h_w, "std_h_w")
|
59
|
+
assert_equal(140, afm.std_v_w, "std_v_w")
|
60
|
+
assert_equal(315, afm.chars_by_name.size, "char_metrics.size")
|
61
|
+
ch = afm.chars_by_name['Euro']
|
62
|
+
assert_equal(-1, ch.code)
|
63
|
+
assert_equal(556, ch.width)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_find_fonts
|
67
|
+
helv = AdobeFontMetrics.find_fonts(:family_name => 'Helvetica')
|
68
|
+
assert_equal(12, helv.size)
|
69
|
+
demi = AdobeFontMetrics.find_fonts(:weight => 'Demi')
|
70
|
+
assert_equal(6, demi.size)
|
71
|
+
italic = AdobeFontMetrics.find_fonts(:italic => true)
|
72
|
+
assert_equal(35, italic.size)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_font_weights
|
76
|
+
assert_equal(['Demi', 'Light'], font_weights('ITC Bookman'))
|
77
|
+
assert_equal(['Bold', 'Medium'], font_weights('Palatino'))
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_font_names
|
81
|
+
assert_equal('ZapfDingbats', font_names.last)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_codepoints_for_encoding
|
85
|
+
codepoints = Codepoints.for_encoding('WinAnsiEncoding')
|
86
|
+
assert_equal(32, codepoints[32])
|
87
|
+
assert_equal(65, codepoints[65])
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_glyphs_for_codepoints
|
91
|
+
assert_equal(['space', 'A'], Glyphs.for_codepoints([32,65]))
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_glyphs_for_encoding
|
95
|
+
glyphs = Glyphs.for_encoding('WinAnsiEncoding')
|
96
|
+
assert_equal(256, glyphs.size, "Wrong number of glyphs")
|
97
|
+
assert_equal('space', glyphs[32])
|
98
|
+
assert_equal('A', glyphs[65])
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_widths_for_glyphs
|
102
|
+
afm = AdobeFontMetrics.find_font('Helvetica-BoldOblique')
|
103
|
+
assert_not_nil(afm, "Font not found.")
|
104
|
+
glyphs = Glyphs.for_encoding('WinAnsiEncoding')
|
105
|
+
widths = Glyphs.widths_for_glyphs(glyphs, afm.chars_by_name)
|
106
|
+
assert_equal(278, widths[32])
|
107
|
+
assert_equal(722, widths[65])
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_widths_for_encoding
|
111
|
+
afm = AdobeFontMetrics.find_font('Helvetica-BoldOblique')
|
112
|
+
assert_not_nil(afm, "Font not found.")
|
113
|
+
widths = Glyphs.widths_for_encoding('WinAnsiEncoding', afm.chars_by_name)
|
114
|
+
assert_equal(278, widths[32])
|
115
|
+
assert_equal(722, widths[65])
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_find_font2
|
119
|
+
afm = find_font('Courier')
|
120
|
+
assert_equal('Courier', afm.font_name)
|
121
|
+
afm = find_font('courier', 'bold')
|
122
|
+
assert_equal('Courier-Bold', afm.font_name)
|
123
|
+
afm = find_font('courier', 'bold', 'italic')
|
124
|
+
assert_equal('Courier-BoldOblique', afm.font_name)
|
125
|
+
afm = find_font('courier', 'bold', 'oblique')
|
126
|
+
assert_equal('Courier-BoldOblique', afm.font_name)
|
127
|
+
afm = find_font('courier', nil, 'italic')
|
128
|
+
assert_equal('Courier-Oblique', afm.font_name)
|
129
|
+
afm = find_font('courier', nil, 'oblique')
|
130
|
+
assert_equal('Courier-Oblique', afm.font_name)
|
131
|
+
|
132
|
+
afm = find_font('helvetica')
|
133
|
+
assert_equal('Helvetica', afm.font_name)
|
134
|
+
afm = find_font('helvetica', 'bold')
|
135
|
+
assert_equal('Helvetica-Bold', afm.font_name)
|
136
|
+
afm = find_font('helvetica', 'bold', 'italic')
|
137
|
+
assert_equal('Helvetica-BoldOblique', afm.font_name)
|
138
|
+
afm = find_font('helvetica', 'bold', 'oblique')
|
139
|
+
assert_equal('Helvetica-BoldOblique', afm.font_name)
|
140
|
+
afm = find_font('helvetica', nil, 'italic')
|
141
|
+
assert_equal('Helvetica-Oblique', afm.font_name)
|
142
|
+
afm = find_font('helvetica', nil, 'oblique')
|
143
|
+
assert_equal('Helvetica-Oblique', afm.font_name)
|
144
|
+
|
145
|
+
afm = find_font('times')
|
146
|
+
assert_equal('Times-Roman', afm.font_name)
|
147
|
+
afm = find_font('times', 'bold')
|
148
|
+
assert_equal('Times-Bold', afm.font_name)
|
149
|
+
afm = find_font('times', 'bold', 'italic')
|
150
|
+
assert_equal('Times-BoldItalic', afm.font_name)
|
151
|
+
afm = find_font('times', 'bold', 'oblique')
|
152
|
+
assert_equal('Times-BoldItalic', afm.font_name)
|
153
|
+
afm = find_font('times', nil, 'italic')
|
154
|
+
assert_equal('Times-Italic', afm.font_name)
|
155
|
+
afm = find_font('times', nil, 'oblique')
|
156
|
+
assert_equal('Times-Italic', afm.font_name)
|
157
|
+
|
158
|
+
afm = find_font('helvetica-condensed', 'bold', 'italic')
|
159
|
+
assert_equal('Helvetica-Condensed-BoldObl', afm.font_name)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_font_metrics1
|
163
|
+
families = ['Courier', 'Helvetica', 'Times']
|
164
|
+
weights = ['', 'Bold']
|
165
|
+
styles = ['', 'Italic']
|
166
|
+
families.each do |family|
|
167
|
+
weights.each do |weight|
|
168
|
+
styles.each do |italic|
|
169
|
+
fm = font_metrics(family, :weight => weight, :style => italic)
|
170
|
+
assert_not_nil(fm, "Should never return nil.")
|
171
|
+
assert_equal(AdobeFontMetrics::NonSymbolic, fm.flags & AdobeFontMetrics::NonSymbolic, "#{family}: NonSymbolic")
|
172
|
+
assert_equal(italic == 'Italic' ? AdobeFontMetrics::Italic : 0, fm.flags & AdobeFontMetrics::Italic, "#{family}: Italic test")
|
173
|
+
assert_equal(family == 'Courier' ? AdobeFontMetrics::FixedPitch : 0, fm.flags & AdobeFontMetrics::FixedPitch, "#{family}: Fixed Pitch test")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_font_metrics2
|
180
|
+
symbol = font_metrics('Symbol')
|
181
|
+
assert_not_nil(symbol)
|
182
|
+
assert_equal(189, symbol.widths.select { |w| w != 0 }.size) # apple symbol not mapped by default
|
183
|
+
assert_equal(750, symbol.ascent, "ascent")
|
184
|
+
assert_equal(-188, symbol.descent, "descent")
|
185
|
+
|
186
|
+
zapf = font_metrics('ZapfDingbats')
|
187
|
+
assert_not_nil(zapf)
|
188
|
+
assert_equal(202, zapf.widths.select { |w| w != 0 }.size)
|
189
|
+
assert_equal(750, zapf.ascent, "ascent")
|
190
|
+
assert_equal(-188, zapf.descent, "descent")
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_font_metrics3
|
194
|
+
fm = font_metrics('Helvetica', :style => 'Italic', :weight => 'Bold', :encoding => 'CP1250')
|
195
|
+
assert_not_nil(fm)
|
196
|
+
assert_equal(256, fm.widths.size)
|
197
|
+
assert_equal(278, fm.widths[32])
|
198
|
+
assert_equal(722, fm.widths[65])
|
199
|
+
assert_not_nil(fm.differences)
|
200
|
+
assert_equal(77, fm.differences.values.size)
|
201
|
+
end
|
202
|
+
end
|
data/test/test_epdfdw.rb
ADDED
@@ -0,0 +1,369 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Brent Rowland on 2007-07-14.
|
4
|
+
# Copyright (c) 2007, 2008 Eidetic Software. All rights reserved.
|
5
|
+
#
|
6
|
+
# Eidetic PDF Document Writer Tests
|
7
|
+
|
8
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
9
|
+
require 'test/unit'
|
10
|
+
require File.join(File.dirname(__FILE__), 'test_helpers')
|
11
|
+
require 'epdfdw'
|
12
|
+
|
13
|
+
include EideticPDF
|
14
|
+
|
15
|
+
class DocumentWriterTestCases < Test::Unit::TestCase
|
16
|
+
SAYING = "This is the first day of the *rest* of your life--or so it has been said (by a forgotten pundit)."
|
17
|
+
SAYING_WRAPPED = ["This is the first day ", "of the *rest* of your ", "life--or so it has been", "said (by a forgotten ", "pundit)."]
|
18
|
+
S2 = "\tThis paragraph starts with a tab\n\nand has two embedded newlines."
|
19
|
+
S2_WRAPPED = ["\tThis paragraph starts with a tab", '', "and has two embedded newlines."]
|
20
|
+
|
21
|
+
def setup
|
22
|
+
PageWriter::DEFAULT_FONT.update(:name => 'Courier', :size => 10)
|
23
|
+
@doc = DocumentWriter.new
|
24
|
+
@doc.open
|
25
|
+
@doc.open_page(:units => :cm)
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
@doc.close_page
|
30
|
+
@doc.close
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_text_ascent
|
34
|
+
assert_equal(6.29, @doc.text_ascent(:pt))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_text_height
|
38
|
+
assert_equal(1.7, @doc.line_height)
|
39
|
+
assert_equal(7.86, @doc.text_height(:pt))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_height
|
43
|
+
h1 = @doc.height("Hello", :pt)
|
44
|
+
assert_in_delta(13.3, h1, 0.1)
|
45
|
+
h2 = @doc.height(SAYING_WRAPPED, :pt)
|
46
|
+
assert_in_delta(66.8, h2, 0.1)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_wrap
|
50
|
+
lines = @doc.wrap(SAYING, 5)
|
51
|
+
assert_equal(SAYING_WRAPPED, lines)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_wrap2
|
55
|
+
lines = @doc.wrap(S2, 10)
|
56
|
+
assert_equal(S2_WRAPPED, lines)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_pen_pos
|
60
|
+
# default position
|
61
|
+
assert_equal(0, @doc.pen_pos.x)
|
62
|
+
assert_equal(0, @doc.pen_pos.y)
|
63
|
+
|
64
|
+
# after moving to integer position
|
65
|
+
@doc.move_to(5, 6)
|
66
|
+
assert_equal(5, @doc.pen_pos.x)
|
67
|
+
assert_equal(6, @doc.pen_pos.y)
|
68
|
+
|
69
|
+
# after moving to float position
|
70
|
+
@doc.move_to(10.5, 11.6)
|
71
|
+
assert_in_delta(10.5, @doc.pen_pos.x, 0.1)
|
72
|
+
assert_in_delta(11.6, @doc.pen_pos.y, 0.1)
|
73
|
+
|
74
|
+
# also works like move_to
|
75
|
+
@doc.pen_pos(10, 20)
|
76
|
+
assert_equal(10, @doc.pen_pos.x)
|
77
|
+
assert_equal(20, @doc.pen_pos.y)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_move_by
|
81
|
+
@doc.move_to(5, 6)
|
82
|
+
@doc.move_by(5, 4)
|
83
|
+
assert_close([10, 10], @doc.pen_pos.to_a)
|
84
|
+
@doc.move_by(-3, 0)
|
85
|
+
assert_close([7, 10], @doc.pen_pos.to_a)
|
86
|
+
@doc.move_by(0, -7)
|
87
|
+
assert_close([7, 3], @doc.pen_pos.to_a)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_margins
|
91
|
+
assert_equal([0, 0, 0, 0], @doc.margins)
|
92
|
+
assert_equal(0, @doc.margin_top)
|
93
|
+
assert_equal(0, @doc.margin_right)
|
94
|
+
assert_equal(0, @doc.margin_bottom)
|
95
|
+
assert_equal(0, @doc.margin_left)
|
96
|
+
@doc.margins(1)
|
97
|
+
assert_equal([1, 1, 1, 1], @doc.margins)
|
98
|
+
@doc.margins(1, 2)
|
99
|
+
assert_equal([1, 2, 1, 2], @doc.margins)
|
100
|
+
@doc.margins(1, 2, 3, 4)
|
101
|
+
assert_array_in_delta([1, 2, 3, 4], @doc.margins, 2 ** -20)
|
102
|
+
assert_in_delta(1.0, @doc.margin_top, 0.01)
|
103
|
+
assert_in_delta(2.0, @doc.margin_right, 0.01)
|
104
|
+
assert_in_delta(3.0, @doc.margin_bottom, 0.01)
|
105
|
+
assert_in_delta(4.0, @doc.margin_left, 0.01)
|
106
|
+
@doc.margins(5, 6, 7)
|
107
|
+
assert_array_in_delta([1, 2, 3, 4], @doc.margins, 2 ** -20) # unchanged
|
108
|
+
@doc.margins(5, 6, 7, 8, 9)
|
109
|
+
assert_array_in_delta([1, 2, 3, 4], @doc.margins, 2 ** -20) # still unchanged
|
110
|
+
assert_equal("q\n1 0 0 1 28.35 -28.35 cm\nQ\nq\n1 0 0 1 56.7 -28.35 cm\nQ\nq\n1 0 0 1 113.4 -28.35 cm\n", @doc.pages.first.stream)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_font
|
114
|
+
# default font
|
115
|
+
assert_equal('Courier', @doc.font.name)
|
116
|
+
assert_equal(10, @doc.font.size)
|
117
|
+
# changed
|
118
|
+
@doc.font 'Times', 12, :style => 'Italic'
|
119
|
+
assert_equal('Times', @doc.font.name)
|
120
|
+
assert_equal(12, @doc.font.size)
|
121
|
+
assert_equal('Italic', @doc.font.style)
|
122
|
+
|
123
|
+
# prev_font = @doc.font
|
124
|
+
prev_font = @doc.font 'Helvetica', 14, :color => 'Blue'
|
125
|
+
assert_equal('Blue', @doc.font_color)
|
126
|
+
# check previous font
|
127
|
+
assert_equal('Times', prev_font.name)
|
128
|
+
assert_equal(12, prev_font.size)
|
129
|
+
assert_equal('Italic', prev_font.style)
|
130
|
+
# set font back to previous font
|
131
|
+
@doc.font prev_font
|
132
|
+
# check that settings took
|
133
|
+
assert_equal('Times', @doc.font.name)
|
134
|
+
assert_equal(12, @doc.font.size)
|
135
|
+
assert_equal('Italic', @doc.font.style)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_font_style
|
139
|
+
# default style
|
140
|
+
assert_equal('', @doc.font_style)
|
141
|
+
# changed
|
142
|
+
prev_font_style = @doc.font_style 'Bold'
|
143
|
+
assert_equal('', prev_font_style)
|
144
|
+
assert_equal('Bold', @doc.font_style)
|
145
|
+
# AFM font metrics backend ignores bogus styles.
|
146
|
+
# invalid style
|
147
|
+
# assert_raise(Exception) { @doc.font_style 'Bogus' }
|
148
|
+
# unchanged by invalid style
|
149
|
+
# assert_equal('Bold', @doc.font_style)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_font_size
|
153
|
+
# default size
|
154
|
+
assert_equal(10, @doc.font_size)
|
155
|
+
# changed
|
156
|
+
prev_font_size = @doc.font_size 12
|
157
|
+
assert_equal(10, prev_font_size)
|
158
|
+
assert_equal(12, @doc.font_size)
|
159
|
+
# changed to float
|
160
|
+
@doc.font_size 14.5
|
161
|
+
assert_equal(14.5, @doc.font_size)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_font_color
|
165
|
+
# default color
|
166
|
+
assert_equal(0, @doc.font_color)
|
167
|
+
# changed
|
168
|
+
prev_font_color = @doc.font_color 'Blue'
|
169
|
+
assert_equal(0, prev_font_color)
|
170
|
+
assert_equal('Blue', @doc.font_color)
|
171
|
+
# rgb
|
172
|
+
@doc.font_color [0xFF,0,0]
|
173
|
+
assert_equal(0xFF0000, @doc.font_color)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_fill_color
|
177
|
+
# default color
|
178
|
+
assert_equal(0xFFFFFF, @doc.fill_color)
|
179
|
+
# changed
|
180
|
+
prev_fill_color = @doc.fill_color 'Blue'
|
181
|
+
assert_equal(0xFFFFFF, prev_fill_color)
|
182
|
+
assert_equal('Blue', @doc.fill_color)
|
183
|
+
# rgb
|
184
|
+
@doc.fill_color [0xFF,0,0]
|
185
|
+
assert_equal(0xFF0000, @doc.fill_color)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_line_color
|
189
|
+
# default color
|
190
|
+
assert_equal(0, @doc.line_color)
|
191
|
+
# changed
|
192
|
+
prev_line_color = @doc.line_color 'Blue'
|
193
|
+
assert_equal(0, prev_line_color)
|
194
|
+
assert_equal('Blue', @doc.line_color)
|
195
|
+
# rgb
|
196
|
+
@doc.line_color [0xFF,0,0]
|
197
|
+
assert_equal(0xFF0000, @doc.line_color)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_line_width
|
201
|
+
# default width
|
202
|
+
assert_equal(1.0, @doc.line_width(:pt))
|
203
|
+
# changed
|
204
|
+
prev_line_width = @doc.line_width 1
|
205
|
+
assert_equal(1/UNIT_CONVERSION[:cm], prev_line_width)
|
206
|
+
assert_equal(1, @doc.line_width)
|
207
|
+
# alternate units
|
208
|
+
assert_equal(28.35, @doc.line_width(:pt))
|
209
|
+
@doc.line_width 1, :in
|
210
|
+
assert_equal(72, @doc.line_width(:pt))
|
211
|
+
@doc.line_width "2in"
|
212
|
+
assert_in_delta(5.08, @doc.line_width, 0.01)
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_units
|
216
|
+
[:pt, :cm, :in].each do |units|
|
217
|
+
@doc.units(units)
|
218
|
+
assert_equal(units, @doc.units)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_tabs
|
223
|
+
assert_nil @doc.tabs
|
224
|
+
@doc.tabs [1, 2, 3]
|
225
|
+
assert_equal [1, 2, 3], @doc.tabs
|
226
|
+
@doc.tabs []
|
227
|
+
assert_nil @doc.tabs
|
228
|
+
@doc.tabs '4, 5, 6'
|
229
|
+
assert_equal [4, 5, 6], @doc.tabs
|
230
|
+
@doc.tabs false
|
231
|
+
assert_nil @doc.tabs
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_tab
|
235
|
+
@doc.tabs [1.5, 3, 4.5, 6]
|
236
|
+
assert_close([0, 0], @doc.pen_pos.to_a)
|
237
|
+
@doc.tab
|
238
|
+
assert_close([1.5, 0], @doc.pen_pos.to_a)
|
239
|
+
@doc.tab
|
240
|
+
assert_close([3, 0], @doc.pen_pos.to_a)
|
241
|
+
@doc.tab
|
242
|
+
assert_close([4.5, 0], @doc.pen_pos.to_a)
|
243
|
+
@doc.tab
|
244
|
+
assert_close([6, 0], @doc.pen_pos.to_a)
|
245
|
+
@doc.tab
|
246
|
+
assert_close([1.5, @doc.height], @doc.pen_pos.to_a)
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_vtabs
|
250
|
+
assert_nil @doc.vtabs
|
251
|
+
@doc.vtabs [1, 2, 3]
|
252
|
+
assert_equal [1, 2, 3], @doc.vtabs
|
253
|
+
@doc.vtabs []
|
254
|
+
assert_nil @doc.vtabs
|
255
|
+
@doc.vtabs '4, 5, 6'
|
256
|
+
assert_equal [4, 5, 6], @doc.vtabs
|
257
|
+
@doc.vtabs false
|
258
|
+
assert_nil @doc.vtabs
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_vtab
|
262
|
+
@doc.vtabs [1.5, 3, 4.5, 6]
|
263
|
+
assert_close([0, 0], @doc.pen_pos.to_a)
|
264
|
+
@doc.vtab
|
265
|
+
assert_close([0, 1.5], @doc.pen_pos.to_a)
|
266
|
+
@doc.vtab
|
267
|
+
assert_close([0, 3], @doc.pen_pos.to_a)
|
268
|
+
@doc.vtab
|
269
|
+
assert_close([0, 4.5], @doc.pen_pos.to_a)
|
270
|
+
@doc.vtab
|
271
|
+
assert_close([0, 6], @doc.pen_pos.to_a)
|
272
|
+
@doc.vtab { 2.5 }
|
273
|
+
assert_close([2.5, 1.5], @doc.pen_pos.to_a)
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_indent
|
277
|
+
assert_close([0, 0], @doc.pen_pos.to_a) # starting location
|
278
|
+
@doc.indent 2
|
279
|
+
assert_equal(2, @doc.pen_pos.x, "indent should set pen_pos.x")
|
280
|
+
prev_indent = @doc.indent 2
|
281
|
+
assert_equal(4, @doc.pen_pos.x, "normal indents are additive")
|
282
|
+
assert_equal(2, prev_indent)
|
283
|
+
prev_indent = @doc.indent -1
|
284
|
+
assert_equal(3, @doc.pen_pos.x, "the other side of additive")
|
285
|
+
assert_equal(4, prev_indent)
|
286
|
+
@doc.indent 5, true
|
287
|
+
assert_equal(5, @doc.pen_pos.x, "absolute indent")
|
288
|
+
@doc.print "here we are: "
|
289
|
+
@doc.puts "testing indent"
|
290
|
+
assert_equal(5, @doc.pen_pos.x, "normal puts should return pen_pos.x to indent")
|
291
|
+
assert_close(@doc.height, @doc.pen_pos.y)
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_paragraph
|
295
|
+
assert_nothing_raised(Exception) do
|
296
|
+
@doc.paragraph("Hello, World!")
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_bullet
|
301
|
+
@doc.bullet(:star, :width => 1) do |w|
|
302
|
+
prev_font = w.font('ZapfDingbats', 12)
|
303
|
+
w.print(0x4E.chr)
|
304
|
+
w.font(prev_font)
|
305
|
+
end
|
306
|
+
|
307
|
+
star = @doc.bullets[:star]
|
308
|
+
assert_not_nil(star)
|
309
|
+
assert_equal('star', star.name)
|
310
|
+
assert_equal(UNIT_CONVERSION[:cm], star.width)
|
311
|
+
|
312
|
+
@doc.bullet('diamond') do |w|
|
313
|
+
prev_font = w.font('Symbol', 12)
|
314
|
+
w.print(0xA8.chr)
|
315
|
+
w.font(prev_font)
|
316
|
+
end
|
317
|
+
|
318
|
+
diamond = @doc.bullet(:diamond)
|
319
|
+
assert_not_nil(diamond)
|
320
|
+
assert_equal('diamond', diamond.name)
|
321
|
+
assert_equal(36, diamond.width)
|
322
|
+
|
323
|
+
@doc.bullet(:dagger, :width => 1, :units => :in) do |w|
|
324
|
+
w.print(0x86.chr)
|
325
|
+
end
|
326
|
+
|
327
|
+
dagger = @doc.bullet(:dagger)
|
328
|
+
assert_not_nil(dagger)
|
329
|
+
assert_equal('dagger', dagger.name)
|
330
|
+
assert_equal(72, dagger.width)
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_underline
|
334
|
+
assert(!@doc.underline)
|
335
|
+
@doc.underline(true)
|
336
|
+
assert(@doc.underline)
|
337
|
+
@doc.underline(false)
|
338
|
+
assert(!@doc.underline)
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_sub_page
|
342
|
+
@doc.instance_eval do
|
343
|
+
@pages_across, @pages_down = 2, 2
|
344
|
+
@pages_up = @pages_across * @pages_down
|
345
|
+
@options[:pages_up_layout] = :across
|
346
|
+
end
|
347
|
+
assert_equal [0, 2, 0, 2], @doc.send(:sub_page, 0) # top left
|
348
|
+
assert_equal [1, 2, 0, 2], @doc.send(:sub_page, 1) # top right
|
349
|
+
assert_equal [0, 2, 1, 2], @doc.send(:sub_page, 2) # bottom left
|
350
|
+
assert_equal [1, 2, 1, 2], @doc.send(:sub_page, 3) # bottom right
|
351
|
+
assert_equal [0, 2, 0, 2], @doc.send(:sub_page, 4) # top left
|
352
|
+
assert_equal [1, 2, 0, 2], @doc.send(:sub_page, 5) # top right
|
353
|
+
assert_equal [0, 2, 1, 2], @doc.send(:sub_page, 6) # bottom left
|
354
|
+
assert_equal [1, 2, 1, 2], @doc.send(:sub_page, 7) # bottom right
|
355
|
+
|
356
|
+
@doc.instance_eval do
|
357
|
+
@options[:pages_up_layout] = :down
|
358
|
+
end
|
359
|
+
assert_equal [0, 2, 0, 2], @doc.send(:sub_page, 0) # top left
|
360
|
+
assert_equal [0, 2, 1, 2], @doc.send(:sub_page, 1) # bottom left
|
361
|
+
assert_equal [1, 2, 0, 2], @doc.send(:sub_page, 2) # top right
|
362
|
+
assert_equal [1, 2, 1, 2], @doc.send(:sub_page, 3) # buttom right
|
363
|
+
|
364
|
+
assert_equal [0, 2, 0, 2], @doc.send(:sub_page, 4) # top left
|
365
|
+
assert_equal [0, 2, 1, 2], @doc.send(:sub_page, 5) # bottom left
|
366
|
+
assert_equal [1, 2, 0, 2], @doc.send(:sub_page, 6) # top right
|
367
|
+
assert_equal [1, 2, 1, 2], @doc.send(:sub_page, 7) # buttom right
|
368
|
+
end
|
369
|
+
end
|
data/test/test_epdfk.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Brent Rowland on 2007-11-03.
|
4
|
+
# Copyright (c) 2007, Eidetic Software. All rights reserved.
|
5
|
+
|
6
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
7
|
+
require 'test/unit'
|
8
|
+
require 'epdfk'
|
9
|
+
|
10
|
+
include EideticPDF
|
11
|
+
|
12
|
+
class PdfKTestCases < Test::Unit::TestCase
|
13
|
+
def test_font_index
|
14
|
+
assert_equal(0, PdfK::font_index('Helvetica'))
|
15
|
+
assert_equal(11, PdfK::font_index('Courier-BoldOblique'))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_font_metrics
|
19
|
+
assert_not_nil(PdfK::font_metrics('Helvetica'))
|
20
|
+
assert_raise(Exception) { PdfK::font_metrics('BogusFontName') }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_glyphs
|
24
|
+
assert_equal('space', PdfK::GLYPHS[32])
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_codepoints
|
28
|
+
assert_equal(32, PdfK::CODEPOINTS['space'])
|
29
|
+
# assert_equal(PdfK::GLYPHS.size, PdfK::CODEPOINTS.size) # 1051 != 1035
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_standard_encodings
|
33
|
+
assert PdfK::STANDARD_ENCODINGS.include?('WinAnsiEncoding')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class FontMetricsTestCases < Test::Unit::TestCase
|
38
|
+
def setup
|
39
|
+
@metrics0 = PdfK::font_metrics('Helvetica')
|
40
|
+
@metrics11 = PdfK::font_metrics('Courier-BoldOblique')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_widths
|
44
|
+
assert_equal(191, @metrics0.widths[39])
|
45
|
+
assert_equal(600, @metrics11.widths[39])
|
46
|
+
end
|
47
|
+
end
|