Sha256: ff384a9f3bfa442b25ed7ae12a1b29bbc6f46b1caacc422c6ebc7ef393dfb1c8

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require "cheapredwine/version"
require "cheapredwine/info"
require "cheapredwine/image"


module CheapRedWine
  class Meta 
    attr_accessor :name, :family, :features, :path, :style

    def initialize
      yield(self) if block_given?
    end

    def file
      File.new(path)
    end
  end

  def self.meta(file)
    parser = Info.new file
    Meta.new do |meta|
      meta.name = parser.font_name
      meta.family = parser.family_name
      meta.features = parser.features
      meta.style = parser.style
      meta.path = file
    end
  end

  def self.image(font, text, options = {})
    features = merge_features(font.features, options.fetch(:features) { [] })
    options.merge!({ 
      features: features,
      font: font.file,
      text: text
    })
    params = Image::Params.new(options)
    Image::Writer.new(params).exec
  end

  def self.ttx_output_folder=(folder)
    CheapRedWine::TTX.configuration.output_folder = folder
  end

  def self.ttx_output_folder
    CheapRedWine::TTX.configuration.output_folder
  end

  private

  def self.merge_features(all_features, selected_features)
    all_features.map do |feature|
      prefix = selected_features.include?(feature) ? '+' : '-'
      prefix + feature
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cheapredwine-0.2.0 lib/cheapredwine.rb