0

I have an RTF document with defined page settings:

(...}\paperw16840\paperh11907\margl794\margt709\margr794\margb983\viewkind4\\uc1\trowd\....)

In my app I use a TRichEdit to show the document.

The TRichEdit has a TPanel as its Parent, and is using Align=alClient and AlignWithMargins=True.

I set the Panel's Width to 16840 * PixelsPerInch/1440 (1123 pixels) and I see that is equal to the page's width, as shown in MSWord (scale=100%).

Setting the RichEdit's Margins to 794 * PixelsPerInch/1440 (53 pixels), the Width of the RichEdit is smaller than it must be, or the margins are bigger than they must be (compared with MSWord).

No borders, no other margins, except what I set in code:

function pixelsOf(prop : string) : integer;
var
  i,j,l : integer;
begin
  result := -1;
  l := length(prop);
  i := pos(prop,s);
  if i > 0 then begin
    j := i+l;
    while s[j] in ['0'..'9'] do inc(j);
    result := round(strToIntDef(copy(s,i+l,j-i-l),-1)*PixelsPerInch/1440);
  end;
end;

paperW := pixelsOf('\paperw'); // pixelsOf() calcs twips*pixelsPerInch/1440
PanelPreview.Width := paperW; 
Lm := pixelsOf('\margl'); 
RichEdit1.Margins.Left := Lm; 
Rm := pixelsOf('\margr'); 
RichEdit1.Margins.Right := Rm; 
Tm := pixelsOf('\margt');   
RichEdit1.Margins.Top := Tm;

The value of paperW gives the correct Panel width (compared with MSWord), but the values of Lm and Rm give bigger margins, so the RichEdit becomes narrower.

How can I calculate the correct margins so the RichEdit has the same layout as MSWord?

This maybe helps. I noticed that :

  1. TRichedit leaves a space about 10 pixels at the left side (the rendering is starting after this space). Is there a parameter that can be fix this other than margins.left ?
  2. TRicheditdoesn't render any table wider than its width (MSword do this adjusting the margins). So the TRichedit trancates everything outside its margins.

The result of the above is that the left margin seems wider than must be and truncates the right side of the table if it is winder.

see the image enter image description here

JimPapas
  • 715
  • 2
  • 12
  • 27
  • Can you please format your question? – RBA Dec 23 '16 at 07:49
  • 1
    You must take into account border width and margin values of both the panel and the TRichEditControl. At the end of the day you want the *clientWidth* property of your *TRichEditControl* to be the value you are trying to achieve, not the *width* of the *parent control*. – Dsm Dec 23 '16 at 07:55
  • Please add this information to your question. It is important. – Dsm Dec 23 '16 at 08:12
  • I think we need to see your pixelsOf function too. Clearly you are using VCL (because it is a TRichEdit) so width etc. of type integer. Depending on your calculation there will almost certainly be rounding errors. Realistically you need to round paperW up and the others down. Since you are using the same function for both, you are not really going to be able to do that. – Dsm Dec 23 '16 at 11:23
  • The difference is more than 20 pixels. So it isn't rounding error. The function pixelsOf just finds the arithetic part of the property (eg \paperw16840) and gives the round(Twips*pixelsPerInch/1440) – JimPapas Dec 23 '16 at 13:11

0 Answers0