Re: DrawText with DT_WORDBREAK: DT_CALCRECT computes too small a height



"David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote in
news:a9Hhf.24108$dO2.4974@xxxxxxxxxxxxxxxxxxxxxxxxxx:

> It seems fine.

Yes, and it works most of the time here, too; it only seems to
fail for some long strings. I should add that I'm using this to
print a rather narrow column of text, about the width of ten 'M's
in my font, and some words in my text are wider than that so they
exceed the column width.

> Could you post actual call with data of the text
> that's not printing properly? Also, how is your DC initialized (what
> font is selected into it, etc.)?

I'm doing this in the OnPrint handler function, using the pDC
passed into OnPrint by the MFC framework. The proper font has
already been selected into the DC. Apart from some looping
through the list of the strings I'm printing, and from one call
to pDC->SetBkMode(TRANSPARENT) needed because I'm printing
every other line with a gray background, I'm doing nothing
much more than shown in my previous message. The actual code
is, as usual, too long to be posted in full, but here are
the relevant lines directly from my source. This makes use
of the CGridCtrl class found on CodeGuru and CodeProject (so
there's a "CGridCtrl &Grd" in my class, plus some more members
as you'll see). You'll be able to understand what's going on
even if you're not familiar with the grid control, however.

// Print the contents of the indicated grid cell at y-position
// yPos. Returns height of output. If DoOutput==false, only
// compute height, put print nothing.
int GridPrintStateTyp::PrintCell(CDC *pDC,int Line,int Col,int yPos,bool
DoOutput) const
{
CString const Str = Grd.GetItemText(Line,Col);
if (Str.IsEmpty())
return 0;

pDC->SelectObject(Line < Grd.GetFixedRowCount()
? HdrFnt
: LstFnt);

int const xPos = ColVec[Col].xPos + MSiz.cx;
int const xSize = ColVec[Col].xSize;

COLORREF const Color = Grd.GetItemFgColour(Line,Col);
pDC->SetTextColor(Color);

UINT const Fmt = Grd.GetItemFormat(Line,Col)
| DT_NOPREFIX | DT_WORDBREAK | DT_NOCLIP;

pDC->SetTextAlign(TA_LEFT | TA_TOP | TA_NOUPDATECP);
CRect Area(0,0,xSize,0);
int const Ret = pDC->DrawText(Str,Area,DT_CALCRECT | Fmt);

if (DoOutput)
{
CRect DArea(xPos,yPos,xPos+xSize,yPos+Area.Height());
int const h = pDC->DrawText(Str,DArea,Fmt);

// Sometimes, we get h > Ret.
}

return Ret;
}

I found a Usenet posting from 1999 which described the same symptoms, but
has no solution either. Have a loot at: http://tinyurl.com/8wdks

So I unstand that, at least, it's not me who's getting something wrong
here, am I? Did anyone else ever encounter that problem?

Thanks for your help
W. Rösler
.



Relevant Pages

  • Re: Print in text mode
    ... write strings to it with TextWriter object. ... few string first or it'll start printing garbage characters. ... For the escape sequence to be used to initalize printer, ... Note that if you need to change the font name, font size, line spacing, page ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: VB Printer Dialog Problem (VB6)
    ... What I would really like to know is exactly what it is you are printing? ... Forms and printers have very different resolutions (typically 96 pixels per inch in the case of a Form and 600 pixels per inch in the case of a printer). ... Font sizes can only be in "whole pixel values", so when you ask for an 11 point font on a specific device the operating system will examine the "pixels per inch" of that device and will give you the nearest font size it can, to the nearest whole pixel value. ... If you are using a RichTextBox then it is very easy to do that. ...
    (comp.lang.basic.visual.misc)
  • Re: Site critique requested (mostly accessibility issues, but anything else welcome)
    ... serif font. ... , and for printing. ... The reader then has the choice of not printing the ... Culpeper is largely maintained by volunteers ...
    (uk.net.web.authoring)
  • Puzzles with printed output
    ... I'm working with printing from a subclass of JTextPane. ... but I had similar problems with Swing's built-in Serif font. ... same as in printed output from Word), but it appears to be bold, although I ... Line spacing on the screen is the same as in Word (with Word's line spacing ...
    (comp.lang.java.gui)
  • Re: Data Report: Do it the hard way :-)
    ... I've never seen that code before so I don't yet know for certain exactly how it works but I've just downloaded it now for a quick look and it seems to be using the more or less standard simple print preview technique of passing a DC to a main printing routine and using more or less the same code to set up the font and graphic settings of the DC and then sending text and images to it. ... You can see the effects of this problem straight away if you download the code from the link you posted and run the PrintPreviewDemo_BMP example and click the Print Preview Instructions button and perform both a Preview and a Print to the printer. ...
    (microsoft.public.vb.general.discussion)