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,75 +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
|
-
# Loca is the Location table class. It provides the offsets of glyphs in
|
23
|
-
# the glyf table.
|
24
|
-
class Loca < Font::TTF::FontChunk
|
25
|
-
|
26
|
-
# An array of glyphs offsets with number of glyphs + 1 elements.
|
27
|
-
# The value associated with a given index of that array
|
28
|
-
# is the offset associated with glyph with index index.
|
29
|
-
# This offset may be used with Font::TTF::Table::Glyf#get_glyph_at_offset
|
30
|
-
# to get the glyph object associated with offset.
|
31
|
-
#
|
32
|
-
# The additional offset is added so that the length of the
|
33
|
-
# last glyph can be calculated:
|
34
|
-
# len of last glyph = additional offs - last glyph offs
|
35
|
-
attr_accessor :glyph_offsets
|
36
|
-
|
37
|
-
# It is not recommended to create Loca objects by hand.
|
38
|
-
# Use Font::TTF::File#get_table or Font::TTF::File#get_new_table
|
39
|
-
# with :loca as parameter instead.
|
40
|
-
def initialize(*args)
|
41
|
-
super(*args)
|
42
|
-
|
43
|
-
if exists_in_file?
|
44
|
-
@font.at_offset(@offset) do
|
45
|
-
n = @font.get_table(:maxp).num_glyphs + 1
|
46
|
-
|
47
|
-
case @font.get_table(:head).index_to_loc_format
|
48
|
-
when Font::TTF::Table::Head::SHORT_FORMAT
|
49
|
-
@glyph_offsets = @font.read_ushorts(n)
|
50
|
-
@glyph_offsets.collect! { |o| o * 2 }
|
51
|
-
when Font::TTF::Table::Head::LONG_FORMAT
|
52
|
-
@glyph_offsets = @font.read_ulongs(n)
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Dumps the loca table in binary raw format as may be found in a font
|
60
|
-
# file.
|
61
|
-
def dump
|
62
|
-
case @font.get_table(:head).index_to_loc_format
|
63
|
-
when Font::TTF::Table::Head::SHORT_FORMAT
|
64
|
-
@glyph_offsets.collect { |o| o / 2 }.to_ushorts
|
65
|
-
when Font::TTF::Table::Head::LONG_FORMAT
|
66
|
-
@glyph_offsets.to_ulongs
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,81 +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
|
-
# Maxp is the Maximum profile tables, which establishes memory requirements
|
23
|
-
# for the associated font.
|
24
|
-
class Maxp < Font::TTF::FontChunk
|
25
|
-
|
26
|
-
attr_accessor :version, :num_glyphs, :max_points, :max_contours,
|
27
|
-
:max_composite_points, :max_composite_contours,
|
28
|
-
:max_zones, :max_twilight_points, :max_storage,
|
29
|
-
:max_function_defs, :max_instruction_defs,
|
30
|
-
:max_stack_elements, :max_sizeof_instructions,
|
31
|
-
:max_component_elements, :max_component_depth
|
32
|
-
|
33
|
-
def initialize(*args)
|
34
|
-
super(*args)
|
35
|
-
|
36
|
-
if exists_in_file?
|
37
|
-
@font.at_offset(@offset) do
|
38
|
-
@version = @font.read_fixed
|
39
|
-
@num_glyphs = @font.read_ushort
|
40
|
-
@max_points = @font.read_ushort
|
41
|
-
@max_contours = @font.read_ushort
|
42
|
-
@max_composite_points = @font.read_ushort
|
43
|
-
@max_composite_contours = @font.read_ushort
|
44
|
-
@max_zones = @font.read_ushort
|
45
|
-
@max_twilight_points = @font.read_ushort
|
46
|
-
@max_storage = @font.read_ushort
|
47
|
-
@max_function_defs = @font.read_ushort
|
48
|
-
@max_instruction_defs = @font.read_ushort
|
49
|
-
@max_stack_elements = @font.read_ushort
|
50
|
-
@max_sizeof_instructions = @font.read_ushort
|
51
|
-
@max_component_elements = @font.read_ushort
|
52
|
-
@max_component_depth = @font.read_ushort
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Dumps the maxp table in binary raw format as may be found in a font
|
58
|
-
# file.
|
59
|
-
def dump
|
60
|
-
raw = (@version || 0).to_fixed
|
61
|
-
raw += (@num_glyphs || 0).to_ushort
|
62
|
-
raw += (@max_points || 0).to_ushort
|
63
|
-
raw += (@max_contours || 0).to_ushort
|
64
|
-
raw += (@max_composite_points || 0).to_ushort
|
65
|
-
raw += (@max_composite_contours || 0).to_ushort
|
66
|
-
raw += (@max_zones || 0).to_ushort
|
67
|
-
raw += (@max_twilight_points || 0).to_ushort
|
68
|
-
raw += (@max_storage || 0).to_ushort
|
69
|
-
raw += (@max_function_defs || 0).to_ushort
|
70
|
-
raw += (@max_instruction_defs || 0).to_ushort
|
71
|
-
raw += (@max_stack_elements || 0).to_ushort
|
72
|
-
raw += (@max_sizeof_instructions || 0).to_ushort
|
73
|
-
raw += (@max_component_elements || 0).to_ushort
|
74
|
-
raw += (@max_component_depth || 0).to_ushort
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,222 +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
|
-
require 'iconv'
|
19
|
-
|
20
|
-
module Font
|
21
|
-
module TTF
|
22
|
-
module Table
|
23
|
-
|
24
|
-
# Name is the the Naming table which allows multilingual strings to be
|
25
|
-
# associated with the TrueType font file.
|
26
|
-
class Name < Font::TTF::FontChunk
|
27
|
-
|
28
|
-
# A NameRecord holds a string for a given Platform and Encoding.
|
29
|
-
class NameRecord < Font::TTF::FontChunk
|
30
|
-
include Font::TTF::Encodings
|
31
|
-
|
32
|
-
COPYRIGHT_NOTICE = 0
|
33
|
-
FONT_FAMILY_NAME = 1
|
34
|
-
FONT_SUBFAMILY_NAME = 2
|
35
|
-
UNIQUE_FONT_IDENTIFIER = 3
|
36
|
-
FULL_FONT_NAME = 4
|
37
|
-
VERSION_STRING = 5
|
38
|
-
POSTSCRIPT_NAME = 6
|
39
|
-
TRADEMARK = 7
|
40
|
-
MANUFACTURER_NAME = 8
|
41
|
-
DESIGNER_NAME = 9
|
42
|
-
DESCRIPTION = 10
|
43
|
-
VENDOR_URL = 11
|
44
|
-
DESIGNER_URL = 12
|
45
|
-
LICENSE_DESCRIPTION = 13
|
46
|
-
LICENSE_URL = 14
|
47
|
-
RESERVED = 15
|
48
|
-
PREFERRED_FAMILY = 16
|
49
|
-
PREFERRED_SUBFAMILY = 17
|
50
|
-
COMPATIBLE_FULL = 18
|
51
|
-
|
52
|
-
ID2NAME = {
|
53
|
-
COPYRIGHT_NOTICE => "Copyright Notice",
|
54
|
-
FONT_FAMILY_NAME => "Font Family Name",
|
55
|
-
FONT_SUBFAMILY_NAME => "Font Subfamily Name",
|
56
|
-
UNIQUE_FONT_IDENTIFIER => "Unique Font Identifier",
|
57
|
-
FULL_FONT_NAME => "Full Font Name",
|
58
|
-
VERSION_STRING => "Version String",
|
59
|
-
POSTSCRIPT_NAME => "Postscript Name",
|
60
|
-
TRADEMARK => "Trademark",
|
61
|
-
MANUFACTURER_NAME => "Manufacturer Name",
|
62
|
-
DESIGNER_NAME => "Designer Name",
|
63
|
-
DESCRIPTION => "Description",
|
64
|
-
VENDOR_URL => "Vendor URL",
|
65
|
-
DESIGNER_URL => "Designer URL",
|
66
|
-
LICENSE_DESCRIPTION => "License Description",
|
67
|
-
LICENSE_URL => "License URL",
|
68
|
-
RESERVED => "Reserved",
|
69
|
-
PREFERRED_FAMILY => "Preferred Family",
|
70
|
-
PREFERRED_SUBFAMILY => "Preferred Subfamily",
|
71
|
-
COMPATIBLE_FULL => "Compatible full"
|
72
|
-
}
|
73
|
-
|
74
|
-
|
75
|
-
SIZEOF_NAME_RECORD = 6 * IO::SIZEOF_USHORT
|
76
|
-
|
77
|
-
attr_accessor :platform_id, :encoding_id, :language_id, :name_id,
|
78
|
-
:str_offset, :str
|
79
|
-
|
80
|
-
def initialize(table, n=nil)
|
81
|
-
@table = table
|
82
|
-
|
83
|
-
if n.nil?
|
84
|
-
# New name record created by hand
|
85
|
-
super(@table.font)
|
86
|
-
@platform_id = @table.font.read_ushort
|
87
|
-
@encoding_id = @table.font.read_ushort
|
88
|
-
@language_id = 0
|
89
|
-
else
|
90
|
-
offset = @table.offset + 3 * IO::SIZEOF_USHORT + \
|
91
|
-
n * SIZEOF_NAME_RECORD
|
92
|
-
|
93
|
-
super(@table.font, offset, SIZEOF_NAME_RECORD)
|
94
|
-
|
95
|
-
@table.font.at_offset(@offset) do
|
96
|
-
@platform_id = @table.font.read_ushort
|
97
|
-
@encoding_id = @table.font.read_ushort
|
98
|
-
@language_id = @table.font.read_ushort
|
99
|
-
@name_id = @table.font.read_ushort
|
100
|
-
@str_len = @table.font.read_ushort
|
101
|
-
@str_offset = @table.font.read_ushort
|
102
|
-
end
|
103
|
-
|
104
|
-
offs = @table.offset + @table.string_storage_offset + \
|
105
|
-
@str_offset
|
106
|
-
@table.font.at_offset(offs) do
|
107
|
-
@str = @table.font.read(@str_len)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
# Returns string "as is".
|
113
|
-
def to_s
|
114
|
-
@str
|
115
|
-
end
|
116
|
-
|
117
|
-
# Returns whether the string is Macintosh Roman or not.
|
118
|
-
def roman?
|
119
|
-
@platform_id == Platform::MACINTOSH and \
|
120
|
-
@encoding_id == MacintoshEncoding::ROMAN
|
121
|
-
end
|
122
|
-
|
123
|
-
# Returns whether the string is unicode or not.
|
124
|
-
def unicode?
|
125
|
-
@platform_id == Platform::UNICODE or \
|
126
|
-
(@platform_id == Platform::MICROSOFT and \
|
127
|
-
@encoding_id == MicrosoftEncoding::UNICODE)
|
128
|
-
end
|
129
|
-
|
130
|
-
# Returns the string in UTF-8 if possible.
|
131
|
-
def utf8_str
|
132
|
-
if unicode?
|
133
|
-
# from utf-16 big endian to utf-8
|
134
|
-
Iconv.new("utf-8", "utf-16be").iconv(@str)
|
135
|
-
else
|
136
|
-
@str
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Sets the NameRecord string with new_string being UTF-8.
|
141
|
-
def utf8_str=(new_string)
|
142
|
-
if unicode?
|
143
|
-
# from utf-8 to utf-16 big endian
|
144
|
-
@str = Iconv.new("utf-16be", "utf-8").iconv(new_string)
|
145
|
-
else
|
146
|
-
@str = new_string
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def dump
|
151
|
-
# Dump everything except str_offset, which can't be calculated
|
152
|
-
# here and the string itself which must be put in the storage
|
153
|
-
# area
|
154
|
-
raw = (@platform_id || Platform::MACINTOSH).to_ushort
|
155
|
-
raw += (@encoding_id || MacintoshEncoding::ROMAN).to_ushort
|
156
|
-
raw += (@language_id || 0).to_ushort
|
157
|
-
raw += (@name_id || 0).to_ushort
|
158
|
-
raw += (@str.length || 0).to_ushort
|
159
|
-
end
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
attr_accessor :format_selector
|
164
|
-
# An Array of NameRecord objects.
|
165
|
-
attr_accessor :name_records
|
166
|
-
attr_reader :string_storage_offset
|
167
|
-
|
168
|
-
def initialize(*args)
|
169
|
-
super(*args)
|
170
|
-
|
171
|
-
if exists_in_file?
|
172
|
-
@font.at_offset(@offset) do
|
173
|
-
@format_selector = @font.read_ushort
|
174
|
-
@name_record_num = @font.read_ushort
|
175
|
-
@string_storage_offset = @font.read_ushort
|
176
|
-
end
|
177
|
-
|
178
|
-
@name_records = []
|
179
|
-
@name_record_num.times do |i|
|
180
|
-
@name_records << NameRecord.new(self, i)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
# Gets a new empty NameRecord which may then be added to the
|
186
|
-
# name_records array.
|
187
|
-
def get_new_name_record
|
188
|
-
NameRecord.new(self)
|
189
|
-
end
|
190
|
-
|
191
|
-
# Dumps the name table in binary raw format as may be found in a font
|
192
|
-
# file.
|
193
|
-
def dump
|
194
|
-
raw = (@format_selector || 0).to_ushort
|
195
|
-
|
196
|
-
nr_num = @name_records.length || 0
|
197
|
-
raw += nr_num.to_ushort
|
198
|
-
|
199
|
-
string_storage_offset = 3 * IO::SIZEOF_USHORT + \
|
200
|
-
nr_num * NameRecord::SIZEOF_NAME_RECORD
|
201
|
-
raw += string_storage_offset.to_ushort
|
202
|
-
|
203
|
-
str_offset = 0 # starting from string_storage_offset
|
204
|
-
strs = []
|
205
|
-
@name_records.each do |nr|
|
206
|
-
raw += nr.dump
|
207
|
-
raw += str_offset.to_ushort
|
208
|
-
str_offset += nr.str.length
|
209
|
-
strs << nr.str
|
210
|
-
end
|
211
|
-
|
212
|
-
strs.each do |str|
|
213
|
-
raw += str
|
214
|
-
end
|
215
|
-
raw
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
@@ -1,172 +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
|
-
# OS2 is the OS/2 and Windows font metrics table.
|
23
|
-
class OS2 < Font::TTF::FontChunk
|
24
|
-
|
25
|
-
INSTALLABLE_EMBEDDING = 0x0000
|
26
|
-
RESTRICTED_LICENCE_EMBEDDING = 0x0002
|
27
|
-
PREVIEW_AND_PRINT_EMBEDDING = 0x0004
|
28
|
-
EDITABLE_EMBEDDING = 0x0008
|
29
|
-
NO_SUBSET_EMBEDDING = 0x0100
|
30
|
-
BITMAP_ONLY_EMBEDDING = 0x0200
|
31
|
-
|
32
|
-
|
33
|
-
attr_accessor :version, :x_avg_char_width, :us_weight_class,
|
34
|
-
:us_width_class, :fs_type, :y_subscriptXSize,
|
35
|
-
:y_subscript_y_size, :y_subscript_x_offset,
|
36
|
-
:y_subscript_y_offset, :y_superscript_x_size,
|
37
|
-
:y_superscript_y_size, :y_superscript_x_offset,
|
38
|
-
:y_superscript_y_offset, :y_strikeout_size,
|
39
|
-
:y_strikeout_position, :s_family_class,
|
40
|
-
:panose, :ul_unicode_range1, :ul_unicode_range2,
|
41
|
-
:ul_unicode_range3, :ul_unicode_range4,
|
42
|
-
:ach_vend_id, :fs_selection, :us_first_char_index,
|
43
|
-
:us_last_char_index, :s_typo_ascender, :s_typo_descender,
|
44
|
-
:s_typo_line_gap, :us_win_ascent, :us_win_descent,
|
45
|
-
:ul_code_page_range1, :ul_code_page_range2,
|
46
|
-
:sx_height, :s_cap_height, :us_default_char,
|
47
|
-
:us_break_char, :us_max_context
|
48
|
-
|
49
|
-
def initialize(*args)
|
50
|
-
super(*args)
|
51
|
-
|
52
|
-
if exists_in_file?
|
53
|
-
@font.at_offset(@offset) do
|
54
|
-
@version = @font.read_ushort
|
55
|
-
@x_avg_char_width = @font.read_short
|
56
|
-
@us_weight_class = @font.read_ushort
|
57
|
-
@us_width_class = @font.read_ushort
|
58
|
-
@fs_type = @font.read_short
|
59
|
-
@y_subscriptXSize = @font.read_short
|
60
|
-
@y_subscript_y_size = @font.read_short
|
61
|
-
@y_subscript_x_offset = @font.read_short
|
62
|
-
@y_subscript_y_offset = @font.read_short
|
63
|
-
@y_superscript_x_size = @font.read_short
|
64
|
-
@y_superscript_y_size = @font.read_short
|
65
|
-
@y_superscript_x_offset = @font.read_short
|
66
|
-
@y_superscript_y_offset = @font.read_short
|
67
|
-
@y_strikeout_size = @font.read_short
|
68
|
-
@y_strikeout_position = @font.read_short
|
69
|
-
@s_family_class = @font.read_short
|
70
|
-
@panose = @font.read_bytes(10)
|
71
|
-
@ul_unicode_range1 = @font.read_ulong
|
72
|
-
@ul_unicode_range2 = @font.read_ulong
|
73
|
-
@ul_unicode_range3 = @font.read_ulong
|
74
|
-
@ul_unicode_range4 = @font.read_ulong
|
75
|
-
@ach_vend_id = @font.read_chars(4)
|
76
|
-
@fs_selection = @font.read_ushort
|
77
|
-
@us_first_char_index = @font.read_ushort
|
78
|
-
@us_last_char_index = @font.read_ushort
|
79
|
-
@s_typo_ascender = @font.read_short
|
80
|
-
@s_typo_descender = @font.read_short
|
81
|
-
@s_typo_line_gap = @font.read_short
|
82
|
-
@us_win_ascent = @font.read_ushort
|
83
|
-
@us_win_descent = @font.read_ushort
|
84
|
-
@ul_code_page_range1 = @font.read_ulong
|
85
|
-
@ul_code_page_range2 = @font.read_ulong
|
86
|
-
# From opentype spec
|
87
|
-
@sx_height = @font.read_short
|
88
|
-
@s_cap_height = @font.read_short
|
89
|
-
@us_default_char = @font.read_ushort
|
90
|
-
@us_break_char = @font.read_ushort
|
91
|
-
@us_max_context = @font.read_ushort
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def installable_embedding?
|
97
|
-
@fs_type == INSTALLABLE_EMBEDDING
|
98
|
-
end
|
99
|
-
|
100
|
-
def editable_embedding?
|
101
|
-
installable_embedding? or @fs_type & EDITABLE_EMBEDDING != 0
|
102
|
-
end
|
103
|
-
|
104
|
-
def preview_and_print_embedding?
|
105
|
-
editable_embedding? or @fs_type & PREVIEW_AND_PRINT_EMBEDDING != 0
|
106
|
-
end
|
107
|
-
|
108
|
-
def restricted_licence_embedding?
|
109
|
-
(not preview_and_print_embedding? and
|
110
|
-
@fs_type & RESTRICTED_LICENCE_EMBEDDING != 0)
|
111
|
-
end
|
112
|
-
|
113
|
-
def no_subset_embedding?
|
114
|
-
@fs_type & NO_SUBSET_EMBEDDING != 0
|
115
|
-
end
|
116
|
-
|
117
|
-
def subset_embedding?
|
118
|
-
not no_subset_embedding?
|
119
|
-
end
|
120
|
-
|
121
|
-
def bitmap_only_embedding?
|
122
|
-
@fs_type & BITMAP_ONLY_EMBEDDING != 0
|
123
|
-
end
|
124
|
-
|
125
|
-
# Dumps the os2 table in binary raw format as may be found in a font
|
126
|
-
# file.
|
127
|
-
def dump
|
128
|
-
raw = (@version || 0).to_ushort
|
129
|
-
raw += (@x_avg_char_width || 0).to_short
|
130
|
-
raw += (@us_weight_class || 0).to_ushort
|
131
|
-
raw += (@us_width_class || 0).to_ushort
|
132
|
-
raw += (@fs_type || 0).to_ushort
|
133
|
-
raw += (@y_subscriptXSize || 0).to_short
|
134
|
-
raw += (@y_subscript_y_size || 0).to_short
|
135
|
-
raw += (@y_subscript_x_offset || 0).to_short
|
136
|
-
raw += (@y_subscript_y_offset || 0).to_short
|
137
|
-
raw += (@y_superscript_x_size || 0).to_short
|
138
|
-
raw += (@y_superscript_y_size || 0).to_short
|
139
|
-
raw += (@y_superscript_x_offset || 0).to_short
|
140
|
-
raw += (@y_superscript_y_offset || 0).to_short
|
141
|
-
raw += (@y_strikeout_size || 0).to_short
|
142
|
-
raw += (@y_strikeout_position || 0).to_short
|
143
|
-
raw += (@s_family_class || 0).to_short
|
144
|
-
raw += (@panose || [0] * 10).to_bytes
|
145
|
-
raw += (@ul_unicode_range1 || 0).to_ulong
|
146
|
-
raw += (@ul_unicode_range2 || 0).to_ulong
|
147
|
-
raw += (@ul_unicode_range3 || 0).to_ulong
|
148
|
-
raw += (@ul_unicode_range4 || 0).to_ulong
|
149
|
-
raw += (@ach_vend_id || " " * 4)
|
150
|
-
raw += (@fs_selection || 0).to_ushort
|
151
|
-
raw += (@us_first_char_index || 0).to_ushort
|
152
|
-
raw += (@us_last_char_index || 0).to_ushort
|
153
|
-
raw += (@s_typo_ascender || 0).to_short
|
154
|
-
raw += (@s_typo_descender || 0).to_short
|
155
|
-
raw += (@s_typo_line_gap || 0).to_short
|
156
|
-
raw += (@us_win_ascent || 0).to_ushort
|
157
|
-
raw += (@us_win_descent || 0).to_ushort
|
158
|
-
raw += (@ul_code_page_range1 || 0).to_ulong
|
159
|
-
raw += (@ul_code_page_range2 || 0).to_ulong
|
160
|
-
# From opentype spec
|
161
|
-
raw += (@sx_height || 0).to_short
|
162
|
-
raw += (@s_cap_height || 0).to_short
|
163
|
-
raw += (@us_default_char || 0).to_ushort
|
164
|
-
raw += (@us_break_char || 0).to_ushort
|
165
|
-
raw += (@us_max_context || 0).to_ushort
|
166
|
-
end
|
167
|
-
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|