forked from prawnpdf/prawn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics_spec.rb
61 lines (45 loc) · 2.14 KB
/
metrics_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# encoding: utf-8
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
describe "adobe font metrics" do
setup do
@times = Prawn::Font::Metrics["Times-Roman"]
@iconv = Iconv.new('ISO-8859-1', 'utf-8')
end
it "should calculate string width taking into account accented characters" do
@times.string_width(@iconv.iconv("é"), 12).should == @times.string_width("e", 12)
end
it "should calculate string width taking into account kerning pairs" do
@times.string_width(@iconv.iconv("To"), 12).should == 13.332
@times.string_width(@iconv.iconv("To"), 12, :kerning => true).should == 12.372
@times.string_width(@iconv.iconv("Tö"), 12, :kerning => true).should == 12.372
end
it "should kern a string" do
@times.kern(@iconv.iconv("To")).should == ["T", 80, "o"]
@times.kern(@iconv.iconv("Télé")).should == ["T", 70, @iconv.iconv("élé")]
@times.kern(@iconv.iconv("Technology")).should == ["T", 70, "echnology"]
@times.kern(@iconv.iconv("Technology...")).should == ["T", 70, "echnology", 65, "..."]
end
end
describe "ttf font metrics" do
setup do
@activa = Prawn::Font::Metrics["#{Prawn::BASEDIR}/data/fonts/Activa.ttf"]
end
it "should calculate string width taking into account accented characters" do
@activa.string_width("é", 12).should == @activa.string_width("e", 12)
end
it "should calculate string width taking into account kerning pairs" do
@activa.string_width("To", 12).should == 15.228
@activa.string_width("To", 12, :kerning => true).should.to_s == 12.996.to_s
end
it "should kern a string" do
@activa.kern("To").should == ["\0007", 186.0, "\000R"]
# Does activa use kerning classes here? Ruby/TTF doesn't support
# format 2 kerning tables, so don't bother for now.
# @activa.kern("Télé").should == ["T", -186, "élé"]
@activa.kern("Technology").should == ["\0007", 186.0,
"\000H\000F\000K\000Q\000R\000O\000R\000J\000\\"]
@activa.kern("Technology...").should == ["\0007", 186.0,
"\000H\000F\000K\000Q\000R\000O\000R\000J\000\\", 88.0,
"\000\021\000\021\000\021"]
end
end