Page 1 of 1

[PrintPreview] GetRichTextRect with an empty RichEdit

PostPosted: September 3rd, 2013, 12:12 pm
by AndrewDiel
I am using GetRichTextRect before PaintRichText to print the contents of a TCustomRichEdit control. I pass it a TDBRichEdit, and it works fine, except when the TDBRichEdit contains no text.

GetRichTextRect, as I understand it, will accept your desired TRect printing area, and then return the bottom position that would be reached when printing the given RTF. If the RTF results in no printing (either because the control is empty or, I have discovered, contains "empty RTF lines" - see below) the returned TRect printing area is not changed. I would expect it to return .Bottom equal to .Top, implying a zero-height TRect.

Might I be missing something?

Example of a blank RTF that I have encountered :

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang1033\f0\fs16
\par }

Part of my code :

Code: Select all
    rParagraph.Left := iPrnAreaLeft + ppOutput^.ConvertX(tpParagraph.iLeftMM100,mmHiMetric,ppOutput^.Units);
    rParagraph.Top := iCurrentYPos;
    rParagraph.Right := iPrnAreaRight - ppOutput^.ConvertX(tpParagraph.iRightMM100,mmHiMetric,ppOutput^.Units);
    rParagraph.Bottom := iPrnAreaBottom;
    iNewCurrentYPos := ppOutput^.GetRichTextRect(rParagraph,creHolder,@iRenderOffset);
    bEndOnThisPage := (iRenderOffset = -1);
    // Do the actual drawing of the paragraph on the current page
    iRenderOffset := iRenderOffsetTemp;
    ppOutput^.PaintRichText(rParagraph,creHolder,1,@iRenderOffset);

Re: [PrintPreview] GetRichTextRect with an empty RichEdit

PostPosted: September 7th, 2013, 4:36 pm
by Kambiz
Hi,

I investigated the issue and find out that it is the RichEdit control that ignores the empty content.
It seems you have to write a workaround for the case that the RichEdit is empty.