#1 2014-11-19 12:34:00

Kurt
Member
Registered: 2014-11-19
Posts: 3

New method for rendering TJVRichEdit in SqLite3Page TGDIPages

Hello 
I´ve to work with TJVRichedit instead of TRichedit because I need RTF-Files with images. Unfortunately the Class/Procedure  TGdiPages.appendRichedit doesn´t work in combination with TJVRichedit. There is a endless loop in the repeat.. until Loop. I´ve taken a look at jvcl and in unit JvPrvwRender (Version jvcl348) there is almost the same code(jvprvwRender.pas / TJvPreviewRenderJvRichEdit.DoAddPage)  with some little differences. Among others they are sending EM_GETTEXTLENGTHEX and there is another breakoption in then repeat-loop.
I´m not firm with GDI so I tried and it works. Perhaps any body else has the pleasure to work with jvrtf, this solution works for me.

Hope it'll be useful!
Kurt

(* new Method for handling TJVRichEdit *)
procedure TGDIPages.AppendJVRichEdit(RichEditHandle: HWnd);
var
  Range: TFormatRange;
  LogX, LogY, LastChar, MaxLen, OldMap: integer;
 
 (* Kurt  inserted for EM_GETTEXTLENGTHEX *)
  TextLenEx: TGetTextLengthEx;
  lastLastChar :integer ;
begin
  lastLastChar  :=0;
  with Range do begin
    LogX := GetDeviceCaps(fCanvas.Handle, LOGPIXELSX);
    LogY := GetDeviceCaps(fCanvas.Handle, LOGPIXELSY);
    rcPage.Left := (fPageMarginsPx.Left*1440) div LogX;
    rcPage.Right := ((fPhysicalSizePx.x-fPageMarginsPx.Right)*1440) div LogX;
    rcPage.Top := ((fPageMarginsPx.Top+fHeaderHeight)*1440) div LogY;
    rcPage.Bottom := ((fPhysicalSizePx.y-fPageMarginsPx.Bottom-fFooterHeight)*1440) div LogY;
    rc := rcPage;
    rc.Top := (fCurrentYPos*1440) div LogY;
    LastChar := 0;
    //MaxLen := SendMessage(RichEditHandle,WM_GETTEXTLENGTH,0,0);
    (*
       Kurt
       use of message EM_GETTEXTLENGTHEX instead of EM_GETTEXTLENGTH
       Now it works with TJvRichEdit
       see also  Jvcl unit JvPrvwRender.pas Class TJvPreviewRenderJvRichEdit procedure DoAddPage
       They' ve had the same problem in 2004 Version??? 
       [url]http://www.codenewsfast.com/cnf/thread/1927716803/permalink.thr-ng976q13492[/url]
    *)
    MaxLen := sendmessage(RicheditHandle ,EM_GETTEXTLENGTHEX, WParam(@TextLenEx), 0);
    chrg.cpMax := -1;
    OldMap := SetMapMode(hdc, MM_TEXT);
    try
      SendMessage(RichEditHandle, EM_FORMATRANGE, 0, 0);
      repeat
        chrg.cpMin := LastChar;
        hdc := fCanvas.Handle;
        hdcTarget := hdc;
       (* Kurt save of the last value *)
        lastLastChar := lastChar;
        LastChar := SendMessage(RichEditHandle, EM_FORMATRANGE, 1, Integer(@Range));

        if cardinal(LastChar)<cardinal(MaxLen) then begin
          NewPageInternal;
          DoHeader;
        end else
          fCurrentYPos := (rc.Bottom*LogY) div 1440;
        rc := rcPage;
      until (LastChar>=MaxLen) or (LastChar=-1)  or (LastChar <= lastLastChar); // Kurt - I´m not really happy , but it works

    finally
      SendMessage(RichEditHandle, EM_FORMATRANGE, 0, 0);
      SetMapMode(hdc, OldMap);
    end;
  end;
end;

Last edited by Kurt (2014-11-19 12:51:04)

Offline

#2 2014-11-19 14:35:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: New method for rendering TJVRichEdit in SqLite3Page TGDIPages

Do you think we could replace the original function in mORMotReport.pas with the new one involving EM_GETTEXTLENGTHEX ?

Offline

#3 2014-11-19 14:43:24

Kurt
Member
Registered: 2014-11-19
Posts: 3

Re: New method for rendering TJVRichEdit in SqLite3Page TGDIPages

Hello
I've not tried yet, but in jvcl they have coded both - one for TRichedit and one for TJVRichedit -
I think they have had some reasons for it , but I will try and inform you the next days.
Best regards
Kurt

Offline

#4 2014-11-20 14:30:58

Kurt
Member
Registered: 2014-11-19
Posts: 3

Re: New method for rendering TJVRichEdit in SqLite3Page TGDIPages

Hello,
I´ve analyzed again and found your unit mORMotReport.pas.
The routine appendRichedit in this unit is working for both -TRichedit and TJVRichedit (and you are sending EM_GETTEXTLENGTHEX).

Kind regards
Kurt

Offline

#5 2014-11-20 15:52:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: New method for rendering TJVRichEdit in SqLite3Page TGDIPages

Good news!

I was talking about this AppendRichEdit() method.
Happy it works as expected.
smile
Code has already be proven by users, I suspect.
wink

Offline

Board footer

Powered by FluxBB