Module: TTF2EOT

Defined in:
lib/ttf2eot.rb

Defined Under Namespace

Classes: ConversionError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert(input, output) ⇒ Object

Public: Converts a TTF font file to an EOT font.

input - the input TTF font as a String (representing a path) or IO object

(responding to #read).

output - the output destination as a String (representing a path) or IO

object where the EOT font will be written.

Examples:

TTF2EOT.convert("input.ttf", "output.eot")
# => #<File:output.eot>

input = StringIO.new(File.read("input.ttf"))
output = StringIO.new
TTF2EOT.convert(input, output)
# => #<StringIO:0x007f815a83a210>

Returns the output IO object. Raises TTF2EOT::ConversionError if the input data is invalid.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ttf2eot.rb', line 21

def convert(input, output)
  input = File.open(input, "rb") unless input.respond_to?(:read)
  output = File.open(output, "wb") unless output.respond_to?(:write)

  source = input.read
  header = eot_header(source)

  output.write header
  output.write source
  output.flush

  output
end

Instance Method Details

#eot_header(font_data) ⇒ Object

Internal: Get an EOT header for a TTF font.

font_data - a String containing valid TTF font data.

Returns a String with the EOT header for the input data. Raises TTF2EOT::ConversionError if the input data is invalid.

Raises:

  • (NotImlementedError)


42
43
44
# File 'lib/ttf2eot.rb', line 42

def eot_header(font_data)
  raise NotImlementedError, "this method is defined by the ttf2eot c extension"
end