FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TPrinter recent methods PrintImage() and SayText()
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
TPrinter recent methods PrintImage() and SayText()
Posted: Mon May 02, 2016 04:00 AM
It appears to me that the recently introduced methods PrintImage and SayText of TPrinter class have gone mostly unnoticed.

oPrn:SayText( nRow, nCol, cText, [nWidth], [nHeight], [oFont], [cAlign], [nClrText], [nClrBack] ) --> nLastRow printed
Useful for priting multi-line text. The return value can be used to continue printing next lines.

oPrn:PrintImage( nRow, nCol, uImage, nWidth, nHeight, lStretch, nAlpha, lTransp, lGray ) --> nLastRow printed
uImage can be any image source.

For those who like, I suggest trying this sample program:
Code (fw): Select all Collapse
#include "fivewin.ch"

//----------------------------------------------------------------------------//
function Main()

   local aText[ 4 ], oPrn, oFont
   local nMargin, nGutter, nWidth, nColWidth
   local nRow, nCol

   TEXT INTO aText[ 1 ]
   Powerful typhoon Koppu ploughed into the northeasten Philppines before dawn on Sunday destroying homes and displacing 10,000 people and whipping up coastal surges four metres high.

   ENDTEXT

   TEXT INTO aText[ 2 ]
   ఉత్తరప్రదేశ్‌లోని నోయిడాలో ఉన్న అమిత్ యూనివర్సిటీలో ఓ తెలుగు విద్యార్ధి దారుణ హత్యకు గురయ్యాడు. స్నేహితులే అతడిని కాల్చి చంపినట్లు తెలుస్తోంది. మృతుడు నల్గొండ పట్టణంలోని శ్రీనగర్ కాలనీకి చెందిన సందేశ్ భాస్కర్ (23)గా గుర్తించారు. సందేశ్ భాస్కర్ నోయిడాలోని అమిత్ యూనివర్సిటీలో బీఎస్సీ మెరైన్ సైన్స్

   ENDTEXT

   TEXT INTO aText[ 3 ]
   I'm hoping that every good film is a commercial film. Every good film should be a commercial film. And my definition of commercial is that if the film goes out and people engage in it and it earns money, then it is a commercial film," said Anurag Kashyap.

   ENDTEXT

   TEXT INTO aText[ 4 ]
   लेखकों द्वारा साहित्य अकादमी सम्मान लौटाने के क्रम में एक नाटकीय मोड़ तब आ गया जब उर्दू के मशहूर शायर मुनव्वर राणा ने टीवी पर सीधे प्रसारण के दौरान अपना साहित्य अकादमी सम्मान लौटा दिया और साथ में एक लाख रूपये का चेक भी दिया। राणा ने घोषणा की कि वह भविष्य में किसी भी तरह का सरकारी सम्मान ग्रहण नहीं करेंगे। समकालीन उर्दू कविता के एक बड़े नाम राणा आज टेलीविजन पर एक कार्यक्रम में भाग ले रहे थे। इसमें कई लेखक और राजनेता भी शामिल हुए। इसी दौरान राणा ने कहा कि उन्होंने अपना सम्मान लौटाने का निर्णय लिया है और वह वर्तमान में देश के हालात से क्षुब्ध हैं। राणा ने कहा

   ENDTEXT

   PRINT oPrn PREVIEW
   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-12 OF oPrn

   nMargin     := Int( 0.1 * oPrn:nHorzRes() )
   nWidth      := 8 * nMargin
   nColWidth   := Int( ( nWidth - nMargin ) / 2 )


   PAGE
   nRow        := 100
   nRow        := oPrn:SayText( nRow, nMargin, aText[ 1 ], nColWidth, nil, oFont )
   nRow        += 20
   nRow        := oPrn:PrintImage( nRow, nMargin, "c:\fwh\bitmaps\olga1.jpg", nColWidth, 2000 )
   nRow        += 40
   nRow        := oPrn:SayText( nRow, nMargin, aText[ 2 ], nColWidth, nil, oFont )
   nRow        += 20
   nRow        := oPrn:PrintImage( nRow, nMargin, "koala.jpg", nColWidth, 1500 )


   nRow        := 100
   nCol        := nMargin + nColWidth + nMargin
   nRow        := oPrn:SayText( nRow, nCol, aText[ 3 ], nColWidth, nil, oFont )
   nRow        += 20
   nRow        := oPrn:PrintImage( nRow, nCol, "eiphil.jpg", nColWidth, nil )
   nRow        += 40
   nRow        := oPrn:SayText( nRow, nCol, aText[ 1 ], nColWidth, nil, oFont )
   nRow        += 20
   nRow        := oPrn:PrintImage( nRow, nCol, "\fwh\bitmaps\alphabmp\design.bmp", nColWidth, 600 )
   nRow        += 40
   nRow        := oPrn:SayText( nRow, nCol, aText[ 4 ], nColWidth, nil, oFont )

   ENDPAGE
   ENDPRINT

return nil

I used some jpg's which are not available in the fwh\samples folder. You may substitute with your own jpgs or other image files.



I hope you will notice much better quality of printing.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 07:00 AM
Nages.
Is posible add Something similar to this ?
Regards.

Code (fw): Select all Collapse
METHOD CmSayText( nRow, nCol, cText, nWidth, nHeight, oFont, cAlign, nClrText, nClrBack ) CLASS TPrinter
  local aTmp := ::CmRect2Pix( { nRow, nCol, nWidth, nHeight } )
  local nRow := ::SayText(  aTmp[ 1 ], aTmp[ 2 ], cText, aTmp[ 3 ], aTmp[ 4 ], oFont, cAlign, nClrText, nClrBack )
Return  ( nRow * 25.4 / ::nLogPixelX() ) / 10

METHOD CmPrintImage( uImage, aRect, lTransp, nResizeMode, nAlphaLevel, lGray ) CLASS TPrinter
   local nRow := ::PrintImage( uImage, ::CmRect2Pix( aRect ), lTransp, nResizeMode, nAlphaLevel, lGray )
Return ( nRow * 25.4 / ::nLogPixelX() ) / 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 07:29 AM
Mr Manuel

1) Actually I am planning to provide convenient command syntax.
Something like :

@ r, c SAY TO oPrn IMAGE/TEXT ...........SIZE <w>,<h> [INCHES/PIXEL/MM/CM] [ENDING AT <nEndrow>]

2) I am also waiting for feedback from users about the compatibility of the new image function with different printers. For obvious reasons I could test with only one printer. May be I need to add check for device capabilities
Regards



G. N. Rao.

Hyderabad, India
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 08:47 AM

Ok.
Mr.Nages.
my feedback....

with oPrn:PrintImage ...
If we use a background image for din a4 ( to lay out an invoice ) .
the image is 1683x1211px 150ppp. == 20,50cm x28.5cm x150ppp ( photoshop data )
The intention is to adjust the image to the paper a4 + - 21x29 cm.

I used these coordinates to highlight the result :

 aD := oPrn:Cmtr2Pix( 30,30 )
 oPrn:PrintImage(  0, 0, cNombreBMP,  aD[1], aD[2], .t. )

No resizes the image never far from a 18x25 more ( printer and screen ) . :(
this is equivalent to 171ppp. image pixel density.

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 09:19 AM
Mr Manuel

No resizes the image never far from a 18x25 more ( printer and screen ) . :-)
this is equivalent to 171ppp. image pixel density.


I did not understand clearly. Can you please explain in greater detail?
Do you mean lStretch did not work?
Did you want to print the image from edge to edge of the paper?

Any suggestion or advice from you?

Return ( nRow * 25.4 / ::nLogPixelX() ) / 10

Should we not adjust the oPrn:yOffSet ?
Regards



G. N. Rao.

Hyderabad, India
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 10:06 AM
Mr. Nages .I will try to create a compact example for this.

nageswaragunupudi wrote:
Return ( nRow * 25.4 / ::nLogPixelX() ) / 10

Should we not adjust the oPrn:yOffSet ?


He has been taken of the code :

METHOD Pix2Cmtr( nRow, nCol ) INLINE ;
( nRow := ( nRow * 25.4 / ::nLogPixelX() ) / 10,;
nCol := ( nCol * 25.4 / ::nLogPixelY() ) / 10,;
{ nRow, nCol } )

Here not oPrn:yOffSet ...
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 10:58 AM

Mr. Nages use testprn2.prg and change :

oPrn:sayBitmap( 1, 1, "..\bitmaps\fivewin.bmp" )
to
oPrn:PrintImage( 1, 1, "..\bitmaps\fivewin.bmp", 2600, 2600 )

or
oPrn:PrintImage( 1, 1, "someimage", 26000, 26000, .t. )

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 11:17 AM

The image does not cover the entire paper.
Is that your point?
That is because I am limiting the width and height.
Let me see.

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 11:43 AM
If I remove ( or comment out ) these two lines
Code (fw): Select all Collapse
//   nWidth      := Min( nWidth, ::nHorzRes() * 0.9 - nCol )
//   nHeight        := Min( nHeight, ::nVertRes() * 0.9 - nRow )

we can print edge to edge.

I sent modified printer.prg to your email.
Please test and advise.
Regards



G. N. Rao.

Hyderabad, India
Posts: 566
Joined: Thu Aug 30, 2007 03:40 PM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 12:26 PM

Hi,

These improvements were introduced in what FWH version?

Regards

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 02:13 PM

FWH 15.09 (Revd Build 4) published in Oct 2015.
There is no change in the code from 15.09(4) till 16.03.
Please see whatsnew.txt for details.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 02:18 PM

Mr. Nages ,now is ok for me :D .

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Wed May 04, 2016 02:33 PM

Thanks

Regards



G. N. Rao.

Hyderabad, India
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Tue Apr 11, 2017 01:59 PM

Mr. Nages, it seems that PrintImage() on WIN XP only paint black boxes!? Some of my user stay on XP.

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: TPrinter recent methods PrintImage() and SayText()
Posted: Mon Apr 17, 2017 01:48 PM

Mr. Nages, is any comment of this? For now i make a call iswinXP() and use SayImage(). But PrintImage() are much better in rendering pictures!

Regards,
Günther
---------------------------------
office@byte-one.com