typographic-unit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +26 -0
- data/README.txt +27 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +71 -0
- data/config/requirements.rb +17 -0
- data/lib/typographic-unit/version.rb +9 -0
- data/lib/typographic-unit.rb +240 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/typographic-unit_spec.rb +281 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +170 -0
- data/website/index.txt +97 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +76 -0
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-fs --colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
TypographicUnit.open
|
4
|
+
|
5
|
+
describe TypographicUnit do
|
6
|
+
it "1pt == 65536sp" do
|
7
|
+
1.pt.should == 65536.sp
|
8
|
+
1.pt.should_not == 65535.sp
|
9
|
+
1.pt.should_not == 65537.sp
|
10
|
+
end
|
11
|
+
|
12
|
+
it "1pc == 12pt" do
|
13
|
+
1.pc.should == 12.pt
|
14
|
+
end
|
15
|
+
|
16
|
+
it "1in == 72.27pt" do
|
17
|
+
1.in.should == 72.27.pt
|
18
|
+
end
|
19
|
+
|
20
|
+
it "72bp == 1in" do
|
21
|
+
72.bp.should == 1.in
|
22
|
+
end
|
23
|
+
|
24
|
+
it "10mm == 1cm" do
|
25
|
+
25.4.mm.should == 2.54.cm
|
26
|
+
end
|
27
|
+
|
28
|
+
it "1cm == 10mm" do
|
29
|
+
1.cm.should == 10.mm
|
30
|
+
end
|
31
|
+
|
32
|
+
it "2.54cm == 1in" do
|
33
|
+
2.54.cm.should == 1.in
|
34
|
+
end
|
35
|
+
|
36
|
+
it "1m == 100cm" do
|
37
|
+
1.m.should == 100.cm
|
38
|
+
end
|
39
|
+
|
40
|
+
it "1157dd == 1238pt" do
|
41
|
+
1157.dd.should == 1238.pt
|
42
|
+
end
|
43
|
+
|
44
|
+
it "1cc == 12dd" do
|
45
|
+
1.cc.should == 12.dd
|
46
|
+
end
|
47
|
+
|
48
|
+
it "1.q == 0.25.mm" do
|
49
|
+
1.q.should == 0.25.mm
|
50
|
+
end
|
51
|
+
|
52
|
+
it "1.jis_pt == 0.3514.mm" do
|
53
|
+
1.jis_pt.should == 0.3514.mm
|
54
|
+
end
|
55
|
+
|
56
|
+
it "1.cm - 1.mm == 0.8.cm + 1.mm" do
|
57
|
+
(1.cm - 1.mm).should == 0.8.cm + 1.mm
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe Numeric do
|
62
|
+
it "%" do
|
63
|
+
(10.cm % 3.cm).should.kind_of?(TypographicUnit::Centimeter)
|
64
|
+
(10.cm % 3.cm).should == 1.cm
|
65
|
+
end
|
66
|
+
|
67
|
+
it "div" do
|
68
|
+
(10.cm.div 3.cm).should.kind_of?(Integer)
|
69
|
+
(10.cm.div 3.cm).should == 3
|
70
|
+
(10.cm.div 3).should == 3
|
71
|
+
end
|
72
|
+
|
73
|
+
it "quo" do
|
74
|
+
(10.cm.quo 3.cm).should.kind_of?(Rational)
|
75
|
+
(10.cm.quo 3.cm).should == Rational(10, 3)
|
76
|
+
(10.cm.quo 3).should == Rational(10, 3)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "+@" do
|
80
|
+
(+(1.cm)).should == +(10.mm)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "1.cm + 1.cm == 2.cm" do
|
84
|
+
(1.cm + 1.cm).should == 2.cm
|
85
|
+
end
|
86
|
+
|
87
|
+
it "1.cm + 1.mm == 1.1cm" do
|
88
|
+
(1.cm + 1.mm).should be_kind_of(TypographicUnit::Centimeter)
|
89
|
+
(1.cm + 1.mm).should == 1.1.cm
|
90
|
+
end
|
91
|
+
|
92
|
+
it "-@" do
|
93
|
+
(-(1.cm)).should == -(10.mm)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "2.cm - 1.cm == 1.cm" do
|
97
|
+
(2.cm - 1.cm).should == 1.cm
|
98
|
+
end
|
99
|
+
|
100
|
+
it "1.cm - 1.mm == 0.9cm" do
|
101
|
+
(1.cm - 1.mm).should be_kind_of(TypographicUnit::Centimeter)
|
102
|
+
(1.cm - 1.mm).should == 0.9.cm
|
103
|
+
end
|
104
|
+
|
105
|
+
it "*" do
|
106
|
+
(1.cm * 10).should be_kind_of(TypographicUnit::Centimeter)
|
107
|
+
(1.cm * 10).should == 10.cm
|
108
|
+
Proc.new{1.cm * 10.cm}.should raise_error(ArgumentError)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "abs" do
|
112
|
+
(-(1.cm)).abs.should == 1.cm
|
113
|
+
(-(1.cm)).abs.should_not == -1.cm
|
114
|
+
end
|
115
|
+
|
116
|
+
it "ceil" do
|
117
|
+
1.5.cm.ceil.should == 2.cm
|
118
|
+
1.5.cm.ceil.should_not == 1.cm
|
119
|
+
end
|
120
|
+
|
121
|
+
it "floor" do
|
122
|
+
1.5.cm.floor.should == 1.cm
|
123
|
+
1.5.cm.floor.should_not == 2.cm
|
124
|
+
end
|
125
|
+
|
126
|
+
it "round" do
|
127
|
+
1.4.cm.round.should == 1.cm
|
128
|
+
1.5.cm.round.should == 2.cm
|
129
|
+
end
|
130
|
+
|
131
|
+
it "truncate" do
|
132
|
+
1.4.cm.truncate.should == 1.cm
|
133
|
+
1.5.cm.truncate.should == 1.cm
|
134
|
+
end
|
135
|
+
|
136
|
+
it "integer?" do
|
137
|
+
1.cm.should be_integer
|
138
|
+
1.5.cm.should_not be_integer
|
139
|
+
end
|
140
|
+
|
141
|
+
it "nonzero?" do
|
142
|
+
1.cm.should be_nonzero
|
143
|
+
0.cm.should_not be_nonzero
|
144
|
+
end
|
145
|
+
|
146
|
+
it "to_i" do
|
147
|
+
1.cm.to_i.should be_kind_of(TypographicUnit::Centimeter)
|
148
|
+
1.cm.to_i.should == 1.cm
|
149
|
+
1.4.cm.to_i.should == 1.cm
|
150
|
+
1.5.cm.to_i.should == 1.cm
|
151
|
+
end
|
152
|
+
|
153
|
+
it "to_int" do
|
154
|
+
1.cm.to_int.should be_kind_of(Integer)
|
155
|
+
1.cm.to_int.should == 1
|
156
|
+
1.4.cm.to_int.should == 1
|
157
|
+
1.5.cm.to_int.should == 1
|
158
|
+
end
|
159
|
+
|
160
|
+
it "zero?" do
|
161
|
+
0.cm.should be_zero
|
162
|
+
0.0.cm.should be_zero
|
163
|
+
0.1.cm.should_not be_zero
|
164
|
+
end
|
165
|
+
|
166
|
+
it "step from 1cm to 5cm" do
|
167
|
+
list = []
|
168
|
+
1.cm.step(5.cm) do |i|
|
169
|
+
list << i
|
170
|
+
end
|
171
|
+
list.should == [1.cm, 2.cm, 3.cm, 4.cm, 5.cm]
|
172
|
+
end
|
173
|
+
|
174
|
+
it "step from 1cm to 3cm by 0.5cm" do
|
175
|
+
list = []
|
176
|
+
1.cm.step(3.cm, 0.5.cm) do |i|
|
177
|
+
i.should be_kind_of(TypographicUnit::Centimeter)
|
178
|
+
list << i
|
179
|
+
end
|
180
|
+
list.should == [1.cm, 1.5.cm, 2.cm, 2.5.cm, 3.cm]
|
181
|
+
end
|
182
|
+
|
183
|
+
it "step from 1cm to 3cm by 5mm" do
|
184
|
+
list = []
|
185
|
+
1.cm.step(3.cm, 5.mm) do |i|
|
186
|
+
i.should be_kind_of(TypographicUnit::Centimeter)
|
187
|
+
list << i
|
188
|
+
end
|
189
|
+
list.should == [1.cm, 1.5.cm, 2.cm, 2.5.cm, 3.cm]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe Range do
|
194
|
+
it "Range.new(1.cm, 5.cm) should be valid" do
|
195
|
+
Proc.new{1.cm..5.cm}.should_not raise_error(ArgumentError)
|
196
|
+
end
|
197
|
+
|
198
|
+
it "Range.new(1.cm, 1.in) should be valid" do
|
199
|
+
Proc.new{1.cm..1.in}.should_not raise_error(ArgumentError)
|
200
|
+
end
|
201
|
+
|
202
|
+
it "#include should work" do
|
203
|
+
(1.cm..1.in).should include(25.4.mm)
|
204
|
+
(1.cm..1.in).should_not include(25.5.mm)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "#each should raise a TypeError" do
|
208
|
+
Proc.new{(1.cm..5.cm).each{}}.should raise_error(TypeError)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "#step" do
|
212
|
+
Proc.new{(1.cm..5.cm).step{}}.should raise_error(ArgumentError)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe TypographicUnit::Millimeter do
|
217
|
+
it "1mm => 1mm" do
|
218
|
+
(1.mm >> :mm).should == 1.mm
|
219
|
+
end
|
220
|
+
|
221
|
+
it "1mm => 0.1cm" do
|
222
|
+
(1.mm >> :cm).should be_a_kind_of(TypographicUnit::Centimeter)
|
223
|
+
(1.mm >> :cm).should == 0.1.cm
|
224
|
+
end
|
225
|
+
|
226
|
+
it "1mm => 0.001m" do
|
227
|
+
(1.mm >> :m).should == 0.001.m
|
228
|
+
end
|
229
|
+
|
230
|
+
it "10mm => 1cm" do
|
231
|
+
(10.mm >> :cm).should == 1.cm
|
232
|
+
end
|
233
|
+
|
234
|
+
it "1000mm => 1m" do
|
235
|
+
(1000.mm >> :m).should == 1.m
|
236
|
+
end
|
237
|
+
|
238
|
+
it "25.4mm => 1in" do
|
239
|
+
(25.4.mm >> :in).should == 1.in
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe TypographicUnit::Centimeter do
|
244
|
+
it "1cm => 1cm" do
|
245
|
+
(1.cm >> :cm).should == 1.cm
|
246
|
+
end
|
247
|
+
|
248
|
+
it "1cm => 10mm" do
|
249
|
+
(1.cm >> :mm).should == 10.mm
|
250
|
+
end
|
251
|
+
|
252
|
+
it "1cm => 0.01m" do
|
253
|
+
(1.cm >> :m).should == 0.01.m
|
254
|
+
end
|
255
|
+
|
256
|
+
it "2.54cm => 1in" do
|
257
|
+
(2.54.cm >> :in).should == 1.in
|
258
|
+
end
|
259
|
+
|
260
|
+
it "254cm => 7227pt" do
|
261
|
+
(254.cm >> :pt).should == 7227.pt
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe TypographicUnit::Meter do
|
266
|
+
it "1m => 1m" do
|
267
|
+
(1.m >> :m).should == 1.m
|
268
|
+
end
|
269
|
+
|
270
|
+
it "1m => 1000mm" do
|
271
|
+
(1.m >> :mm).should == 1000.mm
|
272
|
+
end
|
273
|
+
|
274
|
+
it "1m => 100cm" do
|
275
|
+
(1.m >> :cm).should == 100.cm
|
276
|
+
end
|
277
|
+
|
278
|
+
it "0.0254m => 1in" do
|
279
|
+
(0.0254.m >> :in).should == 1.in
|
280
|
+
end
|
281
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :manifest do
|
30
|
+
desc 'Recreate Manifest.txt to include ALL files'
|
31
|
+
task :refresh do
|
32
|
+
`rake check_manifest | patch -p0 > Manifest.txt`
|
33
|
+
end
|
34
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
21
|
+
end
|
data/tasks/website.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
desc 'Generate website files'
|
2
|
+
task :website_generate => :ruby_env do
|
3
|
+
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
4
|
+
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Upload website files to rubyforge'
|
9
|
+
task :website_upload do
|
10
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
11
|
+
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
12
|
+
local_dir = 'website'
|
13
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate and upload website files'
|
17
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/website/index.html
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
+
<title>
|
8
|
+
TypographicUnit
|
9
|
+
</title>
|
10
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
+
<style>
|
12
|
+
|
13
|
+
</style>
|
14
|
+
<script type="text/javascript">
|
15
|
+
window.onload = function() {
|
16
|
+
settings = {
|
17
|
+
tl: { radius: 10 },
|
18
|
+
tr: { radius: 10 },
|
19
|
+
bl: { radius: 10 },
|
20
|
+
br: { radius: 10 },
|
21
|
+
antiAlias: true,
|
22
|
+
autoPad: true,
|
23
|
+
validTags: ["div"]
|
24
|
+
}
|
25
|
+
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
+
versionBox.applyCornersToAll();
|
27
|
+
}
|
28
|
+
</script>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="main">
|
32
|
+
|
33
|
+
<h1>TypographicUnit</h1>
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/typographicunit"; return false'>
|
35
|
+
<p>Get Version</p>
|
36
|
+
<a href="http://rubyforge.org/projects/typographicunit" class="numbers">0.1.0</a>
|
37
|
+
</div>
|
38
|
+
<h2>What</h2>
|
39
|
+
|
40
|
+
|
41
|
+
<p>TypographicUnit is a library for converting between typographic units according
|
42
|
+
to TeX. This library can handle the following units:</p>
|
43
|
+
|
44
|
+
|
45
|
+
<ul>
|
46
|
+
<li>TeX Scaled Point(sp)</li>
|
47
|
+
<li>TeX Point(pt)</li>
|
48
|
+
<li>Pica(pt)</li>
|
49
|
+
<li>Inch(in)</li>
|
50
|
+
<li>TeX Big Point(bp)</li>
|
51
|
+
<li>PostScript Point(ps_pt)</li>
|
52
|
+
<li>Meter(m)</li>
|
53
|
+
<li>Centimeter(cm)</li>
|
54
|
+
<li>Milimeter(mm)</li>
|
55
|
+
<li>Didot Point(dd)</li>
|
56
|
+
<li>Cicero(cc)</li>
|
57
|
+
<li>Japanese Q(q)</li>
|
58
|
+
<li><span class="caps">JIS</span> Point(jis_pt)</li>
|
59
|
+
</ul>
|
60
|
+
|
61
|
+
|
62
|
+
<h2>Installing</h2>
|
63
|
+
|
64
|
+
|
65
|
+
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">typographicunit</span></pre></p>
|
66
|
+
|
67
|
+
|
68
|
+
<h2>The basics</h2>
|
69
|
+
|
70
|
+
|
71
|
+
<p><pre class='syntax'>
|
72
|
+
<span class="ident">require</span> <span class="punct">"</span><span class="string">typographic-unit</span><span class="punct">"</span>
|
73
|
+
|
74
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">cm</span> <span class="comment"># => #<1cm></span>
|
75
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">cm</span> <span class="punct">-</span> <span class="number">1</span><span class="punct">.</span><span class="ident">mm</span> <span class="comment"># => #<0.9cm></span>
|
76
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">cm</span> <span class="punct">==</span> <span class="number">10</span><span class="punct">.</span><span class="ident">mm</span> <span class="comment"># => true</span>
|
77
|
+
|
78
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">in</span> <span class="punct">>></span> <span class="symbol">:cm</span> <span class="comment"># => #<2.54cm></span>
|
79
|
+
<span class="number">2.54</span><span class="punct">.</span><span class="ident">cm</span> <span class="punct">>></span> <span class="symbol">:in</span> <span class="comment"># => #<1.0in></span>
|
80
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">in</span> <span class="punct">-</span> <span class="number">1</span><span class="punct">.</span><span class="ident">cm</span> <span class="comment"># => #<0.606299212598425in></span>
|
81
|
+
<span class="punct">(</span><span class="number">1</span><span class="punct">.</span><span class="ident">in</span> <span class="punct">-</span> <span class="number">1</span><span class="punct">.</span><span class="ident">cm</span><span class="punct">)</span> <span class="punct">>></span> <span class="symbol">:cm</span> <span class="comment"># => #<1.54cm></span>
|
82
|
+
</pre></p>
|
83
|
+
|
84
|
+
|
85
|
+
<h2>Demonstration of usage</h2>
|
86
|
+
|
87
|
+
|
88
|
+
<h3>Convert</h3>
|
89
|
+
|
90
|
+
|
91
|
+
<p><pre class='syntax'>
|
92
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">pt</span> <span class="punct">>></span> <span class="symbol">:mm</span> <span class="comment"># => #<0.351459803514598mm></span>
|
93
|
+
<span class="number">7227</span><span class="punct">.</span><span class="ident">pt</span> <span class="punct">>></span> <span class="symbol">:cm</span> <span class="comment"># => #<254.0cm></span>
|
94
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">in</span> <span class="punct">>></span> <span class="symbol">:bp</span> <span class="comment"># => #<72.0bp></span>
|
95
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">pt</span> <span class="punct">>></span> <span class="symbol">:sp</span> <span class="comment"># => #<65536.0sp></span>
|
96
|
+
<span class="number">1157</span><span class="punct">.</span><span class="ident">pt</span> <span class="punct">>></span> <span class="symbol">:pt</span> <span class="comment"># => #<1238.0pt></span>
|
97
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">cc</span> <span class="punct">>></span> <span class="symbol">:dd</span> <span class="comment"># => #<12.0dd></span>
|
98
|
+
<span class="number">10</span><span class="punct">.</span><span class="ident">q</span> <span class="punct">>></span> <span class="symbol">:mm</span> <span class="comment"># => #<2.5mm></span>
|
99
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">jis_pt</span> <span class="punct">>></span> <span class="symbol">:mm</span> <span class="comment"># => #<0.3514mm></span>
|
100
|
+
</pre></p>
|
101
|
+
|
102
|
+
|
103
|
+
<h3>Calculate</h3>
|
104
|
+
|
105
|
+
|
106
|
+
<p><pre class='syntax'>
|
107
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">cm</span> <span class="punct">+</span> <span class="number">1</span><span class="punct">.</span><span class="ident">mm</span> <span class="comment"># => #<1.1cm></span>
|
108
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">cm</span> <span class="punct">+</span> <span class="number">1</span><span class="punct">.</span><span class="ident">in</span> <span class="comment"># => #<3.54cm></span>
|
109
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">pt</span> <span class="punct">-</span> <span class="number">1</span><span class="punct">.</span><span class="ident">bp</span> <span class="comment"># => #<-0.00131797426317971mm></span>
|
110
|
+
<span class="number">100</span><span class="punct">.</span><span class="ident">ps_pt</span> <span class="punct">-</span> <span class="number">100</span><span class="punct">.</span><span class="ident">jis_pt</span> <span class="punct">>></span> <span class="symbol">:mm</span> <span class="comment"># => #<0.137777777777779mm></span>
|
111
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">cm</span> <span class="punct">*</span> <span class="number">10</span> <span class="comment"># => #<10cm></span>
|
112
|
+
</pre></p>
|
113
|
+
|
114
|
+
|
115
|
+
<h3>Step</h3>
|
116
|
+
|
117
|
+
|
118
|
+
<p><pre class='syntax'>
|
119
|
+
<span class="ident">list</span> <span class="punct">=</span> <span class="punct">[]</span>
|
120
|
+
<span class="number">1</span><span class="punct">.</span><span class="ident">cm</span><span class="punct">.</span><span class="ident">step</span><span class="punct">(</span><span class="number">3</span><span class="punct">.</span><span class="ident">cm</span><span class="punct">,</span> <span class="number">0.5</span><span class="punct">.</span><span class="ident">cm</span><span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">i</span><span class="punct">|</span>
|
121
|
+
<span class="ident">list</span> <span class="punct"><<</span> <span class="ident">i</span>
|
122
|
+
<span class="keyword">end</span>
|
123
|
+
<span class="ident">list</span> <span class="comment"># => [1.cm, 1.5.cm, 2.cm, 2.5.cm, 3.cm]</span>
|
124
|
+
</pre></p>
|
125
|
+
|
126
|
+
|
127
|
+
<h2>Forum</h2>
|
128
|
+
|
129
|
+
|
130
|
+
<p><a href="http://groups.google.com/group/ruby-typographic-unit">http://groups.google.com/group/ruby-typographic-unit</a></p>
|
131
|
+
|
132
|
+
|
133
|
+
<h2>How to submit patches</h2>
|
134
|
+
|
135
|
+
|
136
|
+
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
|
137
|
+
|
138
|
+
|
139
|
+
<p>The trunk repository is <code>svn://rubyforge.org/var/svn/typographicunit/trunk</code> for anonymous access.</p>
|
140
|
+
|
141
|
+
|
142
|
+
<h2>License</h2>
|
143
|
+
|
144
|
+
|
145
|
+
<p>This code is free to use under the terms of the Ruby license.</p>
|
146
|
+
|
147
|
+
|
148
|
+
<h2>Contact</h2>
|
149
|
+
|
150
|
+
|
151
|
+
<p>Comments are welcome. Send an email to <a href="mailto:keita.yamaguchi@gmail.com">Keita Yamaguchi</a> via the <a href="http://groups.google.com/group/ruby-typographic-unit">forum</a></p>
|
152
|
+
|
153
|
+
|
154
|
+
<h2>Links</h2>
|
155
|
+
|
156
|
+
|
157
|
+
<ul>
|
158
|
+
<li><a href="http://typographicunit.rubyforge.org/">Project Home</a></li>
|
159
|
+
<li><a href="http://rubyforge.org/projects/typographicunit/">RubyForge/TypographicUnit</a></li>
|
160
|
+
</ul>
|
161
|
+
<p class="coda">
|
162
|
+
<a href="keita.yamaguchi@gmail.com">Keita Yamaguchi</a>, 19th December 2007<br>
|
163
|
+
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
164
|
+
</p>
|
165
|
+
</div>
|
166
|
+
|
167
|
+
<!-- insert site tracking codes here, like Google Urchin -->
|
168
|
+
|
169
|
+
</body>
|
170
|
+
</html>
|
data/website/index.txt
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
h1. TypographicUnit
|
2
|
+
|
3
|
+
h2. What
|
4
|
+
|
5
|
+
TypographicUnit is a library for converting between typographic units according
|
6
|
+
to TeX. This library can handle the following units:
|
7
|
+
|
8
|
+
* TeX Scaled Point(sp)
|
9
|
+
* TeX Point(pt)
|
10
|
+
* Pica(pt)
|
11
|
+
* Inch(in)
|
12
|
+
* TeX Big Point(bp)
|
13
|
+
* PostScript Point(ps_pt)
|
14
|
+
* Meter(m)
|
15
|
+
* Centimeter(cm)
|
16
|
+
* Milimeter(mm)
|
17
|
+
* Didot Point(dd)
|
18
|
+
* Cicero(cc)
|
19
|
+
* Japanese Q(q)
|
20
|
+
* JIS Point(jis_pt)
|
21
|
+
|
22
|
+
h2. Installing
|
23
|
+
|
24
|
+
<pre syntax="ruby">sudo gem install typographicunit</pre>
|
25
|
+
|
26
|
+
h2. The basics
|
27
|
+
|
28
|
+
<pre syntax="ruby">
|
29
|
+
require "typographic-unit"
|
30
|
+
|
31
|
+
1.cm # => #<1cm>
|
32
|
+
1.cm - 1.mm # => #<0.9cm>
|
33
|
+
1.cm == 10.mm # => true
|
34
|
+
|
35
|
+
1.in >> :cm # => #<2.54cm>
|
36
|
+
2.54.cm >> :in # => #<1.0in>
|
37
|
+
1.in - 1.cm # => #<0.606299212598425in>
|
38
|
+
(1.in - 1.cm) >> :cm # => #<1.54cm>
|
39
|
+
</pre>
|
40
|
+
|
41
|
+
h2. Demonstration of usage
|
42
|
+
|
43
|
+
h3. Convert
|
44
|
+
|
45
|
+
<pre syntax="ruby">
|
46
|
+
1.pt >> :mm # => #<0.351459803514598mm>
|
47
|
+
7227.pt >> :cm # => #<254.0cm>
|
48
|
+
1.in >> :bp # => #<72.0bp>
|
49
|
+
1.pt >> :sp # => #<65536.0sp>
|
50
|
+
1157.pt >> :pt # => #<1238.0pt>
|
51
|
+
1.cc >> :dd # => #<12.0dd>
|
52
|
+
10.q >> :mm # => #<2.5mm>
|
53
|
+
1.jis_pt >> :mm # => #<0.3514mm>
|
54
|
+
</pre>
|
55
|
+
|
56
|
+
h3. Calculate
|
57
|
+
|
58
|
+
<pre syntax="ruby">
|
59
|
+
1.cm + 1.mm # => #<1.1cm>
|
60
|
+
1.cm + 1.in # => #<3.54cm>
|
61
|
+
1.pt - 1.bp # => #<-0.00131797426317971mm>
|
62
|
+
100.ps_pt - 100.jis_pt >> :mm # => #<0.137777777777779mm>
|
63
|
+
1.cm * 10 # => #<10cm>
|
64
|
+
</pre>
|
65
|
+
|
66
|
+
h3. Step
|
67
|
+
|
68
|
+
<pre syntax="ruby">
|
69
|
+
list = []
|
70
|
+
1.cm.step(3.cm, 0.5.cm) do |i|
|
71
|
+
list << i
|
72
|
+
end
|
73
|
+
list # => [1.cm, 1.5.cm, 2.cm, 2.5.cm, 3.cm]
|
74
|
+
</pre>
|
75
|
+
|
76
|
+
h2. Forum
|
77
|
+
|
78
|
+
"http://groups.google.com/group/ruby-typographic-unit":http://groups.google.com/group/ruby-typographic-unit
|
79
|
+
|
80
|
+
h2. How to submit patches
|
81
|
+
|
82
|
+
Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
|
83
|
+
|
84
|
+
The trunk repository is <code>svn://rubyforge.org/var/svn/typographicunit/trunk</code> for anonymous access.
|
85
|
+
|
86
|
+
h2. License
|
87
|
+
|
88
|
+
This code is free to use under the terms of the Ruby license.
|
89
|
+
|
90
|
+
h2. Contact
|
91
|
+
|
92
|
+
Comments are welcome. Send an email to "Keita Yamaguchi":mailto:keita.yamaguchi@gmail.com via the "forum":http://groups.google.com/group/ruby-typographic-unit
|
93
|
+
|
94
|
+
h2. Links
|
95
|
+
|
96
|
+
* "Project Home":http://typographicunit.rubyforge.org/
|
97
|
+
* "RubyForge/TypographicUnit":http://rubyforge.org/projects/typographicunit/
|