Class: PDF::Writer::Object::Font

Inherits:
PDF::Writer::Object show all
Defined in:
lib/pdf/writer/object/font.rb

Overview

An object to hold the font description

Constant Summary collapse

Details =
%w{FirstChar LastChar Widths FontDescriptor SubType}

Instance Attribute Summary collapse

Attributes inherited from PDF::Writer::Object

#oid

Instance Method Summary collapse

Constructor Details

#initialize(parent, name, encoding = 'WinAnsiEncoding', subtype = 'Type1') ⇒ Font

Returns a new instance of Font.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pdf/writer/object/font.rb', line 15

def initialize(parent, name, encoding = 'WinAnsiEncoding', subtype = 'Type1')
  super(parent)

  @name     = name
  @subtype  = subtype
  @font_id  = @parent.__send__(:generate_font_id)

  if encoding.kind_of?(PDF::Writer::Object::FontEncoding)
    @encoding           = encoding
  elsif encoding == 'none' or encoding.nil?
    @encoding           = nil
  else
    @encoding           = encoding
  end

  @parent.pages << self

  @firstchar      = nil
  @lastchar       = nil
  @widths         = nil
  @fontdescriptor = nil
end

Instance Attribute Details

#encodingObject (readonly)

Valid values: WinAnsiEncoding, MacRomanEncoding, MacExpertEncoding, none, nil, or an instance of PDF::Writer::Object::FontEncoding.



44
45
46
# File 'lib/pdf/writer/object/font.rb', line 44

def encoding
  @encoding
end

#font_idObject (readonly)

Returns the value of attribute font_id.



38
39
40
# File 'lib/pdf/writer/object/font.rb', line 38

def font_id
  @font_id
end

#subtypeObject (readonly)

The type of the font: Type1 and TrueType are the only values supported by



41
42
43
# File 'lib/pdf/writer/object/font.rb', line 41

def subtype
  @subtype
end

Instance Method Details

#basefontObject

:nodoc:



46
47
48
# File 'lib/pdf/writer/object/font.rb', line 46

def basefont #:nodoc:
  @name
end

#basefont=(val) ⇒ Object

:nodoc:



50
51
52
# File 'lib/pdf/writer/object/font.rb', line 50

def basefont=(val) #:nodoc:
  @name = val
end

#to_sObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/pdf/writer/object/font.rb', line 58

def to_s
  res = "\n#{@oid} 0 obj\n<< /Type /Font\n/Subtype /#{@subtype}\n"
  res << "/Name /F#{@font_id}\n/BaseFont /#{@name}\n"
  if @encoding.kind_of?(PDF::Writer::Object::FontEncoding)
    res << "/Encoding #{@encoding.oid} 0 R\n"
  elsif @encoding
    res << "/Encoding /#{@encoding}\n" if @encoding
  end
  res << "/FirstChar #{@firstchar}\n" unless @firstchar.nil?
  res << "/LastChar #{@lastchar}\n" unless @lastchar.nil?
  res << "/Widths #{@widths} 0 R\n" unless @widths.nil?
  res << "/FontDescriptor #{@fontdescriptor} 0 R\n" unless @fontdescriptor.nil?
  res << ">>\nendobj"
end