Class: Fontist::CollectionFile

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fontist/collection_file.rb

Defined Under Namespace

Classes: FontFileMetadata

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fontisan_collection, path) ⇒ CollectionFile

Returns a new instance of CollectionFile.



81
82
83
84
# File 'lib/fontist/collection_file.rb', line 81

def initialize(fontisan_collection, path)
  @collection = fontisan_collection
  @path = path
end

Class Method Details

.from_path(path) {|new(collection, path)| ... } ⇒ Object

Yields:

  • (new(collection, path))


8
9
10
11
12
# File 'lib/fontist/collection_file.rb', line 8

def from_path(path)
  collection = build_collection(path)

  yield new(collection, path)
end

Instance Method Details

#[](index) ⇒ Object

Return font metadata for a font in the collection. This uses Fontisan directly to extract metadata without creating tempfiles, which avoids Windows file locking issues.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/fontist/collection_file.rb', line 101

def [](index)
  # Load the font directly from the collection using Fontisan's FontLoader
  # mode: :metadata gives us just the metadata tables (faster, less memory)
  # lazy: false means we load the tables immediately (not deferred)
  font = Fontisan::FontLoader.load(@path, font_index: index,
                                          mode: :metadata, lazy: false)

  # Extract font metadata directly from Fontisan's font object
  # This avoids creating tempfiles and loading the font twice
  font_info = (font)

  # Create a FontFile-like object to hold the metadata
  # We use a simple struct with accessor methods for compatibility
  FontFileMetadata.new(font_info)
end

#countObject



86
87
88
# File 'lib/fontist/collection_file.rb', line 86

def count
  @collection.num_fonts
end

#eachObject



90
91
92
93
94
95
96
# File 'lib/fontist/collection_file.rb', line 90

def each
  count.times do |index|
    yield self[index]
  end

  self
end