Class: ExtractTtc::TrueTypeCollection
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- ExtractTtc::TrueTypeCollection
- Defined in:
- lib/extract_ttc/true_type_collection.rb
Overview
TrueType Collection domain object using BinData
Represents a complete TrueType Collection file using BinData’s declarative DSL for binary structure definition. The structure definition IS the documentation, and BinData handles all low-level reading/writing.
Class Method Summary collapse
-
.from_file(path) ⇒ TrueTypeCollection
Read TrueType Collection from a file.
Instance Method Summary collapse
-
#extract_fonts(io) ⇒ Array<TrueTypeFont>
Extract fonts as TrueTypeFont objects.
-
#valid? ⇒ Boolean
Validate format correctness.
-
#version ⇒ Integer
Get the TTC version as a single integer.
Class Method Details
.from_file(path) ⇒ TrueTypeCollection
Read TrueType Collection from a file
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/extract_ttc/true_type_collection.rb', line 35 def self.from_file(path) if path.nil? || path.to_s.empty? raise ArgumentError, "path cannot be nil or empty" end raise Errno::ENOENT, "File not found: #{path}" unless File.exist?(path) File.open(path, "rb") { |io| read(io) } rescue BinData::ValidityError => e raise "Invalid TTC file: #{e.}" rescue EOFError => e raise "Invalid TTC file: unexpected end of file - #{e.}" end |
Instance Method Details
#extract_fonts(io) ⇒ Array<TrueTypeFont>
Extract fonts as TrueTypeFont objects
Reads each font from the TTC file and returns them as TrueTypeFont objects.
55 56 57 58 59 60 61 |
# File 'lib/extract_ttc/true_type_collection.rb', line 55 def extract_fonts(io) require_relative "true_type_font" font_offsets.map do |offset| TrueTypeFont.from_ttc(io, offset) end end |
#valid? ⇒ Boolean
Validate format correctness
66 67 68 69 70 |
# File 'lib/extract_ttc/true_type_collection.rb', line 66 def valid? tag == Constants::TTC_TAG && num_fonts.positive? && font_offsets.length == num_fonts rescue StandardError false end |
#version ⇒ Integer
Get the TTC version as a single integer
75 76 77 |
# File 'lib/extract_ttc/true_type_collection.rb', line 75 def version (major_version << 16) | minor_version end |