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.



83
84
85
86
# File 'lib/fontist/collection_file.rb', line 83

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.



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

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



88
89
90
# File 'lib/fontist/collection_file.rb', line 88

def count
  @collection.num_fonts
end

#eachObject



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

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

  self
end