prawn 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +340 -0
- data/LICENSE +56 -0
- data/README +30 -0
- data/Rakefile +83 -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/dice.png +0 -0
- data/data/images/pigs.jpg +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/stef.jpg +0 -0
- data/data/shift_jis_text.txt +1 -0
- data/examples/addressbook.csv +6 -0
- data/examples/alignment.rb +16 -0
- data/examples/bounding_boxes.pdf +62 -0
- data/examples/bounding_boxes.rb +30 -0
- data/examples/canvas.pdf +81 -0
- data/examples/canvas.rb +12 -0
- data/examples/cell.rb +27 -0
- data/examples/currency.csv +1834 -0
- data/examples/curves.rb +10 -0
- data/examples/fancy_table.rb +48 -0
- data/examples/font_size.rb +19 -0
- data/examples/hexagon.rb +14 -0
- data/examples/image.pdf +0 -0
- data/examples/image.rb +23 -0
- data/examples/image2.rb +13 -0
- data/examples/inline_styles.pdf +117 -0
- data/examples/kerning.rb +27 -0
- data/examples/line.rb +31 -0
- data/examples/multi_page_layout.rb +14 -0
- data/examples/on_page_start.rb +17 -0
- data/examples/page_geometry.rb +28 -0
- data/examples/polygons.rb +16 -0
- data/examples/ruport_formatter.rb +47 -0
- data/examples/ruport_helpers.rb +17 -0
- data/examples/russian_boxes.rb +34 -0
- data/examples/simple_text.rb +15 -0
- data/examples/simple_text_ttf.rb +16 -0
- data/examples/sjis.rb +19 -0
- data/examples/table.rb +45 -0
- data/examples/table_bench.rb +92 -0
- data/examples/text_flow.rb +65 -0
- data/examples/utf8.rb +12 -0
- data/lib/prawn.rb +33 -0
- data/lib/prawn/compatibility.rb +33 -0
- data/lib/prawn/document.rb +334 -0
- data/lib/prawn/document/bounding_box.rb +253 -0
- data/lib/prawn/document/page_geometry.rb +78 -0
- data/lib/prawn/document/table.rb +253 -0
- data/lib/prawn/document/text.rb +346 -0
- data/lib/prawn/errors.rb +33 -0
- data/lib/prawn/font.rb +5 -0
- data/lib/prawn/font/cmap.rb +59 -0
- data/lib/prawn/font/metrics.rb +414 -0
- data/lib/prawn/font/wrapping.rb +45 -0
- data/lib/prawn/graphics.rb +285 -0
- data/lib/prawn/graphics/cell.rb +226 -0
- data/lib/prawn/images.rb +241 -0
- data/lib/prawn/images/jpg.rb +43 -0
- data/lib/prawn/images/png.rb +178 -0
- data/lib/prawn/pdf_object.rb +64 -0
- data/lib/prawn/reference.rb +47 -0
- data/spec/bounding_box_spec.rb +120 -0
- data/spec/box_calculation_spec.rb +17 -0
- data/spec/document_spec.rb +152 -0
- data/spec/graphics_spec.rb +250 -0
- data/spec/images_spec.rb +42 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/metrics_spec.rb +60 -0
- data/spec/pdf_object_spec.rb +102 -0
- data/spec/png_spec.rb +35 -0
- data/spec/reference_spec.rb +29 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/table_spec.rb +145 -0
- data/spec/text_spec.rb +190 -0
- data/vendor/font_ttf/ttf.rb +20 -0
- data/vendor/font_ttf/ttf/datatypes.rb +189 -0
- data/vendor/font_ttf/ttf/encodings.rb +140 -0
- data/vendor/font_ttf/ttf/exceptions.rb +28 -0
- data/vendor/font_ttf/ttf/file.rb +290 -0
- data/vendor/font_ttf/ttf/fontchunk.rb +77 -0
- data/vendor/font_ttf/ttf/table/cmap.rb +408 -0
- data/vendor/font_ttf/ttf/table/cvt.rb +49 -0
- data/vendor/font_ttf/ttf/table/fpgm.rb +48 -0
- data/vendor/font_ttf/ttf/table/gasp.rb +88 -0
- data/vendor/font_ttf/ttf/table/glyf.rb +452 -0
- data/vendor/font_ttf/ttf/table/head.rb +86 -0
- data/vendor/font_ttf/ttf/table/hhea.rb +96 -0
- data/vendor/font_ttf/ttf/table/hmtx.rb +98 -0
- data/vendor/font_ttf/ttf/table/kern.rb +186 -0
- data/vendor/font_ttf/ttf/table/loca.rb +75 -0
- data/vendor/font_ttf/ttf/table/maxp.rb +81 -0
- data/vendor/font_ttf/ttf/table/name.rb +222 -0
- data/vendor/font_ttf/ttf/table/os2.rb +172 -0
- data/vendor/font_ttf/ttf/table/post.rb +120 -0
- data/vendor/font_ttf/ttf/table/prep.rb +27 -0
- data/vendor/font_ttf/ttf/table/vhea.rb +45 -0
- data/vendor/font_ttf/ttf/table/vmtx.rb +36 -0
- metadata +180 -0
data/spec/text_spec.rb
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
4
|
+
|
|
5
|
+
class TextObserver
|
|
6
|
+
|
|
7
|
+
attr_accessor :font_settings, :size, :string
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@font_settings = []
|
|
11
|
+
@fonts = {}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def resource_font(*params)
|
|
15
|
+
@fonts[params[0]] = params[1].basefont
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def set_text_font_and_size(*params)
|
|
19
|
+
@font_settings << { :name => @fonts[params[0]], :size => params[1] }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def show_text(*params)
|
|
23
|
+
@string = params[0]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def show_text_with_positioning(*params)
|
|
27
|
+
@string = params[0].join
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class FontObserver
|
|
32
|
+
attr_accessor :page_fonts
|
|
33
|
+
|
|
34
|
+
def initialize
|
|
35
|
+
@page_fonts = []
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def resource_font(*params)
|
|
39
|
+
@page_fonts.last << params[1].basefont
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def begin_page(*params)
|
|
43
|
+
@page_fonts << []
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "Font Metrics" do
|
|
48
|
+
|
|
49
|
+
it "should default to Helvetica if no font is specified" do
|
|
50
|
+
@pdf = Prawn::Document.new
|
|
51
|
+
@pdf.font_metrics.should == Prawn::Font::Metrics["Helvetica"]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should use the currently set font for font_metrics" do
|
|
55
|
+
@pdf = Prawn::Document.new
|
|
56
|
+
@pdf.font "Courier"
|
|
57
|
+
@pdf.font_metrics.should == Prawn::Font::Metrics["Courier"]
|
|
58
|
+
|
|
59
|
+
comicsans = "#{Prawn::BASEDIR}/data/fonts/comicsans.ttf"
|
|
60
|
+
@pdf.font(comicsans)
|
|
61
|
+
@pdf.font_metrics.should == Prawn::Font::Metrics[comicsans]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "when drawing text" do
|
|
67
|
+
|
|
68
|
+
before(:each) { create_pdf }
|
|
69
|
+
|
|
70
|
+
it "should advance down the document based on font_height" do
|
|
71
|
+
position = @pdf.y
|
|
72
|
+
@pdf.text "Foo"
|
|
73
|
+
|
|
74
|
+
@pdf.y.should be_close(position - @pdf.font_metrics.font_height(12),
|
|
75
|
+
0.0001)
|
|
76
|
+
|
|
77
|
+
position = @pdf.y
|
|
78
|
+
@pdf.text "Foo\nBar\nBaz"
|
|
79
|
+
@pdf.y.should be_close(position - 3*@pdf.font_metrics.font_height(12),
|
|
80
|
+
0.0001)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should default to 12 point helvetica" do
|
|
84
|
+
@pdf.text "Blah", :at => [100,100]
|
|
85
|
+
text = observer(TextObserver)
|
|
86
|
+
text.font_settings[0][:name].should == :Helvetica
|
|
87
|
+
text.font_settings[0][:size].should == 12
|
|
88
|
+
text.string.should == "Blah"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should allow setting font size" do
|
|
92
|
+
@pdf.text "Blah", :at => [100,100], :size => 16
|
|
93
|
+
text = observer(TextObserver)
|
|
94
|
+
text.font_settings[0][:size].should == 16
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should allow setting a default font size" do
|
|
98
|
+
@pdf.font_size! 16
|
|
99
|
+
@pdf.text "Blah"
|
|
100
|
+
text = observer(TextObserver)
|
|
101
|
+
text.font_settings[0][:size].should == 16
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should allow overriding default font for a single instance" do
|
|
105
|
+
@pdf.font_size! 16
|
|
106
|
+
|
|
107
|
+
@pdf.text "Blah", :size => 11
|
|
108
|
+
@pdf.text "Blaz"
|
|
109
|
+
text = observer(TextObserver)
|
|
110
|
+
text.font_settings[0][:size].should == 11
|
|
111
|
+
text.font_settings[1][:size].should == 16
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
it "should allow setting a font size transaction with a block" do
|
|
116
|
+
@pdf.font_size 16 do
|
|
117
|
+
@pdf.text 'Blah'
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
@pdf.text 'blah'
|
|
121
|
+
|
|
122
|
+
text = observer(TextObserver)
|
|
123
|
+
text.font_settings[0][:size].should == 16
|
|
124
|
+
text.font_settings[1][:size].should == 12
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "should allow manual setting the font size " +
|
|
128
|
+
"when in a font size block" do
|
|
129
|
+
@pdf.font_size 16 do
|
|
130
|
+
@pdf.text 'Foo'
|
|
131
|
+
@pdf.text 'Blah', :size => 11
|
|
132
|
+
@pdf.text 'Blaz'
|
|
133
|
+
end
|
|
134
|
+
text = observer(TextObserver)
|
|
135
|
+
text.font_settings[0][:size].should == 16
|
|
136
|
+
text.font_settings[1][:size].should == 11
|
|
137
|
+
text.font_settings[2][:size].should == 16
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "should allow registering of built-in font_settings on the fly" do
|
|
141
|
+
@pdf.font "Courier"
|
|
142
|
+
@pdf.text "Blah", :at => [100,100]
|
|
143
|
+
@pdf.font "Times-Roman"
|
|
144
|
+
@pdf.text "Blaz", :at => [150,150]
|
|
145
|
+
text = observer(TextObserver)
|
|
146
|
+
|
|
147
|
+
text.font_settings[0][:name].should == :Courier
|
|
148
|
+
text.font_settings[1][:name].should == :"Times-Roman"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "should utilise the same default font across multiple pages" do
|
|
152
|
+
@pdf.text "Blah", :at => [100,100]
|
|
153
|
+
@pdf.start_new_page
|
|
154
|
+
@pdf.text "Blaz", :at => [150,150]
|
|
155
|
+
text = observer(FontObserver)
|
|
156
|
+
|
|
157
|
+
text.page_fonts.size.should eql(2)
|
|
158
|
+
text.page_fonts[0][0].should eql(:Helvetica)
|
|
159
|
+
text.page_fonts[1][0].should eql(:Helvetica)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "should raise an exception when an unknown font is used" do
|
|
163
|
+
lambda { @pdf.font "Pao bu" }.should raise_error(Prawn::Errors::UnknownFont)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
if "spec".respond_to?(:encode!)
|
|
167
|
+
# Handle non utf-8 string encodings in a sane way on M17N aware VMs
|
|
168
|
+
it "should raise an exception when a utf-8 incompatible string is rendered" do
|
|
169
|
+
str = "Blah \xDD"
|
|
170
|
+
str.force_encoding("ASCII-8BIT")
|
|
171
|
+
lambda { @pdf.text str }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
|
|
172
|
+
end
|
|
173
|
+
it "should not raise an exception when a shift-jis string is rendered" do
|
|
174
|
+
datafile = "#{Prawn::BASEDIR}/data/shift_jis_text.txt"
|
|
175
|
+
sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
|
|
176
|
+
lambda { @pdf.text sjis_str }.should_not raise_error(Prawn::Errors::IncompatibleStringEncoding)
|
|
177
|
+
end
|
|
178
|
+
else
|
|
179
|
+
# Handle non utf-8 string encodings in a sane way on non-M17N aware VMs
|
|
180
|
+
it "should raise an exception when a corrupt utf-8 string is rendered" do
|
|
181
|
+
str = "Blah \xDD"
|
|
182
|
+
lambda { @pdf.text str }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
|
|
183
|
+
end
|
|
184
|
+
it "should raise an exception when a shift-jis string is rendered" do
|
|
185
|
+
sjis_str = File.read("#{Prawn::BASEDIR}/data/shift_jis_text.txt")
|
|
186
|
+
lambda { @pdf.text sjis_str }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# TTF/Ruby, a library to read and write TrueType fonts in Ruby.
|
|
2
|
+
# Copyright (C) 2006 Mathieu Blondel
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program; if not, write to the Free Software
|
|
16
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
+
|
|
18
|
+
require 'ttf/file'
|
|
19
|
+
|
|
20
|
+
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# TTF/Ruby, a library to read and write TrueType fonts in Ruby.
|
|
2
|
+
# Copyright (C) 2006 Mathieu Blondel
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program; if not, write to the Free Software
|
|
16
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
+
|
|
18
|
+
class IO
|
|
19
|
+
SIZEOF_USHORT = 2
|
|
20
|
+
SIZEOF_ULONG = 4
|
|
21
|
+
SIZEOF_FIXED = 4
|
|
22
|
+
SIZEOF_LONG_DATE_TIME = 8
|
|
23
|
+
SIZEOF_SHORT = SIZEOF_FWORD = 2
|
|
24
|
+
SHORT_BOUND = 2 ** (8 * SIZEOF_SHORT - 1)
|
|
25
|
+
USHORT_BOUND = SHORT_BOUND * 2
|
|
26
|
+
|
|
27
|
+
def at_offset(offset)
|
|
28
|
+
prev_pos = self.pos
|
|
29
|
+
self.pos = offset
|
|
30
|
+
ret = yield
|
|
31
|
+
self.pos = prev_pos
|
|
32
|
+
ret
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
alias :old_read :read
|
|
36
|
+
|
|
37
|
+
#ef read(n)
|
|
38
|
+
# ret = old_read(n)
|
|
39
|
+
# raise Font::TTF::MalformedFont if ret.nil?
|
|
40
|
+
# ret
|
|
41
|
+
#end
|
|
42
|
+
|
|
43
|
+
def read_ushort
|
|
44
|
+
read(SIZEOF_USHORT).unpack("n")[0]
|
|
45
|
+
end
|
|
46
|
+
alias :read_ufword :read_ushort
|
|
47
|
+
alias :read_f2dot14 :read_ushort
|
|
48
|
+
|
|
49
|
+
def read_ushorts(n)
|
|
50
|
+
read(SIZEOF_USHORT * n).unpack("n#{n.to_s}")
|
|
51
|
+
end
|
|
52
|
+
alias :read_ufwords :read_ushorts
|
|
53
|
+
alias :read_f2dot14s :read_ushorts
|
|
54
|
+
|
|
55
|
+
def read_ulong
|
|
56
|
+
read(SIZEOF_ULONG).unpack("N")[0]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def read_ulongs(n)
|
|
60
|
+
read(SIZEOF_ULONG * n).unpack("N#{n.to_s}")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def read_fixed
|
|
64
|
+
f = read_ulong
|
|
65
|
+
#"%d.%d" % [f >> 16, f & 0xff00]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def read_ulong_as_text
|
|
69
|
+
read(SIZEOF_ULONG)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def read_byte
|
|
73
|
+
read(1).unpack("C")[0]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def read_bytes(n)
|
|
77
|
+
read(n).unpack("C" + n.to_s)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def read_long_date_time
|
|
81
|
+
# Don't know how to compute dates
|
|
82
|
+
read(SIZEOF_LONG_DATE_TIME)
|
|
83
|
+
""
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def read_short
|
|
87
|
+
# No unpack support for signed network short
|
|
88
|
+
n = read_ushort
|
|
89
|
+
n = n - 2 * SHORT_BOUND if n >= SHORT_BOUND
|
|
90
|
+
n
|
|
91
|
+
end
|
|
92
|
+
alias :read_fword :read_short
|
|
93
|
+
|
|
94
|
+
def read_shorts(n)
|
|
95
|
+
arr = []
|
|
96
|
+
n.times { arr << read_short }
|
|
97
|
+
arr
|
|
98
|
+
end
|
|
99
|
+
alias :read_fwords :read_shorts
|
|
100
|
+
|
|
101
|
+
def read_char
|
|
102
|
+
read(1)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def read_chars(n)
|
|
106
|
+
read(n)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
class Integer
|
|
112
|
+
|
|
113
|
+
def to_ushort
|
|
114
|
+
[self].pack("n")
|
|
115
|
+
end
|
|
116
|
+
alias :to_ufword :to_ushort
|
|
117
|
+
alias :to_f2dot14 :to_ushort
|
|
118
|
+
|
|
119
|
+
def to_ulong
|
|
120
|
+
[self].pack("N")
|
|
121
|
+
end
|
|
122
|
+
alias :to_fixed :to_ulong
|
|
123
|
+
|
|
124
|
+
def to_short
|
|
125
|
+
n = self
|
|
126
|
+
n + 2 * IO::SHORT_BOUND if n < 0
|
|
127
|
+
n.to_ushort
|
|
128
|
+
end
|
|
129
|
+
alias :to_fword :to_short
|
|
130
|
+
|
|
131
|
+
def to_byte
|
|
132
|
+
[self].pack("C")
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
class String
|
|
138
|
+
|
|
139
|
+
def to_long_date_time
|
|
140
|
+
# Don't know how to compute dates
|
|
141
|
+
# So just returns something at the good size
|
|
142
|
+
" " * IO::SIZEOF_LONG_DATE_TIME
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def four_chars!
|
|
146
|
+
str = self
|
|
147
|
+
while str.length < 4
|
|
148
|
+
str += " "
|
|
149
|
+
end
|
|
150
|
+
self.replace(str.slice(0,4))
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
class Array
|
|
155
|
+
|
|
156
|
+
def to_bytes
|
|
157
|
+
self.pack("C*")
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def to_ushorts
|
|
161
|
+
self.pack("n*")
|
|
162
|
+
end
|
|
163
|
+
alias :to_ufwords :to_ushorts
|
|
164
|
+
alias :to_f2dot14s :to_ushorts
|
|
165
|
+
|
|
166
|
+
def to_shorts
|
|
167
|
+
str = ""
|
|
168
|
+
self.each do |int|
|
|
169
|
+
str += int.to_short
|
|
170
|
+
end
|
|
171
|
+
str
|
|
172
|
+
end
|
|
173
|
+
alias :to_fwords :to_shorts
|
|
174
|
+
|
|
175
|
+
def to_ulongs
|
|
176
|
+
self.pack("N*")
|
|
177
|
+
end
|
|
178
|
+
alias :to_fixeds :to_ulongs
|
|
179
|
+
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# This allows to sort an array of symbols as if they were strings
|
|
183
|
+
class Symbol
|
|
184
|
+
|
|
185
|
+
def <=>(symb)
|
|
186
|
+
self.to_s <=> symb.to_s
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# TTF/Ruby, a library to read and write TrueType fonts in Ruby.
|
|
2
|
+
# Copyright (C) 2006 Mathieu Blondel
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program; if not, write to the Free Software
|
|
16
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
+
|
|
18
|
+
module Font
|
|
19
|
+
module TTF
|
|
20
|
+
module Encodings
|
|
21
|
+
|
|
22
|
+
module Platform
|
|
23
|
+
UNICODE = 0
|
|
24
|
+
MACINTOSH = 1
|
|
25
|
+
ISO = 2
|
|
26
|
+
MICROSOFT = 3
|
|
27
|
+
|
|
28
|
+
ID2NAME = {
|
|
29
|
+
UNICODE => "Unicode",
|
|
30
|
+
MACINTOSH => "Macintosh",
|
|
31
|
+
ISO => "ISO",
|
|
32
|
+
MICROSOFT => "Microsoft"
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
module UnicodeEncoding
|
|
37
|
+
# When Platform == 0
|
|
38
|
+
DEFAULT_SEMANTICS = 0
|
|
39
|
+
VERSION_1_1_SEMANTICS = 1
|
|
40
|
+
ISO_10646_1993_SEMANTICS = 2
|
|
41
|
+
UNICODE = 3
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
module MicrosoftEncoding
|
|
45
|
+
# When Platform == 3
|
|
46
|
+
SYMBOL = 0
|
|
47
|
+
UNICODE = 1
|
|
48
|
+
SHIFTJIS = 2
|
|
49
|
+
BIG5 = 3
|
|
50
|
+
PRC = 4
|
|
51
|
+
WASUNG = 5
|
|
52
|
+
JOHAB = 6
|
|
53
|
+
|
|
54
|
+
ID2NAME = {
|
|
55
|
+
SYMBOL => "Symbol",
|
|
56
|
+
UNICODE => "Unicode",
|
|
57
|
+
SHIFTJIS => "ShiftJIS",
|
|
58
|
+
BIG5 => "Big5",
|
|
59
|
+
PRC => "PRC",
|
|
60
|
+
WASUNG => "Wasung",
|
|
61
|
+
JOHAB => "Johab"
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
module MacintoshEncoding
|
|
66
|
+
# When Platform == 1
|
|
67
|
+
ROMAN = 0
|
|
68
|
+
JAPANESE = 1
|
|
69
|
+
TRADITIONAL_CHINESE = 2
|
|
70
|
+
KOREAN = 3
|
|
71
|
+
ARABIC = 4
|
|
72
|
+
HEBREW = 5
|
|
73
|
+
GREEK = 6
|
|
74
|
+
RUSSIAN = 7
|
|
75
|
+
RSYMBOL = 8
|
|
76
|
+
DEVANAGARI = 9
|
|
77
|
+
GURMUKHI = 10
|
|
78
|
+
GUJARATI = 11
|
|
79
|
+
ORIYA = 12
|
|
80
|
+
BENGALI = 13
|
|
81
|
+
TAMIL = 14
|
|
82
|
+
TELUGU = 15
|
|
83
|
+
KANNADA = 16
|
|
84
|
+
MALAYALAM = 17
|
|
85
|
+
SINHALESE = 18
|
|
86
|
+
BURMESE = 19
|
|
87
|
+
KHMER = 20
|
|
88
|
+
THAI = 21
|
|
89
|
+
LAOTIAN = 22
|
|
90
|
+
GEORGIAN = 23
|
|
91
|
+
ARMENIAN = 24
|
|
92
|
+
SIMPLIFIED_CHINESE = 25
|
|
93
|
+
TIBETAN = 26
|
|
94
|
+
MONGOLIAN = 27
|
|
95
|
+
GEEZ = 28
|
|
96
|
+
SLAVIC = 29
|
|
97
|
+
VIETNAMESE = 30
|
|
98
|
+
SINDHI = 31
|
|
99
|
+
UNINTERPRETED = 32
|
|
100
|
+
|
|
101
|
+
ID2NAME = {
|
|
102
|
+
ROMAN => "Roman",
|
|
103
|
+
JAPANESE => "Japanese",
|
|
104
|
+
TRADITIONAL_CHINESE => "Traditional Chinese",
|
|
105
|
+
KOREAN => "Korean",
|
|
106
|
+
ARABIC => "Arabic",
|
|
107
|
+
HEBREW => "Hebrew",
|
|
108
|
+
GREEK => "Greek",
|
|
109
|
+
RUSSIAN => "Russian",
|
|
110
|
+
RSYMBOL => "RSymbol",
|
|
111
|
+
DEVANAGARI => "Devanagari",
|
|
112
|
+
GURMUKHI => "Gurmukhi",
|
|
113
|
+
GUJARATI => "Gujarati",
|
|
114
|
+
ORIYA => "Orya",
|
|
115
|
+
BENGALI => "Bengali",
|
|
116
|
+
TAMIL => "Tamil",
|
|
117
|
+
TELUGU => "Telugu",
|
|
118
|
+
KANNADA => "Kannada",
|
|
119
|
+
MALAYALAM => "Malayalam",
|
|
120
|
+
SINHALESE => "Sinhalese",
|
|
121
|
+
BURMESE => "Burmese",
|
|
122
|
+
KHMER => "Khmer",
|
|
123
|
+
THAI => "Thai",
|
|
124
|
+
LAOTIAN => "Laotian",
|
|
125
|
+
GEORGIAN => "Georgian",
|
|
126
|
+
ARMENIAN => "Armenian",
|
|
127
|
+
SIMPLIFIED_CHINESE => "Simplified Chinese",
|
|
128
|
+
TIBETAN => "Tibetan",
|
|
129
|
+
MONGOLIAN => "Mongolian",
|
|
130
|
+
GEEZ => "Geez",
|
|
131
|
+
SLAVIC => "Slavic",
|
|
132
|
+
VIETNAMESE => "Vietnamese",
|
|
133
|
+
SINDHI => "Sindhi",
|
|
134
|
+
UNINTERPRETED => "Uninterpreted"
|
|
135
|
+
}
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|