Class: EideticPDF::AFM::AdobeFontMetrics
- Inherits:
-
Object
- Object
- EideticPDF::AFM::AdobeFontMetrics
- Defined in:
- lib/epdfafm.rb
Constant Summary collapse
- FixedPitch =
0x01
- Serif =
0x02
- Symbolic =
0x04
- Script =
0x08
- NonSymbolic =
0x20
- Italic =
0x40
- AllCap =
0x10000
- SmallCap =
0x20000
- ForceBold =
0x40000
Instance Attribute Summary collapse
-
#ascender ⇒ Object
readonly
Returns the value of attribute ascender.
-
#cap_height ⇒ Object
readonly
Returns the value of attribute cap_height.
-
#character_set ⇒ Object
readonly
Returns the value of attribute character_set.
-
#chars_by_code ⇒ Object
readonly
Returns the value of attribute chars_by_code.
-
#chars_by_name ⇒ Object
readonly
Returns the value of attribute chars_by_name.
-
#descender ⇒ Object
readonly
Returns the value of attribute descender.
-
#encoding_scheme ⇒ Object
readonly
Returns the value of attribute encoding_scheme.
-
#family_name ⇒ Object
readonly
Returns the value of attribute family_name.
-
#font_b_box ⇒ Object
readonly
Returns the value of attribute font_b_box.
-
#font_name ⇒ Object
readonly
Returns the value of attribute font_name.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#is_fixed_pitch ⇒ Object
readonly
Returns the value of attribute is_fixed_pitch.
-
#italic_angle ⇒ Object
readonly
Returns the value of attribute italic_angle.
-
#leading ⇒ Object
readonly
Returns the value of attribute leading.
-
#missing_width ⇒ Object
readonly
Returns the value of attribute missing_width.
-
#notice ⇒ Object
readonly
Returns the value of attribute notice.
-
#serif ⇒ Object
readonly
Returns the value of attribute serif.
-
#std_h_w ⇒ Object
readonly
Returns the value of attribute std_h_w.
-
#std_v_w ⇒ Object
readonly
Returns the value of attribute std_v_w.
-
#underline_position ⇒ Object
readonly
Returns the value of attribute underline_position.
-
#underline_thickness ⇒ Object
readonly
Returns the value of attribute underline_thickness.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
-
#x_height ⇒ Object
readonly
Returns the value of attribute x_height.
Class Method Summary collapse
- .afm_cache(reload = false) ⇒ Object
- .find_font(full_name) ⇒ Object
- .find_fonts(options) ⇒ Object
- .load(afm_file) ⇒ Object
Instance Method Summary collapse
- #differences(encoding) ⇒ Object
- #flags ⇒ Object
- #italic ⇒ Object
- #load_afm(lines) ⇒ Object
- #load_inf(lines) ⇒ Object
- #needs_descriptor(encoding) ⇒ Object
- #widths(encoding) ⇒ Object
Instance Attribute Details
#ascender ⇒ Object (readonly)
Returns the value of attribute ascender.
98 99 100 |
# File 'lib/epdfafm.rb', line 98 def ascender @ascender end |
#cap_height ⇒ Object (readonly)
Returns the value of attribute cap_height.
98 99 100 |
# File 'lib/epdfafm.rb', line 98 def cap_height @cap_height end |
#character_set ⇒ Object (readonly)
Returns the value of attribute character_set.
97 98 99 |
# File 'lib/epdfafm.rb', line 97 def character_set @character_set end |
#chars_by_code ⇒ Object (readonly)
Returns the value of attribute chars_by_code.
99 100 101 |
# File 'lib/epdfafm.rb', line 99 def chars_by_code @chars_by_code end |
#chars_by_name ⇒ Object (readonly)
Returns the value of attribute chars_by_name.
99 100 101 |
# File 'lib/epdfafm.rb', line 99 def chars_by_name @chars_by_name end |
#descender ⇒ Object (readonly)
Returns the value of attribute descender.
98 99 100 |
# File 'lib/epdfafm.rb', line 98 def descender @descender end |
#encoding_scheme ⇒ Object (readonly)
Returns the value of attribute encoding_scheme.
97 98 99 |
# File 'lib/epdfafm.rb', line 97 def encoding_scheme @encoding_scheme end |
#family_name ⇒ Object (readonly)
Returns the value of attribute family_name.
94 95 96 |
# File 'lib/epdfafm.rb', line 94 def family_name @family_name end |
#font_b_box ⇒ Object (readonly)
Returns the value of attribute font_b_box.
95 96 97 |
# File 'lib/epdfafm.rb', line 95 def font_b_box @font_b_box end |
#font_name ⇒ Object (readonly)
Returns the value of attribute font_name.
94 95 96 |
# File 'lib/epdfafm.rb', line 94 def font_name @font_name end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
94 95 96 |
# File 'lib/epdfafm.rb', line 94 def full_name @full_name end |
#is_fixed_pitch ⇒ Object (readonly)
Returns the value of attribute is_fixed_pitch.
94 95 96 |
# File 'lib/epdfafm.rb', line 94 def is_fixed_pitch @is_fixed_pitch end |
#italic_angle ⇒ Object (readonly)
Returns the value of attribute italic_angle.
94 95 96 |
# File 'lib/epdfafm.rb', line 94 def italic_angle @italic_angle end |
#leading ⇒ Object (readonly)
Returns the value of attribute leading.
95 96 97 |
# File 'lib/epdfafm.rb', line 95 def leading @leading end |
#missing_width ⇒ Object (readonly)
Returns the value of attribute missing_width.
95 96 97 |
# File 'lib/epdfafm.rb', line 95 def missing_width @missing_width end |
#notice ⇒ Object (readonly)
Returns the value of attribute notice.
96 97 98 |
# File 'lib/epdfafm.rb', line 96 def notice @notice end |
#serif ⇒ Object (readonly)
Returns the value of attribute serif.
98 99 100 |
# File 'lib/epdfafm.rb', line 98 def serif @serif end |
#std_h_w ⇒ Object (readonly)
Returns the value of attribute std_h_w.
98 99 100 |
# File 'lib/epdfafm.rb', line 98 def std_h_w @std_h_w end |
#std_v_w ⇒ Object (readonly)
Returns the value of attribute std_v_w.
98 99 100 |
# File 'lib/epdfafm.rb', line 98 def std_v_w @std_v_w end |
#underline_position ⇒ Object (readonly)
Returns the value of attribute underline_position.
95 96 97 |
# File 'lib/epdfafm.rb', line 95 def underline_position @underline_position end |
#underline_thickness ⇒ Object (readonly)
Returns the value of attribute underline_thickness.
95 96 97 |
# File 'lib/epdfafm.rb', line 95 def underline_thickness @underline_thickness end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
96 97 98 |
# File 'lib/epdfafm.rb', line 96 def version @version end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
94 95 96 |
# File 'lib/epdfafm.rb', line 94 def weight @weight end |
#x_height ⇒ Object (readonly)
Returns the value of attribute x_height.
98 99 100 |
# File 'lib/epdfafm.rb', line 98 def x_height @x_height end |
Class Method Details
.afm_cache(reload = false) ⇒ Object
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/epdfafm.rb', line 211 def self.afm_cache(reload=false) return $afm_cache unless $afm_cache.nil? or reload $afm_cache = [] FontPath.each do |path| Dir[File.join(path, '*.afm')].each do |file| $afm_cache << AdobeFontMetrics.load(file) end end $afm_cache end |
.find_font(full_name) ⇒ Object
189 190 191 192 193 194 195 |
# File 'lib/epdfafm.rb', line 189 def self.find_font(full_name) if full_name.is_a?(Regexp) afm_cache.find { |afm| full_name =~ afm.font_name } else afm_cache.find { |afm| full_name.casecmp(afm.font_name) == 0 } end end |
.find_fonts(options) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/epdfafm.rb', line 197 def self.find_fonts() afm_cache.select do |afm| .all? do |key, value| if value.respond_to?(:to_str) value.casecmp(afm.send(key)) == 0 elsif value.is_a?(Regexp) value =~ afm.send(key) else value == afm.send(key) end end end end |
.load(afm_file) ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/epdfafm.rb', line 181 def self.load(afm_file) result = self.new result.load_afm(IO.readlines(afm_file)) inf_file = afm_file.sub(/\.afm$/, '.inf') result.load_inf(IO.readlines(inf_file)) if File.exist?(inf_file) result end |
Instance Method Details
#differences(encoding) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/epdfafm.rb', line 152 def differences(encoding) if (encoding != :unicode) and needs_descriptor(encoding) Glyphs.differences_for_encodings('WinAnsiEncoding', encoding) else false end end |
#flags ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/epdfafm.rb', line 125 def flags @flags = 0 @flags |= FixedPitch if @is_fixed_pitch @flags |= Serif if @serif if ['Symbol','ZapfDingbats'].include?(@family_name) @flags |= Symbolic else @flags |= NonSymbolic end # TODO: detect Script @flags |= Italic if @italic_angle != 0 @flags |= ForceBold if @weight =~ /Bold|Demi/i @flags end |
#italic ⇒ Object
140 141 142 |
# File 'lib/epdfafm.rb', line 140 def italic @italic_angle != 0 end |
#load_afm(lines) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/epdfafm.rb', line 101 def load_afm(lines) lines.each do |line| break if @kern_data_started if @char_metrics_started load_char_metrics(line) else load_line(line) end end # symbolic fonts don't specify ascender and descender, so default to reasonable numbers. @ascender ||= 750 @descender ||= -188 @missing_width = 0 # for CJK charsets only? @leading = 0 # for CJK charsets only? self end |
#load_inf(lines) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/epdfafm.rb', line 118 def load_inf(lines) lines.grep(/^Serif/).each do |line| load_line(line) end self end |
#needs_descriptor(encoding) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/epdfafm.rb', line 144 def needs_descriptor(encoding) if encoding_scheme == 'FontSpecific' false else !(0...14).include?(PdfK::font_index(font_name)) || !PdfK::STANDARD_ENCODINGS.include?(encoding) end end |
#widths(encoding) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/epdfafm.rb', line 160 def widths(encoding) result = (@widths ||= {})[encoding] if result.nil? if encoding == :unicode result = Hash.new(missing_width) chars_by_name.each do |name, ch| results[PdfK::CODEPOINTS[name]] = ch.width end elsif encoding.nil? or encoding == 'StandardEncoding' result = Array.new(256, 0) chars_by_code.each do |ch| result[ch.code] = ch.width unless ch.nil? end else result = Glyphs.widths_for_encoding(encoding, chars_by_name) end @widths[encoding] = result end result end |