NPRG - generate reports to graphic output devices


SYNOPSYS

 use Wingraph;
 use NPRG;
 $dc=new Wingraph(device=>'PS', desc=>'Desc' [, metafile=>'metafilename');
 $rp=new NPRG(dc=>$dc);
 $rp->{'atbreak'}=sub {...}
 $rp->{'beforebeak'}=sub {...}
 $rp->pushq({...},{...}...{...});
 $rp->flushq();

DESCRIPTION

This module allow you generate reports to graphic outpus deviceses using objects like Wingraph. The $dc object must have methods, described in the Wingraph manpage documentation.

NPRG methods

new
Create new NPRG object. Parameter passed by hash, allowed: dc and footerh. The dc is object like Wingrpah. Description of footerh see below.

$rp->{'atbreak'}
Allows you set up callback to proceed page breaking, after page eject. To function passed only one parameter - the report object itself.

$rp->{'beforebreak'}
Like 'atbreak', but only before page eject. You can reserve page space for footer by creating report object with footerh parameter - the footerh virtual points will be reserved and every page for footer.

$rp->pushq({}...{})>, $rp->flushq()
The pushq functions is core of NPRG. At every call of pushq the report data pushed into report queue, and at every call of flushq() data flushed. If no enough space in page then page ejected, calling the NextPage method of $dc object. Data, pushed together between flushq calls cannot be splitted between pages. Data passed as array of references to hashes, where every hash described a column, and this columns will be equal high and placed from the left to the right in order when they appear in pushq call. For example, call
$rp->pushq( {width=>100, value=>'1.Lala'},
            {width=>200, value=>'1.Dodo'}
     );
$rp->pushq( {width=>100, value=>'2.Lala'},
            {width=>200, value=>'2.Dodo'}
     );
$rp->flushq();

give the something like

<PRE> 1.Lala 1.Dodo 2.Lala 2.Dodo </PRE>

and so on. You can use following hash pairs in column hashes:

HashDescription
fontoptional. Specifies font for data in format, understanding by $dc object, 'Courier, 12, 0' for example.
widthrequired.Width of column in vitrual points.
valueoptional. Value to display. If value is scalar then corresponding string is displayed. If value is reference to sub, then this sub will be called. In addition to decribed here params new params $dc, xpos, ypos, 'height', width, compute will be passed. xpos, ypos defines the coordinates of top left corner of bounding rectangle, width and height defines width and height. If parameter compute is defined then sub must return minimal requred height of rectangle, if not - display the data. See drawmatrix sub for detail and as example.
borderoptional. Define a border around displayed data. Must be string with T>, B, L, R chars for border on top, bottom, left and right side of bounding rectangle. Default is empty string.
penoptional. Define width of pen of border. Default =1.
brushoptional. Define the brush to fill background. If not defined then background is not filled.
optoptional. Define the style used to display data. Must be string of chars. These chars are:
Horiz alignment
LLeft-aligment text
RRight-alignment
JJustified
Vert alignment
-Center
VBottom
emptyTop
you can use any case.
heightMinimail height of displayed data

drawmatrix subroutine

drawmatrix sub allow to display structured data into one cell of report. drawmatrix use matrix hash key, which is a reference to array of references to array of references to hashes:

$val is:
[
  [{},{},{}...{}]
  [{},{},{}...{}]
  ....
  [{},{},{}...{}]
]

Size of each cell in displayed matrix is 1/n of total width, where n is a number of columns in matrix row.

Putting all together

use ExtUtils::testlib;
use Wingraph;
use NPRG qw(drawmatrix);
$dc=new Wingraph( device=>"PS",  desc=>'test', metafile=>'tsta.emf') or die; #orientation=>'Landscape',
print "Start\n";
%st1=(font=>'Times New Roman Bold', size=>12, opt=>'C', border=>'TBLR', pen=>2);
$rp=new NPRG(dc=>$dc);
$rp->{'atbreak'}=sub{
                  $rp->pushq({font=>'Times, 6', opt=>'R', border=>'B', value=>'Отчет по чему-то там, стр. '.$rp->pagenum(), width=>980}
                            );
                  $rp->pushq({height=>20, value=>' ', width=>100}
                            );
                  $rp->pushq({font=>'Arial italic, 16', opt=>'-L', border=>'TBLR', value=>'Пушкин', width=>300, brush=>220},
                             {font=>'Courier Bold, 12', opt=>'-C', border=>'TBLR', value=>'Что-то еще', width=>250, brush=>220},
                             {value=>\&NPRG::drawmatrix, width=>400,
                                matrix=>[
                                  [ {font=>'Arial Bold Italic, 12', value=>'Месяцы', border=>'TBLR', opt=>'C'}],
                                  [
                                      {font=>'Times New Roman,8', value=>'I', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,8', value=>'II', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,8', value=>'III', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,8', value=>'IV', border=>'TBLR', opt=>'-C'},
                                  ],
                                  [
                                      {font=>'Times New Roman,7', value=>'I', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'II', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'III', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'IV', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'V', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'VI', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'VII', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'VIII', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'IX', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'X', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'XI', border=>'TBLR', opt=>'-C'},
                                      {font=>'Times New Roman,7', value=>'XII', border=>'TBLR', opt=>'-C'},
                                   ]
                                ],
                             }
                            );
                  $rp->pushq({width=>950, height=>3, brush=>0});
                  $rp->flushq();
                  print "Here\n";
               };
$rp->{'beforebreak'}=sub{
                  $rp->pushq({height=>20, value=>' ', width=>100}
                            );
                  $rp->pushq({font=>'Times New Roman, 12', opt=>'R', border=>'T', value=>'Отчет по чему-то там, стр. '.$rp->pagenum(), width=>980}
                            );
                  $rp->flushq();
               };
%st=(font=>'Courier New Bold, 10', opt=>'C-', border=>'TBLR');
for(1..10){
   $rp->pushq({height=>20, value=>' ', width=>100}) if $rp->pagenum == $oldpagenum;
   $oldpagenum=$rp->pagenum;
   for(1..4){
     $rp->pushq( {font=>'Times New Roman, 12', opt=>'JL', border=>'TBLR', value=>'Вот пистолеты уж',
                  width=>300},
                 {font=>'Courier Bold Italic, 12', opt=>'-C', border=>'TBLR', value=>"$_ 12121-1212", width=>250},
                 {width=>400, value=>\&drawmatrix,
                 matrix=>[
                           [{value=>"$_", %st},{value=>"$_", %st},{value=>"$_", %st},{value=>"$_",%st},]
                         ]
                 }
          );
   }
   $rp->flushq();
}
$rp->flushq();
print "End\n";
You must got something like:

It's all, folks!

Back to Top


AUTHOR

Copyright 2000 Ivan Frolcov.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Back to Top

 NPRG - generate reports to graphic output devices