File: font.rb

package info (click to toggle)
ruby-rghost 0.9.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,188 kB
  • sloc: ruby: 3,374; makefile: 6; sh: 1
file content (40 lines) | stat: -rw-r--r-- 1,170 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require "rghost/ps_object"
require "rghost/constants"
require "rghost/helpers"

class RGhost::Font < RGhost::PsObject # :nodoc:
  DEFAULT_OPTONS = {size: 8, name: "Helvetica", encoding: true}
  include RGhost::Constants::Fonts

  attr_reader :name

  def initialize(options)
    @options = DEFAULT_OPTONS.dup.merge(options)
    @options.default ""
    @options[:name] = @options[:font] if @options[:font]
    @name = @options[:name].to_s
    @name += "-encoding" if @options[:encoding]
  end

  def ps
    o = @options
    str_ret = ""
    #    if o[:barcode]
    #      bc=RGhost::Barcode.new(o[:barcode])
    #      @name=bc.font_name
    #      o[:encoding]=false
    #    end
    if o[:encoding] # define enconding
      str_ret = "/#{o[:name]} encoding_font\n" +
        "/#{o[:name]}-encoding exch definefont pop\n"
    end

    size = o[:size]
    str_ret += case size
    when Hash then "/#{@name} findfont [ #{size[:width]} 0 0 #{size[:height]} 0 0] makefont setfont "
    when Array then "/#{@name} findfont [ #{size[0]} 0 0 #{size[1]} 0 0] makefont setfont "
    when Numeric then "/#{@name} findfont #{size} scalefont setfont "
    end
    str_ret
  end
end