home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / p / prohp5.zip / NEWSLET.PRG < prev    next >
Text File  |  1993-02-10  |  11KB  |  313 lines

  1. /*
  2.   ┌─────────────────────────────────────────────────────────────────────────┐
  3.   │                                                                         │
  4.   │    Program : NEWSLET.PRG                                                │
  5.   │                                                                         │
  6.   │    Purpose : To demonstrate creating newsletters and column printing.   │
  7.   │                                                                         │
  8.   │   Author  : Copyright (C) 1992,1993 I.L.A.,Inc. All Rights reserved.    │
  9.   │                                                                         │
  10.   │   Comments: This source code may be distributed and used freely         │
  11.   │             provided that the copyright notice is not removed.          │
  12.   │                                                                         │
  13.   └─────────────────────────────────────────────────────────────────────────┘
  14.  
  15. */
  16. #include "prohp.ch"
  17. #include "protfm.ch"
  18.  
  19. #define TMGRAY  1
  20. #define TMPATTERN 2
  21. #define TMBLACK  3
  22. #define TMWHITE  4
  23. #define TMDEFAULT NIL
  24.  
  25. proc main(lpt)
  26. Local cStr:="United States of America",cFname:="BCNN.TXT",cStr1:=''
  27. local nMode:=0,nTlines:=0,aModeVal,i,aGray,nMarg,nTextWidth,nLeftM,nPageW
  28. cStr1:=memoread(cFname)
  29.  
  30. HP_init()               // must start with this
  31. set2print(lpt)          // set output device
  32. HP_reset()              // clear printer
  33. HP_lmiset(0.5);HP_rmiset(7.5)   // set margins
  34. nPageW:=7               // page width 7"
  35. HP_pitch(10)            // courier 10
  36.  
  37. HP_center(,,"Demonstrating use of HP_prmode()",nPageW);qout()
  38. HP_center(,,"and text processing with full justification.",nPageW);qout()
  39. HP_center(,,HPreplicate("=",HP_data(D_RMI)-HP_data(D_LMI)),nPageW);qout()
  40. qout()
  41.  
  42. HP_scalef(48)   // use 48 Pt universe
  43. qout()
  44. HP_textmode(TMGRAY,40)        // select gray shade
  45. HP_fjust(,,cStr,nPageW)       // print text
  46.  
  47. /* if you have do not have enough memory in your printer
  48.    then you may get a printer overrun error. Use the following
  49.    to replcae the 4 code lines above.
  50.  
  51. HP_scalef(48)   // use 48 Pt universe
  52. aGray:={10,20,30,40} // make gray shade array
  53. qout()
  54. HP_setpos(-0.02*len(aGray),0.02*len(aGray),.t.)
  55. for i:=1 TO len(aGray)
  56.     HP_textmode(TMGRAY,aGray[i])        // select gray shade
  57.     HP_savecsr()                        // save csr
  58.     qqout(cStr)                         // print text
  59.     HP_restcsr()                        // restore csr
  60.     HP_setpos(0.02,0.02,.t.)            // move down and right a little
  61. next
  62. */
  63. /* uncomment the following to print white on black
  64. HP_setpos(,0.5) // move csr (CAP) to left margin
  65. HP_bar(1.25/HP_data(D_LPI),7,GFILLBLACK)
  66. qout()
  67.  aGray:={10,20,30,40}
  68. for i:=1 TO len(aGray)
  69.     HP_textmode(TMGRAY,aGray[i])
  70.     HP_savecsr()
  71.     qqout(cStr)
  72.     HP_restcsr()
  73.     HP_setpos(0.02,0.02,.t.)
  74. next
  75. HP_textmode(TMWHITE)
  76. qqout(cStr)
  77. */
  78.  
  79. HP_prmode()             // print mode to default
  80. HPprtext(cStr1,0.5,7)   // print the text we read from "bcnn.txt" file
  81. HP_bar(HPfxheight(),nPageW,GFILLGRAY,20)
  82. qout()
  83.  
  84. // change font to UNIVERSE using the current size, style
  85. HP_scalef(,,,,,TF_UNIVERSE)
  86.  
  87. HP_rbox(1.5,nPageW)
  88.  
  89. HP_lmiset(0.7)  // new margin
  90.  
  91. qout("This entire page created with ProHP. We used column definintion and relative cursor")
  92. qout("positioning and printing.")
  93. qout("You can easily modify the code for your own purposes, change orientation, add more")
  94. qout("columns/pages or change width, height, justification, typeface or style.")
  95.  
  96. HP_scalef(14,,3,,TF_UNIVERSE);qout();qout()
  97. HP_negative("   I.L.A., Inc.  (407) 774-7734, (800) 374-7734 USA and CANADA   ",GFILLGRAY,100)
  98. qout()
  99. HP_reset()      // Finished, this clears and exits.
  100. set2screen()
  101. return
  102.  
  103. /*
  104.         The following procedure will show you how easily you can
  105.         control text with ProHP. Please modify this code as you
  106.         like ( play with it ) and watch the result of your
  107.         changes. You can use this technique to design
  108.         multi column reports and forms.
  109. */
  110.  
  111.  
  112. Function HPprtext(cStr1,nLeft,nWidth,cJust,cDelim,nStart)
  113. Local cLine:="",nStartAt:=1,nLines:=0,nRest:=0,ohmi:=0
  114. Local nSpaces:=0,nLinesize:=0
  115. Local nPt,nStyle,nWgt,nTF,nPoints,nLogoH,nCalH
  116. Local nStlen:=len(cStr1),lRtrim:=.t.,trspc:=0
  117. Local nColW,nColH,nTop,nCol,nBoxH,nBoxW,aCol,nHpos,nCLeft,nCmarg,nCtop,nCapH
  118. nStartAt:=iif(nStart==NIL,nStartAt,nStart)
  119. cJust:=iif(cJust==NIL,"L",cJust)
  120. nWidth:=HPcur2i(nWidth)
  121.  
  122. nPt:=11
  123. nStyle:=ITALIC  // UPRIGHT
  124. nWgt:=0
  125. nTF:=TF_CGTIMES // 4116
  126.  
  127. HP_scalef(nPt,nStyle,nWgt,,nTF)    // set working font
  128.  
  129. // lets define 4 columns
  130. nCMarg:=0.2             // margins for columns
  131. nColW:=(nWidth-(nCMarg*2))/4       // make 4 columns
  132. nColH:=6                // set max column height to x
  133. nCTop:=2                // start at top
  134. nCLeft:=nLeft           // use imported parameter
  135.  
  136. /*
  137.  
  138.    define columns metrics
  139.    array (n Columns, array(5))
  140.    array column has 5 elements
  141.    [1] := nCtop (distance from top of page)
  142.    [2] := nCLeft ( distance from left of page )
  143.    [3] := nColW ( column width )
  144.    [4] := nColH ( column Height )
  145.    [5] := cCjust ( any of the following "L","C","R","F" )
  146.  
  147. Hint :  You may add one or more elements to the above array to define
  148.         a column type ( mixed text and image (PCX) or other drawings ).
  149.         Define a font or point size.
  150. */
  151.  
  152. aCol:={ {nCTop,nCLeft,nColW,nColH,"F"},;
  153.         {nCTop,nCLeft+nColW+nCMarg,nColW*2,nColH/2,"F"},;
  154.         {nCTop,nCLeft+(nColW*3)+(nCmarg*2),nColW,nColH,"F"}}
  155. //         {nCTop+nColH,nCLeft,nWidth,nColH,"F"}}
  156.  
  157. HP_data(D_FONTWCHARS)[32] := HP_data(D_HMI)*10
  158. nCol:=1         // start at column 1
  159. nHpos:=0        // use this to keep track of line position
  160. nWidth:=aCol[nCol,3]    // set width for current column
  161. cJust:=aCol[nCol,5]     // set justification
  162. nLeft:=aCol[nCol,2]     // set left of column
  163.  
  164. HP_setpos(aCol[nCol,1],aCol[nCol,2]) // posotion csr at begining of column
  165.  
  166. /*
  167.   get the first line. Notice that the width must be in inches * 1200
  168.   this is to match the character width table of the font, and insure
  169.   high accuracy.
  170. */
  171.  
  172. cline:=_hpgetline(cStr1,nWidth*1200,cDelim,@nStartAt,HP_data(D_FONTWCHARS),@nSpaces)
  173. // nHpos+=1/HP_data(D_LPI) // keep track of cursor pos
  174.  
  175. WHILE .T.
  176. if nLeft!=0 .and. nLeft!=NIL
  177.    HP_setpos(,nLeft)       // go to the left margin
  178. else
  179.    // line will be printed started at the left margin
  180. endif
  181. nLines++        // count the lines printed
  182.  
  183. // to make nice full justification we'll trim spaces from the right
  184. cLine:=iif(lRtrim,trim(cLine),cLine)
  185.  
  186. // switch cJust 
  187. do case
  188.    case cJust== "F"
  189.         // print full justify.
  190.         if nSpaces > 0
  191.            HP_fjust(,,cline,nWidth)
  192.         else
  193.            qqout(cline)    // no full justification if end of paragraph
  194.         endif
  195.    case cJust== "C"
  196.         HP_center(,,cline,nWidth)       // center between the current CAP
  197.                                         // and CAP+nWidth
  198.    case cJust== "R"
  199.         HP_setpos(,nWidth,.t.)  // move to end of line
  200.         HP_rjust(,,cline)       // print right justify
  201. otherwise
  202.         qqout(cline)    // just print the line starting at CAP
  203. endcase
  204. qout()  // advance to next line
  205. if nStartAt >= nStlen   // check that we still have text to process
  206.    exit                 // otherwise exit loop
  207. endif
  208. nHpos+=1/HP_data(D_LPI) // keep track of cursor position
  209.  
  210. if nHpos > aCol[nCol,4] // if it is over the H limit of the current column
  211.    if nCol=2    // we left space to draw a box
  212.       HP_setpos(,aCol[nCol,2])  // go to column left margin
  213.       // get capital height
  214.       nCapH:=HPfcapH() // HPi2cur(zDU2i(HP_data(D_SCALEFDATA)[CAPHEIGHT]))
  215.       HP_setpos(-(nCapH),,.t.)
  216.  
  217.       nBoxH:=aCol[nCol-1,4]-nHpos-nCapH+abs(HPfdescent()) // find height available for box
  218.       nBoxW:=aCol[nCol,3]               // box width = column width
  219.       nCalH:=nBoxH*.8
  220.       HP_savecsr()
  221.       HPdrawmonth(date(),aCol[nCol,1]+nHpos-nCapH,aCol[nCol,2],nCalH,aCol[nCol,3],.t.)
  222.       HP_restcsr()
  223.       HP_setpos(nCalH,,.t.)
  224.  
  225.       HP_setpos(nCMarg/2,,.t.)
  226.       nLogoH:=nBoxH-nCalH-(nCMarg/2)
  227.  
  228.       HP_rbox(nLogoH,nBoxW)              // draw the box
  229. /*
  230.       HP_savecsr()                      // save csr for next process
  231.       HP_setpos(nCmarg/2,nCmarg/2,.t.)      // pos csr for margins
  232.       HP_restcsr()      // restore csr
  233. */
  234.       // draw black area
  235.       HP_bar(nLogoH,nBoxW,GFILLBLACK)
  236.  
  237.       HP_textmode(TMWHITE)         // make text appear as white
  238.       nPoints:=round((nCalH*.2)*.8*72,2)
  239.       HP_scalef(nPoints,,3,,TF_UNIVERSE)     // 64 Pt Universe bold
  240.       nCapH:=HPfcapH() // HPi2cur(zDU2i(HP_data(D_SCALEFDATA)[CAPHEIGHT]))
  241.       HP_setpos((nLogoH-nCapH)/2+nCapH,,.t.)       // Position to vertical center
  242.       HP_center(,,"ProHP",nBoxW)                // and horizontal center the text
  243.       HP_prmode()                       // default print mode
  244.  
  245.    endif
  246.    HP_scalef(nPt,nStyle,nWgt,,nTF)      // back to normal point
  247.    HPstsize("")         // this will make sure we have a correct and current
  248.                         // width table
  249.    nCol++                       // skip to next column
  250.  
  251.    if nCol > len(aCol)          // have we used all column
  252.       exit                      // Yes, exit
  253.  
  254.       /*
  255.         at this point you can eject a page and use the same or another
  256.         column array to print the rest of the text or go out to
  257.         another procedure. nStartAt saves the position of the text
  258.         printed so far */
  259.  
  260.    endif
  261.  
  262.    cJust:=aCol[nCol,5]          // set new justification
  263.    nHpos:=0 // 1/HP_data(D_LPI)                     // reset H pos
  264.    nWidth:=aCol[nCol,3]         // new width for new column
  265.    nLeft:=aCol[nCol,2]          // new left pos
  266.    nTop:=aCol[nCol,1]           // new top pos
  267.    HP_setpos(nTop,nLeft)        // move cursor to new location
  268. endif
  269. // get the next line
  270. cLine:=_hpgetline(cStr1,nWidth*1200,cDelim,@nStartAt,HP_data(D_FONTWCHARS),@nSpaces)
  271. enddo
  272. return nLines
  273.  
  274.  
  275. // use this function
  276. Function HPlcount(cStr1,nWidth,cDelim,nStart)
  277. Local cLine:="",nStartAt:=1,nLines:=0,nRest:=0,ohmi:=0
  278. Local nSpaces:=0,nLinesize:=0
  279. Local nStlen:=len(cStr1),lRtrim:=.t.,trspc:=0
  280. nStartAt:=iif(nStart==NIL,nStartAt,nStart)
  281. cline:=_hpgetline(cStr1,HPcur2i(nWidth)*HP_data(D_UOM),cDelim,@nStartAt,HP_data(D_FONTWCHARS),@nSpaces,@nLinesize,lRtrim)
  282. while(.t.)
  283. nLines++
  284. if nStartAt >= nStlen
  285.    exit
  286. endif
  287. cline:=_hpgetline(cStr1,HPcur2i(nWidth)*HP_data(D_UOM),cDelim,@nStartAt,HP_data(D_FONTWCHARS),@nSpaces,@nLinesize,lRtrim)
  288. enddo
  289. return nLines
  290.  
  291. FUNCTION HP_textmode(nMode,nVal)
  292. Local os:=HP_send(.f.),o:=''
  293. do case
  294.    case nMode=1         // gray text
  295.         // nVal : see gray shading level in the manual
  296.         o:=HP_prmode(TRANSPARENT,OPAQUE,nVal,GFILLGRAY)
  297.    case nMode=2         // pattern text
  298.         // nVal : 1 - 6 , see FILL PATTERNS in the manual
  299.         o:=HP_prmode(TRANSPARENT,OPAQUE,nVal,GFILLPATTERN)
  300.    case nMode=3         //  Black text
  301.         // nVal : ignored
  302.         o:=HP_prmode(TRANSPARENT,OPAQUE,nVal,GFILLBLACK)
  303.    case nMode=4         // white text
  304.         // nVal ignored
  305.         o:=HP_prmode(TRANSPARENT,OPAQUE,nVal,GFILLWHITE)
  306.    otherwise
  307.         // default mode = black
  308.         o:=HP_prmode(TRANSPARENT,TRANSPARENT,0,0)
  309. endcase
  310. HP_send(os)
  311. return iif(HP_send(),qqout(o),o)
  312.  
  313.