Class: Symbol

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

Instance Method Summary collapse

Instance Method Details

#to_postscriptObject

Convert this symbol into a PostScript expression evaluating to a PostScript name object. If the string does not look like a PostScript name, the resulting expression will use the [[cvn]] operator to convert a PostScript string into a PostScript name.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pson.rb', line 52

def to_postscript
  s = self.to_s
  # Does this symbol parse cleanly if treated as a PostScript name?
  # We're deliberately conservative here.
  if s.unpack('C*').all?{ |cp|
      [
        0x30 .. 0x39, # digits
        0x41 .. 0x5A, # uppercase
        0x61 .. 0x7A, # lowercase
        "-_", # special
      ].any?{ |range|
          range.include? cp}} then
    return '/' + s
  else
    # If not, represent the symbol as a string and convert it to name in
    # PostScript.
    return s.to_postscript + " cvn"
  end
end