From 238975d96166e9ceabe7255ed2ca46ec798b2f0b Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Sat, 16 Jan 2010 11:26:08 +0000 Subject: [PATCH] 2010-01-16 12:25 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbwin/hbwin.ch * harbour/contrib/hbwin/win_tprn.prg * harbour/contrib/hbwin/win_prn1.c + added support for custom paper size - based on code borrowed from xHarbour by Peter Rees and Budyanto Dj. Unlike in xHarbour to use custom page size it's necessary to set :FormType to FORM_CUSTOM --- harbour/ChangeLog | 9 + harbour/contrib/hbwin/hbwin.ch | 311 +++++++++++++++-------------- harbour/contrib/hbwin/win_prn1.c | 12 +- harbour/contrib/hbwin/win_tprn.prg | 42 +++- 4 files changed, 212 insertions(+), 162 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 67a263b7f2..1feb2d1da7 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,15 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-01-16 12:25 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/hbwin/hbwin.ch + * harbour/contrib/hbwin/win_tprn.prg + * harbour/contrib/hbwin/win_prn1.c + + added support for custom paper size - based on code borrowed from + xHarbour by Peter Rees and Budyanto Dj. + Unlike in xHarbour to use custom page size it's necessary to set + :FormType to FORM_CUSTOM + 2010-01-16 12:20 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbct/Makefile + contrib/hbct/diskhb.prg diff --git a/harbour/contrib/hbwin/hbwin.ch b/harbour/contrib/hbwin/hbwin.ch index 1b3a20fca9..44c5223d64 100644 --- a/harbour/contrib/hbwin/hbwin.ch +++ b/harbour/contrib/hbwin/hbwin.ch @@ -56,204 +56,207 @@ /* Positions for WIN_MAPISENDMAIL() array */ -#define HB_WIN_MAPI_TO 1 -#define HB_WIN_MAPI_CC 2 -#define HB_WIN_MAPI_BCC 3 +#define HB_WIN_MAPI_TO 1 +#define HB_WIN_MAPI_CC 2 +#define HB_WIN_MAPI_BCC 3 /* Positions for WIN_PRINTERLIST() array */ -#define HB_WINPRN_NAME 1 -#define HB_WINPRN_PORT 2 -#define HB_WINPRN_TYPE 3 -#define HB_WINPRN_DRIVER 4 -#define HB_WINPRN_SHARE 5 -#define HB_WINPRN_SERVER 6 -#define HB_WINPRN_LEN_ 6 +#define HB_WINPRN_NAME 1 +#define HB_WINPRN_PORT 2 +#define HB_WINPRN_TYPE 3 +#define HB_WINPRN_DRIVER 4 +#define HB_WINPRN_SHARE 5 +#define HB_WINPRN_SERVER 6 +#define HB_WINPRN_LEN_ 6 /* Registry related values */ -#define HKEY_CLASSES_ROOT 0x80000000 -#define HKEY_CURRENT_USER 0x80000001 -#define HKEY_LOCAL_MACHINE 0x80000002 -#define HKEY_USERS 0x80000003 -#define HKEY_PERFORMANCE_DATA 0x80000004 -#define HKEY_CURRENT_CONFIG 0x80000005 -#define HKEY_DYN_DATA 0x80000006 +#define HKEY_CLASSES_ROOT 0x80000000 +#define HKEY_CURRENT_USER 0x80000001 +#define HKEY_LOCAL_MACHINE 0x80000002 +#define HKEY_USERS 0x80000003 +#define HKEY_PERFORMANCE_DATA 0x80000004 +#define HKEY_CURRENT_CONFIG 0x80000005 +#define HKEY_DYN_DATA 0x80000006 /* win_Port() related values */ /* The following are from winbase.h */ -#define CBR_110 110 -#define CBR_300 300 -#define CBR_600 600 -#define CBR_1200 1200 -#define CBR_2400 2400 -#define CBR_4800 4800 -#define CBR_9600 9600 -#define CBR_14400 14400 -#define CBR_19200 19200 -#define CBR_38400 38400 -#define CBR_56000 56000 -#define CBR_57600 57600 -#define CBR_115200 115200 -#define CBR_128000 128000 -#define CBR_256000 256000 +#define CBR_110 110 +#define CBR_300 300 +#define CBR_600 600 +#define CBR_1200 1200 +#define CBR_2400 2400 +#define CBR_4800 4800 +#define CBR_9600 9600 +#define CBR_14400 14400 +#define CBR_19200 19200 +#define CBR_38400 38400 +#define CBR_56000 56000 +#define CBR_57600 57600 +#define CBR_115200 115200 +#define CBR_128000 128000 +#define CBR_256000 256000 -#define NOPARITY 0 -#define ODDPARITY 1 -#define EVENPARITY 2 -#define MARKPARITY 3 -#define SPACEPARITY 4 +#define NOPARITY 0 +#define ODDPARITY 1 +#define EVENPARITY 2 +#define MARKPARITY 3 +#define SPACEPARITY 4 -#define ONESTOPBIT 0 -#define ONE5STOPBITS 1 -#define TWOSTOPBITS 2 +#define ONESTOPBIT 0 +#define ONE5STOPBITS 1 +#define TWOSTOPBITS 2 /* DTR Control Flow Values. */ -#define DTR_CONTROL_DISABLE 0x00 -#define DTR_CONTROL_ENABLE 0x01 -#define DTR_CONTROL_HANDSHAKE 0x02 +#define DTR_CONTROL_DISABLE 0x00 +#define DTR_CONTROL_ENABLE 0x01 +#define DTR_CONTROL_HANDSHAKE 0x02 /* RTS Control Flow Values */ -#define RTS_CONTROL_DISABLE 0x00 -#define RTS_CONTROL_ENABLE 0x01 -#define RTS_CONTROL_HANDSHAKE 0x02 -#define RTS_CONTROL_TOGGLE 0x03 +#define RTS_CONTROL_DISABLE 0x00 +#define RTS_CONTROL_ENABLE 0x01 +#define RTS_CONTROL_HANDSHAKE 0x02 +#define RTS_CONTROL_TOGGLE 0x03 -#define WIN_COM_DBGBASIC 0x01 -#define WIN_COM_DBGFLOW 0x02 -#define WIN_COM_DBGXTRAFLOW 0x04 -#define WIN_COM_DBGOTHER 0x08 -#define WIN_COM_DBGTIMEOUTS 0x10 -#define WIN_COM_DBGQUEUE 0x20 -#define WIN_COM_DBGALL 0x3F +#define WIN_COM_DBGBASIC 0x01 +#define WIN_COM_DBGFLOW 0x02 +#define WIN_COM_DBGXTRAFLOW 0x04 +#define WIN_COM_DBGOTHER 0x08 +#define WIN_COM_DBGTIMEOUTS 0x10 +#define WIN_COM_DBGQUEUE 0x20 +#define WIN_COM_DBGALL 0x3F /* win_Prn() related values */ -#define FORM_A4 9 +/* these are DMPAPER_* values from wingdi.h */ +#define FORM_LETTER 1 +#define FORM_A4 9 +#define FORM_CUSTOM 256 -#define PS_SOLID 0 +#define PS_SOLID 0 -#define RGB( nR, nG, nB ) ( nR + ( nG * 256 ) + ( nB * 256 * 256 ) ) +#define RGB( nR, nG, nB ) ( nR + ( nG * 256 ) + ( nB * 256 * 256 ) ) -#define RGB_BLACK RGB( 0x00, 0x00, 0x00 ) -#define RGB_BLUE RGB( 0x00, 0x00, 0x85 ) -#define RGB_GREEN RGB( 0x00, 0x85, 0x00 ) -#define RGB_CYAN RGB( 0x00, 0x85, 0x85 ) -#define RGB_RED RGB( 0x85, 0x00, 0x00 ) -#define RGB_MAGENTA RGB( 0x85, 0x00, 0x85 ) -#define RGB_BROWN RGB( 0x85, 0x85, 0x00 ) -#define RGB_WHITE RGB( 0xC6, 0xC6, 0xC6 ) +#define RGB_BLACK RGB( 0x00, 0x00, 0x00 ) +#define RGB_BLUE RGB( 0x00, 0x00, 0x85 ) +#define RGB_GREEN RGB( 0x00, 0x85, 0x00 ) +#define RGB_CYAN RGB( 0x00, 0x85, 0x85 ) +#define RGB_RED RGB( 0x85, 0x00, 0x00 ) +#define RGB_MAGENTA RGB( 0x85, 0x00, 0x85 ) +#define RGB_BROWN RGB( 0x85, 0x85, 0x00 ) +#define RGB_WHITE RGB( 0xC6, 0xC6, 0xC6 ) /* Cut from wingdi.h */ -#define MM_TEXT 1 -#define MM_LOMETRIC 2 -#define MM_HIMETRIC 3 -#define MM_LOENGLISH 4 -#define MM_HIENGLISH 5 +#define MM_TEXT 1 +#define MM_LOMETRIC 2 +#define MM_HIMETRIC 3 +#define MM_LOENGLISH 4 +#define MM_HIENGLISH 5 -#define FW_DONTCARE 0 -#define FW_THIN 100 -#define FW_EXTRALIGHT 200 -#define FW_ULTRALIGHT FW_EXTRALIGHT -#define FW_LIGHT 300 -#define FW_NORMAL 400 -#define FW_REGULAR FW_NORMAL -#define FW_MEDIUM 500 -#define FW_SEMIBOLD 600 -#define FW_DEMIBOLD FW_SEMIBOLD -#define FW_BOLD 700 -#define FW_EXTRABOLD 800 -#define FW_ULTRABOLD FW_EXTRABOLD -#define FW_HEAVY 900 -#define FW_BLACK FW_HEAVY +#define FW_DONTCARE 0 +#define FW_THIN 100 +#define FW_EXTRALIGHT 200 +#define FW_ULTRALIGHT FW_EXTRALIGHT +#define FW_LIGHT 300 +#define FW_NORMAL 400 +#define FW_REGULAR FW_NORMAL +#define FW_MEDIUM 500 +#define FW_SEMIBOLD 600 +#define FW_DEMIBOLD FW_SEMIBOLD +#define FW_BOLD 700 +#define FW_EXTRABOLD 800 +#define FW_ULTRABOLD FW_EXTRABOLD +#define FW_HEAVY 900 +#define FW_BLACK FW_HEAVY -#define ANSI_CHARSET 0 -#define DEFAULT_CHARSET 1 -#define SYMBOL_CHARSET 2 -#define MAC_CHARSET 77 -#define SHIFTJIS_CHARSET 128 -#define HANGEUL_CHARSET 129 -#define HANGUL_CHARSET 129 -#define JOHAB_CHARSET 130 -#define GB2312_CHARSET 134 -#define CHINESEBIG5_CHARSET 136 -#define GREEK_CHARSET 161 -#define TURKISH_CHARSET 162 -#define VIETNAMESE_CHARSET 163 -#define HEBREW_CHARSET 177 -#define ARABIC_CHARSET 178 -#define BALTIC_CHARSET 186 -#define RUSSIAN_CHARSET 204 -#define THAI_CHARSET 222 -#define EASTEUROPE_CHARSET 238 -#define OEM_CHARSET 255 +#define ANSI_CHARSET 0 +#define DEFAULT_CHARSET 1 +#define SYMBOL_CHARSET 2 +#define MAC_CHARSET 77 +#define SHIFTJIS_CHARSET 128 +#define HANGEUL_CHARSET 129 +#define HANGUL_CHARSET 129 +#define JOHAB_CHARSET 130 +#define GB2312_CHARSET 134 +#define CHINESEBIG5_CHARSET 136 +#define GREEK_CHARSET 161 +#define TURKISH_CHARSET 162 +#define VIETNAMESE_CHARSET 163 +#define HEBREW_CHARSET 177 +#define ARABIC_CHARSET 178 +#define BALTIC_CHARSET 186 +#define RUSSIAN_CHARSET 204 +#define THAI_CHARSET 222 +#define EASTEUROPE_CHARSET 238 +#define OEM_CHARSET 255 /* Device Parameters for win_GetDeviceCaps() */ -#define HORZSIZE 4 // Horizontal size in millimeters -#define VERTSIZE 6 // Vertical size in millimeters -#define HORZRES 8 // Horizontal width in pixels -#define VERTRES 10 // Vertical height in pixels -#define NUMBRUSHES 16 // Number of brushes the device has -#define NUMPENS 18 // Number of pens the device has -#define NUMFONTS 22 // Number of fonts the device has -#define NUMCOLORS 24 // Number of colors the device supports -#define RASTERCAPS 38 // Bitblt capabilities +#define HORZSIZE 4 // Horizontal size in millimeters +#define VERTSIZE 6 // Vertical size in millimeters +#define HORZRES 8 // Horizontal width in pixels +#define VERTRES 10 // Vertical height in pixels +#define NUMBRUSHES 16 // Number of brushes the device has +#define NUMPENS 18 // Number of pens the device has +#define NUMFONTS 22 // Number of fonts the device has +#define NUMCOLORS 24 // Number of colors the device supports +#define RASTERCAPS 38 // Bitblt capabilities -#define LOGPIXELSX 88 // Logical pixels/inch in X -#define LOGPIXELSY 90 // Logical pixels/inch in Y +#define LOGPIXELSX 88 // Logical pixels/inch in X +#define LOGPIXELSY 90 // Logical pixels/inch in Y -#define PHYSICALWIDTH 110 // Physical Width in device units -#define PHYSICALHEIGHT 111 // Physical Height in device units -#define PHYSICALOFFSETX 112 // Physical Printable Area x margin -#define PHYSICALOFFSETY 113 // Physical Printable Area y margin -#define SCALINGFACTORX 114 // Scaling factor x -#define SCALINGFACTORY 115 // Scaling factor y +#define PHYSICALWIDTH 110 // Physical Width in device units +#define PHYSICALHEIGHT 111 // Physical Height in device units +#define PHYSICALOFFSETX 112 // Physical Printable Area x margin +#define PHYSICALOFFSETY 113 // Physical Printable Area y margin +#define SCALINGFACTORX 114 // Scaling factor x +#define SCALINGFACTORY 115 // Scaling factor y /* bin selections */ -#define DMBIN_FIRST DMBIN_UPPER -#define DMBIN_UPPER 1 -#define DMBIN_ONLYONE 1 -#define DMBIN_LOWER 2 -#define DMBIN_MIDDLE 3 -#define DMBIN_MANUAL 4 -#define DMBIN_ENVELOPE 5 -#define DMBIN_ENVMANUAL 6 -#define DMBIN_AUTO 7 -#define DMBIN_TRACTOR 8 -#define DMBIN_SMALLFMT 9 -#define DMBIN_LARGEFMT 10 -#define DMBIN_LARGECAPACITY 11 -#define DMBIN_CASSETTE 14 -#define DMBIN_FORMSOURCE 15 -#define DMBIN_LAST DMBIN_FORMSOURCE +#define DMBIN_FIRST DMBIN_UPPER +#define DMBIN_UPPER 1 +#define DMBIN_ONLYONE 1 +#define DMBIN_LOWER 2 +#define DMBIN_MIDDLE 3 +#define DMBIN_MANUAL 4 +#define DMBIN_ENVELOPE 5 +#define DMBIN_ENVMANUAL 6 +#define DMBIN_AUTO 7 +#define DMBIN_TRACTOR 8 +#define DMBIN_SMALLFMT 9 +#define DMBIN_LARGEFMT 10 +#define DMBIN_LARGECAPACITY 11 +#define DMBIN_CASSETTE 14 +#define DMBIN_FORMSOURCE 15 +#define DMBIN_LAST DMBIN_FORMSOURCE /* print qualities */ -#define DMRES_DRAFT ( -1 ) -#define DMRES_LOW ( -2 ) -#define DMRES_MEDIUM ( -3 ) -#define DMRES_HIGH ( -4 ) +#define DMRES_DRAFT ( -1 ) +#define DMRES_LOW ( -2 ) +#define DMRES_MEDIUM ( -3 ) +#define DMRES_HIGH ( -4 ) /* duplex enable */ -#define DMDUP_SIMPLEX 1 -#define DMDUP_VERTICAL 2 -#define DMDUP_HORIZONTAL 3 +#define DMDUP_SIMPLEX 1 +#define DMDUP_VERTICAL 2 +#define DMDUP_HORIZONTAL 3 /* Text Alignment Options */ -#define TA_NOUPDATECP 0 -#define TA_UPDATECP 1 +#define TA_NOUPDATECP 0 +#define TA_UPDATECP 1 -#define TA_LEFT 0 -#define TA_RIGHT 2 -#define TA_CENTER 6 +#define TA_LEFT 0 +#define TA_RIGHT 2 +#define TA_CENTER 6 -#define TA_TOP 0 -#define TA_BOTTOM 8 -#define TA_BASELINE 24 +#define TA_TOP 0 +#define TA_BOTTOM 8 +#define TA_BASELINE 24 -#define MM_TO_INCH 25.4 +#define MM_TO_INCH 25.4 #endif /* HBWIN_CH_ */ diff --git a/harbour/contrib/hbwin/win_prn1.c b/harbour/contrib/hbwin/win_prn1.c index 8ee54ee674..00bd5c72a3 100644 --- a/harbour/contrib/hbwin/win_prn1.c +++ b/harbour/contrib/hbwin/win_prn1.c @@ -472,7 +472,7 @@ HB_FUNC( WIN_SETDOCUMENTPROPERTIES ) if( lSize > 0 ) { PDEVMODE pDevMode = ( PDEVMODE ) hb_xgrab( lSize ); - int iProp; + int iProp, iProp2; DocumentProperties( 0, hPrinter, ( LPTSTR ) lpDeviceName, pDevMode, pDevMode, DM_OUT_BUFFER ); @@ -494,6 +494,14 @@ HB_FUNC( WIN_SETDOCUMENTPROPERTIES ) if( ( iProp = hb_parni( 8 ) ) != 0 ) /* [2007-02-22] don't change if 0 */ pDevMode->dmPrintQuality = ( short ) iProp; + if( pDevMode->dmPaperSize == DMPAPER_USER && + ( iProp = hb_parni( 9 ) ) > 0 && + ( iProp2 = hb_parni( 10 ) ) > 0 ) + { + pDevMode->dmPaperLength = ( short ) iProp; + pDevMode->dmPaperWidth = ( short ) iProp2; + } + bResult = ( ResetDC( hDC, pDevMode ) != NULL ); hb_xfree( pDevMode ); @@ -531,6 +539,8 @@ HB_FUNC( WIN_GETDOCUMENTPROPERTIES ) hb_storni( pDevMode->dmDefaultSource, 5 ); hb_storni( pDevMode->dmDuplex, 6 ); hb_storni( pDevMode->dmPrintQuality, 7 ); + hb_storni( pDevMode->dmPaperLength, 8 ); + hb_storni( pDevMode->dmPaperWidth, 9 ); bResult = HB_TRUE; hb_xfree( pDevMode ); diff --git a/harbour/contrib/hbwin/win_tprn.prg b/harbour/contrib/hbwin/win_tprn.prg index fed712d00c..e95618511b 100644 --- a/harbour/contrib/hbwin/win_tprn.prg +++ b/harbour/contrib/hbwin/win_tprn.prg @@ -159,6 +159,9 @@ CREATE CLASS WIN_PRN VAR Landscape INIT .F. VAR Copies INIT 1 + VAR PaperLength INIT 0 // Value is * 1/10 of mm 1000 = 10cm + VAR PaperWidth INIT 0 // " " " " " " + VAR SetFontOk INIT .F. VAR hFont INIT 0 VAR FontName INIT "" // Current Point size for font @@ -191,6 +194,8 @@ CREATE CLASS WIN_PRN VAR fOldLandScape INIT .F. HIDDEN VAR fOldBinNumber INIT 0 HIDDEN VAR fOldFormType INIT 0 HIDDEN + VAR fOldPaperLength INIT 0 HIDDEN + VAR fOldPaperWidth INIT 0 HIDDEN VAR PosX INIT 0 VAR PosY INIT 0 @@ -224,7 +229,10 @@ METHOD Create() CLASS WIN_PRN // Set Orientation // Set Duplex mode // Set PrintQuality - win_SetDocumentProperties( ::hPrinterDC, ::PrinterName, ::FormType, ::Landscape, ::Copies, ::BinNumber, ::fDuplexType, ::fPrintQuality ) + win_SetDocumentProperties( ::hPrinterDC, ::PrinterName, ; + ::FormType, ::Landscape, ; + ::Copies, ::BinNumber, ::fDuplexType, ; + ::fPrintQuality, ::PaperLength, ::PaperWidth ) // Set mapping mode to pixels, topleft down win_SetMapMode( ::hPrinterDC, MM_TEXT ) // win_SetTextCharacterExtra( ::hPrinterDC, 0 ) // do not add extra char spacing even if bold @@ -249,11 +257,13 @@ METHOD Create() CLASS WIN_PRN ::SetDefaultFont() ::PageNumber := 0 ::HavePrinted := ::Printing := ::PageInit := .F. - ::fOldFormType := ::FormType // Last formtype used - ::fOldLandScape := ::LandScape - ::fOldBinNumber := ::BinNumber - ::fNewDuplexType := ::fDuplexType + ::fOldFormType := ::FormType // Last formtype used + ::fOldLandScape := ::LandScape + ::fOldBinNumber := ::BinNumber + ::fNewDuplexType := ::fDuplexType ::fNewPrintQuality := ::fPrintQuality + ::fOldPaperLength := ::PaperLength + ::fOldPaperWidth := ::PaperWidth lResult := .T. ENDIF RETURN lResult @@ -308,6 +318,8 @@ METHOD StartPage() CLASS WIN_PRN LOCAL nLFormType LOCAL nLDuplexType LOCAL nLPrintQuality + LOCAL nLPaperLength + LOCAL nLPaperWidth LOCAL lChangeDP := .F. IF ::LandScape != ::fOldLandScape // Direct-modify property @@ -330,8 +342,21 @@ METHOD StartPage() CLASS WIN_PRN nLPrintQuality := ::fPrintQuality := ::fNewPrintQuality lChangeDP := .T. ENDIF + IF ::fOldPaperLength != ::PaperLength .OR. ; // Get/Set property + ::fOldPaperWidth != ::PaperWidth // Get/Set property + nLFormType := ::FormType + nLPaperLength := ::fOldPaperLength := ::PaperLength + nLPaperWidth := ::fOldPaperWidth := ::PaperWidth + lChangeDP := .T. + ENDIF + IF ::fOldPaperWidth != ::PaperWidth // Get/Set property + lChangeDP := .T. + ENDIF IF lChangeDP - win_SetDocumentProperties( ::hPrinterDC, ::PrinterName, nLFormType, lLLandscape, , nLBinNumber, nLDuplexType, nLPrintQuality ) + win_SetDocumentProperties( ::hPrinterDC, ::PrinterName, ; + nLFormType, lLLandscape, , ; + nLBinNumber, nLDuplexType, nLPrintQuality, ; + nLPaperLength, nLPaperWidth ) ENDIF win_StartPage( ::hPrinterDC ) ::PageNumber++ @@ -389,7 +414,10 @@ METHOD NewPage( lDelay ) CLASS WIN_PRN RETURN .T. METHOD GetDocumentProperties() CLASS WIN_PRN - RETURN win_GetDocumentProperties( ::PrinterName, @::FormType, @::Landscape, @::Copies, @::BinNumber, @::fDuplexType, @::fPrintQuality ) + RETURN win_GetDocumentProperties( ::PrinterName, @::FormType, @::Landscape, ; + @::Copies, @::BinNumber, @::fDuplexType, ; + @::fPrintQuality, ; + @::PaperLength, @::PaperWidth ) // If font width is specified it is in "characters per inch" to emulate DotMatrix // An array {nMul,nDiv} is used to get precise size such a the Dot Matric equivalent