Class: Fontisan::Type1::INFGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/type1/inf_generator.rb

Overview

INF (Font Information) Generator

INFGenerator generates INF files for Windows Type 1 font installation.

INF files contain metadata for installing Type 1 fonts on Windows systems. They reference the PFB, PFM, and AFM files that make up a Windows Type 1 font.

Examples:

Generate INF from TTF

font = Fontisan::FontLoader.load("font.ttf")
inf_data = Fontisan::Type1::INFGenerator.generate(font)
File.write("font.inf", inf_data)

Generate INF with custom file names

inf_data = Fontisan::Type1::INFGenerator.generate(font,
  pfb_file: "myfont.pfb",
  afm_file: "myfont.afm",
  pfm_file: "myfont.pfm"
)

See Also:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(font, options = {}) ⇒ INFGenerator

Initialize a new INFGenerator

Parameters:



56
57
58
59
60
# File 'lib/fontisan/type1/inf_generator.rb', line 56

def initialize(font, options = {})
  @font = font
  @options = options
  @metrics = MetricsCalculator.new(font)
end

Class Method Details

.generate(font, options = {}) ⇒ String

Generate INF file content from a font

Parameters:

Options Hash (options):

  • :pfb_file (String)

    PFB filename (default: based on font name)

  • :afm_file (String)

    AFM filename (default: based on font name)

  • :pfm_file (String)

    PFM filename (default: based on font name)

  • :inf_file (String)

    INF filename (default: based on font name)

  • :otf_file (String)

    OTF filename (for OpenType fonts)

Returns:

  • (String)

    INF file content



37
38
39
# File 'lib/fontisan/type1/inf_generator.rb', line 37

def self.generate(font, options = {})
  new(font, options).generate
end

.generate_to_file(font, path, options = {}) ⇒ void

This method returns an undefined value.

Generate INF file from a font and write to file

Parameters:



47
48
49
50
# File 'lib/fontisan/type1/inf_generator.rb', line 47

def self.generate_to_file(font, path, options = {})
  inf_content = generate(font, options)
  File.write(path, inf_content, encoding: "ISO-8859-1")
end

Instance Method Details

#generateString

Generate INF file content

Returns:

  • (String)

    INF file content



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fontisan/type1/inf_generator.rb', line 65

def generate
  lines = []

  # Font description section
  lines << "[Font Description]"
  lines << build_font_description
  lines << ""

  # Files section
  lines << "[Files]"
  lines << build_file_list
  lines << ""

  # Other section
  lines << "[Other]"
  lines << build_other_section

  lines.join("\n")
end