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

  1. /*
  2.   ┌─────────────────────────────────────────────────────────────────────────┐
  3.   │                                                                         │
  4.   │    Program : PCX.PRG                                                    │
  5.   │                                                                         │
  6.   │    Purpose : To demonstrate use of ProHP PCX functions.                 │
  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 "propcx.ch"
  18.  
  19. proc main(cPcxf,lpt)
  20. Local aPcx[14],cPcxFile:="",cLpt:="LPT1"
  21. Local nImageH,nImageW,nMarg:=0.05
  22. Local bImageH,bImageW,nRes
  23. Local nTop:=0.5,nLeft:=0.5
  24. bImageW:={|r|HPi2cur((aPcx[PCXX2]-aPcx[PCXX1]+1)/r)}
  25. bImageH:={|r|HPi2cur((aPcx[PCXY2]-aPcx[PCXY1]+1)/r)}
  26.  
  27. if cPcxF==NIL
  28.    scroll(,,,,5)
  29.    accept "Show data for PCX file : " to cPcxFile
  30. else
  31.    cPcxFile:=trim(cPcxF)
  32. endif
  33.  
  34. cls
  35. HP_init()
  36. aPcx:=pcx_info(cPcxFile,.t.)    // read image info into array
  37.  
  38. scroll(,,,,5)
  39. qout("Sending Image to :",cLpt, ", Please Wait...")
  40. if lpt!=NIL
  41.    cLpt:=lpt
  42. endif
  43. set2print(cLpt)
  44.  
  45. HP_stmacro(1)   // start a macro definition
  46. SET2SCREEN()
  47. HP_PRpcx(cPcxFile,.f.,cLpt)       // send macro data
  48. SET2PRINT(cLpt,.T.)
  49. HP_endmacro(1,PERMMACRO)        // make macro permanent
  50.  
  51. HP_orient(LANDSCAPE)
  52. HP_rastdir(0)   // direction of printing for raster image
  53. HPshadow(.t.)   // we like shadow boxes
  54. nRes:=100
  55. HP_setres(nRes)  // use 100 DPI
  56. nImageH:=eval(bImageH,nRes)
  57. nImageW:=eval(bImageW,nRes)
  58. HP_setpos(nTop,nLeft)   // position cursor
  59. HP_savecsr()    // save CAP
  60. HP_rbox(nImageH+(nMarg*2),nImageW+(nMarg*2))
  61. HP_setpos(nMarg,nMarg,.t.)      // move nMarg down and nMarg to the right
  62. HP_prmode(TRANSPARENT,OPAQUE,50,GFILLGRAY)      // print as 50% gray shade
  63. HP_callmacro(1)         // print image
  64. HP_prmode()     // back to default
  65. HP_restcsr()    // restore CAP
  66.  
  67. // Now we draw the same image using 300 DPI resolution
  68.  
  69. HP_setpos(0,nImageW+(nMarg*5),.t.)      // move to next pos
  70. HP_savecsr()    // save CAP
  71. nRes:=300
  72. HP_setres(nRes)
  73. nImageH:=eval(bImageH,nRes)
  74. nImageW:=eval(bImageW,nRes)
  75. HP_rbox(nImageH+(nMarg*2),nImageW+(nMarg*2))
  76. HP_setpos(nMarg,nMarg,.t.)      // move nMarg down and nMarg to the right
  77. HP_callmacro(1)         // print image
  78. HP_restcsr()    // restore CAP
  79.  
  80.  
  81. // set new H and W for image
  82.  
  83. HP_setpos(nImageH+(nMarg*5),0,.t.)      // move to next pos
  84. HP_savecsr()    // save CAP
  85. nRes:=300
  86. HP_setres(nRes)
  87.  
  88. nImageH:=eval(bImageH,nRes)* 0.75       // reduce Height to 75%
  89. nImageW:=eval(bImageW,nRes)* 0.6        // reduce Width to 60%
  90.  
  91. HP_rastW(nImageW*nRes)  // set Width of raster
  92. HP_rastH(nImageH*nRes)  // set Height of raster
  93.  
  94. HP_rbox(nImageH+(nMarg*2),nImageW+(nMarg*2))
  95. HP_setpos(nMarg,nMarg,.t.)      // move nMarg down and nMarg to the right
  96. HP_callmacro(1)         // print image
  97. HP_restcsr()    // restore CAP
  98.  
  99. HP_reset()
  100. // PCX image is still kept in printer memory
  101. set2screen()
  102. return
  103.  
  104. Function pcx_info(cPcxFile,lShow)
  105. Local aPcxDescr,aPcx[PCXDATASIZE]
  106. Local i,nLm:=5,nLm2:=36,nTop:=4,nTtop:=0
  107. Local nImageW:=0,nImageH:=0,sFactor:=1
  108. Local nWIsize,nHIsize,nWCMsize,nHCMsize
  109. aPcxDescr := {;
  110.  cPCXMANUF,cPCXVERSION,cPCXRLE,cPCXBITPIXEL,cPCXX1,cPCXY1,cPCXX2,;
  111.  cPCXY2,cPCXHRES,cPCXVRES,cPCXPLANES,cPCXBYTELINE,cPCXSCANNERH,cPCXSCANNERV }
  112. lShow:=iif(lShow==NIL,.f.,lShow)
  113. if (pcxinfo(trim(cPcxFile),aPcx) < 0)
  114.    qout("Error reading file :",cPcxFile)
  115.    wait
  116.    return {}
  117. endif
  118. if lShow
  119. cls
  120. @ 0,0 TO maxrow(),maxcol() DOUBLE
  121. @ 0,1 SAY padc("[ PCX image Info. ]",maxcol()-2,"═")
  122. @ 2,nLm say "PCX File : "+cPcxFile
  123. nTtop:=nTop
  124. for i:=1 to len(aPcx)
  125.     @ ++nTop,nLm say padr(aPcxDescr[i],18,".")+"="+str(aPcx[i],8)
  126. next
  127.  
  128. nTop:=nTtop
  129. set decimal to 2
  130. sFactor:=2.54
  131. nImageW:=aPcx[PCXX2]-aPcx[PCXX1]+1
  132. nImageH:=aPcx[PCXY2]-aPcx[PCXY1]+1
  133. nWIsize:=nImageW/300
  134. nHIsize:=nImageH/300
  135. nWCMsize:=nImageW/300*2.54
  136. nHCMsize:=nImageH/300*2.54
  137.  
  138. @ ++nTop,nLm2 say "Image size :"+str(nImageW,5)+" W "+str(nImageH,5)+" H pixels."
  139. nTop++
  140. @ ++nTop,nLm2 SAY "Res. "+padc("Size Inch",12)+'   '+padc("Size CM",12)
  141. @ ++nTop,nLm2 SAY "---- "+PADC("",12,"-")+'   '+PADR("",12,"-")
  142. @ ++nTop,nLm2 SAY " 300 "+str(nWIsize,5,2)+" x"+str(nHIsize,5,2)+'  '+str(nWCMsize,5,2)+" x"+str(nHCMsize,5,2)
  143. @ ++nTop,nLm2 SAY " 150 "+str(nWIsize*2,5,2)+" x"+str(nHIsize*2,5,2)+'  '+str(nWCMsize*2,5,2)+" x"+str(nHCMsize*2,5,2)
  144. @ ++nTop,nLm2 SAY " 100 "+str(nWIsize*3,5,2)+" x"+str(nHIsize*3,5,2)+'  '+str(nWCMsize*3,5,2)+" x"+str(nHCMsize*3,5,2)
  145. @ ++nTop,nLm2 SAY "  75 "+str(nWIsize*4,5,2) +" x"+str(nHIsize*4,5,2)+'  '+str(nWCMsize*4,5,2) +" x"+str(nHCMsize*4,5,2)
  146. set decimal to
  147. @ maxrow()-2,nLm say "Press Any key to continue..."
  148. inkey(0)
  149. endif
  150.  
  151. return aPcx
  152.  
  153.