BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DrawText DrawTextEx on multiple pages - some error

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Native API
View previous topic :: View next topic  
Author Message
danielgudang@gmail.com
Guest





PostPosted: Thu Jan 12, 2006 1:41 pm    Post subject: DrawText DrawTextEx on multiple pages - some error Reply with quote



I will begin copying an old post about the subject:

From: ebo.die... (AT) mmp-obec (DOT) nl (Ebo Dieben)
Date: 1999/01/04

Hi,
I'm printing ascii text on the printercanvas and use DT_CALCRECT to
determine the size of the rectangle that will be needed to fit it all.
Everything works fine unless I don't have enough space and need another
page. In that case I will have to breakup the string. But how do I
determine how to break the string up in parts that will fit on the
seperate pages?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -


Well, my problem is the same: I'm printing in a canvas
(metafile/printer, don't matter) long lines of text from a Tmemo. I
need to make some margins and wrap text, ok, it's simple using the rect
paramenter of function DrawText or DrawTextEx. Also wrapping words at
spaces these functions do the job well...

But, if the text is longer than the page, the field "uiLengthDrawn" of
DRAWTEXTPARAMS (DrawTextEx) informs that the text was draw up to some
length, but at canvas always are missing some characters/letters at
end...

And if I try to begin "a next page" at that position, of course the
printted text will be missing some part.


Here is some code to exemplify:


procedure Print;
const text: ansistring = '1st line - long paragraph long paragraph long
paragraph long paragraph long paragraph long paragraph long paragraph
long paragraph long paragraph '#13#10+
'2nd line - long paragraph long paragraph .....'#13#10+
.......
'nth line - long paragraph....';

PageWidth = 100; // total page width

var printArea: Trect; // area to print, let make some margins
yHeight: integer; // height of 1 single line of text
PageHeight: integer; // height of the printable area

hdc: Windows.HDC; (some HDC, let's say, the memo1.canvas.handle)
rectText: TRECT; // rect to get information about text dimensions
yPos: integer;
dtp: TDrawTextParams;

begin
yHeight:= .......Font.Height;
// will print 5 lines of text, may be only a few paragraphs...
PageHeight:= yHeight * 5;

// create the TRect: margins top-left-right = 5 pixels , height =
10 lines of text
printArea:=Rect( 5, 5, PageWidth-5, PageHeight+5 );


// initalize DRAWTEXTPARAMS
dtp.cbSize:=sizeof(dtp);
dtp.iTabLength:=10;
dtp.iLeftMargin:=0;
dtp.iRightMargin:=0;
dtp.uiLengthDrawn:=0;


// 1st page
yPos:=DrawTextEx(hdc,@text[1],-1,printArea,
DT_TOP or DT_LEFT or DT_WORDBREAK or DT_EXPANDTABS or
DT_NOPREFIX,@dtp);

// FIRST ERROR RESULT !!!
// yPos must be equal to the height of text draw, but not... it is
more...
// yPos > (printArea.bottom - printArea.top)

// SECOND ERROR RESULT !!!
// dtp.uiLengthDrawn doesn't point to the last printed char/text,
// then if next print begin at text[dtp.uiLengthDrawn]
// some characters will be missing at printed canvas


// 2nd page
// I will put bellow 1st only to show the error!

printArea.top := printArea.bottom+yPos;
printArea.bottom := printArea.top + PageHeight;

yPos:=DrawTextEx(hdc,@text[dtp.uiLengthDrawn],-1,printArea,
DT_TOP or DT_LEFT or DT_WORDBREAK or DT_EXPANDTABS or
DT_NOPREFIX,@dtp);

The 1st page
Quote:
--------------------------|
1 | 1st line long paragraph|

2 |paragraph long paragraph |
3 |long paragraph long |
4 |paragraph long paragraph |
5 |long paragraph long |

--> it's missing a whole word!

The 2nd page
0 |--------------------------|
1 |long paragraph long |
2 |paragraph long paragraph |
3 |long paragraph long |
4 |paragraph long paragraph |
5 |long paragraph long |



Well, if this is some bug or there is a better code to print long text
in more than one page, using Delphi and Windows API, please, help me!

thanks, yours,
Daniel,
from Brazil


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Native API All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.