RichEdit eating last line (Solution)

edited 10:45PM in FreeReport
I'm using feereport 234 and after making some reports my clients discovered that many times the last line wasn't printed.

I found out to be a problem in the calculation of the Height of the richedit. Here is the modified code I'm using. This is in FR_rich file.
function TfrRichView.DoCalcHeight: Integer;
var
  Range: TFormatRange;
  LastChar, MaxLen, LogX, LogY, NewDY, LowDy, HighDy: Integer;
  StopRender, Fit: Boolean;
begin
  FillChar(Range, SizeOf(TFormatRange), 0);
  with Range do
  begin
    hdc := GetDC(0);
    hdcTarget := hdc;
    LogX := Screen.PixelsPerInch;
    LogY := LogX;

    LowDy := 0;
    HighDY := 1000000;

    MaxLen := SRichEdit.GetTextLen;
    while HighDy - LowDy > 8 do //no tiene ning??n sentido seguir si ya pas?© el m?­nimo
    begin
      NewDY := LowDy + (HighDy - LowDy) div 2;
      rc := Rect(0, 0, Round(DX * 1440 / LogX), Round(NewDY * 1440.0 / LogY));
      rcPage := rc;
      LastChar := CharFrom;
      chrg.cpMax := -1;
      repeat
        chrg.cpMin := LastChar;
        LastChar := SRichEdit.Perform(EM_FORMATRANGE, 0, Integer(@Range));
        Fit := (LastChar >= MaxLen) or (LastChar = -1) or (LastChar = 0);
        StopRender := ((LastChar < MaxLen) and (LastChar <> -1)) or Fit;
      until StopRender;

      if Fit then
        HighDy := NewDY else
        LowDy := NewDY;
    end;
    ReleaseDC(0, hdc);
  end;
  SRichEdit.Perform(EM_FORMATRANGE, 0, 0);
  if HighDy < MinHeight then begin
    (* verificar que no sea un problema de c??lculo cuando queda una ??ltima l?­nea *)
    SRichEdit.Lines.Add('.');
    HighDy := DoCalcHeight div 2;
    SRichEdit.Lines.Delete(SRichEdit.Lines.Count-1);
  end;
  Result := HighDy;
end;

The first comment: No sense to keep going if we are under the min height
Second comment: Check that it is not a calculation problem when there is just one last line

DAvid.

Comments

  • edited 10:45PM
    Sorry, I don't get the problem! can you explain it more?
  • edited 10:45PM
    peleus wrote: »
    Got nothing on top of my head on this? Got a work aroundso far David?

    The code in the original post IS the solution to the problem. I posted it in case someone else faced the issue.
    In any case, the Freereport-utf project has the fix, and some other minor fixes.

    DAvid.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.