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 >
Wrap
Text File
|
1993-02-10
|
11KB
|
313 lines
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ │
│ Program : NEWSLET.PRG │
│ │
│ Purpose : To demonstrate creating newsletters and column printing. │
│ │
│ Author : Copyright (C) 1992,1993 I.L.A.,Inc. All Rights reserved. │
│ │
│ Comments: This source code may be distributed and used freely │
│ provided that the copyright notice is not removed. │
│ │
└─────────────────────────────────────────────────────────────────────────┘
*/
#include "prohp.ch"
#include "protfm.ch"
#define TMGRAY 1
#define TMPATTERN 2
#define TMBLACK 3
#define TMWHITE 4
#define TMDEFAULT NIL
proc main(lpt)
Local cStr:="United States of America",cFname:="BCNN.TXT",cStr1:=''
local nMode:=0,nTlines:=0,aModeVal,i,aGray,nMarg,nTextWidth,nLeftM,nPageW
cStr1:=memoread(cFname)
HP_init() // must start with this
set2print(lpt) // set output device
HP_reset() // clear printer
HP_lmiset(0.5);HP_rmiset(7.5) // set margins
nPageW:=7 // page width 7"
HP_pitch(10) // courier 10
HP_center(,,"Demonstrating use of HP_prmode()",nPageW);qout()
HP_center(,,"and text processing with full justification.",nPageW);qout()
HP_center(,,HPreplicate("=",HP_data(D_RMI)-HP_data(D_LMI)),nPageW);qout()
qout()
HP_scalef(48) // use 48 Pt universe
qout()
HP_textmode(TMGRAY,40) // select gray shade
HP_fjust(,,cStr,nPageW) // print text
/* if you have do not have enough memory in your printer
then you may get a printer overrun error. Use the following
to replcae the 4 code lines above.
HP_scalef(48) // use 48 Pt universe
aGray:={10,20,30,40} // make gray shade array
qout()
HP_setpos(-0.02*len(aGray),0.02*len(aGray),.t.)
for i:=1 TO len(aGray)
HP_textmode(TMGRAY,aGray[i]) // select gray shade
HP_savecsr() // save csr
qqout(cStr) // print text
HP_restcsr() // restore csr
HP_setpos(0.02,0.02,.t.) // move down and right a little
next
*/
/* uncomment the following to print white on black
HP_setpos(,0.5) // move csr (CAP) to left margin
HP_bar(1.25/HP_data(D_LPI),7,GFILLBLACK)
qout()
aGray:={10,20,30,40}
for i:=1 TO len(aGray)
HP_textmode(TMGRAY,aGray[i])
HP_savecsr()
qqout(cStr)
HP_restcsr()
HP_setpos(0.02,0.02,.t.)
next
HP_textmode(TMWHITE)
qqout(cStr)
*/
HP_prmode() // print mode to default
HPprtext(cStr1,0.5,7) // print the text we read from "bcnn.txt" file
HP_bar(HPfxheight(),nPageW,GFILLGRAY,20)
qout()
// change font to UNIVERSE using the current size, style
HP_scalef(,,,,,TF_UNIVERSE)
HP_rbox(1.5,nPageW)
HP_lmiset(0.7) // new margin
qout("This entire page created with ProHP. We used column definintion and relative cursor")
qout("positioning and printing.")
qout("You can easily modify the code for your own purposes, change orientation, add more")
qout("columns/pages or change width, height, justification, typeface or style.")
HP_scalef(14,,3,,TF_UNIVERSE);qout();qout()
HP_negative(" I.L.A., Inc. (407) 774-7734, (800) 374-7734 USA and CANADA ",GFILLGRAY,100)
qout()
HP_reset() // Finished, this clears and exits.
set2screen()
return
/*
The following procedure will show you how easily you can
control text with ProHP. Please modify this code as you
like ( play with it ) and watch the result of your
changes. You can use this technique to design
multi column reports and forms.
*/
Function HPprtext(cStr1,nLeft,nWidth,cJust,cDelim,nStart)
Local cLine:="",nStartAt:=1,nLines:=0,nRest:=0,ohmi:=0
Local nSpaces:=0,nLinesize:=0
Local nPt,nStyle,nWgt,nTF,nPoints,nLogoH,nCalH
Local nStlen:=len(cStr1),lRtrim:=.t.,trspc:=0
Local nColW,nColH,nTop,nCol,nBoxH,nBoxW,aCol,nHpos,nCLeft,nCmarg,nCtop,nCapH
nStartAt:=iif(nStart==NIL,nStartAt,nStart)
cJust:=iif(cJust==NIL,"L",cJust)
nWidth:=HPcur2i(nWidth)
nPt:=11
nStyle:=ITALIC // UPRIGHT
nWgt:=0
nTF:=TF_CGTIMES // 4116
HP_scalef(nPt,nStyle,nWgt,,nTF) // set working font
// lets define 4 columns
nCMarg:=0.2 // margins for columns
nColW:=(nWidth-(nCMarg*2))/4 // make 4 columns
nColH:=6 // set max column height to x
nCTop:=2 // start at top
nCLeft:=nLeft // use imported parameter
/*
define columns metrics
array (n Columns, array(5))
array column has 5 elements
[1] := nCtop (distance from top of page)
[2] := nCLeft ( distance from left of page )
[3] := nColW ( column width )
[4] := nColH ( column Height )
[5] := cCjust ( any of the following "L","C","R","F" )
Hint : You may add one or more elements to the above array to define
a column type ( mixed text and image (PCX) or other drawings ).
Define a font or point size.
*/
aCol:={ {nCTop,nCLeft,nColW,nColH,"F"},;
{nCTop,nCLeft+nColW+nCMarg,nColW*2,nColH/2,"F"},;
{nCTop,nCLeft+(nColW*3)+(nCmarg*2),nColW,nColH,"F"}}
// {nCTop+nColH,nCLeft,nWidth,nColH,"F"}}
HP_data(D_FONTWCHARS)[32] := HP_data(D_HMI)*10
nCol:=1 // start at column 1
nHpos:=0 // use this to keep track of line position
nWidth:=aCol[nCol,3] // set width for current column
cJust:=aCol[nCol,5] // set justification
nLeft:=aCol[nCol,2] // set left of column
HP_setpos(aCol[nCol,1],aCol[nCol,2]) // posotion csr at begining of column
/*
get the first line. Notice that the width must be in inches * 1200
this is to match the character width table of the font, and insure
high accuracy.
*/
cline:=_hpgetline(cStr1,nWidth*1200,cDelim,@nStartAt,HP_data(D_FONTWCHARS),@nSpaces)
// nHpos+=1/HP_data(D_LPI) // keep track of cursor pos
WHILE .T.
if nLeft!=0 .and. nLeft!=NIL
HP_setpos(,nLeft) // go to the left margin
else
// line will be printed started at the left margin
endif
nLines++ // count the lines printed
// to make nice full justification we'll trim spaces from the right
cLine:=iif(lRtrim,trim(cLine),cLine)
// switch cJust
do case
case cJust== "F"
// print full justify.
if nSpaces > 0
HP_fjust(,,cline,nWidth)
else
qqout(cline) // no full justification if end of paragraph
endif
case cJust== "C"
HP_center(,,cline,nWidth) // center between the current CAP
// and CAP+nWidth
case cJust== "R"
HP_setpos(,nWidth,.t.) // move to end of line
HP_rjust(,,cline) // print right justify
otherwise
qqout(cline) // just print the line starting at CAP
endcase
qout() // advance to next line
if nStartAt >= nStlen // check that we still have text to process
exit // otherwise exit loop
endif
nHpos+=1/HP_data(D_LPI) // keep track of cursor position
if nHpos > aCol[nCol,4] // if it is over the H limit of the current column
if nCol=2 // we left space to draw a box
HP_setpos(,aCol[nCol,2]) // go to column left margin
// get capital height
nCapH:=HPfcapH() // HPi2cur(zDU2i(HP_data(D_SCALEFDATA)[CAPHEIGHT]))
HP_setpos(-(nCapH),,.t.)
nBoxH:=aCol[nCol-1,4]-nHpos-nCapH+abs(HPfdescent()) // find height available for box
nBoxW:=aCol[nCol,3] // box width = column width
nCalH:=nBoxH*.8
HP_savecsr()
HPdrawmonth(date(),aCol[nCol,1]+nHpos-nCapH,aCol[nCol,2],nCalH,aCol[nCol,3],.t.)
HP_restcsr()
HP_setpos(nCalH,,.t.)
HP_setpos(nCMarg/2,,.t.)
nLogoH:=nBoxH-nCalH-(nCMarg/2)
HP_rbox(nLogoH,nBoxW) // draw the box
/*
HP_savecsr() // save csr for next process
HP_setpos(nCmarg/2,nCmarg/2,.t.) // pos csr for margins
HP_restcsr() // restore csr
*/
// draw black area
HP_bar(nLogoH,nBoxW,GFILLBLACK)
HP_textmode(TMWHITE) // make text appear as white
nPoints:=round((nCalH*.2)*.8*72,2)
HP_scalef(nPoints,,3,,TF_UNIVERSE) // 64 Pt Universe bold
nCapH:=HPfcapH() // HPi2cur(zDU2i(HP_data(D_SCALEFDATA)[CAPHEIGHT]))
HP_setpos((nLogoH-nCapH)/2+nCapH,,.t.) // Position to vertical center
HP_center(,,"ProHP",nBoxW) // and horizontal center the text
HP_prmode() // default print mode
endif
HP_scalef(nPt,nStyle,nWgt,,nTF) // back to normal point
HPstsize("") // this will make sure we have a correct and current
// width table
nCol++ // skip to next column
if nCol > len(aCol) // have we used all column
exit // Yes, exit
/*
at this point you can eject a page and use the same or another
column array to print the rest of the text or go out to
another procedure. nStartAt saves the position of the text
printed so far */
endif
cJust:=aCol[nCol,5] // set new justification
nHpos:=0 // 1/HP_data(D_LPI) // reset H pos
nWidth:=aCol[nCol,3] // new width for new column
nLeft:=aCol[nCol,2] // new left pos
nTop:=aCol[nCol,1] // new top pos
HP_setpos(nTop,nLeft) // move cursor to new location
endif
// get the next line
cLine:=_hpgetline(cStr1,nWidth*1200,cDelim,@nStartAt,HP_data(D_FONTWCHARS),@nSpaces)
enddo
return nLines
// use this function
Function HPlcount(cStr1,nWidth,cDelim,nStart)
Local cLine:="",nStartAt:=1,nLines:=0,nRest:=0,ohmi:=0
Local nSpaces:=0,nLinesize:=0
Local nStlen:=len(cStr1),lRtrim:=.t.,trspc:=0
nStartAt:=iif(nStart==NIL,nStartAt,nStart)
cline:=_hpgetline(cStr1,HPcur2i(nWidth)*HP_data(D_UOM),cDelim,@nStartAt,HP_data(D_FONTWCHARS),@nSpaces,@nLinesize,lRtrim)
while(.t.)
nLines++
if nStartAt >= nStlen
exit
endif
cline:=_hpgetline(cStr1,HPcur2i(nWidth)*HP_data(D_UOM),cDelim,@nStartAt,HP_data(D_FONTWCHARS),@nSpaces,@nLinesize,lRtrim)
enddo
return nLines
FUNCTION HP_textmode(nMode,nVal)
Local os:=HP_send(.f.),o:=''
do case
case nMode=1 // gray text
// nVal : see gray shading level in the manual
o:=HP_prmode(TRANSPARENT,OPAQUE,nVal,GFILLGRAY)
case nMode=2 // pattern text
// nVal : 1 - 6 , see FILL PATTERNS in the manual
o:=HP_prmode(TRANSPARENT,OPAQUE,nVal,GFILLPATTERN)
case nMode=3 // Black text
// nVal : ignored
o:=HP_prmode(TRANSPARENT,OPAQUE,nVal,GFILLBLACK)
case nMode=4 // white text
// nVal ignored
o:=HP_prmode(TRANSPARENT,OPAQUE,nVal,GFILLWHITE)
otherwise
// default mode = black
o:=HP_prmode(TRANSPARENT,TRANSPARENT,0,0)
endcase
HP_send(os)
return iif(HP_send(),qqout(o),o)