class Quadtone::Printer
Constants
- ImportantOptions
Attributes
attributes[RW]
inks[RW]
name[RW]
options[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/quadtone/printer.rb, line 18 def initialize(name) @name = name @cups_ppd = CupsPPD.new(@name, nil) @options = Hash[ @cups_ppd.options.map { |o| [o.delete(:keyword).to_sym, HashStruct.new(o)] } ] @attributes = Hash[ @cups_ppd.attributes.map { |a| [a.delete(:name).to_sym, HashStruct.new(a)] } ] @cups_printer = CupsPrinter.new(@name) get_inks end
Public Instance Methods
default_options()
click to toggle source
# File lib/quadtone/printer.rb, line 58 def default_options Hash[ @options.map do |name, option| [name, option.default_choice] end ] end
get_inks()
click to toggle source
# File lib/quadtone/printer.rb, line 35 def get_inks # FIXME: It would be nice to get this path programmatically. ppd_file = Path.new("/etc/cups/ppd/#{@name}.ppd") ppd_file.readlines.each do |line| if line =~ /^\*%Inks\s*(.*?)\s*$/ @inks = $1.split(/,/).map(&:downcase).map(&:to_sym) break end end end
page_size(name=nil)
click to toggle source
# File lib/quadtone/printer.rb, line 46 def page_size(name=nil) name ||= @cups_ppd.attribute('DefaultPageSize').first[:value] page_size = @cups_ppd.page_size(name) or raise "Can't determine page size #{name.inspect}" size = HashStruct.new(page_size) # change 'length' to 'height', or else there are problems with Hash#length size[:height] = size.delete(:length) size = HashStruct.new(size) size.imageable_width = size.margin.right - size.margin.left size.imageable_height = size.margin.top - size.margin.bottom size end
print_file(path, options)
click to toggle source
# File lib/quadtone/printer.rb, line 95 def print_file(path, options) warn "Printing #{path}" warn "Options:" options.each do |key, value| warn "\t" + "%10s: %s" % [key, value] end @cups_printer.print_file(path, options) end
quadtone?()
click to toggle source
# File lib/quadtone/printer.rb, line 31 def quadtone? @attributes[:Manufacturer].value == 'QuadToneRIP' end
show_attributes()
click to toggle source
# File lib/quadtone/printer.rb, line 66 def show_attributes puts "Attributes:" max_field_length = @attributes.keys.map(&:length).max @attributes.sort_by { |name, info| name }.each do |name, attribute| puts "\t" + "%#{max_field_length}s: %s%s" % [ name, attribute.value.inspect, attribute.spec.empty? ? '' : " [#{attribute.spec.inspect}]" ] end end
show_inks()
click to toggle source
# File lib/quadtone/printer.rb, line 90 def show_inks puts "Inks:" puts "\t" + @inks.map { |ink| ink.to_s.upcase }.join(', ') end
show_options()
click to toggle source
# File lib/quadtone/printer.rb, line 78 def show_options puts "Options:" max_field_length = @options.keys.map(&:length).max @options.sort_by { |name, option| name }.each do |name, option| puts "\t" + "%#{max_field_length}s: %s [%s]" % [ name, option.default_choice.inspect, (option.choices.map { |o| o.choice } - [option.default_choice]).map { |o| o.inspect }.join(', ') ] end end