prawn 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +6 -10
- data/Rakefile +4 -13
- data/data/encodings/win_ansi.txt +29 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/examples/bounding_box/bounding_boxes.rb +44 -0
- data/examples/bounding_box/lazy_bounding_boxes.rb +28 -0
- data/examples/bounding_box/padded_box.rb +24 -0
- data/examples/{russian_boxes.rb → bounding_box/russian_boxes.rb} +9 -6
- data/examples/general/background.rb +20 -0
- data/examples/{canvas.rb → general/canvas.rb} +6 -2
- data/examples/general/measurement_units.rb +52 -0
- data/examples/{multi_page_layout.rb → general/multi_page_layout.rb} +6 -3
- data/examples/{page_geometry.rb → general/page_geometry.rb} +6 -2
- data/examples/{image.rb → graphics/basic_images.rb} +8 -4
- data/examples/graphics/cmyk.rb +13 -0
- data/examples/graphics/curves.rb +12 -0
- data/examples/{hexagon.rb → graphics/hexagon.rb} +5 -5
- data/examples/graphics/image_fit.rb +16 -0
- data/examples/graphics/image_flow.rb +38 -0
- data/examples/graphics/image_position.rb +18 -0
- data/examples/{line.rb → graphics/line.rb} +4 -2
- data/examples/{png_types.rb → graphics/png_types.rb} +4 -4
- data/examples/{polygons.rb → graphics/polygons.rb} +5 -4
- data/examples/graphics/remote_images.rb +12 -0
- data/examples/{ruport_helpers.rb → graphics/ruport_style_helpers.rb} +8 -5
- data/examples/graphics/stroke_bounds.rb +23 -0
- data/examples/{chinese_text_wrapping.rb → m17n/chinese_text_wrapping.rb} +7 -4
- data/examples/m17n/euro.rb +16 -0
- data/examples/m17n/sjis.rb +29 -0
- data/examples/m17n/utf8.rb +14 -0
- data/examples/m17n/win_ansi_charset.rb +55 -0
- data/examples/{addressbook.csv → table/addressbook.csv} +0 -0
- data/examples/{cell.rb → table/cell.rb} +8 -6
- data/examples/{currency.csv → table/currency.csv} +0 -0
- data/examples/{fancy_table.rb → table/fancy_table.rb} +9 -6
- data/examples/{ruport_formatter.rb → table/ruport_formatter.rb} +6 -3
- data/examples/{table.rb → table/table.rb} +6 -2
- data/examples/table/table_alignment.rb +18 -0
- data/examples/table/table_border_color.rb +17 -0
- data/examples/table/table_colspan.rb +19 -0
- data/examples/table/table_header_color.rb +19 -0
- data/examples/table/table_header_underline.rb +15 -0
- data/examples/{alignment.rb → text/alignment.rb} +5 -2
- data/examples/text/family_based_styling.rb +25 -0
- data/examples/{flowing_text_with_header_and_footer.rb → text/flowing_text_with_header_and_footer.rb} +19 -8
- data/examples/text/font_calculations.rb +91 -0
- data/examples/text/font_size.rb +34 -0
- data/examples/{kerning.rb → text/kerning.rb} +5 -1
- data/examples/text/simple_text.rb +18 -0
- data/examples/text/simple_text_ttf.rb +18 -0
- data/examples/{span.rb → text/span.rb} +5 -2
- data/examples/text/text_box.rb +26 -0
- data/examples/{text_flow.rb → text/text_flow.rb} +5 -2
- data/lib/prawn.rb +26 -20
- data/lib/prawn/compatibility.rb +5 -8
- data/lib/prawn/document.rb +29 -13
- data/lib/prawn/document/annotations.rb +63 -0
- data/lib/prawn/document/bounding_box.rb +18 -3
- data/lib/prawn/document/destinations.rb +81 -0
- data/lib/prawn/document/internals.rb +16 -2
- data/lib/prawn/document/page_geometry.rb +58 -57
- data/lib/prawn/document/span.rb +8 -0
- data/lib/prawn/document/table.rb +81 -31
- data/lib/prawn/document/text.rb +66 -21
- data/lib/prawn/document/text/box.rb +77 -0
- data/lib/prawn/encoding.rb +121 -0
- data/lib/prawn/errors.rb +4 -0
- data/lib/prawn/font.rb +70 -42
- data/lib/prawn/font/metrics.rb +64 -119
- data/lib/prawn/graphics.rb +105 -87
- data/lib/prawn/graphics/cell.rb +55 -28
- data/lib/prawn/graphics/color.rb +8 -0
- data/lib/prawn/images.rb +55 -12
- data/lib/prawn/images/jpg.rb +2 -1
- data/lib/prawn/images/png.rb +2 -1
- data/lib/prawn/literal_string.rb +14 -0
- data/lib/prawn/measurement_extensions.rb +46 -0
- data/lib/prawn/measurements.rb +71 -0
- data/lib/prawn/name_tree.rb +165 -0
- data/lib/prawn/pdf_object.rb +8 -1
- data/spec/annotations_spec.rb +90 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +39 -2
- data/spec/font_spec.rb +22 -0
- data/spec/graphics_spec.rb +99 -87
- data/spec/images_spec.rb +29 -1
- data/spec/measurement_units_spec.rb +23 -0
- data/spec/metrics_spec.rb +3 -2
- data/spec/name_tree_spec.rb +103 -0
- data/spec/pdf_object_spec.rb +15 -5
- data/spec/png_spec.rb +14 -14
- data/spec/spec_helper.rb +8 -6
- data/spec/table_spec.rb +40 -0
- data/spec/text_spec.rb +6 -4
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +5 -0
- data/vendor/ttfunk/lib/ttfunk.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/table.rb +27 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +94 -0
- data/vendor/ttfunk/lib/ttfunk/table/directory.rb +25 -0
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +25 -0
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +27 -0
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +20 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +52 -0
- metadata +93 -62
- data/examples/bounding_boxes.rb +0 -30
- data/examples/curves.rb +0 -10
- data/examples/family_based_styling.rb +0 -21
- data/examples/font_size.rb +0 -19
- data/examples/image2.rb +0 -13
- data/examples/image_flow.rb +0 -29
- data/examples/lazy_bounding_boxes.rb +0 -19
- data/examples/remote_images.rb +0 -7
- data/examples/simple_text.rb +0 -15
- data/examples/simple_text_ttf.rb +0 -16
- data/examples/sjis.rb +0 -21
- data/examples/utf8.rb +0 -12
- data/vendor/font_ttf/ttf.rb +0 -20
- data/vendor/font_ttf/ttf/datatypes.rb +0 -189
- data/vendor/font_ttf/ttf/encodings.rb +0 -140
- data/vendor/font_ttf/ttf/exceptions.rb +0 -28
- data/vendor/font_ttf/ttf/file.rb +0 -290
- data/vendor/font_ttf/ttf/fontchunk.rb +0 -77
- data/vendor/font_ttf/ttf/table/cmap.rb +0 -408
- data/vendor/font_ttf/ttf/table/cvt.rb +0 -49
- data/vendor/font_ttf/ttf/table/fpgm.rb +0 -48
- data/vendor/font_ttf/ttf/table/gasp.rb +0 -88
- data/vendor/font_ttf/ttf/table/glyf.rb +0 -452
- data/vendor/font_ttf/ttf/table/head.rb +0 -86
- data/vendor/font_ttf/ttf/table/hhea.rb +0 -96
- data/vendor/font_ttf/ttf/table/hmtx.rb +0 -98
- data/vendor/font_ttf/ttf/table/kern.rb +0 -186
- data/vendor/font_ttf/ttf/table/loca.rb +0 -75
- data/vendor/font_ttf/ttf/table/maxp.rb +0 -81
- data/vendor/font_ttf/ttf/table/name.rb +0 -222
- data/vendor/font_ttf/ttf/table/os2.rb +0 -172
- data/vendor/font_ttf/ttf/table/post.rb +0 -120
- data/vendor/font_ttf/ttf/table/prep.rb +0 -27
- data/vendor/font_ttf/ttf/table/vhea.rb +0 -45
- data/vendor/font_ttf/ttf/table/vmtx.rb +0 -36
@@ -1,86 +0,0 @@
|
|
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 Table
|
21
|
-
|
22
|
-
# Head is the font header table, which gives global informations about the font.
|
23
|
-
class Head < Font::TTF::FontChunk
|
24
|
-
|
25
|
-
LONG_FORMAT = 1
|
26
|
-
SHORT_FORMAT = 0
|
27
|
-
|
28
|
-
attr_accessor :version, :font_revision, :check_sum_adjustment,
|
29
|
-
:magic_number, :flags, :units_per_em, :created,
|
30
|
-
:modified, :x_min, :y_min, :x_max, :y_max, :mac_style,
|
31
|
-
:lowest_rec_ppem, :font_direction_hint,
|
32
|
-
:index_to_loc_format, :glyph_data_format
|
33
|
-
|
34
|
-
def initialize(*args)
|
35
|
-
super(*args)
|
36
|
-
|
37
|
-
if exists_in_file?
|
38
|
-
@font.at_offset(@offset) do
|
39
|
-
@version = @font.read_fixed
|
40
|
-
@font_revision = @font.read_fixed
|
41
|
-
@check_sum_adjustment = @font.read_ulong
|
42
|
-
@magic_number = @font.read_ulong
|
43
|
-
@flags = @font.read_ushort
|
44
|
-
@units_per_em = @font.read_ushort
|
45
|
-
@created = @font.read_long_date_time
|
46
|
-
@modified = @font.read_long_date_time
|
47
|
-
@x_min = @font.read_fword
|
48
|
-
@y_min = @font.read_fword
|
49
|
-
@x_max = @font.read_fword
|
50
|
-
@y_max = @font.read_fword
|
51
|
-
@mac_style = @font.read_ushort
|
52
|
-
@lowest_rec_ppem = @font.read_ushort
|
53
|
-
@font_direction_hint = @font.read_short
|
54
|
-
@index_to_loc_format = @font.read_short
|
55
|
-
@glyph_data_format = @font.read_short
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Dumps the head table in binary raw format as may be found in a font
|
61
|
-
# file.
|
62
|
-
def dump
|
63
|
-
raw = (@version || 0).to_fixed
|
64
|
-
raw += (@font_revision || 0).to_fixed
|
65
|
-
raw += (@check_sum_adjustment || 0).to_ulong
|
66
|
-
raw += (@magic_number || 0).to_ulong
|
67
|
-
raw += (@flags || 0).to_ushort
|
68
|
-
raw += (@units_per_em || 0).to_ushort
|
69
|
-
raw += (@created || "").to_long_date_time
|
70
|
-
raw += (@modified || "").to_long_date_time
|
71
|
-
raw += (@x_min || 0).to_fword
|
72
|
-
raw += (@y_min || 0).to_fword
|
73
|
-
raw += (@x_max || 0).to_fword
|
74
|
-
raw += (@y_max || 0).to_fword
|
75
|
-
raw += (@mac_style || 0).to_ushort
|
76
|
-
raw += (@lowest_rec_ppem || 0).to_ushort
|
77
|
-
raw += (@font_direction_hint || 0).to_short
|
78
|
-
raw += (@index_to_loc_format || 0).to_short
|
79
|
-
raw += (@glyph_data_format || 0).to_short
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,96 +0,0 @@
|
|
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 Table
|
21
|
-
|
22
|
-
# Hea is a base class for Hhea and Vhea.
|
23
|
-
class Hea < Font::TTF::FontChunk
|
24
|
-
|
25
|
-
attr_accessor :version, :ascender, :descender, :line_gap,
|
26
|
-
:advance_max, :min_side_bearing_1,
|
27
|
-
:min_side_bearing_2, :max_extent,
|
28
|
-
:caret_slope_rise, :caret_slope_run,
|
29
|
-
:metric_data_format, :number_of_metrics
|
30
|
-
|
31
|
-
def initialize(*args)
|
32
|
-
super(*args)
|
33
|
-
|
34
|
-
if exists_in_file?
|
35
|
-
@font.at_offset(@offset) do
|
36
|
-
@version = @font.read_fixed
|
37
|
-
@ascender = @font.read_fword
|
38
|
-
@descender = @font.read_fword
|
39
|
-
@line_gap = @font.read_fword
|
40
|
-
@advance_max = @font.read_ufword
|
41
|
-
@min_side_bearing_1 = @font.read_fword
|
42
|
-
@min_side_bearing_2 = @font.read_fword
|
43
|
-
@max_extent = @font.read_fword
|
44
|
-
@caret_slope_rise = @font.read_short
|
45
|
-
@caret_slope_run = @font.read_short
|
46
|
-
5.times { @font.read_fword } # reserved, unused fields
|
47
|
-
@metric_data_format = @font.read_short
|
48
|
-
@number_of_metrics = @font.read_ushort
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Dumps the hhea table in binary raw format as may be found in a font
|
54
|
-
# file.
|
55
|
-
def dump
|
56
|
-
raw = (@version || 0).to_fixed
|
57
|
-
raw += (@ascender || 0).to_fword
|
58
|
-
raw += (@descender || 0).to_fword
|
59
|
-
raw += (@line_grap || 0).to_fword
|
60
|
-
raw += (@advance_max || 0).to_ufword
|
61
|
-
raw += (@min_side_bearing_1 || 0).to_fword
|
62
|
-
raw += (@min_side_bearing_2 || 0).to_fword
|
63
|
-
raw += (@max_extent || 0).to_fword
|
64
|
-
raw += (@caret_slope_rise || 0).to_short
|
65
|
-
raw += (@caret_slope_run || 0).to_short
|
66
|
-
5.times { raw += 0.to_fword } # reserved, unused fields
|
67
|
-
raw += (@metric_data_format || 0).to_short
|
68
|
-
raw += (@number_of_metrics || 0).to_ushort
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
# Hhea is the Horizontal header table.
|
74
|
-
class Hhea < Hea
|
75
|
-
|
76
|
-
alias :advance_width_max :advance_max
|
77
|
-
alias :min_left_side_bearing :min_side_bearing_1
|
78
|
-
alias :min_right_side_bearing :min_side_bearing_2
|
79
|
-
alias :x_max_extent :max_extent
|
80
|
-
alias :number_of_hmetrics :number_of_metrics
|
81
|
-
|
82
|
-
alias :advance_width_max= :advance_max=
|
83
|
-
alias :min_left_side_bearing= :min_side_bearing_1=
|
84
|
-
alias :min_right_side_bearing= :min_side_bearing_2=
|
85
|
-
alias :x_max_extent= :max_extent=
|
86
|
-
alias :number_of_hmetrics= :number_of_metrics=
|
87
|
-
|
88
|
-
def initialize(*args)
|
89
|
-
super(*args)
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,98 +0,0 @@
|
|
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 Table
|
21
|
-
|
22
|
-
# Mtx is a base class for Hmtx and Vmtx.
|
23
|
-
class Mtx < Font::TTF::FontChunk
|
24
|
-
|
25
|
-
def initialize(*args)
|
26
|
-
super(*args)
|
27
|
-
|
28
|
-
if self.tag == :hmtx
|
29
|
-
@hea = :hhea
|
30
|
-
else
|
31
|
-
@hea = :vhea
|
32
|
-
end
|
33
|
-
|
34
|
-
if exists_in_file?
|
35
|
-
@font.at_offset(@offset) do
|
36
|
-
@metrics = []
|
37
|
-
|
38
|
-
num_metrics = @font.get_table(@hea).number_of_metrics
|
39
|
-
num_metrics.times do
|
40
|
-
@metrics << [@font.read_ufword, @font.read_fword]
|
41
|
-
end
|
42
|
-
|
43
|
-
@side_bearings = []
|
44
|
-
|
45
|
-
(@font.get_table(:maxp).num_glyphs - num_metrics).times do
|
46
|
-
@side_bearings << @font.read_fword
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Returns an Array of [advance_width, left/top_side_bearing] pairs.
|
53
|
-
def metrics
|
54
|
-
last_aw = @metrics.last[0]
|
55
|
-
@metrics + @side_bearings.collect { |sb| [last_aw, sb] }
|
56
|
-
end
|
57
|
-
|
58
|
-
# Sets metrics.
|
59
|
-
def metrics=(mtrx)
|
60
|
-
len = mtrx.length
|
61
|
-
raise "Number of (h/v)metrics must be equal to number of glyphs" \
|
62
|
-
if len != @font.get_table(:maxp).num_glyphs
|
63
|
-
@font.get_table(@hea).number_of_metrics = len
|
64
|
-
@side_bearings = []
|
65
|
-
@metrics = mtrx
|
66
|
-
end
|
67
|
-
|
68
|
-
# Dumps the (h/v)mtx table in binary raw format as may be found in a font
|
69
|
-
# file.
|
70
|
-
def dump
|
71
|
-
raw = ""
|
72
|
-
(@metrics || []).each do |advanced_width, side_bearing|
|
73
|
-
raw += advanced_width.to_ufword
|
74
|
-
raw += side_bearing.to_fword
|
75
|
-
end
|
76
|
-
(@side_bearings || []).each do |side_bearing|
|
77
|
-
raw += side_bearing.to_fword
|
78
|
-
end
|
79
|
-
raw
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
# Hmtx is the horizontal metrics table.
|
85
|
-
class Hmtx < Mtx
|
86
|
-
|
87
|
-
alias :hmetrics :metrics
|
88
|
-
alias :hmetrics= :metrics=
|
89
|
-
|
90
|
-
def initialize(*args)
|
91
|
-
super(*args)
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,186 +0,0 @@
|
|
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 Table
|
21
|
-
|
22
|
-
# Kern is the Kerning table, which contains values for intercharacter spacing.
|
23
|
-
class Kern < Font::TTF::FontChunk
|
24
|
-
|
25
|
-
# KerningSubtable is a base class for KerningSubtable0 and KerningSubtable2.
|
26
|
-
class KerningSubtable < Font::TTF::FontChunk
|
27
|
-
|
28
|
-
HORIZONTAL = 0b1
|
29
|
-
MINIMUM = 0b10
|
30
|
-
CROSS_STREAM = 0b100
|
31
|
-
OVERRIDE = 0b1000
|
32
|
-
|
33
|
-
attr_accessor :version, :coverage
|
34
|
-
|
35
|
-
def initialize(table, offs_from_table=nil, length=nil)
|
36
|
-
|
37
|
-
if not offs_from_table.nil? and not length.nil?
|
38
|
-
super(table.font, table.offset + offs_from_table, length)
|
39
|
-
@font.at_offset(@offset) do
|
40
|
-
@version = @font.read_ushort
|
41
|
-
@length = @font.read_ushort
|
42
|
-
@coverage = @font.read_ushort
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Returns the format (Fixnum) of the KerningSubtable.
|
48
|
-
def format
|
49
|
-
@coverage >> 8
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# KerningTable in format 0.
|
54
|
-
class KerningSubtable0 < KerningSubtable
|
55
|
-
|
56
|
-
KerningPair = Struct.new(:left, :right, :value)
|
57
|
-
KERNING_PAIR_SIZE = 2 * IO::SIZEOF_USHORT + IO::SIZEOF_FWORD
|
58
|
-
|
59
|
-
# An Array of KerningPair structures.
|
60
|
-
attr_accessor :kerning_pairs
|
61
|
-
|
62
|
-
def initialize(*args)
|
63
|
-
super(*args)
|
64
|
-
|
65
|
-
@kerning_pairs = []
|
66
|
-
|
67
|
-
if exists_in_file?
|
68
|
-
@font.at_offset(@offset + 3 * IO::SIZEOF_USHORT) do
|
69
|
-
@num_pairs = @font.read_ushort
|
70
|
-
@search_range = @font.read_ushort
|
71
|
-
@entry_selector = @font.read_ushort
|
72
|
-
@range_shift = @font.read_ushort
|
73
|
-
|
74
|
-
@num_pairs.times do
|
75
|
-
kp = KerningPair.new
|
76
|
-
kp.left = @font.read_ushort
|
77
|
-
kp.right = @font.read_ushort
|
78
|
-
kp.value = @font.read_fword
|
79
|
-
@kerning_pairs << kp
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def update_for_search!
|
87
|
-
res = 1
|
88
|
-
power = 0
|
89
|
-
while res <= @kerning_pairs.length
|
90
|
-
res *= 2
|
91
|
-
power += 1
|
92
|
-
end
|
93
|
-
@search_range = res * KERNING_PAIR_SIZE
|
94
|
-
@entry_selector = power - 1
|
95
|
-
@range_shift = (@kerning_pairs.length - res) * KERNING_PAIR_SIZE
|
96
|
-
end
|
97
|
-
private :update_for_search!
|
98
|
-
|
99
|
-
def dump
|
100
|
-
update_for_search!
|
101
|
-
raw = (@version || 0).to_ushort
|
102
|
-
len = 7 * IO::SIZEOF_USHORT + \
|
103
|
-
@kerning_pairs.length * KERNING_PAIR_SIZE
|
104
|
-
raw += len.to_ushort
|
105
|
-
raw += (@coverage || 1).to_ushort
|
106
|
-
raw += @kerning_pairs.length.to_ushort
|
107
|
-
raw += @search_range.to_ushort
|
108
|
-
raw += @entry_selector.to_ushort
|
109
|
-
raw += @range_shift.to_ushort
|
110
|
-
@kerning_pairs.each do |kp|
|
111
|
-
raw += kp.left.to_ushort
|
112
|
-
raw += kp.right.to_ushort
|
113
|
-
raw += kp.value.to_fword
|
114
|
-
end
|
115
|
-
raw
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
# KerningTable in format 2. Not implemented.
|
121
|
-
class KerningSubtable2 < KerningSubtable
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
# An Array of KerningSubtable (KerningSubtable0 or KerningSubtable2)
|
126
|
-
# objects.
|
127
|
-
attr_accessor :subtables
|
128
|
-
|
129
|
-
def initialize(*args)
|
130
|
-
super(*args)
|
131
|
-
|
132
|
-
@subtables = []
|
133
|
-
|
134
|
-
if exists_in_file?
|
135
|
-
@font.at_offset(@offset) do
|
136
|
-
@version = @font.read_ushort
|
137
|
-
@num_tables = @font.read_ushort
|
138
|
-
end
|
139
|
-
|
140
|
-
offs = 2 * IO::SIZEOF_USHORT
|
141
|
-
@num_tables.times do
|
142
|
-
@font.at_offset(@offset + offs) do
|
143
|
-
version = @font.read_ushort
|
144
|
-
length = @font.read_ushort
|
145
|
-
coverage = @font.read_ushort
|
146
|
-
|
147
|
-
@subtables << case coverage >> 8
|
148
|
-
when 0
|
149
|
-
KerningSubtable0.new(self, offs, length)
|
150
|
-
when 2
|
151
|
-
KerningSubtable2.new(self, offs, length)
|
152
|
-
end
|
153
|
-
offs += length
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
# Returns an empty kerning subtable in format 0 that then may be added to
|
160
|
-
# the subtables array.
|
161
|
-
def get_new_kerning_subtable0
|
162
|
-
KerningSubtable0.new(self)
|
163
|
-
end
|
164
|
-
|
165
|
-
# Returns an empty kerning subtable in format 2 that then may be added to
|
166
|
-
# the subtables array.
|
167
|
-
def get_new_kerning_subtable2
|
168
|
-
KerningSubtable2.new(self)
|
169
|
-
end
|
170
|
-
|
171
|
-
# Dumps the kern table in binary raw format as may be found in a font
|
172
|
-
# file.
|
173
|
-
def dump
|
174
|
-
raw = (@version || 0).to_ushort
|
175
|
-
raw += @subtables.length.to_ushort
|
176
|
-
@subtables.each do |subtbl|
|
177
|
-
raw += subtbl.dump
|
178
|
-
end
|
179
|
-
raw
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|