home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / PrintCardDB / ScriptLibrary.ps < prev    next >
Text File  |  2000-06-11  |  5KB  |  233 lines

  1. %!PS-Adobe
  2. %
  3. % Script library.
  4. %
  5. % $Id: ScriptLibrary.ps,v 1.2 2000/06/10 22:17:52 sergey Exp $
  6. %
  7.  
  8. %--- Parameters
  9.  
  10. /LastName       (${lastName}$)  def
  11. /FirstName      (${firstName}$) def
  12. /Company        (${company}$) def
  13. /Title          (${title}$) def
  14. /Phones         [ (${phone1}$) (${phone2}$) (${phone3}$) (${phone4}$) (${phone5}$) ] def
  15. /PhoneLabels    [ (${phoneLabel1}$) (${phoneLabel2}$) (${phoneLabel3}$) (${phoneLabel4}$) (${phoneLabel5}$) ] def
  16. /Address        (${address}$) def
  17. /City           (${city}$)  def
  18. /State          (${state}$) def
  19. /Zip            (${zip}$) def
  20. /Country        (${country}$) def
  21.  
  22. true {
  23.     /FrameHeight    ${frameHeight}$ def
  24.     /FrameWidth     ${frameWidth}$  def
  25.     /FrameMargin    ${frameMargin}$ def
  26.     /ScaleX         ${scaleX}$  def
  27.     /ScaleY         ${scaleY}$  def
  28.     /OneCopy        ${oneCopy}$ def
  29. } {
  30.     /FrameHeight    150 def
  31.     /FrameWidth     235 def
  32.     /FrameMargin    10 def
  33.     /ScaleX         100 def
  34.     /ScaleY         100 def
  35.     /OneCopy        false def
  36. } ifelse
  37.  
  38. %--- Utilities
  39.  
  40. % n -- str
  41. /itoa { /buff { 20 string } def buff cvs } def
  42.  
  43. % str -- bool
  44. /NotEmpty { length 0 ne } def
  45.  
  46. % llx lly urx ury -- Wx Wy
  47. /BoxSize {
  48.     /ury exch def /urx exch def /lly exch def /llx exch def
  49.     urx llx sub ury lly sub
  50. } def
  51.  
  52. %--- Position
  53.  
  54. % -- width height
  55. /PageSize {
  56.     currentpagedevice (PageSize) get
  57.     dup 0 get exch 1 get
  58. } def
  59.  
  60. /PageMargin 60 def
  61. /Left PageMargin def
  62. /Top { PageSize  exch pop PageMargin sub } def
  63. /X Left def
  64. /Y Top def
  65.  
  66. % x y --
  67. /MoveTo {
  68.     /Y exch def /X exch def
  69.     X Y moveto
  70. } def
  71.  
  72. % -- width height  ; Width and height of the char in current font
  73. /CharSize {
  74.     gsave newpath 0 0 moveto
  75.     (0) true charpath pathbbox BoxSize
  76.     newpath grestore
  77. } def
  78.  
  79. % -- n  ; Distance to next line for current font
  80. /LineSkip { CharSize exch pop 4 add } def
  81.  
  82. % --
  83. /CRLF {
  84.     currentpoint exch pop
  85.     X exch moveto 0 LineSkip neg rmoveto
  86. } def
  87.  
  88. % -- ; one line down
  89. /VSPACE { 0 CharSize exch pop neg rmoveto } def
  90.  
  91. % -- ; one char right
  92. /SPACE { CharSize pop 0 rmoveto } def
  93.  
  94. % -- bool ; check for BOL
  95. /NotBOL { currentpoint pop X CharSize pop add ge } def
  96.  
  97. % -- ; CRLF only when line not empty
  98. /_CRLF { NotBOL { CRLF } if } def
  99.  
  100. % -- ; SPACE only when line not empty
  101. /_SPACE { NotBOL { SPACE } if } def
  102.  
  103. %--- Block operations
  104.  
  105. % block-proc --
  106. /DrawBlock {
  107.     { show } exch exec
  108.     stroke
  109. } def
  110.  
  111. % block-proc -- width height
  112. /BlockSize {
  113.     newpath 0 0 MoveTo
  114.     { false charpath } exch exec
  115.     pathbbox BoxSize
  116.     newpath
  117. } def
  118.  
  119. %--- Block fonts
  120.  
  121. /SetNameFont            { /Times-Bold findfont 15 scalefont setfont } def
  122. /SetTitleFont           { /Times-Italic findfont 10 scalefont setfont } def
  123. /SetCompanyFont         { /Helvetica-Bold findfont 10 scalefont setfont } def
  124. /SetAddressFont         { /Helvetica findfont 7 scalefont setfont } def
  125. /SetContactTitleFont    { /Courier-Italic findfont 7 scalefont setfont } def
  126. /SetContactFont         { /Helvetica findfont 7 scalefont setfont } def
  127.  
  128. %--- Blocks
  129.  
  130. % do-proc --
  131. /PersonalBlock {
  132.     /do exch def
  133.     SetNameFont VSPACE
  134.     FirstName do _SPACE LastName do _CRLF
  135.     SetTitleFont Title do _CRLF
  136.     SetCompanyFont Company do
  137. } def
  138.  
  139. % do-proc --
  140. /AddressBlock {
  141.     /do exch def
  142.     SetAddressFont VSPACE
  143.     Address do _CRLF
  144.     City do _SPACE State do _SPACE Zip do _CRLF
  145.     Country do
  146. } def
  147.  
  148. % title text do-proc --
  149. /ContactItem {
  150.     /do exch def /text exch def /title exch def
  151.     text NotEmpty {
  152.         SetContactTitleFont title do (: ) do
  153.         SetContactFont text do
  154.         CRLF
  155.     } if
  156. } def
  157.  
  158. % do-proc --
  159. /ContactBlock {
  160.     SetContactFont VSPACE
  161.     0 1 Phones length 1 sub {
  162.         /i exch def
  163.         PhoneLabels i get Phones i get
  164.         2 index ContactItem
  165.     } for
  166.     pop
  167. } def
  168.  
  169. %--- Drawing
  170.  
  171. % --
  172. /DrawFrame {
  173.     % we are in upper-left corner
  174.     FrameWidth 0 rlineto
  175.     0 FrameHeight neg rlineto
  176.     FrameWidth neg 0 rlineto
  177.     closepath stroke
  178. } def
  179.  
  180. % --
  181. /DrawPersonalInfo {
  182.     PersonalInfoPos MoveTo { PersonalBlock } DrawBlock
  183. } def
  184.  
  185. % --
  186. /DrawContactInfo {
  187.     ContactInfoPos MoveTo { ContactBlock } DrawBlock
  188. } def
  189.  
  190. % --
  191. /DrawAddressInfo {
  192.     AddressInfoPos MoveTo { AddressBlock } DrawBlock
  193. } def
  194.  
  195. % --
  196. /DrawCard {
  197.     DrawPersonalInfo DrawAddressInfo DrawContactInfo
  198.     0 0 MoveTo DrawFrame
  199. } def
  200.  
  201. % --
  202. /DrawManyCards {
  203.     PageSize
  204.     PageMargin 2 mul sub FrameHeight 2 add div truncate cvi /rows exch def
  205.     PageMargin 2 mul sub FrameWidth 2 add div truncate cvi /cols exch def
  206.  
  207.     rows {
  208.        matrix currentmatrix
  209.        cols {
  210.            DrawCard FrameWidth 2 add 0 translate
  211.        } repeat
  212.        setmatrix
  213.        0 FrameHeight 2 add neg translate
  214.     } repeat
  215. } def
  216.  
  217. %-- main
  218.  
  219. % --
  220. /Main {
  221.     clear
  222.     erasepage
  223.     initmatrix
  224.  
  225.     Left Top translate
  226.  
  227.     % scale in persent
  228.     ScaleX 100 div ScaleY 100 div scale
  229.  
  230.     OneCopy { DrawCard } { DrawManyCards } ifelse
  231. } def
  232.  
  233.