Class: CombinePDF::Fonts::Font
- Inherits:
-
Hash
- Object
- Hash
- CombinePDF::Fonts::Font
- Defined in:
- lib/combine_pdf/fonts.rb
Overview
the internal class for the Fonts model
this is an internal class, used by PDFWriter and PDF. you don’t normally need to use this.
Instance Attribute Summary collapse
-
#cmap ⇒ Object
set/get a character/Glyph mapping for the font (the equivilant of a CMap).
-
#metrics ⇒ Object
get the metrics dictionary for the font.
-
#name ⇒ Object
set/get the name of the font.
Instance Method Summary collapse
-
#encode(text) ⇒ Object
This function translate a unicode string, to a character glyph ID stream.
-
#initialize(name = nil, font_metrics = { 32 => { wx: 250, boundingbox: [0, 0, 0, 0] } }, object = nil, c_map = nil) ⇒ Font
constructor
internelized a new Font object, setting it’s name, it’s metrics Hash and the object Hash.
Constructor Details
#initialize(name = nil, font_metrics = { 32 => { wx: 250, boundingbox: [0, 0, 0, 0] } }, object = nil, c_map = nil) ⇒ Font
internelized a new Font object, setting it’s name, it’s metrics Hash and the object Hash. Optionally set a CMap, if the glyph ID and character codes aren’t the same.
40 41 42 43 44 45 46 |
# File 'lib/combine_pdf/fonts.rb', line 40 def initialize(name = nil, font_metrics = { 32 => { wx: 250, boundingbox: [0, 0, 0, 0] } }, object = nil, c_map = nil) self.name = name self.cmap = c_map self.metrics = font_metrics self[:is_reference_only] = true self[:referenced_object] = object end |
Instance Attribute Details
#cmap ⇒ Object
set/get a character/Glyph mapping for the font (the equivilant of a CMap)
the cmap is a Hash were each key is the unicode character code and the value is the glyph ID for the font.
29 30 31 |
# File 'lib/combine_pdf/fonts.rb', line 29 def cmap @cmap end |
#metrics ⇒ Object
get the metrics dictionary for the font
31 32 33 |
# File 'lib/combine_pdf/fonts.rb', line 31 def metrics @metrics end |
#name ⇒ Object
set/get the name of the font
25 26 27 |
# File 'lib/combine_pdf/fonts.rb', line 25 def name @name end |
Instance Method Details
#encode(text) ⇒ Object
This function translate a unicode string, to a character glyph ID stream.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/combine_pdf/fonts.rb', line 49 def encode(text) # FIXME: embed RTL text convertion return format_string_to_pdf(text) unless cmap coded_array = text.chars.map do |c| if cmap[c] cmap[c] else warn "CombinePDF ERROR: couldn't encode string - characters not supported by the chosen font." '' end end coded_array.unshift '<' coded_array.push '>' coded_array.join end |