Page 1 of 3

How to print filled rectangle?

Posted: Wed Aug 26, 2009 8:31 am
by mol
Hi guys (sorry, no women found :( )
I wanna print black rectangle. How Can I do that?

Re: How to print filled rectangle?

Posted: Wed Aug 26, 2009 8:43 am
by Rathinagiri
In draw command, 'filled' facility is available. I noticed now that it is not available in 'print'. I think some changes in source code is required. :(

Re: How to print filled rectangle?

Posted: Wed Aug 26, 2009 6:42 pm
by mol
I've tried to print line with width like a height of required rectangle - it works, but .... :-( line has rounded endings and my rectangle looked like egg :lol:

Re: How to print filled rectangle?

Posted: Wed Aug 26, 2009 6:44 pm
by mol
Maybe is somewhere place to define style of pen of line and I don't know where???

Re: How to print filled rectangle?

Posted: Wed Aug 26, 2009 7:59 pm
by Rathinagiri
Hi,

We have to alter HMG source and recreate the library file.

If you are really interested, replace "HB_FUNC ( _HMG_PRINTER_C_RECTANGLE )" in c_controlmisc.c (around line #998) with the following.

This will make all the rectangles to be filled.

Code: Select all

HB_FUNC ( _HMG_PRINTER_C_RECTANGLE )
{

	// 1: hDC
	// 2: y
	// 3: x
	// 4: toy
	// 5: tox
	// 6: width
	// 7: R Color
	// 8: G Color
	// 9: B Color
	// 10: lWindth
	// 11: lColor 

	int r ;
	int g ;
	int b ;

	int x = hb_parni(3) ;
	int y = hb_parni(2) ;

	int tox = hb_parni(5) ;
	int toy = hb_parni(4) ;

	int width ;

	HDC hdcPrint = (HDC) hb_parnl(1) ;
	HGDIOBJ hgdiobj;
//	HPEN hpen;
    HBRUSH hbrush;
    
	if ( hdcPrint != 0 )
	{

		// Width

		if ( hb_parl(10) )
		{
			width = hb_parni(6) ;
		}
		else
		{
			width = 1 * 10000 / 254 ;
		}

		// Color

		if ( hb_parl(11) )
		{
			r = hb_parni(7) ;
			g = hb_parni(8) ;
			b = hb_parni(9) ;
		}
		else
		{
			r = 0 ;
			g = 0 ;
			b = 0 ;
		}
        hbrush = CreateSolidBrush((COLORREF) RGB((int) r,(int) g,(int) b));
//		hpen = CreatePen( (int) PS_SOLID, ( width * GetDeviceCaps ( hdcPrint , LOGPIXELSX ) / 1000 ), (COLORREF) RGB( r , g , b ) );

		hgdiobj = SelectObject( (HDC) hdcPrint , hbrush );

		Rectangle( (HDC) hdcPrint , 
			( x * GetDeviceCaps ( hdcPrint , LOGPIXELSX ) / 1000 ) - GetDeviceCaps ( hdcPrint , PHYSICALOFFSETX ) ,
			( y * GetDeviceCaps ( hdcPrint , LOGPIXELSY ) / 1000 ) - GetDeviceCaps ( hdcPrint , PHYSICALOFFSETY ) ,	 
			( tox * GetDeviceCaps ( hdcPrint , LOGPIXELSX ) / 1000 ) - GetDeviceCaps ( hdcPrint , PHYSICALOFFSETX ) ,
			( toy * GetDeviceCaps ( hdcPrint , LOGPIXELSY ) / 1000 ) - GetDeviceCaps ( hdcPrint , PHYSICALOFFSETY ) 
			);

		SelectObject( (HDC) hdcPrint , (HGDIOBJ) hgdiobj );

		DeleteObject( hbrush );
//		DeleteObject( hpen );

	}

}

Re: How to print filled rectangle?

Posted: Thu Aug 27, 2009 5:24 am
by mol
Many thanks Rathi!

Re: How to print filled rectangle?

Posted: Thu Aug 27, 2009 9:39 am
by swapan
Great Rathi! Hope you'll note down this "would be correction" for future version.

Re: How to print filled rectangle?

Posted: Thu Aug 27, 2009 11:48 am
by Rathinagiri
swapan wrote:Great Rathi! Hope you'll note down this "would be correction" for future version.
No Swapan, It is not a correction. :) It is a feature. It will be useful only if you want filled rectangle. All the rectangles hereafter will be filled. We have to add an option "filled" in the command, like in draw to have both filled and non-filled rectangles.

Re: How to print filled rectangle?

Posted: Thu Aug 27, 2009 12:17 pm
by mol
I think, it must be special parameter "filled" - after this correction we must draw all rectangles from lines...

Re: How to print filled rectangle?

Posted: Thu Aug 27, 2009 12:31 pm
by Rathinagiri
For having this feature, we have to alter i_print.ch, h_controlmisc.prg and c_controlmisc.c. I will do it tonight, verify it and give it to you.