⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmprinter.cpp

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************/
/*                              SOURCE FILE                                  */
/*****************************************************************************/
/*
       $Archive:   $

      $Revision:   $
          $Date:   $
        $Author:   $

    Description:   This file contains the printer primitives. This is a very 
                   low-level implemtation and should never be called directly.
                   A member of this class is included in the CPage class and 
                   is used to print the page. Information in the PRTTYPE struct 
                   is modified here and is reflected in the structure.

                   This file is based on a project found on the web at:

                   http://www.codeproject.com/printing/printlib.asp
                   by
                   Richard Stringer

                   However, this file has been significantly reformatted and
                   modified for the needs of integrating this work into the 
                   TOOL / XMLForms project, so may not resemble the original
                   files very much at all. 
*/
static char OBJECT_ID[] = "$Revision:   $ : $Date:   $";
/*****************************************************************************/


#include "../../../stdafx.h"
#include "VMPrinter.h"


/*****************************************************************************/
/*

     FUNCTION NAME:  VMPrinter::VMPrinter

       DESCRIPTION:  ctor.

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  none
*/
VMPrinter::VMPrinter( void )
{
  RotationAngle = 0;
}
/* End of function "VMPrinter::VMPrinter"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMPrinter::~VMPrinter

       DESCRIPTION:  dtor

             INPUT:  void 
            OUTPUT:  none

           RETURNS:  none
*/
VMPrinter::~VMPrinter( void )
{
}
/* End of function "VMPrinter::~VMPrinter"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMPrinter::FillRect

       DESCRIPTION:  

             INPUT:  ps - 
            OUTPUT:  none

           RETURNS:  void  - 
*/
void VMPrinter::FillRect( PRTTYPE* ps )
{
  HBRUSH hOldBrush;
  HBRUSH hBrush;
  RECT   lpRect;

   hBrush = (HBRUSH)::GetStockObject( ( ps->uFillFlags & FILL_GRAY ) 
                                      ? GRAY_BRUSH :
                                      ( ps->uFillFlags & FILL_LTGRAY ) 
                                      ? LTGRAY_BRUSH :
                                      ( ps->uFillFlags & FILL_DKGRAY ) 
                                      ? DKGRAY_BRUSH :
                                      ( ps->uFillFlags & FILL_BLACK ) 
                                      ? BLACK_BRUSH : HOLLOW_BRUSH );

  hOldBrush = (HBRUSH)::SelectObject( ps->pDC->GetSafeHdc(), hBrush );

  lpRect.left   = ps->rc.left + ps->MarginOffset;
  lpRect.top    = ps->rc.top;
  lpRect.right  = ps->rc.right + ps->MarginOffset;
  lpRect.bottom = ps->rc.bottom;
    
  ::FillRect( ps->pDC->GetSafeHdc(), &lpRect, hBrush );
  ::DeleteObject( SelectObject( ps->pDC->GetSafeHdc(), hOldBrush ) );
}
/* End of function "VMPrinter::FillRect"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMPrinter::DrawRect

       DESCRIPTION:  

             INPUT:  ps - 
                     LineSize - 
            OUTPUT:  

           RETURNS:  void  
*/
void VMPrinter::DrawRect( PRTTYPE* ps, int LineSize )
{
  HPEN   hOldPen;
  HPEN   hPen;
  HBRUSH hOldBrush;
  HBRUSH hBrush;
  int    nLineWidth;
  POINT  lpPT[ 4 ];

  hBrush = (HBRUSH)::GetStockObject( ( ps->uFillFlags & FILL_GRAY )
                                     ? GRAY_BRUSH : ( ps->uFillFlags & FILL_LTGRAY ) 
                                     ? LTGRAY_BRUSH : ( ps->uFillFlags & FILL_DKGRAY ) 
                                     ? DKGRAY_BRUSH : ( ps->uFillFlags & FILL_BLACK )
                                     ? BLACK_BRUSH  : HOLLOW_BRUSH );

  hOldBrush = (HBRUSH)::SelectObject( ps->pDC->GetSafeHdc(), hBrush );
        
  nLineWidth = LineSize;
        
  hPen = ::CreatePen( ( ps->uPenFlags & PEN_DASH ) 
                      ? PS_DASH : ( ps->uPenFlags & PEN_DOT )  
                      ? PS_DOT : PS_SOLID,
                      nLineWidth, 
                      ps->pDC->GetTextColor() );

  hOldPen = (HPEN)::SelectObject( ps->pDC->GetSafeHdc(), hPen );

  lpPT[ 0 ].x = ps->rc.left + ps->MarginOffset;
  lpPT[ 0 ].y = ps->rc.top;

  lpPT[ 1 ].x = ps->rc.right + ps->MarginOffset;
  lpPT[ 1 ].y = ps->rc.top;

  lpPT[ 2 ].x = ps->rc.right + ps->MarginOffset;
  lpPT[ 2 ].y = ps->rc.bottom;

  lpPT[ 3 ].x = ps->rc.left + ps->MarginOffset;
  lpPT[ 3 ].y = ps->rc.bottom;

  Polygon( ps->pDC->GetSafeHdc(), lpPT, sizeof( lpPT ) / sizeof( POINT ) );

  ::DeleteObject( SelectObject( ps->pDC->GetSafeHdc(), hOldPen ) );
  ::DeleteObject( SelectObject( ps->pDC->GetSafeHdc(), hOldBrush ) );
}
/* End of function "VMPrinter::DrawRect"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMPrinter::DrawLine

       DESCRIPTION:  

             INPUT:  ps - 
                     LineSize - 
            OUTPUT:  

           RETURNS:  void  
*/
void VMPrinter::DrawLine( PRTTYPE* ps, int LineSize )                    
{
  HPEN  hOldPen;
  HPEN  hPen;
  POINT pt[ 2 ];
  int   nPenStyle;
  int   nLineWidth;

  nPenStyle = ( ps->uPenFlags & PEN_DASH )
                ? PS_DASH : ( ps->uPenFlags & PEN_DOT )
                ? PS_DOT : ( ps->uPenFlags & PEN_DASHDOT )
                ? PS_DASHDOT : ( ps->uPenFlags & PEN_DASHDOTDOT )
                ? PS_DASHDOTDOT : PS_SOLID;


  nLineWidth = LineSize;

  hPen = ::CreatePen( nPenStyle, nLineWidth, ps->pDC->GetTextColor() );
      
  pt[ 0 ].x = ps->rc.left + ps->MarginOffset;
  pt[ 0 ].y = ps->rc.top;

  pt[ 1 ].x = ps->rc.right + ps->MarginOffset;
  pt[ 1 ].y = ps->rc.bottom;
        
  hOldPen = (HPEN)::SelectObject( ps->pDC->GetSafeHdc(), hPen );                   
      
  ::Polyline( ps->pDC->GetSafeHdc(), pt, sizeof( pt ) / sizeof( POINT ) );
        
  ::DeleteObject( SelectObject(ps->pDC->GetSafeHdc(), hOldPen ) );
}
/* End of function "VMPrinter::DrawLine"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMPrinter::PrintText

       DESCRIPTION:  

             INPUT:  ps - 
                     LineSpacing - 
            OUTPUT:  

           RETURNS:  int  
*/
int VMPrinter::PrintText( PRTTYPE* ps, double LineSpacing )
{         
  LOGFONT      lf;
  HFONT        hOldFont;
  HFONT        hFont;
  COLORREF     OldColor;
  int          saveContext;
  int          OldBkMode;
  RECT         rc;
  RECT         LastPos;
  HBRUSH       hOldBrush;
  HBRUSH       hBrush;
  UINT         fuFormat = DT_NOPREFIX;
  int          uiLineSpacing;
        
  if ( strlen( ps->Text )==0 )
  {
    return(  2 * ps->PointSize );
  }       

  // initialize the rect structure
  //
  rc.left   = ps->rc.left + ps->MarginOffset;
  rc.top    = ps->rc.top;
  rc.right  = ps->rc.right + ps->MarginOffset;

  if ( rc.right > (signed)ps->n_maxWidth-ps->MarginOffset )
  {
    rc.right=ps->n_maxWidth - ps->MarginOffset;
  }
  rc.bottom = ps->rc.bottom;

  // convert logical coordinates to device coordinates
  //
  ps->pDC->LPtoDP( (LPPOINT)&rc, 2 );

  // save the dc and change map mode to MM_TEXT.  Much
  //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -