Class: Rpdf2txt::Font

Inherits:
PdfObject show all
Defined in:
lib/rpdf2txt/object.rb

Constant Summary collapse

ENCODINGS =
{
    '/Identity-H'       =>  'ascii',
	'/MacRomanEncoding'	=>	'mac',
    '/UTF8'             =>  'utf8',
	'/WinAnsiEncoding'	=>	'ms-ansi',
}
AFM_PTRN =
/^C\s*(\d+)\s*;\s*
WX\s*(\d+)\s*;\s*
N\s*(\w+)/xn

Instance Attribute Summary collapse

Attributes inherited from PdfObject

#attributes, #decoder, #oid, #src

Instance Method Summary collapse

Methods inherited from PdfObject

#_parse_attributes, #catalogue_object, #decoded_stream, #extract_attribute_stream, #initialize, #parse_attributes, #revision_id

Constructor Details

This class inherits a constructor from Rpdf2txt::PdfObject

Instance Attribute Details

#cmapObject

Returns the value of attribute cmap.



274
275
276
# File 'lib/rpdf2txt/object.rb', line 274

def cmap
  @cmap
end

#descriptorObject

Returns the value of attribute descriptor.



274
275
276
# File 'lib/rpdf2txt/object.rb', line 274

def descriptor
  @descriptor
end

#rendering_modeObject

Returns the value of attribute rendering_mode.



274
275
276
# File 'lib/rpdf2txt/object.rb', line 274

def rendering_mode
  @rendering_mode
end

#skewedObject

Returns the value of attribute skewed.



274
275
276
# File 'lib/rpdf2txt/object.rb', line 274

def skewed
  @skewed
end

Instance Method Details

#basefont_nameObject



284
285
286
# File 'lib/rpdf2txt/object.rb', line 284

def basefont_name
	@attributes[:basefont]
end

#basefont_width(char) ⇒ Object



287
288
289
# File 'lib/rpdf2txt/object.rb', line 287

def basefont_width(char)
  basefont_widths[char]
end

#basefont_widthsObject



290
291
292
# File 'lib/rpdf2txt/object.rb', line 290

def basefont_widths
  @basefont_widths ||= load_basefont_widths
end

#bold?Boolean

Returns:

  • (Boolean)


293
294
295
# File 'lib/rpdf2txt/object.rb', line 293

def bold?
	(!!/bold/in.match(basefont_name.to_s)) || @rendering_mode == "2"
end

#build_tree(object_catalogue, parent = nil) ⇒ Object



296
297
298
299
300
301
302
# File 'lib/rpdf2txt/object.rb', line 296

def build_tree(object_catalogue, parent = nil)
  super
  if(desc = @attributes[:descriptor])
    @descriptor = desc
    desc.build_tree(object_catalogue, self)
  end
end

#encodingObject



303
304
305
306
307
308
309
310
311
312
313
# File 'lib/rpdf2txt/object.rb', line 303

def encoding
    enc = @attributes[:encoding]
    if(enc.is_a?(Encoding))
      enc
    else
      ENCODINGS.fetch(enc) { 
        warn "unknown encoding #{enc}"
        enc
      }
    end
end

#italic?Boolean

Returns:

  • (Boolean)


314
315
316
# File 'lib/rpdf2txt/object.rb', line 314

def italic?
	@skewed || !!/italic/in.match(basefont_name.to_s)
end

#symbol?Boolean

Returns:

  • (Boolean)


330
331
332
# File 'lib/rpdf2txt/object.rb', line 330

def symbol?
  !!/symbol/in.match(basefont_name.to_s)
end

#to_unicodeObject



333
334
335
# File 'lib/rpdf2txt/object.rb', line 333

def to_unicode
  @to_unicode ||= (tu = @attributes[:tounicode]) && tu.to_cmap
end

#width(char) ⇒ Object



317
318
319
320
321
322
323
324
325
326
# File 'lib/rpdf2txt/object.rb', line 317

def width(char)
	if(char.is_a?(String) && char.length == 1)
              if RUBY_VERSION > "1.9"
                char = char.bytes.to_a[0]
              else
		  char = char[0]
              end
	end
    _width(char) || named_width(char)
end

#widthsObject



327
328
329
# File 'lib/rpdf2txt/object.rb', line 327

def widths
  @widths ||= (@attributes[:widths] || [])
end