Location: PHPKode > scripts > APrint > aprint/aprint.php
<?php
  /**
   * APrint.php
   *
   * Simple class for printing text
   *
   * $Header: d:\cvs/classistd/aprint/aprint.php,v 1.15 2005/02/13 20:29:29 Darvin Exp $
   * 
   * @author Andrioli Darvin
   * @version 1.4.0
   *
   * @copyright 
   * Copyright (C) 2003-2005  Andrioli Darvin <hide@address.com>
   *
   *   This library is free software; you can redistribute it and/or
   *   modify it under the terms of the GNU Lesser General Public
   *   License as published by the Free Software Foundation; either
   *   version 2 of the License, or (at your option) any later version.
   *
   *   This library is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   *   Lesser General Public License for more details.
   *
   *   You should have received a copy of the GNU Lesser General Public
   *   License along with this library; if not, write to the Free Software
   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
   *
   */

/**
 * Print using courier new, with predefined size, weight 400 (normal)
 * @const AP_NORMAL_FONT
 * @access public
 */
define('AP_NORMAL_FONT',0);   // print using NORMAL FONT
/**
 * Print using courier new, with predefined size, weight 800 (bold)
 * @const AP_BOLD_FONT
 * @access public
 */
define('AP_BOLD_FONT',1);   // print using bold font
/**
 * Small font used to print the page's footer
 * @const AP_FOOTER_FONT
 * @access public
 */
define('AP_FOOTER_FONT',2);
/**
 * left text align.
 * @const AP_LEFT
 * @access public
 * @see text()
 */
define('AP_LEFT',0);
/**
 * center text align.
 * @const AP_CENTER
 * @access public
 * @see text()
 */
define('AP_CENTER',1);
/**
 * right text align.
 * @const AP_RIGHT
 * @access public
 * @see text()
 */
define('AP_RIGHT',2);

/**
* class APrint
*
*/
class APrint {

/**
* Selected printer (Windows name)
*
* @var string $PrinterName
*/
var $PrinterName;
/**
 * I've already established a connection to the printer?
 *  (TRUE/FALSE)
 * @var bool $ConnectionOpened
 */
var $ConnectionOpened;
/**
* printer handler
*
* @var resource
*/
var $hPrinter;

/**
* Current row
* @var integer
*/
var $row;

/**
* Orizontal resolution
* @var integer
*/
var $Res_X;
/**
* Vertical resolution
* @var integer
*/
var $Res_Y;

/**
* Value for the font height
* @var integer
*/
var $FontH;
/**
* Value for the font width
*
*/
var $FontW;
/**
* Page counter
*
*/
var $NPag;

/**
* handler of current selected font
*/
var $CurrentFont;
/**
* Paper hight
*
*/
var $PaperDimX;
/**
* Paper width
*
*/
var $PaperDimY;
/**
* Margins, size of the top margin
*/
var $MarginTop;
/**
* Margins, size of the bottom margin
*/
var $MarginBottom;
/**
* Margins, size of the left margin
*/
var $MarginLeft;
/**
* Margins, size of the right margin
*/
var $MarginRight;

/**
* array with all created font
* @var array $FontTable
* @see CreateFont()
*/
var $FontTable;

/**
* Job name
* @var string $JobTitle
* @see _OpenPrinter()
*/
var $JobTitle;

var $ScriptId;
/**
 * Callbacks array. Ths index holdsall callback defined.
 * Each index map to a particular function that supports the callback
 * The supported call back are:
 * 'newpage' -> Call the function each time just before execute the
 *              'NewPage' function code
 *
 * @var array
 * @see NewPage()
 * @see SetCallBack();
 * @see $CallBacksParm
 */
var $CallBacks;
/**
 * Parameters for the callbacks functions
 * @var array
 * @see $CallBacks
 */
var $CallBacksParm;
/**
 * Array holding the supported callbacks
 * @var array
 * @see SetCallBack()
 */
var $ValidCallbacks=array('newpage');
/**
 * Should this module print its own page footer. If set to
 * false, you may supply your custom footer using TextFooter
 * and 'newpage' callback
 * @var boolean
 * @see NewPage()
 * @see TextFooter()
 * @see SetPrintFooter()
 */
var $PrintPageFooter=TRUE;
/**
 * Array holding the supported unit of measure used by movement
 * function.
 * @var array
 * @see MvRelativePos()
 * @see MvAbsolutePos()
 */
var $ValidMeasure=array('row','mm','inch','twip');
/**
 * Array containing texts to print as header into each page
 * Also, into the array are stored the font id request to print the text
 * You may set different font to each row.
 * @var array
 * @see SetNewPageHeader()
 */
var $NewPageHeader;
/**
 * @var boolean
 * @see SetAutoNewPage()
 */
var $AutoNewPage;
/**
* Initialize this class. It doesn not attempt to
* establish the connection to the printer
* This class will perform this job at the first time that you send any text
* @param string $TitleText document title
* @param string $ScriptId script identification
* @access public
*/
function APrint($TitleText="",$ScriptId="") {
$this->PrinterName=""; // If no choice, use the default printer
$this->ConnectionOpened=false;
$this->row=10;
$this->NPag=0;
// Margins default settings
$this->MarginTop=400;
$this->MarginBottom=400;
$this->MarginLeft=40;
$this->MarginRight=40;
// Start with an empty array
$this->FontTable=array();
// Initial value for paper size. I'll set the correct value after I'll open the connection
// to the printer
$this->PaperDimX=-1;
$this->PaperDimY=-1;
$this->JobTitle=$TitleText;
$this->ScriptId=$ScriptId;
$this->CallBacks=array();
$this->CallBacksParm=array();
$this->NewPageHeader=array();
$this->SetAutoNewPage(TRUE);
}
/**
* inizialize all parameter about the page size
* Require a printer handler.
* Unit used: twip,
* 1 inch = 1440 twip
* 1 mm = 56.7 twip
* @access private
*/
function _DefinePageSize()
{
$PaperType=printer_get_option($this->hPrinter, PRINTER_PAPER_FORMAT);
switch($PaperType)
  {
  case PRINTER_FORMAT_CUSTOM:
       // custom paper width in mm
       $this->PaperDimX=printer_get_option($this->hPrinter, PRINTER_PAPER_WIDTH)*56.7;
       $this->PaperDimY=printer_get_option($this->hPrinter, PRINTER_PAPER_LENGTH)*56.7;
       break;
  case PRINTER_FORMAT_LETTER:
       $this->PaperDimX=8.5*1440;
       $this->PaperDimY=11*1440;
       break;
  case PRINTER_FORMAT_LEGAL:
       $this->PaperDimX=8.5*1440;
       $this->PaperDimY=14*1440;
       break;
  case PRINTER_FORMAT_A3:
       $this->PaperDimX=297*56.7;
       $this->PaperDimY=420*56.7;
       break;
  case PRINTER_FORMAT_A4:
       $this->PaperDimX=8*1440;
       $this->PaperDimY=11.69*1440;
       break;
  case PRINTER_FORMAT_A5:
       $this->PaperDimX=148*56.7;
       $this->PaperDimY=210*56.7;
       break;
  case PRINTER_FORMAT_B4:
       $this->PaperDimX=250*56.7;
       $this->PaperDimY=354*56.7;
       break;
  case PRINTER_FORMAT_B5:
       $this->PaperDimX=182*56.7;
       $this->PaperDimY=257*56.7;
       break;
  case PRINTER_FORMAT_FOLIO:
       $this->PaperDimX=8.5*1440;
       $this->PaperDimY=13*1440;
       break;

  default:
       $this->PaperDimX=8.27*1440;
       $this->PaperDimY=11.69*1440;
       break;
       // trigger_error("Paper format type:".$PaperType." not supported",E_USER_ERROR);
  }
// Now that I know the size of the page, I check tha value for margins
$this->_CheckMarginValue();
}

/**
 * Check the value for the margin. They should be >0 and
 * less then the page size
 *
 * @access private
 */
function _CheckMarginValue()
{
if($this->MarginTop<0)
  trigger_error("Top margin is < 0. It should be greater or equal to 0",E_USER_ERROR);
if($this->PaperDimY>0 && $this->MarginTop>$this->PaperDimY)
   trigger_error("Top margin bigger then paper size",E_USER_ERROR);
  
if($this->MarginBottom<0)
  trigger_error("Bottom margin is < 0. It should be greater or equal to 0",E_USER_ERROR);
if($this->PaperDimY>0 && $this->MarginBottom>$this->PaperDimY)
   trigger_error("Bottom margin bigger then paper size",E_USER_ERROR);
if($this->PaperDimY>0 && ($this->MarginBottom+$this->MarginTop)>$this->PaperDimY)
   trigger_error("No rows to write left. Bottom margin + top margin bigger then paper size",E_USER_ERROR);

if($this->MarginLeft<0)
  trigger_error("Left margin is < 0. It should be greater or equal to 0",E_USER_ERROR);
if($this->PaperDimX>0 && $this->MarginLeft>$this->PaperDimX)
   trigger_error("Left margin bigger then paper width",E_USER_ERROR);

if($this->MarginRight<0)
  trigger_error("Right margin is < 0. It should be greater or equal to 0",E_USER_ERROR);
if($this->PaperDimX>0 && $this->MarginRight>$this->PaperDimX)
   trigger_error("Right margin bigger then paper width",E_USER_ERROR);
if($this->PaperDimX>0 && ($this->MarginLeft+$this->MarginRight)>$this->PaperDimX)
   trigger_error("No columns to write left. Left margin + right margin bigger then paper width",E_USER_ERROR);

}

/**
 * Set the callback function
 * @param string $callback which callback apply the function
 * @param mixed $func function name or array holding object and method
 *                    (see call_uzer_func_array manual page for more detail)
 * @param array $parm parameters to pass to the function
 * @access public
 * @see $ValidCallbacks
 * @see $CallBacks
 */
function SetCallBack($callback,$func,$parm)
{
if(!in_array($callback,$this->ValidCallbacks))
  trigger_error('Callback '. $callback. ' does not supported',E_USER_ERROR);
$this->CallBacks[$callback]=$func;
$this->CallBacksParm[$callback]=$parm;
}

/**
 * Useful function to setup all margins with one function
 * use -1 to skip the parameter
 *
 * @param integer $top top margin size
 * @param integer $bottom bottom margin size
 * @param integer $left left margiclass
 * @param integer $right right margin size
 * @access public
 */

function SetMargin($top,$bottom=-1,$left=-1,$right=-1)
{
if(!($top<0))
   $this->MarginTop=$top;
if(!($bottom<0))
   $this->MarginBottom=$bottom;
if(!($left<0))
   $this->MarginLeft=$left;
if(!($right<0))
   $this->MarginRight=$right;
$this->_CheckMarginValue();
}

/**
 * Set the size for the top margin
 * @param integer
 * @access public
 */
function SetTopMargin($value)
{
$this->MarginTop=$value;
$this->_CheckMarginValue();
}
/**
 * Set the size for the bottom margin
 * @param integer
 * @access public
 */
function SetBottomMargin($value)
{
$this->MarginBottom=$value;
$this->_CheckMarginValue();
}
/**
 * Set the size for the left margin
 * @param integer
 * @access public
 */
function SetLeftMargin($value)
{
$this->MarginLeft=$value;
$this->_CheckMarginValue();
}

/**
 * Set the size for the right margin
 * @param integer
 * @access public
 */
function SetRightMargin($value)
{
$this->MarginRight=$value;
$this->_CheckMarginValue();
}

/**
 * Specifiy which printer I'll use. If you don't give any printer, the default printer
 * will be used.
 * @param string $Name printer name as defined in Window
 * @access public
 */
function SetPrinter($Name)
{
if($this->ConnectionOpened)
  trigger_error("Set the printer name before send any text (or title)",E_USER_ERROR);
$this->PrinterName=$Name;
}

/**
 * Set if the module should print its own footer or not.
 * @param bool $print TRUE=print its own page footer
 * @access public
 */
function SetPrintFooter($print)
{
$this->PrintPageFooter=$print;
}

/**
 * Setup the text to print on each page.
 * The text, passed as array, allow you to pass many rows
 * ( 1 row =  1 item).
 * @var array text to print. Due to compatibility toward previous version
 *                           text may be a string, in that case font will be ignored
 * @var array font to use to print each row
 * @var bool Should I print the header on the first page?
 * @access public
 */
function SetPageHeader($Text,$fontArray=array(),$OnFirstPage=true)
{
$this->PageHeader=$Text;
// Each call will destroy the previous values
$this->NewPageHeader=array();
if(is_array($Text))
  {
  // new parameters version aprint >= 1.2
  foreach($Text as $Key => $Value)
     {
     if(array_key_exists($Key,$fontArray))
       $txtFont=$fontArray[$Key];
     else
       $txtFont="";
     $this->NewPageHeader[]=array('Text'=>$Value,
                                  'Font'=>$txtFont);
     }
  }
else
  {
  // 1.0 version, $Text only one string
  $this->NewPageHeader[]=array('Text'=>$Text,
                               'Font'=>"");
  }
if($OnFirstPage&&$this->NPag==1)
  $this->PrintPageHeader();
}

/**
 * Set the AutoNewPage flag. If set to true, the module call the functionNewPage
 * automatically at the end of the page, if set to off, the user must call the
 * NewPage function
 * @param boolean
 * @return boolean The function returns the old value
 * @see NewPage()
 */
function SetAutoNewPage($bool)
{
$old=$this->AutoNewPage;
$this->AutoNewPage=$bool;
return($old);
}

/**
 * Write an header at the top of the first page.
 * @param string Text to print
 * @param integer $hFont font handle returned by CreateFont
 * @access public
 * @see CreateFont();
 */
function HeaderText($TitleText,$hFont=-1)
{
if(!$this->ConnectionOpened) $this->_OpenPrinter();
$this->Text("----------------------------------------------------------",AP_NORMAL_FONT);
$font=($hFont==-1)?AP_BOLD_FONT:$hFont;
$this->Text($TitleText,$font);
$this->Text("----------------------------------------------------------",AP_NORMAL_FONT);
}

/**
 * Skip a row, left a blank row.
 * @access public
 *
 */
function BlankRow()
{
if(!$this->ConnectionOpened) $this->_OpenPrinter();
$this->Text(" ");
}

/**
 * printout the text
 * @param string $text text to printout
 * @param integer $hFont Handle to the font to use. Handle returned by CreateFont
 * @param integer $align text alignment
 * @param integer $col Orizontal position where start to print the text. This value
 *                     will be added to the left margin.
 * @access public
 * @see CreateFont()
 * @see TextFooter()
 */
function Text($text,$hFont=-1,$align=AP_LEFT,$col=0)
{
if(!$this->ConnectionOpened) $this->_OpenPrinter();
// Select new font?
if($hFont!=-1)
   {
   $this->_SetFont($hFont);
   }
$this->FontH=$this->FontTable[$this->CurrentFont]['fontHeight'];
$width=$this->FontTable[$this->CurrentFont]['fontWidth'];
$textWidth=strlen($text)*$width;
$StartCol=$this->_BeginCol($align,$textWidth,$col);
printer_draw_text($this->hPrinter,$text,$this->ResConv_x($StartCol),$this->ResConv_y($this->row));
$this->row+=$this->FontH;
if($this->row>($this->PaperDimY-$this->MarginBottom-300-$this->FontH)&&$this->AutoNewPage)
  {
  $this->NewPage();
  }
}

/**
 * printout the text at the exact position requested
 * @param integer orizontal position
 * @param integer vertical position where print the text
 * @param string $text text to printout
 * @param integer $hFont Handle to the font to use. Handle returned by CreateFont
 * @access public
 * @see CreateFont()
 * @see Text()
 */
function TextXY($Xpos,$Ypos,$text,$hFont=-1)
{
if(!$this->ConnectionOpened) $this->_OpenPrinter();
// Select new font?
if($hFont!=-1)
   {
   $this->_SetFont($hFont);
   }
$this->FontH=$this->FontTable[$this->CurrentFont]['fontHeight'];
$width=$this->FontTable[$this->CurrentFont]['fontWidth'];
printer_draw_text($this->hPrinter,$text,$this->ResConv_x($Xpos),$this->ResConv_y($Ypos));
$this->row=$Ypos+$this->FontH;
if($this->row>($this->PaperDimY-$this->MarginBottom-300-$this->FontH)&&$this->AutoNewPage)
  {
  $this->NewPage();
  }
}

/**
 * Print the page header
 * @access public
 * @see Text()
 */
function PrintPageHeader()
{
if(!$this->ConnectionOpened) $this->_OpenPrinter();
$OriginalFont=-1;
// var_dump($this->NewPageHeader);
foreach($this->NewPageHeader as $Value)
  {
  	
  $Text=$Value['Text'];
  $hFont=$Value['Font'];
  // Select new font?
  // var_dump($hFont);
  if($hFont!=-1 && $hFont!="")
     {
     $oldFont=$this->_SetFont($hFont);
     }
   if($OriginalFont<0) $OriginalFont=$oldFont;
   $width=$this->FontTable[$this->CurrentFont]['fontWidth'];
   $FontH=$this->FontTable[$this->CurrentFont]['fontHeight'];
   $textWidth=strlen($Text)*$width;
   $StartCol=$this->_BeginCol(AP_LEFT,$textWidth,0);
   printer_draw_text($this->hPrinter,$Text,$this->ResConv_x($StartCol),
                     $this->ResConv_y($this->row));
   $this->row+=$FontH;
  }  // Loop on each row

if($OriginalFont>-1)
  $this->_SetFont($OriginalFont);
}


/**
 * Print the given text as page footer
 * @param string $text text to printout
 * @param integer $hFont Handle to the font to use. Handle returned by CreateFont
 * @param integer $align text alignment
 * @param integer $col Orizontal position where start to print the text. This value
 *                     will be added to the left margin.
 * @access public
 * @see CreateFont()
 * @see Text()
 */
function TextFooter($text,$hFont=-1,$align=AP_LEFT,$col=0)
{
if(!$this->ConnectionOpened) $this->_OpenPrinter();
// Select new font?
if($hFont!=-1)
   {
   $oldFont=$this->_SetFont($hFont);
   }
else
   {
   $oldFont=$this->_SetFont(AP_FOOTER_FONT);
   }
$width=$this->FontTable[$this->CurrentFont]['fontWidth'];
$FontH=$this->FontTable[$this->CurrentFont]['fontHeight'];
$textWidth=strlen($text)*$width;
$StartCol=$this->_BeginCol($align,$textWidth,$col);
printer_draw_text($this->hPrinter,$text,$this->ResConv_x($StartCol),
                  $this->ResConv_y($this->PaperDimY-$this->MarginBottom-$FontH));
printer_end_page($this->hPrinter);
$this->_SetFont($oldFont);
}

/**
 * This function compute the starting position given the
 * text alignment, the left margin and the starting column
 * @param integer $align text alignment
 * @param integer $textWidth text width
 * @param integer $col Orizontal position where start to print the text. This value
 *                     will be added to the left margin.
 * @access private
 * @see TextFooter()
 * @see Text()
 *
 */
function _BeginCol($align,$textWidth,$col)
{
switch($align)
  {
  case AP_LEFT:
       $StartCol=$this->MarginLeft+$col;
       break;
  case AP_CENTER:
       if(($this->MarginLeft+$this->MarginRight+$textWidth+$col)>$this->PaperDimX)
         $StartCol=$this->MarginLeft;
       else
         $StartCol=$this->MarginLeft+$col+floor(($this->PaperDimX-$this->MarginLeft-$this->MarginRight-$textWidth-$col)/2);
       break;
  case AP_RIGHT:       
       if(($this->MarginLeft+$this->MarginRight+$textWidth+$col)>$this->PaperDimX)
         $StartCol=$this->MarginLeft;
       else
         $StartCol=$this->PaperDimX-$this->MarginRight-$textWidth;
       break;
  }
return($StartCol);
}
  
/**
* Draw a dash line.
* @access public
*/
function Line()
{
$this->Text("----------------------------------------------------------");
}

/**
* Close the output to the printer and start to print
* @access public
*/
function run()
{
$this->_FooterNote();
printer_end_doc($this->hPrinter);
printer_close($this->hPrinter);
}

/**
 * Close the current page and start a new one.
 *
 * @access public
 */
function NewPage()
{
if(!$this->ConnectionOpened)
  trigger_error("Open the connection to the printer before run the function NewPage",E_USER_ERROR);
// run the callback, if set
if(array_key_exists('newpage',$this->CallBacks))
  call_user_func_array($this->CallBacks['newpage'],$this->CallBacksParm['newpage']);

if($this->NPag&&$this->PrintPageFooter) {
     $this->_FooterNote();
     }
if($this->NPag) {
   printer_end_page($this->hPrinter);
   }
$this->NPag++;
printer_start_page($this->hPrinter);
$this->row=$this->MarginTop;
$this->PrintPageHeader();
}

/**
 * Printout page number and script name as footer
 *
 * @access private
 */
function _FooterNote()
{
$oldFont=$this->_SetFont(AP_FOOTER_FONT);
printer_draw_text($this->hPrinter,$this->ScriptId,
                  $this->ResConv_x($this->MarginLeft),
                  $this->ResConv_y($this->PaperDimY-$this->MarginBottom-$this->FontTable[AP_FOOTER_FONT]['fontHeight']));
printer_draw_text($this->hPrinter,$this->NPag,
                  $this->ResConv_x($this->PaperDimX-$this->MarginRight-4000),
                  $this->ResConv_y($this->PaperDimY-$this->MarginBottom-$this->FontTable[AP_FOOTER_FONT]['fontHeight']));
$this->_SetFont($oldFont);
}

/**
* Create a new font
*
* @param string $fName Font Name, default: Courier New
* @param integer $fHeight Font height, default: 336
* @param integer $fWidth Font width, default: 168
* @param integer $fWeight Font weight, default: 400. 0 -> thin, 800 -> bold
* @param boolean $fItalic Italic script? True/False
* @param boolean $fUnderline Text with underline? True/False
* @param boolean $fStrikeout True/False
* @param integer $fOrientation Should be always 3 digits, i.e 020. See printer_create_font in the note to the manual
* @see _SetFont()
* @see Text()
* @access public
*
*/
function CreateFont($fName="Courier new",$fHeight=336,$fWidth=168,$fWeight=400,$fItalic=false,$fUnderline=false,$fStrikeout=false,$fOrientaton=0)
{
if(!$this->ConnectionOpened)
  trigger_error("Open the connection to the printer before define the font",E_USER_ERROR);
$LastFontId=count($this->FontTable);
$this->FontTable[$LastFontId]['fontName']=$fName;
$this->FontTable[$LastFontId]['fontHeight']=$fHeight;
$this->FontTable[$LastFontId]['fontWidth']=$fWidth;
$this->FontTable[$LastFontId]['fontWeight']=$fWeight;
$this->FontTable[$LastFontId]['fontItalic']=$fItalic;
$this->FontTable[$LastFontId]['fontUnderline']=$fUnderline;
$this->FontTable[$LastFontId]['fontStrikeout']=$fStrikeout;
$this->FontTable[$LastFontId]['fontOrientaton']=$fOrientaton;
// printer_create_font("Courier New",66,33,400,false,false,false,0);
$this->FontTable[$LastFontId]['fontHandler']=printer_create_font($fName,$this->ResConv_y($fHeight),$this->ResConv_x($fWidth),$fWeight,$fItalic,$fUnderline,$fStrikeout,$fOrientaton);
return($LastFontId);
}

/**
* Establish the connection to the printer
* @access private
*/
function _OpenPrinter()
{
if($this->PrinterName=="")
  $this->hPrinter=printer_open();
else
  $this->hPrinter=printer_open($this->PrinterName);

//
$this->ConnectionOpened=true;
$this->_DefinePageSize();    // inizialize all parameter relate the margins, and page size
if(!$this->Res_X)
   $this->Res_X=printer_get_option($this->hPrinter, PRINTER_RESOLUTION_X);
if(!$this->Res_Y)
   $this->Res_Y=printer_get_option($this->hPrinter, PRINTER_RESOLUTION_Y);
printer_start_doc($this->hPrinter, $this->JobTitle);
$this->_DefaultFont();
$this->_SetFont(AP_NORMAL_FONT);
$this->NewPage();
}


/**
 * Start the connection to the printer. This is the public interface
 * to _OpenPrinter.
 * @param string Name of the printer to use. If not set use the system default
 * @access public
 * @see _OpenPrinter()
 */
function OpenPrinter($PrinterName="")
{
if($PrinterName!="") $this->SetPrinter($PrinterName);
$this->_OpenPrinter();
}

/**
 * Define some dafault font
 * @access private
 */
function _DefaultFont()
{
// create predefined font. Don't change the row order
$this->CreateFont("Courier New",336,168,400,false,false,false,0);
$this->CreateFont("Courier New",336,168,800,false,false,false,0);
// echo $this->CreateFont("arial",163,84,200,false,false,false,0);
$this->CreateFont("Courier new",163,50,200,false,false,false,0);
}

/**
* Convert the internal point size to the printer point size according to its resolution
* As internal unit I use the twip. 1 inch = 1440 twip, 1 mm = 56,7 twip
* @param integer
* @return integer
* @access private
* @see ResConv_y()
*/
function ResConv_x($value)
{
return(floor($value*$this->Res_X/1440));
}

/**
 * @param integer
 * @return integer
 * @see ResConv_x()
 */
function ResConv_y($value)
{
return(floor($value*$this->Res_Y/1440));
}

/**
* Convert the printer point size into internal point size according to its resolution
* As internal unit I use the twip. 1 inch = 1440 twip, 1 mm = 56,7 twip
* @param integer
* @return integer
* @access private
* @see Conv2Twip_y()
* @see ResConv_x()
* @see ResConv_y()
*/
function Conv2Twip_x($value)
{
return(floor($value*1440/$this->Res_X));
}

/**
 * @param integer
 * @return integer
 * @see Conv2Twip_x()
 */
function Conv2Twip_y($value)
{
return(floor($value*1440/$this->Res_Y));
}

/**
* Activate the specified font
*
* @param int $fnt font handle returned by CreateFont
* @access private
* @see CreateFont()
*/
function _SetFont($fnt=-1)
{
if($fnt==-1)
   $fntHandler=$this->CurrentFont;
else 
   $fntHandler=$fnt;    
assert('array_key_exists($fntHandler,$this->FontTable)');
printer_select_font($this->hPrinter,$this->FontTable[$fntHandler]['fontHandler']);
$oldFont=$this->CurrentFont;
$this->CurrentFont=$fntHandler;
return($oldFont);
}

/**
 * Move the currentline up or down of nRow rows. It return TRUE on success,
 * FALSE otherwise
 * @parameter integer $nUnit Numebr of 'unit' may be less or greater then zero
 * @parameter string $unit measurement used to set the movement
 * @access public
 * @return boolean
 */
function MvRelativePos($nUnit,$unit='row')
{
$move=$this->_CalculatePos($nUnit,$unit);
if($move<0&&abs($move)>$this->row)
   return(FALSE);
if($move>0&&$this->row+$move>$this->PaperDimY)
   return(FALSE);
$this->row+=$move;
return(TRUE);
}

/**
 * Move the currentline to nRow. It return TRUE on success,
 * FALSE otherwise
 * @parameter integer $nUnit Numebr of 'unit' it must be greater then zero
 * @parameter string $unit measurement used to set the movement
 * @access public
 * @return boolean
 */
function MvAbsolutePos($nUnit,$unit='row')
{
$move=$this->_CalculatePos($nUnit,$unit);
if($move<1||$move>$this->PaperDimY)
   return(FALSE);
$this->row=$move;
return(TRUE);
}

/**
 * Move to the first row after the top margin It return TRUE on success,
 * FALSE otherwise
 * @access public
 * @return boolean
 */
function MvTop()
{
$this->row=$this->MarginTop;
return(TRUE);
}

/**
 * Move to the last row before the bottom margin It return TRUE on success,
 * FALSE otherwise.
 * Notice: the bottom is calculated using as row hight the current font
 * @parameter integer $nRow New current line number
 * @access public
 * @return boolean
 */
function MvBottom()
{
$this->PaperDimY-$this->MarginBottom-300-$this->FontH;
return(TRUE);
}

/**
 * Internal function used to calculate the movement.
 * @parameter integer $nUnit Numebr of 'unit' may be less or greater then zero
 * @parameter string $unit measurement used to set the movement
 * @access public
 * @return boolean
 */
function _CalculatePos($nUnit,$unit)
{
if(!in_array($unit,$this->ValidMeasure))
   trigger_error('Unit of measure '.$unit.' not supported',E_USER_ERROR);
switch($unit)
  {
  case 'row':
              $move=$this->FontH*$nUnit;
              break;
  case 'inch':
              $move=$nUnit*1440;
              break;
  case 'mm':
              $move=$nUnit*56.7;
              break;
  case 'twip':
              $move=$nUnit;
              break;
  }
return($move);
}

/**
 * Retrieve the page size
 *
 * @return array (width,length)
 * @access public
 */
function GetPageSize()
{
return(array($this->PaperDimX,$this->PaperDimY));
}

} // end class APrint

?>

Return current item: APrint