Class: FontProcessor::FontFileNamingStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/fontprocessor/font_file_naming_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_name, file_dir) ⇒ FontFileNamingStrategy

Returns a new instance of FontFileNamingStrategy.



4
5
6
7
# File 'lib/fontprocessor/font_file_naming_strategy.rb', line 4

def initialize(file_name, file_dir)
  @file_name = file_name
  @file_dir = file_dir
end

Instance Method Details

#char_set(charset_id, font_format) ⇒ Object

Public: Generates the file path to a specific character subset of a given file format.

charset_id - The CharsetID representing the character set included within

the file.

font_format - The FontFormat of the file.

Returns the file path to the primary source file.



59
60
61
# File 'lib/fontprocessor/font_file_naming_strategy.rb', line 59

def char_set(charset_id, font_format)
  File.join(@file_dir, "charset-#{charset_id}-#{font_format.container_format}.#{font_format.extension}")
end

#primary_sourceObject

Public: Generates the file path of the primary source file. The primary is defined as the PostScript source file if it exists and otherwise the TrueType source file.

Returns the file path to the primary source file.



42
43
44
45
46
47
48
49
# File 'lib/fontprocessor/font_file_naming_strategy.rb', line 42

def primary_source
  cff = FontFormat.new(:cff, :otf)
  if File.exists?(source(cff))
    source(cff)
  else
    source(FontFormat.new(:ttf, :otf))
  end
end

#source(font_format = nil) ⇒ Object

Public: Generates the file path for both the pristine (original from the foundry file) and the source file (which is the typekit modified base file) if a FontFormat is given.

font_format - If nothing is given then the file path returned is for the

pristine file. If a FontFormat is given, that the source
file path for that FontFormat is for.

Returns either the file path for the pristine file or the source file

depending on font_format.


19
20
21
22
23
24
25
# File 'lib/fontprocessor/font_file_naming_strategy.rb', line 19

def source(font_format=nil)
  if font_format
    File.join(@file_dir, "source.#{font_format.extension}")
  else
    File.join(@file_dir, @file_name)
  end
end

#unlocked(font_format) ⇒ Object

Public: Generates the file path for a pristine file that has been only unlocked. Useful as fontforge can’t inspect any files which are locked and some foundries give us locked prisitine files.

Returns a file path for a pristine file that has been unlocked

and no other manipulations have occurred.


33
34
35
# File 'lib/fontprocessor/font_file_naming_strategy.rb', line 33

def unlocked(font_format)
  File.join(@file_dir, "unlocked.#{font_format.extension}")
end